extract get_current_user, fix tests

This commit is contained in:
dandds 2018-08-06 09:18:53 -04:00
parent ea5c9732ba
commit ad1e1e771b
4 changed files with 26 additions and 15 deletions

View File

@ -8,11 +8,19 @@ def login_required(f):
@wraps(f)
def decorated_function(*args, **kwargs):
if session.get("user_id"):
g.user = Users.get(session.get("user_id"))
user = get_current_user()
if user:
g.user = user
return f(*args, **kwargs)
else:
return redirect(url_for("atst.root"))
return decorated_function
def get_current_user():
user_id = session.get("user_id")
if user_id:
return Users.get(user_id)
else:
return False

View File

@ -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):

View File

@ -1,13 +1,8 @@
from flask import session
from .mocks import DOD_SDN
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):

View File

@ -1,5 +1,6 @@
def test_routes(client):
for path in (
import pytest
@pytest.mark.parametrize("path", (
"/",
"/home",
"/workspaces",
@ -9,8 +10,9 @@ def test_routes(client):
"/users",
"/reports",
"/calculator",
):
response = client.get(path)
if response.status_code == 404:
__import__('ipdb').set_trace()
assert response.status_code == 200
))
def test_routes(path, client, monkeypatch):
monkeypatch.setattr("atst.domain.auth.get_current_user", lambda *args: True)
response = client.get(path)
assert response.status_code == 200