extract get_current_user, fix tests
This commit is contained in:
parent
ea5c9732ba
commit
ad1e1e771b
@ -8,11 +8,19 @@ def login_required(f):
|
|||||||
|
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def decorated_function(*args, **kwargs):
|
def decorated_function(*args, **kwargs):
|
||||||
if session.get("user_id"):
|
user = get_current_user()
|
||||||
g.user = Users.get(session.get("user_id"))
|
if user:
|
||||||
|
g.user = user
|
||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return redirect(url_for("atst.root"))
|
return redirect(url_for("atst.root"))
|
||||||
|
|
||||||
return decorated_function
|
return decorated_function
|
||||||
|
|
||||||
|
def get_current_user():
|
||||||
|
user_id = session.get("user_id")
|
||||||
|
if user_id:
|
||||||
|
return Users.get(user_id)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
@ -19,6 +19,12 @@ MOCK_REQUEST = RequestFactory.create(
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
DOD_SDN_INFO = {
|
||||||
|
'first_name': 'ART',
|
||||||
|
'last_name': 'GARFUNKEL',
|
||||||
|
'dod_id': '5892460358'
|
||||||
|
}
|
||||||
|
DOD_SDN = f"CN={DOD_SDN_INFO['last_name']}.{DOD_SDN_INFO['first_name']}.G.{DOD_SDN_INFO['dod_id']},OU=OTHER,OU=PKI,OU=DoD,O=U.S. Government,C=US"
|
||||||
|
|
||||||
|
|
||||||
class MockApiClient(ApiClient):
|
class MockApiClient(ApiClient):
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
from flask import session
|
from flask import session
|
||||||
|
from .mocks import DOD_SDN
|
||||||
|
|
||||||
|
|
||||||
MOCK_USER = {"id": "438567dd-25fa-4d83-a8cc-8aa8366cb24a"}
|
MOCK_USER = {"id": "438567dd-25fa-4d83-a8cc-8aa8366cb24a"}
|
||||||
DOD_SDN_INFO = {
|
|
||||||
'first_name': 'ART',
|
|
||||||
'last_name': 'GARFUNKEL',
|
|
||||||
'dod_id': '5892460358'
|
|
||||||
}
|
|
||||||
DOD_SDN = f"CN={DOD_SDN_INFO['last_name']}.{DOD_SDN_INFO['first_name']}.G.{DOD_SDN_INFO['dod_id']},OU=OTHER,OU=PKI,OU=DoD,O=U.S. Government,C=US"
|
|
||||||
|
|
||||||
|
|
||||||
def _fetch_user_info(c, t):
|
def _fetch_user_info(c, t):
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
def test_routes(client):
|
import pytest
|
||||||
for path in (
|
|
||||||
|
@pytest.mark.parametrize("path", (
|
||||||
"/",
|
"/",
|
||||||
"/home",
|
"/home",
|
||||||
"/workspaces",
|
"/workspaces",
|
||||||
@ -9,8 +10,9 @@ def test_routes(client):
|
|||||||
"/users",
|
"/users",
|
||||||
"/reports",
|
"/reports",
|
||||||
"/calculator",
|
"/calculator",
|
||||||
):
|
))
|
||||||
response = client.get(path)
|
def test_routes(path, client, monkeypatch):
|
||||||
if response.status_code == 404:
|
monkeypatch.setattr("atst.domain.auth.get_current_user", lambda *args: True)
|
||||||
__import__('ipdb').set_trace()
|
|
||||||
assert response.status_code == 200
|
response = client.get(path)
|
||||||
|
assert response.status_code == 200
|
||||||
|
Loading…
x
Reference in New Issue
Block a user