More test config updates

Note that this commit has some failing tests with it that also needed to be fixed; it is unclear why they are failing at the moment, though.

Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
This commit is contained in:
Carlo Costino
2023-09-25 17:55:42 -04:00
parent d2411e6cbe
commit 9a4afe44bb
4 changed files with 64 additions and 58 deletions

View File

@@ -16,22 +16,23 @@ from tests.conftest import (
@pytest.fixture()
def mock_no_users_for_service(mocker):
def _mock_no_users_for_service(mocker):
mocker.patch("app.models.user.Users.client_method", return_value=[])
@pytest.fixture(scope="function")
@pytest.fixture()
def mock_get_existing_user_by_email(mocker, api_user_active):
return mocker.patch(
"app.user_api_client.get_user_by_email", return_value=api_user_active
)
@pytest.fixture(scope="function")
@pytest.fixture()
def mock_check_invite_token(mocker, sample_invite):
return mocker.patch("app.invite_api_client.check_token", return_value=sample_invite)
@pytest.mark.usefixtures("_mock_no_users_for_service")
@freeze_time("2021-12-12 12:12:12")
def test_existing_user_accept_invite_calls_api_and_redirects_to_dashboard(
client_request,
@@ -39,7 +40,6 @@ def test_existing_user_accept_invite_calls_api_and_redirects_to_dashboard(
api_user_active,
mock_check_invite_token,
mock_get_existing_user_by_email,
mock_no_users_for_service,
mock_accept_invite,
mock_add_user_to_service,
mock_get_service,
@@ -76,6 +76,7 @@ def test_existing_user_accept_invite_calls_api_and_redirects_to_dashboard(
)
@pytest.mark.usefixtures("_mock_no_users_for_service")
def test_existing_user_with_no_permissions_or_folder_permissions_accept_invite(
client_request,
mocker,
@@ -84,7 +85,6 @@ def test_existing_user_with_no_permissions_or_folder_permissions_accept_invite(
sample_invite,
mock_check_invite_token,
mock_get_existing_user_by_email,
mock_no_users_for_service,
mock_add_user_to_service,
mock_get_service,
mock_events,
@@ -143,6 +143,7 @@ def test_if_existing_user_accepts_twice_they_redirect_to_sign_in(
assert mock_update_user_attribute.called is False
@pytest.mark.usefixtures("_mock_no_users_for_service")
def test_invite_goes_in_session(
client_request,
mocker,
@@ -151,7 +152,6 @@ def test_invite_goes_in_session(
api_user_active,
mock_check_invite_token,
mock_get_user_by_email,
mock_no_users_for_service,
mock_add_user_to_service,
mock_accept_invite,
):
@@ -172,8 +172,9 @@ def test_invite_goes_in_session(
assert session["invited_user_id"] == sample_invite["id"]
@pytest.mark.usefixtures("_mock_no_users_for_service")
@pytest.mark.parametrize(
"user, landing_page_title",
("user", "landing_page_title"),
[
(create_active_user_with_permissions(), "Dashboard"),
(create_active_caseworking_user(), "Templates"),
@@ -187,7 +188,6 @@ def test_accepting_invite_removes_invite_from_session(
service_one,
mock_check_invite_token,
mock_get_user_by_email,
mock_no_users_for_service,
mock_add_user_to_service,
mock_accept_invite,
mock_get_service_templates,
@@ -251,6 +251,7 @@ def test_existing_user_of_service_get_redirected_to_signin(
assert mock_accept_invite.call_count == 1
@pytest.mark.usefixtures("_mock_no_users_for_service")
def test_accept_invite_redirects_if_api_raises_an_error_that_they_are_already_part_of_the_service(
client_request,
mocker,
@@ -260,7 +261,6 @@ def test_accept_invite_redirects_if_api_raises_an_error_that_they_are_already_pa
mock_check_invite_token,
mock_accept_invite,
mock_get_service,
mock_no_users_for_service,
mock_get_user,
mock_update_user_attribute,
):
@@ -290,6 +290,7 @@ def test_accept_invite_redirects_if_api_raises_an_error_that_they_are_already_pa
)
@pytest.mark.usefixtures("_mock_no_users_for_service")
def test_existing_signed_out_user_accept_invite_redirects_to_sign_in(
client_request,
service_one,
@@ -297,7 +298,6 @@ def test_existing_signed_out_user_accept_invite_redirects_to_sign_in(
sample_invite,
mock_check_invite_token,
mock_get_existing_user_by_email,
mock_no_users_for_service,
mock_add_user_to_service,
mock_accept_invite,
mock_get_service,
@@ -339,13 +339,13 @@ def test_existing_signed_out_user_accept_invite_redirects_to_sign_in(
)
@pytest.mark.usefixtures("_mock_no_users_for_service")
def test_new_user_accept_invite_calls_api_and_redirects_to_registration(
client_request,
service_one,
mock_check_invite_token,
mock_dont_get_user_by_email,
mock_add_user_to_service,
mock_no_users_for_service,
mock_get_service,
mocker,
):
@@ -360,6 +360,7 @@ def test_new_user_accept_invite_calls_api_and_redirects_to_registration(
mock_dont_get_user_by_email.assert_called_with("invited_user@test.gsa.gov")
@pytest.mark.usefixtures("_mock_no_users_for_service")
def test_new_user_accept_invite_calls_api_and_views_registration_page(
client_request,
service_one,
@@ -368,7 +369,6 @@ def test_new_user_accept_invite_calls_api_and_views_registration_page(
mock_dont_get_user_by_email,
mock_get_invited_user_by_id,
mock_add_user_to_service,
mock_no_users_for_service,
mock_get_service,
mocker,
):
@@ -426,7 +426,7 @@ def test_cancelled_invited_user_accepts_invited_redirect_to_cancelled_invitation
@pytest.mark.parametrize(
"admin_endpoint, api_endpoint",
("admin_endpoint", "api_endpoint"),
[
("main.accept_invite", "app.invite_api_client.check_token"),
("main.accept_org_invite", "app.org_invite_api_client.check_token"),
@@ -470,6 +470,7 @@ def test_new_user_accept_invite_with_malformed_token(
)
@pytest.mark.usefixtures("_mock_no_users_for_service")
def test_new_user_accept_invite_completes_new_registration_redirects_to_verify(
client_request,
service_one,
@@ -482,7 +483,6 @@ def test_new_user_accept_invite_completes_new_registration_redirects_to_verify(
mock_send_verify_code,
mock_get_invited_user_by_id,
mock_accept_invite,
mock_no_users_for_service,
mock_add_user_to_service,
mock_get_service,
mocker,
@@ -583,6 +583,7 @@ def test_accept_invite_does_not_treat_email_addresses_as_case_sensitive(
)
@pytest.mark.usefixtures("_mock_no_users_for_service")
def test_new_invited_user_verifies_and_added_to_service(
client_request,
service_one,
@@ -604,7 +605,6 @@ def test_new_invited_user_verifies_and_added_to_service(
mock_get_template_statistics,
mock_has_no_jobs,
mock_has_permissions,
mock_no_users_for_service,
mock_get_service_statistics,
mock_get_annual_usage_for_service,
mock_get_free_sms_fragment_limit,
@@ -666,11 +666,11 @@ def test_new_invited_user_verifies_and_added_to_service(
@pytest.mark.parametrize(
"service_permissions, trial_mode, expected_endpoint, extra_args",
(
("service_permissions", "trial_mode", "expected_endpoint", "extra_args"),
[
([], True, "main.service_dashboard", {}),
([], False, "main.service_dashboard", {}),
),
],
)
def test_new_invited_user_is_redirected_to_correct_place(
mocker,
@@ -721,6 +721,7 @@ def test_new_invited_user_is_redirected_to_correct_place(
)
@pytest.mark.usefixtures("_mock_no_users_for_service")
@freeze_time("2021-12-12 12:12:12")
def test_existing_user_accepts_and_sets_email_auth(
client_request,
@@ -728,7 +729,6 @@ def test_existing_user_accepts_and_sets_email_auth(
service_one,
sample_invite,
mock_get_existing_user_by_email,
mock_no_users_for_service,
mock_accept_invite,
mock_check_invite_token,
mock_update_user_attribute,
@@ -759,6 +759,7 @@ def test_existing_user_accepts_and_sets_email_auth(
)
@pytest.mark.usefixtures("_mock_no_users_for_service")
@freeze_time("2021-12-12 12:12:12")
def test_platform_admin_user_accepts_and_preserves_auth(
client_request,
@@ -766,7 +767,6 @@ def test_platform_admin_user_accepts_and_preserves_auth(
service_one,
sample_invite,
mock_check_invite_token,
mock_no_users_for_service,
mock_accept_invite,
mock_add_user_to_service,
mocker,
@@ -801,6 +801,7 @@ def test_platform_admin_user_accepts_and_preserves_auth(
assert mock_add_user_to_service.called
@pytest.mark.usefixtures("_mock_no_users_for_service")
@freeze_time("2021-12-12 12:12:12")
def test_existing_user_doesnt_get_auth_changed_by_service_without_permission(
client_request,
@@ -808,7 +809,6 @@ def test_existing_user_doesnt_get_auth_changed_by_service_without_permission(
service_one,
sample_invite,
mock_get_user_by_email,
mock_no_users_for_service,
mock_check_invite_token,
mock_accept_invite,
mock_update_user_attribute,
@@ -836,13 +836,13 @@ def test_existing_user_doesnt_get_auth_changed_by_service_without_permission(
)
@pytest.mark.usefixtures("_mock_no_users_for_service")
@freeze_time("2021-12-12 12:12:12")
def test_existing_email_auth_user_without_phone_cannot_set_sms_auth(
client_request,
api_user_active,
service_one,
sample_invite,
mock_no_users_for_service,
mock_check_invite_token,
mock_accept_invite,
mock_update_user_attribute,
@@ -874,13 +874,13 @@ def test_existing_email_auth_user_without_phone_cannot_set_sms_auth(
)
@pytest.mark.usefixtures("_mock_no_users_for_service")
@freeze_time("2021-12-12 12:12:12")
def test_existing_email_auth_user_with_phone_can_set_sms_auth(
client_request,
api_user_active,
service_one,
sample_invite,
mock_no_users_for_service,
mock_get_existing_user_by_email,
mock_check_invite_token,
mock_accept_invite,

View File

@@ -20,7 +20,13 @@ from tests.conftest import (
@pytest.mark.parametrize(
"user,extra_args,expected_update_endpoint,expected_limit_days,page_title",
(
"user",
"extra_args",
"expected_update_endpoint",
"expected_limit_days",
"page_title",
),
[
(
create_active_user_view_permissions(),
@@ -46,7 +52,7 @@ from tests.conftest import (
],
)
@pytest.mark.parametrize(
"status_argument, expected_api_call",
("status_argument", "expected_api_call"),
[
(
"",
@@ -78,10 +84,10 @@ from tests.conftest import (
],
)
@pytest.mark.parametrize(
"page_argument, expected_page_argument", [(1, 1), (22, 22), (None, 1)]
("page_argument", "expected_page_argument"), [(1, 1), (22, 22), (None, 1)]
)
@pytest.mark.parametrize(
"to_argument, expected_to_argument",
("to_argument", "expected_to_argument"),
[
("", ""),
("+12029000123", "+12029000123"),
@@ -210,7 +216,7 @@ def test_can_show_notifications_if_data_retention_not_available(
@pytest.mark.parametrize(
"user, query_parameters, expected_download_link",
("user", "query_parameters", "expected_download_link"),
[
(
create_active_user_with_permissions(),
@@ -303,10 +309,10 @@ def test_shows_message_when_no_notifications(
@pytest.mark.parametrize(
(
"initial_query_arguments,"
"form_post_data,"
"expected_search_box_label,"
"expected_search_box_contents"
"initial_query_arguments",
"form_post_data",
"expected_search_box_label",
"expected_search_box_contents",
),
[
(
@@ -385,7 +391,7 @@ def test_search_recipient_form(
@pytest.mark.parametrize(
"message_type, expected_search_box_label",
("message_type", "expected_search_box_label"),
[
(None, "Search by recipient or reference"),
("sms", "Search by phone number or reference"),
@@ -412,7 +418,7 @@ def test_api_users_are_told_they_can_search_by_reference_when_service_has_api_ke
@pytest.mark.parametrize(
"message_type, expected_search_box_label",
("message_type", "expected_search_box_label"),
[
(None, "Search by recipient"),
("sms", "Search by phone number"),
@@ -509,7 +515,7 @@ def test_doesnt_show_pagination_with_search_term(
@pytest.mark.parametrize(
"job_created_at, expected_message",
("job_created_at", "expected_message"),
[
("2016-01-10 11:09:00.000000+00:00", "Data available for 7 days"),
("2016-01-04 11:09:00.000000+00:00", "Data available for 1 day"),
@@ -604,11 +610,11 @@ def test_html_contains_links_for_failed_notifications(
@pytest.mark.parametrize(
"notification_type, expected_row_contents",
(
("notification_type", "expected_row_contents"),
[
("sms", ("2021234567 hello & welcome hidden")),
("email", ("example@gsa.gov hidden, hello & welcome")),
),
],
)
def test_redacts_templates_that_should_be_redacted(
client_request,
@@ -645,7 +651,7 @@ def test_redacts_templates_that_should_be_redacted(
@freeze_time("2017-09-27 12:30:00.000000")
@pytest.mark.parametrize(
"message_type, status, expected_hint_status, single_line",
("message_type", "status", "expected_hint_status", "single_line"),
[
("email", "created", "Sending since 27 September at 12:30 UTC", True),
("email", "sending", "Sending since 27 September at 12:30 UTC", True),

View File

@@ -22,10 +22,10 @@ def test_non_gov_user_cannot_see_add_service_button(
@pytest.mark.parametrize(
"org_json",
(
[
None,
organization_json(organization_type=None),
),
],
)
def test_get_should_render_add_service_template(
client_request,
@@ -74,18 +74,18 @@ def test_show_different_page_if_user_org_type_is_local(
@pytest.mark.parametrize(
"email_address",
(
[
# Users email address doesnt matter when the organization is known
"test@example.gsa.gov",
"test@anotherexample.gsa.gov",
),
],
)
@pytest.mark.parametrize(
"inherited, posted, persisted, sms_limit",
(
("inherited", "posted", "persisted", "sms_limit"),
[
(None, "federal", "federal", 150_000),
# ('federal', None, 'federal', 150_000),
),
],
)
@freeze_time("2021-01-01")
def test_should_add_service_and_redirect_to_tour_when_no_services(
@@ -169,12 +169,12 @@ def test_add_service_has_to_choose_org_type(
@pytest.mark.parametrize(
"email_address",
(
[
"test@nhs.net",
"test@nhs.uk",
"test@example.NhS.uK",
"test@EXAMPLE.NHS.NET",
),
],
)
@pytest.mark.skip(reason="Update for TTS")
def test_get_should_only_show_nhs_org_types_radios_if_user_has_nhs_email(
@@ -205,7 +205,7 @@ def test_get_should_only_show_nhs_org_types_radios_if_user_has_nhs_email(
@pytest.mark.parametrize(
"organization_type, free_allowance",
("organization_type", "free_allowance"),
[
("federal", 150_000),
("state", 150_000),
@@ -240,7 +240,7 @@ def test_should_add_service_and_redirect_to_dashboard_when_existing_service(
@pytest.mark.parametrize(
"name, error_message",
("name", "error_message"),
[
("", "Cannot be empty"),
(".", "Must include at least two alphanumeric characters"),

View File

@@ -138,7 +138,7 @@ def test_should_show_api_keys_page(
@pytest.mark.parametrize(
"restricted, expected_options",
("restricted", "expected_options"),
[
(
True,
@@ -436,7 +436,7 @@ def test_should_validate_guestlist_items(
],
)
@pytest.mark.parametrize(
"url, bearer_token, expected_errors",
("url", "bearer_token", "expected_errors"),
[
("https://example.com", "", "Cannot be empty"),
("http://not_https.com", "1234567890", "Must be a valid https URL"),
@@ -472,7 +472,7 @@ def test_callback_forms_validation(
@pytest.mark.parametrize("bearer_token", ["", "some-bearer-token"])
@pytest.mark.parametrize(
"endpoint, expected_delete_url",
("endpoint", "expected_delete_url"),
[
(
"main.delivery_status_callback",
@@ -522,7 +522,7 @@ def test_callback_forms_can_be_cleared(
@pytest.mark.parametrize("bearer_token", ["", "some-bearer-token"])
@pytest.mark.parametrize(
"endpoint, expected_delete_url",
("endpoint", "expected_delete_url"),
[
(
"main.delivery_status_callback",
@@ -565,7 +565,7 @@ def test_callback_forms_can_be_cleared_when_callback_and_inbound_apis_are_empty(
@pytest.mark.parametrize(
"has_inbound_sms, expected_link",
("has_inbound_sms", "expected_link"),
[
(True, "main.api_callbacks"),
(False, "main.delivery_status_callback"),
@@ -611,7 +611,7 @@ def test_callbacks_page_redirects_to_delivery_status_if_service_has_no_inbound_s
@pytest.mark.parametrize(
"has_inbound_sms, expected_link",
("has_inbound_sms", "expected_link"),
[
(True, "main.api_callbacks"),
(False, "main.api_integration"),
@@ -791,7 +791,7 @@ def test_update_receive_text_message_callback_without_changes_does_not_update(
@pytest.mark.parametrize(
"service_callback_api, delivery_url, expected_1st_table_row",
("service_callback_api", "delivery_url", "expected_1st_table_row"),
[
(None, {}, "Delivery receipts Not set Change"),
(
@@ -802,7 +802,7 @@ def test_update_receive_text_message_callback_without_changes_does_not_update(
],
)
@pytest.mark.parametrize(
"inbound_api, inbound_url, expected_2nd_table_row",
("inbound_api", "inbound_url", "expected_2nd_table_row"),
[
(None, {}, "Received text messages Not set Change"),
(