From a6eb89ffb8aa7f726dbdc55039f556f366dd0bbb Mon Sep 17 00:00:00 2001 From: leigh-mil Date: Thu, 8 Aug 2019 11:27:04 -0400 Subject: [PATCH] Add tests for route functions --- templates/ccpo/confirm_user.html | 2 +- tests/routes/test_ccpo.py | 54 ++++++++++++++++++++++++++++++++ translations.yaml | 2 ++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tests/routes/test_ccpo.py diff --git a/templates/ccpo/confirm_user.html b/templates/ccpo/confirm_user.html index a20cc3f9..150d25fd 100644 --- a/templates/ccpo/confirm_user.html +++ b/templates/ccpo/confirm_user.html @@ -31,7 +31,7 @@ {% endcall %} {% else %} - {% call Alert('User not found') %} + {% call Alert('forms.ccpo_user.user_not_found' | translate) %} To add someone as a CCPO user, they must already have an ATAT account.
diff --git a/tests/routes/test_ccpo.py b/tests/routes/test_ccpo.py new file mode 100644 index 00000000..8129408f --- /dev/null +++ b/tests/routes/test_ccpo.py @@ -0,0 +1,54 @@ +from flask import url_for + +from atst.utils.localization import translate + +from tests.factories import UserFactory + + +def test_ccpo_users(user_session, client): + ccpo = UserFactory.create_ccpo() + user_session(ccpo) + response = client.get(url_for("ccpo.ccpo_users")) + assert ccpo.email in response.data.decode() + + +def test_submit_add_new_ccpo_user(user_session, client): + ccpo = UserFactory.create_ccpo() + new_user = UserFactory.create() + random_dod_id = "1234567890" + user_session(ccpo) + + # give new_user CCPO permissions + response = client.post( + url_for("ccpo.submit_add_new_ccpo_user"), data={"dod_id": new_user.dod_id} + ) + assert new_user.email in response.data.decode() + + # give person with out ATAT account CCPO permissions + response = client.post( + url_for("ccpo.submit_add_new_ccpo_user"), data={"dod_id": random_dod_id} + ) + assert translate("forms.ccpo_user.user_not_found") in response.data.decode() + + +def test_confirm_new_ccpo_user(user_session, client): + ccpo = UserFactory.create_ccpo() + new_user = UserFactory.create() + random_dod_id = "1234567890" + user_session(ccpo) + + # give new_user CCPO permissions + response = client.post( + url_for("ccpo.confirm_new_ccpo_user"), + data={"dod_id": new_user.dod_id}, + follow_redirects=True, + ) + assert new_user.dod_id in response.data.decode() + + # give person with out ATAT account CCPO permissions + response = client.post( + url_for("ccpo.confirm_new_ccpo_user"), + data={"dod_id": random_dod_id}, + follow_redirects=True, + ) + assert random_dod_id not in response.data.decode() diff --git a/translations.yaml b/translations.yaml index fd5563c1..0a4f9dcf 100644 --- a/translations.yaml +++ b/translations.yaml @@ -103,6 +103,8 @@ forms: name_label: Name assign_ppoc: dod_id: 'Select new primary point of contact:' + ccpo_user: + user_not_found: "User not found" environments: name_label: Environment Name edit_user: