From 73590840eedd9517ddd0c6b4303e91256c4d84c4 Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Wed, 6 Sep 2023 10:57:38 -0400 Subject: [PATCH 01/14] Update and cleanup our test configuration This changeset updates a few of the testing and linting dependencies and makes several adjustments to cleanup and improve our tests and test configuration. Signed-off-by: Carlo Costino --- poetry.lock | 29 +++++++++++++++++++++++++++-- pyproject.toml | 22 +++++++++++----------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/poetry.lock b/poetry.lock index 86af9a042..808d4432b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -848,6 +848,17 @@ flake8 = ">=6.0.0" [package.extras] dev = ["coverage", "hypothesis", "hypothesmith (>=0.2)", "pre-commit", "pytest", "tox"] +[[package]] +name = "flake8-plugin-utils" +version = "1.3.3" +description = "The package provides base classes and utils for flake8 plugin writing" +optional = false +python-versions = ">=3.6,<4.0" +files = [ + {file = "flake8-plugin-utils-1.3.3.tar.gz", hash = "sha256:39f6f338d038b301c6fd344b06f2e81e382b68fa03c0560dff0d9b1791a11a2c"}, + {file = "flake8_plugin_utils-1.3.3-py3-none-any.whl", hash = "sha256:e4848c57d9d50f19100c2d75fa794b72df068666a9041b4b0409be923356a3ed"}, +] + [[package]] name = "flake8-print" version = "5.0.0" @@ -863,6 +874,20 @@ files = [ flake8 = ">=3.0" pycodestyle = "*" +[[package]] +name = "flake8-pytest-style" +version = "1.7.2" +description = "A flake8 plugin checking common style issues or inconsistencies with pytest-based tests." +optional = false +python-versions = ">=3.7.2,<4.0.0" +files = [ + {file = "flake8_pytest_style-1.7.2-py3-none-any.whl", hash = "sha256:f5d2aa3219163a052dd92226589d45fab8ea027a3269922f0c4029f548ea5cd1"}, + {file = "flake8_pytest_style-1.7.2.tar.gz", hash = "sha256:b924197c99b951315949920b0e5547f34900b1844348432e67a44ab191582109"}, +] + +[package.dependencies] +flake8-plugin-utils = ">=1.3.2,<2.0.0" + [[package]] name = "flask" version = "2.3.3" @@ -1035,8 +1060,8 @@ requests = "*" [[package]] name = "govuk-frontend-jinja" -version = "0.5.8-alpha" -description = "" +version = "0.5.8a0" +description = "Tools to use the GOV.UK Design System with Jinja-powered Python apps" optional = false python-versions = "*" files = [] diff --git a/pyproject.toml b/pyproject.toml index a96062fa6..3949e59a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,20 +42,20 @@ coverage = "*" vulture = "==2.10" radon = "==6.0.1" - [tool.poetry.group.dev.dependencies] -isort = "==5.12.0" -pytest = "==7.4.2" -pytest-env = "==1.0.1" -pytest-mock = "==3.11.1" -pytest-playwright = "==0.4.3" -pytest-xdist = "==3.3.1" +isort = "~5.12.0" +pytest = "~7.4.2" +pytest-env = "~1.0.1" +pytest-mock = "~3.11.1" +pytest-playwright = "~0.4.3" +pytest-xdist = "~3.3.1" beautifulsoup4 = "==4.12.2" freezegun = "==1.2.2" -flake8 = "==6.1.0" -flake8-bugbear = "==23.9.16" -flake8-print = "==5.0.0" -moto = "~=4.2" +flake8 = "~6.1.0" +flake8-bugbear = "~23.9.16" +flake8-print = "~5.0.0" +flake8-pytest-style = "~1.7.2" +moto = "~4.2" requests-mock = "==1.11.0" jinja2-cli = {version = "==0.8.2", extras = ["yaml"]} pip-audit = "*" From 47695b97d395758fd7da434e89038b393358447a Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Wed, 6 Sep 2023 16:49:40 -0400 Subject: [PATCH 02/14] Address flake8-pytest-style issues with conftest.py Signed-off-by: Carlo Costino --- .../app/main/views/uploads/test_upload_hub.py | 4 +- tests/conftest.py | 448 +++++++++--------- 2 files changed, 226 insertions(+), 226 deletions(-) diff --git a/tests/app/main/views/uploads/test_upload_hub.py b/tests/app/main/views/uploads/test_upload_hub.py index 96223e660..0756c55fe 100644 --- a/tests/app/main/views/uploads/test_upload_hub.py +++ b/tests/app/main/views/uploads/test_upload_hub.py @@ -17,7 +17,7 @@ def test_get_upload_hub_with_no_uploads( mocker, client_request, service_one, - mock_get_no_uploads, + _mock_get_no_uploads, extra_permissions, expected_empty_message, ): @@ -67,7 +67,7 @@ def test_get_upload_hub_page( def test_uploads_page_shows_scheduled_jobs( mocker, client_request, - mock_get_no_uploads, + _mock_get_no_uploads, mock_get_jobs, user, ): diff --git a/tests/conftest.py b/tests/conftest.py index 4fc2f5490..5a9ed3d0f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -50,20 +50,20 @@ def notify_admin(): ctx.push() app.test_client_class = TestClient - yield app + return app -@pytest.fixture(scope="function") +@pytest.fixture() def service_one(api_user_active): return service_json(SERVICE_ONE_ID, "service one", [api_user_active["id"]]) -@pytest.fixture(scope="function") +@pytest.fixture() def service_two(api_user_active): return service_json(SERVICE_TWO_ID, "service two", [api_user_active["id"]]) -@pytest.fixture(scope="function") +@pytest.fixture() def multiple_reply_to_email_addresses(mocker): def _get(service_id): return [ @@ -99,7 +99,7 @@ def multiple_reply_to_email_addresses(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def no_reply_to_email_addresses(mocker): def _get(service_id): return [] @@ -109,7 +109,7 @@ def no_reply_to_email_addresses(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def single_reply_to_email_address(mocker): def _get(service_id): return [ @@ -128,7 +128,7 @@ def single_reply_to_email_address(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def get_default_reply_to_email_address(mocker): def _get(service_id, reply_to_email_id): return { @@ -145,7 +145,7 @@ def get_default_reply_to_email_address(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def get_non_default_reply_to_email_address(mocker): def _get(service_id, reply_to_email_id): return { @@ -162,7 +162,7 @@ def get_non_default_reply_to_email_address(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_add_reply_to_email_address(mocker): def _add_reply_to(service_id, email_address, is_default=False): return @@ -172,7 +172,7 @@ def mock_add_reply_to_email_address(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_update_reply_to_email_address(mocker): def _update_reply_to( service_id, reply_to_email_id, email_address=None, active=None, is_default=False @@ -185,7 +185,7 @@ def mock_update_reply_to_email_address(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def multiple_sms_senders(mocker): def _get(service_id): return [ @@ -221,7 +221,7 @@ def multiple_sms_senders(mocker): return mocker.patch("app.service_api_client.get_sms_senders", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def multiple_sms_senders_with_diff_default(mocker): def _get(service_id): return [ @@ -257,7 +257,7 @@ def multiple_sms_senders_with_diff_default(mocker): return mocker.patch("app.service_api_client.get_sms_senders", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def multiple_sms_senders_no_inbound(mocker): def _get(service_id): return [ @@ -284,7 +284,7 @@ def multiple_sms_senders_no_inbound(mocker): return mocker.patch("app.service_api_client.get_sms_senders", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def no_sms_senders(mocker): def _get(service_id): return [] @@ -292,7 +292,7 @@ def no_sms_senders(mocker): return mocker.patch("app.service_api_client.get_sms_senders", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def single_sms_sender(mocker): def _get(service_id): return [ @@ -310,7 +310,7 @@ def single_sms_sender(mocker): return mocker.patch("app.service_api_client.get_sms_senders", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def get_default_sms_sender(mocker): def _get(service_id, sms_sender_id): return { @@ -326,7 +326,7 @@ def get_default_sms_sender(mocker): return mocker.patch("app.service_api_client.get_sms_sender", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def get_non_default_sms_sender(mocker): def _get(service_id, sms_sender_id): return { @@ -342,7 +342,7 @@ def get_non_default_sms_sender(mocker): return mocker.patch("app.service_api_client.get_sms_sender", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_add_sms_sender(mocker): def _add_sms_sender( service_id, sms_sender, is_default=False, inbound_number_id=None @@ -354,7 +354,7 @@ def mock_add_sms_sender(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_update_sms_sender(mocker): def _update_sms_sender( service_id, sms_sender_id, sms_sender=None, active=None, is_default=False @@ -366,7 +366,7 @@ def mock_update_sms_sender(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def multiple_available_inbound_numbers(mocker): def _get(): return { @@ -406,7 +406,7 @@ def multiple_available_inbound_numbers(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def no_available_inbound_numbers(mocker): def _get(): return {"data": []} @@ -416,12 +416,12 @@ def no_available_inbound_numbers(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def fake_uuid(): return sample_uuid() -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_service(mocker, api_user_active): def _get(service_id): service = service_json( @@ -432,7 +432,7 @@ def mock_get_service(mocker, api_user_active): return mocker.patch("app.service_api_client.get_service", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_service_statistics(mocker, api_user_active): def _get(service_id, limit_days=None): return { @@ -445,7 +445,7 @@ def mock_get_service_statistics(mocker, api_user_active): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_detailed_services(mocker, fake_uuid): service_one = service_json( id_=SERVICE_ONE_ID, @@ -476,7 +476,7 @@ def mock_get_detailed_services(mocker, fake_uuid): return mocker.patch("app.service_api_client.get_services", return_value=services) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_live_service(mocker, api_user_active): def _get(service_id): service = service_json( @@ -487,7 +487,7 @@ def mock_get_live_service(mocker, api_user_active): return mocker.patch("app.service_api_client.get_service", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_create_service(mocker): def _create( service_name, @@ -510,7 +510,7 @@ def mock_create_service(mocker): return mocker.patch("app.service_api_client.create_service", side_effect=_create) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_update_service(mocker): def _update(service_id, **kwargs): service = service_json( @@ -538,7 +538,7 @@ def mock_update_service(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_update_service_raise_httperror_duplicate_name(mocker): def _update(service_id, **kwargs): json_mock = Mock( @@ -563,7 +563,7 @@ TEMPLATE_ONE_ID = "b22d7d94-2197-4a7d-a8e7-fd5f9770bf48" USER_ONE_ID = "7b395b52-c6c1-469c-9d61-54166461c1ab" -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_services(mocker, active_user_with_permissions): def _get_services(params_dict=None): service_one = service_json( @@ -589,7 +589,7 @@ def mock_get_services(mocker, active_user_with_permissions): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_services_with_no_services(mocker): def _get_services(params_dict=None): return {"data": []} @@ -599,7 +599,7 @@ def mock_get_services_with_no_services(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_services_with_one_service(mocker, api_user_active): def _get_services(params_dict=None): return { @@ -620,7 +620,7 @@ def mock_get_services_with_one_service(mocker, api_user_active): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_service_template(mocker): def _get(service_id, template_id, version=None): template = template_json( @@ -637,7 +637,7 @@ def mock_get_service_template(mocker): return mocker.patch("app.service_api_client.get_service_template", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_service_template_with_priority(mocker): def _get(service_id, template_id, version=None): template = template_json( @@ -655,7 +655,7 @@ def mock_get_service_template_with_priority(mocker): return mocker.patch("app.service_api_client.get_service_template", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_deleted_template(mocker): def _get(service_id, template_id, version=None): template = template_json( @@ -673,7 +673,7 @@ def mock_get_deleted_template(mocker): return mocker.patch("app.service_api_client.get_service_template", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_template_version(mocker, api_user_active): def _get(service_id, template_id, version): template_version = template_version_json( @@ -684,7 +684,7 @@ def mock_get_template_version(mocker, api_user_active): return mocker.patch("app.service_api_client.get_service_template", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_template_versions(mocker, api_user_active): def _get(service_id, template_id): template_version = template_version_json( @@ -697,7 +697,7 @@ def mock_get_template_versions(mocker, api_user_active): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_service_template_with_placeholders(mocker): def _get(service_id, template_id, version=None): template = template_json( @@ -712,7 +712,7 @@ def mock_get_service_template_with_placeholders(mocker): return mocker.patch("app.service_api_client.get_service_template", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_empty_service_template_with_optional_placeholder(mocker): def _get(service_id, template_id, version=None): template = template_json( @@ -726,7 +726,7 @@ def mock_get_empty_service_template_with_optional_placeholder(mocker): return mocker.patch("app.service_api_client.get_service_template", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_service_template_with_multiple_placeholders(mocker): def _get(service_id, template_id, version=None): template = template_json( @@ -741,7 +741,7 @@ def mock_get_service_template_with_multiple_placeholders(mocker): return mocker.patch("app.service_api_client.get_service_template", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_service_template_with_placeholders_same_as_recipient(mocker): def _get(service_id, template_id, version=None): template = template_json( @@ -756,7 +756,7 @@ def mock_get_service_template_with_placeholders_same_as_recipient(mocker): return mocker.patch("app.service_api_client.get_service_template", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_service_email_template(mocker): def _get(service_id, template_id, version=None): template = template_json( @@ -773,7 +773,7 @@ def mock_get_service_email_template(mocker): return mocker.patch("app.service_api_client.get_service_template", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_service_email_template_without_placeholders(mocker): def _get(service_id, template_id, version=None): template = template_json( @@ -790,7 +790,7 @@ def mock_get_service_email_template_without_placeholders(mocker): return mocker.patch("app.service_api_client.get_service_template", side_effect=_get) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_create_service_template(mocker, fake_uuid): def _create( name, @@ -811,7 +811,7 @@ def mock_create_service_template(mocker, fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_update_service_template(mocker): def _update(id_, name, type_, content, service, subject=None, process_type=None): template = template_json( @@ -824,7 +824,7 @@ def mock_update_service_template(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_create_service_template_content_too_big(mocker): def _create( name, @@ -861,7 +861,7 @@ def mock_create_service_template_content_too_big(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_update_service_template_400_content_too_big(mocker): def _update(id_, name, type_, content, service, subject=None, process_type=None): json_mock = Mock( @@ -923,7 +923,7 @@ def _template(template_type, name, parent=None, template_id=None): } -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_service_templates(mocker): def _create(service_id): return create_service_templates(service_id) @@ -933,7 +933,7 @@ def mock_get_service_templates(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_more_service_templates_than_can_fit_onscreen(mocker): def _create(service_id): return create_service_templates(service_id, number_of_templates=20) @@ -943,7 +943,7 @@ def mock_get_more_service_templates_than_can_fit_onscreen(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_service_templates_when_no_templates_exist(mocker): def _create(service_id): return {"data": []} @@ -953,7 +953,7 @@ def mock_get_service_templates_when_no_templates_exist(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_service_templates_with_only_one_template(mocker): def _get(service_id): return { @@ -973,7 +973,7 @@ def mock_get_service_templates_with_only_one_template(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_delete_service_template(mocker): def _delete(service_id, template_id): template = template_json( @@ -990,12 +990,12 @@ def mock_delete_service_template(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_redact_template(mocker): return mocker.patch("app.service_api_client.redact_service_template") -@pytest.fixture(scope="function") +@pytest.fixture() def mock_update_service_template_sender(mocker): def _update(service_id, template_id, reply_to): return @@ -1005,12 +1005,12 @@ def mock_update_service_template_sender(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def api_user_pending(fake_uuid): return create_user(id=fake_uuid, state="pending") -@pytest.fixture(scope="function") +@pytest.fixture() def platform_admin_user(fake_uuid): return create_platform_admin_user( permissions={ @@ -1027,7 +1027,7 @@ def platform_admin_user(fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def platform_admin_user_no_service_permissions(): """ this fixture is for situations where we want to test that platform admin can access @@ -1036,17 +1036,17 @@ def platform_admin_user_no_service_permissions(): return create_platform_admin_user() -@pytest.fixture(scope="function") +@pytest.fixture() def api_user_active(): return create_api_user_active() -@pytest.fixture(scope="function") +@pytest.fixture() def api_user_active_email_auth(fake_uuid): return create_user(id=fake_uuid, auth_type="email_auth") -@pytest.fixture(scope="function") +@pytest.fixture() def active_user_with_permissions_no_mobile(fake_uuid): return create_service_one_admin( id=fake_uuid, @@ -1054,7 +1054,7 @@ def active_user_with_permissions_no_mobile(fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def api_nongov_user_active(fake_uuid): return create_service_one_admin( id=fake_uuid, @@ -1062,12 +1062,12 @@ def api_nongov_user_active(fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def active_user_with_permissions(fake_uuid): return create_active_user_with_permissions() -@pytest.fixture(scope="function") +@pytest.fixture() def active_user_with_permission_to_two_services(fake_uuid): permissions = [ "send_texts", @@ -1090,7 +1090,7 @@ def active_user_with_permission_to_two_services(fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def active_user_with_permission_to_other_service( active_user_with_permission_to_two_services, ): @@ -1103,22 +1103,22 @@ def active_user_with_permission_to_other_service( return active_user_with_permission_to_two_services -@pytest.fixture(scope="function") +@pytest.fixture() def active_caseworking_user(): return create_active_caseworking_user() -@pytest.fixture +@pytest.fixture() def active_user_view_permissions(): return create_active_user_view_permissions() -@pytest.fixture +@pytest.fixture() def active_user_no_settings_permission(): return create_active_user_no_settings_permission() -@pytest.fixture(scope="function") +@pytest.fixture() def api_user_locked(fake_uuid): return create_user( id=fake_uuid, @@ -1127,7 +1127,7 @@ def api_user_locked(fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def api_user_request_password_reset(fake_uuid): return create_user( id=fake_uuid, @@ -1135,7 +1135,7 @@ def api_user_request_password_reset(fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def api_user_changed_password(fake_uuid): return create_user( id=fake_uuid, @@ -1144,12 +1144,12 @@ def api_user_changed_password(fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_send_change_email_verification(mocker): return mocker.patch("app.user_api_client.send_change_email_verification") -@pytest.fixture(scope="function") +@pytest.fixture() def mock_register_user(mocker, api_user_pending): def _register(name, email_address, mobile_number, password, auth_type): api_user_pending["name"] = name @@ -1162,7 +1162,7 @@ def mock_register_user(mocker, api_user_pending): return mocker.patch("app.user_api_client.register_user", side_effect=_register) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_non_govuser(mocker, api_user_active): api_user_active["email_address"] = "someuser@example.com" @@ -1173,7 +1173,7 @@ def mock_get_non_govuser(mocker, api_user_active): return mocker.patch("app.user_api_client.get_user", side_effect=_get_user) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_user(mocker, api_user_active): def _get_user(id_): api_user_active["id"] = id_ @@ -1182,7 +1182,7 @@ def mock_get_user(mocker, api_user_active): return mocker.patch("app.user_api_client.get_user", side_effect=_get_user) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_locked_user(mocker, api_user_locked): def _get_user(id_): api_user_locked["id"] = id_ @@ -1191,12 +1191,12 @@ def mock_get_locked_user(mocker, api_user_locked): return mocker.patch("app.user_api_client.get_user", side_effect=_get_user) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_user_pending(mocker, api_user_pending): return mocker.patch("app.user_api_client.get_user", return_value=api_user_pending) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_user_by_email(mocker, api_user_active): def _get_user(email_address): api_user_active["email_address"] = email_address @@ -1205,7 +1205,7 @@ def mock_get_user_by_email(mocker, api_user_active): return mocker.patch("app.user_api_client.get_user_by_email", side_effect=_get_user) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_dont_get_user_by_email(mocker): def _get_user(email_address): return None @@ -1215,7 +1215,7 @@ def mock_dont_get_user_by_email(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_user_by_email_request_password_reset( mocker, api_user_request_password_reset ): @@ -1225,28 +1225,28 @@ def mock_get_user_by_email_request_password_reset( ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_user_by_email_user_changed_password(mocker, api_user_changed_password): return mocker.patch( "app.user_api_client.get_user_by_email", return_value=api_user_changed_password ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_user_by_email_locked(mocker, api_user_locked): return mocker.patch( "app.user_api_client.get_user_by_email", return_value=api_user_locked ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_user_by_email_pending(mocker, api_user_pending): return mocker.patch( "app.user_api_client.get_user_by_email", return_value=api_user_pending ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_user_by_email_not_found(mocker, api_user_active): def _get_user(email): json_mock = Mock(return_value={"message": "Not found", "result": "error"}) @@ -1257,7 +1257,7 @@ def mock_get_user_by_email_not_found(mocker, api_user_active): return mocker.patch("app.user_api_client.get_user_by_email", side_effect=_get_user) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_verify_password(mocker): def _verify_password(user, password): return True @@ -1267,7 +1267,7 @@ def mock_verify_password(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_update_user_password(mocker, api_user_active): def _update(user_id, password): api_user_active["id"] = user_id @@ -1276,7 +1276,7 @@ def mock_update_user_password(mocker, api_user_active): return mocker.patch("app.user_api_client.update_password", side_effect=_update) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_update_user_attribute(mocker, api_user_active): def _update(user_id, **kwargs): api_user_active["id"] = user_id @@ -1287,7 +1287,7 @@ def mock_update_user_attribute(mocker, api_user_active): ) -@pytest.fixture +@pytest.fixture() def mock_activate_user(mocker, api_user_active): def _activate(user_id): api_user_active["id"] = user_id @@ -1296,14 +1296,14 @@ def mock_activate_user(mocker, api_user_active): return mocker.patch("app.user_api_client.activate_user", side_effect=_activate) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_email_is_not_already_in_use(mocker): return mocker.patch( "app.user_api_client.get_user_by_email_or_none", return_value=None ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_revoke_api_key(mocker): def _revoke(service_id, key_id): return {} @@ -1311,7 +1311,7 @@ def mock_revoke_api_key(mocker): return mocker.patch("app.api_key_api_client.revoke_api_key", side_effect=_revoke) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_api_keys(mocker, fake_uuid): def _get_keys(service_id, key_id=None): keys = { @@ -1332,7 +1332,7 @@ def mock_get_api_keys(mocker, fake_uuid): return mocker.patch("app.api_key_api_client.get_api_keys", side_effect=_get_keys) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_no_api_keys(mocker): def _get_keys(service_id): keys = {"apiKeys": []} @@ -1341,7 +1341,7 @@ def mock_get_no_api_keys(mocker): return mocker.patch("app.api_key_api_client.get_api_keys", side_effect=_get_keys) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_login(mocker, mock_get_user, mock_update_user_attribute, mock_events): def _verify_code(user_id, code, code_type): return True, "" @@ -1355,17 +1355,17 @@ def mock_login(mocker, mock_get_user, mock_update_user_attribute, mock_events): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_send_verify_code(mocker): return mocker.patch("app.user_api_client.send_verify_code") -@pytest.fixture(scope="function") +@pytest.fixture() def mock_send_verify_email(mocker): return mocker.patch("app.user_api_client.send_verify_email") -@pytest.fixture(scope="function") +@pytest.fixture() def mock_check_verify_code(mocker): def _verify(user_id, code, code_type): return True, "" @@ -1373,7 +1373,7 @@ def mock_check_verify_code(mocker): return mocker.patch("app.user_api_client.check_verify_code", side_effect=_verify) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_check_verify_code_code_not_found(mocker): def _verify(user_id, code, code_type): return False, "Code not found" @@ -1381,7 +1381,7 @@ def mock_check_verify_code_code_not_found(mocker): return mocker.patch("app.user_api_client.check_verify_code", side_effect=_verify) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_check_verify_code_code_expired(mocker): def _verify(user_id, code, code_type): return False, "Code has expired" @@ -1389,7 +1389,7 @@ def mock_check_verify_code_code_expired(mocker): return mocker.patch("app.user_api_client.check_verify_code", side_effect=_verify) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_create_job(mocker, api_user_active): def _create(job_id, service_id, scheduled_for=None): return job_json( @@ -1401,7 +1401,7 @@ def mock_create_job(mocker, api_user_active): return mocker.patch("app.job_api_client.create_job", side_effect=_create) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_job(mocker, api_user_active): def _get_job(service_id, job_id): return {"data": job_json(service_id, api_user_active, job_id=job_id)} @@ -1409,7 +1409,7 @@ def mock_get_job(mocker, api_user_active): return mocker.patch("app.job_api_client.get_job", side_effect=_get_job) -@pytest.fixture +@pytest.fixture() def mock_get_job_doesnt_exist(mocker): def _get_job(service_id, job_id): raise HTTPError(response=Mock(status_code=404, json={}), message={}) @@ -1417,7 +1417,7 @@ def mock_get_job_doesnt_exist(mocker): return mocker.patch("app.job_api_client.get_job", side_effect=_get_job) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_scheduled_job(mocker, api_user_active): def _get_job(service_id, job_id): return { @@ -1433,7 +1433,7 @@ def mock_get_scheduled_job(mocker, api_user_active): return mocker.patch("app.job_api_client.get_job", side_effect=_get_job) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_cancelled_job(mocker, api_user_active): def _get_job(service_id, job_id): return { @@ -1449,7 +1449,7 @@ def mock_get_cancelled_job(mocker, api_user_active): return mocker.patch("app.job_api_client.get_job", side_effect=_get_job) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_job_in_progress(mocker, api_user_active): def _get_job(service_id, job_id): return { @@ -1466,7 +1466,7 @@ def mock_get_job_in_progress(mocker, api_user_active): return mocker.patch("app.job_api_client.get_job", side_effect=_get_job) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_job_with_sending_limits_exceeded(mocker, api_user_active): def _get_job(service_id, job_id): return { @@ -1483,17 +1483,17 @@ def mock_get_job_with_sending_limits_exceeded(mocker, api_user_active): return mocker.patch("app.job_api_client.get_job", side_effect=_get_job) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_has_jobs(mocker): return mocker.patch("app.job_api_client.has_jobs", return_value=True) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_has_no_jobs(mocker): return mocker.patch("app.job_api_client.has_jobs", return_value=False) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_jobs(mocker, api_user_active, fake_uuid): def _get_jobs(service_id, limit_days=None, statuses=None, page=1): if statuses is None: @@ -1549,7 +1549,7 @@ def mock_get_jobs(mocker, api_user_active, fake_uuid): return mocker.patch("app.job_api_client.get_jobs", side_effect=_get_jobs) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_scheduled_job_stats(mocker, api_user_active): return mocker.patch( "app.job_api_client.get_scheduled_job_stats", @@ -1561,7 +1561,7 @@ def mock_get_scheduled_job_stats(mocker, api_user_active): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_uploads(mocker, api_user_active): def _get_uploads(service_id, limit_days=None, statuses=None, page=1): uploads = [ @@ -1593,8 +1593,8 @@ def mock_get_uploads(mocker, api_user_active): ) -@pytest.fixture(scope="function") -def mock_get_no_uploads(mocker, api_user_active): +@pytest.fixture() +def _mock_get_no_uploads(mocker, api_user_active): mocker.patch( "app.models.job.PaginatedUploads.client_method", return_value={ @@ -1603,7 +1603,7 @@ def mock_get_no_uploads(mocker, api_user_active): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_no_jobs(mocker, api_user_active): return mocker.patch( "app.models.job.PaginatedJobs.client_method", @@ -1614,7 +1614,7 @@ def mock_get_no_jobs(mocker, api_user_active): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_notifications( mocker, api_user_active, @@ -1665,7 +1665,7 @@ def mock_get_notifications( ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_notifications_with_previous_next(mocker): def _get_notifications( service_id, @@ -1690,7 +1690,7 @@ def mock_get_notifications_with_previous_next(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_notifications_with_no_notifications(mocker): def _get_notifications( service_id, @@ -1713,7 +1713,7 @@ def mock_get_notifications_with_no_notifications(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_inbound_sms(mocker): def _get_inbound_sms(service_id, user_number=None, page=1): return inbound_sms_json() @@ -1724,7 +1724,7 @@ def mock_get_inbound_sms(mocker): ) -@pytest.fixture +@pytest.fixture() def mock_get_inbound_sms_by_id_with_no_messages(mocker): def _get_inbound_sms_by_id(service_id, notification_id): raise HTTPError(response=Mock(status_code=404)) @@ -1735,7 +1735,7 @@ def mock_get_inbound_sms_by_id_with_no_messages(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_most_recent_inbound_sms(mocker): def _get_most_recent_inbound_sms(service_id, user_number=None, page=1): return inbound_sms_json() @@ -1746,7 +1746,7 @@ def mock_get_most_recent_inbound_sms(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_most_recent_inbound_sms_with_no_messages(mocker): def _get_most_recent_inbound_sms(service_id, user_number=None, page=1): return {"has_next": False, "data": []} @@ -1757,7 +1757,7 @@ def mock_get_most_recent_inbound_sms_with_no_messages(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_inbound_sms_summary(mocker): def _get_inbound_sms_summary( service_id, @@ -1770,7 +1770,7 @@ def mock_get_inbound_sms_summary(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_inbound_sms_summary_with_no_messages(mocker): def _get_inbound_sms_summary( service_id, @@ -1783,7 +1783,7 @@ def mock_get_inbound_sms_summary_with_no_messages(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_inbound_number_for_service(mocker): return mocker.patch( "app.inbound_number_client.get_inbound_sms_number_for_service", @@ -1791,7 +1791,7 @@ def mock_get_inbound_number_for_service(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_no_inbound_number_for_service(mocker): return mocker.patch( "app.inbound_number_client.get_inbound_sms_number_for_service", @@ -1799,7 +1799,7 @@ def mock_no_inbound_number_for_service(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_has_permissions(mocker): def _has_permission(*permissions, restrict_admin_usage=False, allow_org_user=False): return True @@ -1809,7 +1809,7 @@ def mock_has_permissions(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_users_by_service(mocker): def _get_users_for_service(service_id): return [ @@ -1828,7 +1828,7 @@ def mock_get_users_by_service(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_s3_upload(mocker): def _upload(service_id, filedata): return sample_uuid() @@ -1836,7 +1836,7 @@ def mock_s3_upload(mocker): return mocker.patch("app.main.views.send.s3upload", side_effect=_upload) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_s3_download(mocker): def _download(service_id, upload_id): return """ @@ -1848,7 +1848,7 @@ def mock_s3_download(mocker): return mocker.patch("app.main.views.send.s3download", side_effect=_download) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_s3_get_metadata(mocker): def _get_metadata(service_id, upload_id): return {"original_file_name": "example.csv"} @@ -1858,12 +1858,12 @@ def mock_s3_get_metadata(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_s3_set_metadata(mocker): return mocker.patch("app.main.views.send.set_metadata_on_csv_upload") -@pytest.fixture(scope="function") +@pytest.fixture() def sample_invite(mocker, service_one): id_ = USER_ONE_ID from_user = service_one["users"][0] @@ -1887,7 +1887,7 @@ def sample_invite(mocker, service_one): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_create_invite(mocker, sample_invite): def _create_invite( from_user, service_id, email_address, permissions, folder_permissions @@ -1905,7 +1905,7 @@ def mock_create_invite(mocker, sample_invite): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_invites_for_service(mocker, service_one, sample_invite): def _get_invites(service_id): data = [] @@ -1920,7 +1920,7 @@ def mock_get_invites_for_service(mocker, service_one, sample_invite): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_invites_without_manage_permission(mocker, service_one, sample_invite): def _get_invites(service_id): return [ @@ -1942,7 +1942,7 @@ def mock_get_invites_without_manage_permission(mocker, service_one, sample_invit ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_accept_invite(mocker, sample_invite): def _accept(service_id, invite_id): return sample_invite @@ -1950,7 +1950,7 @@ def mock_accept_invite(mocker, sample_invite): return mocker.patch("app.invite_api_client.accept_invite", side_effect=_accept) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_add_user_to_service(mocker, service_one, api_user_active): def _add_user(service_id, user_id, permissions, folder_permissions): return @@ -1960,19 +1960,19 @@ def mock_add_user_to_service(mocker, service_one, api_user_active): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_set_user_permissions(mocker): return mocker.patch("app.user_api_client.set_user_permissions", return_value=None) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_remove_user_from_service(mocker): return mocker.patch( "app.service_api_client.remove_user_from_service", return_value=None ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_template_statistics(mocker, service_one, fake_uuid): template = template_json( service_one["id"], @@ -1998,7 +1998,7 @@ def mock_get_template_statistics(mocker, service_one, fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_monthly_template_usage(mocker, service_one, fake_uuid): def _stats(service_id, year): return [ @@ -2018,7 +2018,7 @@ def mock_get_monthly_template_usage(mocker, service_one, fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_monthly_notification_stats(mocker, service_one, fake_uuid): def _stats(service_id, year): return { @@ -2041,7 +2041,7 @@ def mock_get_monthly_notification_stats(mocker, service_one, fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_annual_usage_for_service(mocker, service_one, fake_uuid): def _get_usage(service_id, year=None): return [ @@ -2076,7 +2076,7 @@ def mock_get_annual_usage_for_service(mocker, service_one, fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_monthly_usage_for_service(mocker): def _get_usage(service_id, year): return [ @@ -2127,7 +2127,7 @@ def mock_get_monthly_usage_for_service(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_annual_usage_for_service_in_future(mocker, service_one, fake_uuid): def _get_usage(service_id, year=None): return [ @@ -2154,7 +2154,7 @@ def mock_get_annual_usage_for_service_in_future(mocker, service_one, fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_monthly_usage_for_service_in_future(mocker): def _get_usage(service_id, year): return [] @@ -2164,7 +2164,7 @@ def mock_get_monthly_usage_for_service_in_future(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_events(mocker): def _create_event(event_type, event_data): return {"some": "data"} @@ -2172,7 +2172,7 @@ def mock_events(mocker): return mocker.patch("app.events_api_client.create_event", side_effect=_create_event) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_send_already_registered_email(mocker): return mocker.patch("app.user_api_client.send_already_registered_email") @@ -2201,7 +2201,7 @@ def create_email_brandings( return brandings -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_all_email_branding(mocker): def _get_all_email_branding(sort_key=None): non_standard_values = [ @@ -2221,7 +2221,7 @@ def mock_get_all_email_branding(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_no_email_branding(mocker): def _get_email_branding(): return [] @@ -2248,7 +2248,7 @@ def create_email_branding(id, non_standard_values=None): return {"email_branding": branding} -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_email_branding(mocker, fake_uuid): def _get_email_branding(id): return create_email_branding(fake_uuid) @@ -2258,7 +2258,7 @@ def mock_get_email_branding(mocker, fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_email_branding_with_govuk_brand_type(mocker, fake_uuid): def _get_email_branding(id): return create_email_branding(fake_uuid, {"brand_type": "govuk"}) @@ -2268,7 +2268,7 @@ def mock_get_email_branding_with_govuk_brand_type(mocker, fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_email_branding_with_both_brand_type(mocker, fake_uuid): def _get_email_branding(id): return create_email_branding(fake_uuid, {"brand_type": "both"}) @@ -2278,7 +2278,7 @@ def mock_get_email_branding_with_both_brand_type(mocker, fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_email_branding_with_org_banner_brand_type(mocker, fake_uuid): def _get_email_branding(id): return create_email_branding(fake_uuid, {"brand_type": "org_banner"}) @@ -2288,7 +2288,7 @@ def mock_get_email_branding_with_org_banner_brand_type(mocker, fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_email_branding_without_brand_text(mocker, fake_uuid): def _get_email_branding_without_brand_text(id): return create_email_branding( @@ -2301,7 +2301,7 @@ def mock_get_email_branding_without_brand_text(mocker, fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_create_email_branding(mocker): def _create_email_branding(logo, name, text, colour, brand_type): return @@ -2312,7 +2312,7 @@ def mock_create_email_branding(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_update_email_branding(mocker): def _update_email_branding(branding_id, logo, name, text, colour, brand_type): return @@ -2323,7 +2323,7 @@ def mock_update_email_branding(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_guest_list(mocker): def _get_guest_list(service_id): return { @@ -2336,17 +2336,17 @@ def mock_get_guest_list(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_update_guest_list(mocker): return mocker.patch("app.service_api_client.update_guest_list") -@pytest.fixture(scope="function") +@pytest.fixture() def mock_reset_failed_login_count(mocker): return mocker.patch("app.user_api_client.reset_failed_login_count") -@pytest.fixture +@pytest.fixture() def mock_get_notification(mocker): def _get_notification( service_id, @@ -2377,7 +2377,7 @@ def mock_get_notification(mocker): ) -@pytest.fixture +@pytest.fixture() def mock_send_notification(mocker, fake_uuid): def _send_notification( service_id, *, template_id, recipient, personalisation, sender_id @@ -2389,8 +2389,8 @@ def mock_send_notification(mocker, fake_uuid): ) -@pytest.fixture(scope="function") -def _client(notify_admin): +@pytest.fixture() +def client(notify_admin): """ Do not use this fixture directly – use `client_request` instead """ @@ -2399,19 +2399,19 @@ def _client(notify_admin): yield client -@pytest.fixture(scope="function") -def _logged_in_client( - _client, active_user_with_permissions, mocker, service_one, mock_login +@pytest.fixture() +def logged_in_client( + client, active_user_with_permissions, mocker, service_one, mock_login ): """ Do not use this fixture directly – use `client_request` instead """ - _client.login(active_user_with_permissions, mocker, service_one) - yield _client + client.login(active_user_with_permissions, mocker, service_one) + return client -@pytest.fixture -def os_environ(): +@pytest.fixture() +def _os_environ(): """ clear os.environ, and restore it after the test runs """ @@ -2424,21 +2424,21 @@ def os_environ(): @pytest.fixture # noqa (C901 too complex) -def client_request(_logged_in_client, mocker, service_one): # noqa (C901 too complex) +def client_request(logged_in_client, mocker, service_one): # noqa (C901 too complex) class ClientRequest: @staticmethod @contextmanager def session_transaction(): - with _logged_in_client.session_transaction() as session: + with logged_in_client.session_transaction() as session: yield session @staticmethod def login(user, service=service_one): - _logged_in_client.login(user, mocker, service) + logged_in_client.login(user, mocker, service) @staticmethod def logout(): - _logged_in_client.logout(None) + logged_in_client.logout(None) @staticmethod def get( @@ -2470,7 +2470,7 @@ def client_request(_logged_in_client, mocker, service_one): # noqa (C901 too co _test_for_elements_without_class=True, **endpoint_kwargs ): - resp = _logged_in_client.get( + resp = logged_in_client.get( url, follow_redirects=_follow_redirects, ) @@ -2535,7 +2535,7 @@ def client_request(_logged_in_client, mocker, service_one): # noqa (C901 too co post_kwargs = {} if _content_type: post_kwargs.update(content_type=_content_type) - resp = _logged_in_client.post( + resp = logged_in_client.post( url, data=_data, follow_redirects=_follow_redirects, **post_kwargs ) assert resp.status_code == _expected_status @@ -2558,7 +2558,7 @@ def client_request(_logged_in_client, mocker, service_one): # noqa (C901 too co url, _expected_status=200, ): - resp = _logged_in_client.get(url) + resp = logged_in_client.get(url) assert resp.status_code == _expected_status return resp @@ -2588,7 +2588,7 @@ def client_request(_logged_in_client, mocker, service_one): # noqa (C901 too co post_kwargs = {} if _content_type: post_kwargs.update(content_type=_content_type) - resp = _logged_in_client.post(url, data=_data, **post_kwargs) + resp = logged_in_client.post(url, data=_data, **post_kwargs) assert resp.status_code == _expected_status return resp @@ -2601,7 +2601,7 @@ def normalize_spaces(input): return normalize_spaces(" ".join(item.text for item in input)) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_service_data_retention(mocker): data = { "id": str(sample_uuid()), @@ -2617,17 +2617,17 @@ def mock_get_service_data_retention(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_create_service_data_retention(mocker): return mocker.patch("app.service_api_client.create_service_data_retention") -@pytest.fixture(scope="function") +@pytest.fixture() def mock_update_service_data_retention(mocker): return mocker.patch("app.service_api_client.update_service_data_retention") -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_free_sms_fragment_limit(mocker): sample_limit = 250000 return mocker.patch( @@ -2636,7 +2636,7 @@ def mock_get_free_sms_fragment_limit(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_create_or_update_free_sms_fragment_limit(mocker): sample_limit = 250000 return mocker.patch( @@ -2667,7 +2667,7 @@ def set_config_values(app, dict): app.config[key] = old_values[key] -@pytest.fixture(scope="function") +@pytest.fixture() def valid_token(notify_admin, fake_uuid): return generate_token( json.dumps({"user_id": fake_uuid, "secret_code": "my secret"}), @@ -2676,7 +2676,7 @@ def valid_token(notify_admin, fake_uuid): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_valid_service_inbound_api(mocker): def _get(service_id, inbound_api_id): return { @@ -2693,7 +2693,7 @@ def mock_get_valid_service_inbound_api(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_valid_service_callback_api(mocker): def _get(service_id, callback_api_id): return { @@ -2710,7 +2710,7 @@ def mock_get_valid_service_callback_api(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_empty_service_inbound_api(mocker): return mocker.patch( "app.service_api_client.get_service_inbound_api", @@ -2718,7 +2718,7 @@ def mock_get_empty_service_inbound_api(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_empty_service_callback_api(mocker): return mocker.patch( "app.service_api_client.get_service_callback_api", @@ -2726,7 +2726,7 @@ def mock_get_empty_service_callback_api(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_create_service_inbound_api(mocker): def _create_service_inbound_api(service_id, url, bearer_token, user_id): return @@ -2737,7 +2737,7 @@ def mock_create_service_inbound_api(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_update_service_inbound_api(mocker): def _update_service_inbound_api( service_id, url, bearer_token, user_id, inbound_api_id @@ -2750,7 +2750,7 @@ def mock_update_service_inbound_api(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_create_service_callback_api(mocker): def _create_service_callback_api(service_id, url, bearer_token, user_id): return @@ -2761,7 +2761,7 @@ def mock_create_service_callback_api(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_update_service_callback_api(mocker): def _update_service_callback_api( service_id, url, bearer_token, user_id, callback_api_id @@ -2774,14 +2774,14 @@ def mock_update_service_callback_api(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def organization_one(api_user_active): return organization_json( ORGANISATION_ID, "organization one", [api_user_active["id"]] ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_organizations(mocker): def _get_organizations(): return [ @@ -2801,7 +2801,7 @@ def mock_get_organizations(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_organizations_with_unusual_domains(mocker): def _get_organizations(): return [ @@ -2822,7 +2822,7 @@ def mock_get_organizations_with_unusual_domains(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_organization(mocker): def _get_organization(org_id): return organization_json( @@ -2839,7 +2839,7 @@ def mock_get_organization(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_organization_by_domain(mocker): def _get_organization_by_domain(domain): return organization_json(ORGANISATION_ID) @@ -2850,7 +2850,7 @@ def mock_get_organization_by_domain(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_no_organization_by_domain(mocker): return mocker.patch( "app.organizations_client.get_organization_by_domain", @@ -2858,7 +2858,7 @@ def mock_get_no_organization_by_domain(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_service_organization( mocker, mock_get_organization, @@ -2870,7 +2870,7 @@ def mock_get_service_organization( ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_update_service_organization(mocker): def _update_service_organization(service_id, org_id): return @@ -2901,7 +2901,7 @@ def _get_organization_services(organization_id): ] -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_organization_services(mocker, api_user_active): return mocker.patch( "app.organizations_client.get_organization_services", @@ -2909,7 +2909,7 @@ def mock_get_organization_services(mocker, api_user_active): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_users_for_organization(mocker): def _get_users_for_organization(org_id): return [ @@ -2923,7 +2923,7 @@ def mock_get_users_for_organization(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_invited_users_for_organization(mocker, sample_org_invite): def _get_invited_invited_users_for_organization(org_id): return [sample_org_invite] @@ -2934,7 +2934,7 @@ def mock_get_invited_users_for_organization(mocker, sample_org_invite): ) -@pytest.fixture(scope="function") +@pytest.fixture() def sample_org_invite(mocker, organization_one): id_ = str(UUID(bytes=b"sample_org_invit", version=4)) invited_by = organization_one["users"][0] @@ -2948,7 +2948,7 @@ def sample_org_invite(mocker, organization_one): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_invites_for_organization(mocker, sample_org_invite): def _get_org_invites(org_id): data = [] @@ -2964,7 +2964,7 @@ def mock_get_invites_for_organization(mocker, sample_org_invite): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_check_org_invite_token(mocker, sample_org_invite): def _check_org_token(token): return sample_org_invite @@ -2974,7 +2974,7 @@ def mock_check_org_invite_token(mocker, sample_org_invite): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_check_org_cancelled_invite_token(mocker, sample_org_invite): def _check_org_token(token): sample_org_invite["status"] = "cancelled" @@ -2985,7 +2985,7 @@ def mock_check_org_cancelled_invite_token(mocker, sample_org_invite): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_check_org_accepted_invite_token(mocker, sample_org_invite): sample_org_invite["status"] = "accepted" @@ -2997,7 +2997,7 @@ def mock_check_org_accepted_invite_token(mocker, sample_org_invite): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_accept_org_invite(mocker, sample_org_invite): def _accept(organization_id, invite_id): return sample_org_invite @@ -3005,7 +3005,7 @@ def mock_accept_org_invite(mocker, sample_org_invite): return mocker.patch("app.org_invite_api_client.accept_invite", side_effect=_accept) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_add_user_to_organization(mocker, organization_one, api_user_active): def _add_user(organization_id, user_id): return api_user_active @@ -3015,7 +3015,7 @@ def mock_add_user_to_organization(mocker, organization_one, api_user_active): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_update_organization(mocker): def _update_org(org, **kwargs): return @@ -3025,7 +3025,7 @@ def mock_update_organization(mocker): ) -@pytest.fixture +@pytest.fixture() def mock_get_organizations_and_services_for_user( mocker, organization_one, api_user_active ): @@ -3038,7 +3038,7 @@ def mock_get_organizations_and_services_for_user( ) -@pytest.fixture +@pytest.fixture() def mock_get_non_empty_organizations_and_services_for_user( mocker, organization_one, api_user_active ): @@ -3085,7 +3085,7 @@ def mock_get_non_empty_organizations_and_services_for_user( ) -@pytest.fixture +@pytest.fixture() def mock_get_just_services_for_user(mocker, organization_one, api_user_active): def _make_services(name, trial_mode=False): return [ @@ -3110,7 +3110,7 @@ def mock_get_just_services_for_user(mocker, organization_one, api_user_active): ) -@pytest.fixture +@pytest.fixture() def mock_get_empty_organizations_and_one_service_for_user( mocker, organization_one, api_user_active ): @@ -3132,7 +3132,7 @@ def mock_get_empty_organizations_and_one_service_for_user( ) -@pytest.fixture +@pytest.fixture() def mock_create_event(mocker): """ This should be used whenever your code is calling `flask_login.login_user` @@ -3149,19 +3149,19 @@ def url_for_endpoint_with_token(endpoint, token, next=None): return url_for(endpoint, token=token, next=next) -@pytest.fixture +@pytest.fixture() def mock_get_template_folders(mocker): return mocker.patch( "app.template_folder_api_client.get_template_folders", return_value=[] ) -@pytest.fixture +@pytest.fixture() def mock_move_to_template_folder(mocker): return mocker.patch("app.template_folder_api_client.move_to_folder") -@pytest.fixture +@pytest.fixture() def mock_create_template_folder(mocker): return mocker.patch( "app.template_folder_api_client.create_template_folder", @@ -3169,7 +3169,7 @@ def mock_create_template_folder(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_service_and_organization_counts(mocker): return mocker.patch( "app.status_api_client.get_count_of_live_services_and_organizations", @@ -3180,7 +3180,7 @@ def mock_get_service_and_organization_counts(mocker): ) -@pytest.fixture(scope="function") +@pytest.fixture() def mock_get_service_history(mocker): return mocker.patch( "app.service_api_client.get_service_history", @@ -3578,7 +3578,7 @@ def create_template( ) -@pytest.fixture +@pytest.fixture() def mock_get_invited_user_by_id(mocker, sample_invite): def _get(invited_user_id): return sample_invite @@ -3589,7 +3589,7 @@ def mock_get_invited_user_by_id(mocker, sample_invite): ) -@pytest.fixture +@pytest.fixture() def mock_get_invited_org_user_by_id(mocker, sample_org_invite): def _get(invited_org_user_id): return sample_org_invite @@ -3666,7 +3666,7 @@ def login_for_end_to_end_testing(browser): @pytest.fixture(scope="session") def end_to_end_context(browser): context = browser.new_context() - yield context + return context @pytest.fixture(scope="session") @@ -3680,4 +3680,4 @@ def end_to_end_authenticated_context(browser): ) context = browser.new_context(storage_state=auth_state_path) - yield context + return context From 95ba7c3099eda3877810d30754cf705f61efc6e7 Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Wed, 6 Sep 2023 18:29:04 -0400 Subject: [PATCH 03/14] More formatting fixes for tests Signed-off-by: Carlo Costino --- tests/app/test_utils.py | 2 +- tests/app/utils/test_branding.py | 8 +++---- tests/app/utils/test_csv.py | 24 ++++++++++++-------- tests/app/utils/test_login.py | 4 ++-- tests/app/utils/test_time.py | 8 +++---- tests/app/utils/test_user.py | 28 ++++++++++++------------ tests/app/utils/test_user_permissions.py | 2 +- 7 files changed, 41 insertions(+), 35 deletions(-) diff --git a/tests/app/test_utils.py b/tests/app/test_utils.py index 9473fce00..4da7e8718 100644 --- a/tests/app/test_utils.py +++ b/tests/app/test_utils.py @@ -4,7 +4,7 @@ from app.utils import merge_jsonlike @pytest.mark.parametrize( - "source_object, destination_object, expected_result", + ("source_object", "destination_object", "expected_result"), [ # simple dicts: ({"a": "b"}, {"c": "d"}, {"a": "b", "c": "d"}), diff --git a/tests/app/utils/test_branding.py b/tests/app/utils/test_branding.py index 4704c7ac9..8c1aae4bd 100644 --- a/tests/app/utils/test_branding.py +++ b/tests/app/utils/test_branding.py @@ -10,7 +10,7 @@ from tests.conftest import create_email_branding @pytest.mark.parametrize("function", [get_email_choices]) @pytest.mark.parametrize( - "org_type, expected_options", + ("org_type", "expected_options"), [ ("federal", []), ("state", []), @@ -30,7 +30,7 @@ def test_get_choices_service_not_assigned_to_org( @pytest.mark.parametrize( - "org_type, branding_id, expected_options", + ("org_type", "branding_id", "expected_options"), [ ( "federal", @@ -86,7 +86,7 @@ def test_get_email_choices_service_assigned_to_org( @pytest.mark.parametrize( - "org_type, branding_id, expected_options", + ("org_type", "branding_id", "expected_options"), [ ( "federal", @@ -141,7 +141,7 @@ def test_get_email_choices_org_has_default_branding( @pytest.mark.parametrize( - "branding_name, expected_options", + ("branding_name", "expected_options"), [ ( "gsa.gov and something else", diff --git a/tests/app/utils/test_csv.py b/tests/app/utils/test_csv.py index 35d48c233..545afd6dd 100644 --- a/tests/app/utils/test_csv.py +++ b/tests/app/utils/test_csv.py @@ -65,8 +65,8 @@ def _get_notifications_csv( return _get -@pytest.fixture(scope="function") -def _get_notifications_csv_mock( +@pytest.fixture() +def get_notifications_csv_mock( mocker, api_user_active, ): @@ -77,7 +77,7 @@ def _get_notifications_csv_mock( @pytest.mark.parametrize( - "created_by_name, expected_content", + ("created_by_name", "expected_content"), [ ( None, @@ -114,7 +114,7 @@ def test_generate_notifications_csv_without_job( @pytest.mark.parametrize( - "original_file_contents, expected_column_headers, expected_1st_row", + ("original_file_contents", "expected_column_headers", "expected_1st_row"), [ ( """ @@ -211,7 +211,7 @@ def test_generate_notifications_csv_without_job( def test_generate_notifications_csv_returns_correct_csv_file( notify_admin, mocker, - _get_notifications_csv_mock, + get_notifications_csv_mock, original_file_contents, expected_column_headers, expected_1st_row, @@ -231,11 +231,11 @@ def test_generate_notifications_csv_returns_correct_csv_file( def test_generate_notifications_csv_only_calls_once_if_no_next_link( notify_admin, - _get_notifications_csv_mock, + get_notifications_csv_mock, ): list(generate_notifications_csv(service_id="1234")) - assert _get_notifications_csv_mock.call_count == 1 + assert get_notifications_csv_mock.call_count == 1 @pytest.mark.parametrize("job_id", ["some", None]) @@ -303,8 +303,14 @@ MockRecipients = namedtuple( @pytest.mark.parametrize( - "rows_with_bad_recipients, rows_with_missing_data, " - "rows_with_message_too_long, rows_with_empty_message, template_type, expected_errors", + ( + "rows_with_bad_recipients", + "rows_with_missing_data", + "rows_with_message_too_long", + "rows_with_empty_message", + "template_type", + "expected_errors", + ), [ ([], [], [], [], "sms", []), ({2}, [], [], [], "sms", ["fix 1 phone number"]), diff --git a/tests/app/utils/test_login.py b/tests/app/utils/test_login.py index fdcd3c437..7e1dc2468 100644 --- a/tests/app/utils/test_login.py +++ b/tests/app/utils/test_login.py @@ -8,10 +8,10 @@ from app.utils.login import email_needs_revalidating @freeze_time("2020-11-27T12:00:00") @pytest.mark.parametrize( ("email_access_validated_at", "expected_result"), - ( + [ ("2020-10-01T11:35:21.726132Z", False), ("2020-07-23T11:35:21.726132Z", True), - ), + ], ) def test_email_needs_revalidating( api_user_active, diff --git a/tests/app/utils/test_time.py b/tests/app/utils/test_time.py index 1ee6bdd24..931fdb816 100644 --- a/tests/app/utils/test_time.py +++ b/tests/app/utils/test_time.py @@ -5,7 +5,7 @@ from app.utils.time import get_current_financial_year, is_less_than_days_ago @pytest.mark.parametrize( - "date_from_db, expected_result", + ("date_from_db", "expected_result"), [ ("2019-11-17T11:35:21.726132Z", True), ("2019-11-16T11:35:21.726132Z", False), @@ -18,13 +18,13 @@ def test_is_less_than_days_ago(date_from_db, expected_result): @pytest.mark.parametrize( - "datetime_string, financial_year", - ( + ("datetime_string", "financial_year"), + [ ("2021-01-01T00:00:00+00:00", 2020), # Start of 2021 ("2021-04-01T03:59:59+00:00", 2020), # One minute before midnight (BST) ("2021-10-01T04:05:00+00:00", 2021), # Midnight (BST) ("2021-12-12T12:12:12+01:00", 2021), # Later in the year - ), + ], ) def test_get_financial_year(datetime_string, financial_year): with freeze_time(datetime_string): diff --git a/tests/app/utils/test_user.py b/tests/app/utils/test_user.py index e6dde3576..d1fd1b844 100644 --- a/tests/app/utils/test_user.py +++ b/tests/app/utils/test_user.py @@ -7,25 +7,25 @@ from app.utils.user import user_has_permissions @pytest.mark.parametrize( "permissions", - ( - [ + [ + ( # Route has one of the permissions which the user has "manage_service" - ], - [ + ), + ( # Route has more than one of the permissions which the user has "manage_templates", "manage_service", - ], - [ + ), + ( # Route has one of the permissions which the user has, and one they do not "manage_service", "send_messages", - ], - [ + ), + ( # Route has no specific permissions required - ], - ), + ), + ], ) def test_permissions( client_request, @@ -50,12 +50,12 @@ def test_permissions( @pytest.mark.parametrize( "permissions", - ( - [ + [ + ( # Route has a permission which the user doesn’t have "send_messages" - ], - ), + ), + ], ) def test_permissions_forbidden( client_request, diff --git a/tests/app/utils/test_user_permissions.py b/tests/app/utils/test_user_permissions.py index 594b62a27..b2930e458 100644 --- a/tests/app/utils/test_user_permissions.py +++ b/tests/app/utils/test_user_permissions.py @@ -7,7 +7,7 @@ from app.utils.user_permissions import ( @pytest.mark.parametrize( - "db_permissions,expected_ui_permissions", + ("db_permissions", "expected_ui_permissions"), [ ( ["manage_templates"], From 06fab2dd03a9765d231d0b11e6212c89cc5e6255 Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Thu, 7 Sep 2023 17:22:39 -0400 Subject: [PATCH 04/14] Ignoring two specific warnings about wrong values type The test makes use of list item unpacking and expects the parameter data structure to allow for that. It does not make sense to modify the code in this case just to make test format linting pass. Signed-off-by: Carlo Costino --- tests/app/utils/test_user.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/app/utils/test_user.py b/tests/app/utils/test_user.py index d1fd1b844..788813fc3 100644 --- a/tests/app/utils/test_user.py +++ b/tests/app/utils/test_user.py @@ -5,27 +5,27 @@ from werkzeug.exceptions import Forbidden from app.utils.user import user_has_permissions -@pytest.mark.parametrize( +@pytest.mark.parametrize( # noqa: PT007 # Ignoring wrong values type because of the list unpacking in the test. "permissions", - [ - ( + ( + [ # Route has one of the permissions which the user has "manage_service" - ), - ( + ], + [ # Route has more than one of the permissions which the user has "manage_templates", "manage_service", - ), - ( + ], + [ # Route has one of the permissions which the user has, and one they do not "manage_service", "send_messages", - ), - ( + ], + [ # Route has no specific permissions required - ), - ], + ], + ), ) def test_permissions( client_request, @@ -48,14 +48,14 @@ def test_permissions( index() -@pytest.mark.parametrize( +@pytest.mark.parametrize( # noqa: PT007 # Ignoring wrong values type because of the list unpacking in the test. "permissions", - [ - ( + ( + [ # Route has a permission which the user doesn’t have "send_messages" - ), - ], + ], + ), ) def test_permissions_forbidden( client_request, From 23f894581cce419bacd9285fce70ede290d54b0d Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Thu, 7 Sep 2023 17:52:38 -0400 Subject: [PATCH 05/14] More test cleanup Signed-off-by: Carlo Costino --- tests/app/s3_client/test_s3_logo_client.py | 4 ++-- tests/app/test_cloudfoundry_config.py | 2 +- tests/app/test_navigation.py | 4 ++-- tests/app/test_statistics_utils.py | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/app/s3_client/test_s3_logo_client.py b/tests/app/s3_client/test_s3_logo_client.py index 2041d54c1..c6ec7a6f2 100644 --- a/tests/app/s3_client/test_s3_logo_client.py +++ b/tests/app/s3_client/test_s3_logo_client.py @@ -19,14 +19,14 @@ svg_filename = "test.svg" upload_id = "test_uuid" -@pytest.fixture +@pytest.fixture() def upload_filename(fake_uuid): return EMAIL_LOGO_LOCATION_STRUCTURE.format( temp=TEMP_TAG.format(user_id=fake_uuid), unique_id=upload_id, filename=filename ) -@pytest.fixture +@pytest.fixture() def bucket_credentials(notify_admin): return notify_admin.config["LOGO_UPLOAD_BUCKET"] diff --git a/tests/app/test_cloudfoundry_config.py b/tests/app/test_cloudfoundry_config.py index 433f2c73e..6eea0dd95 100644 --- a/tests/app/test_cloudfoundry_config.py +++ b/tests/app/test_cloudfoundry_config.py @@ -13,7 +13,7 @@ bucket_credentials = { } -@pytest.fixture +@pytest.fixture() def vcap_services(): return { "aws-elasticache-redis": [{"credentials": {"uri": "redis://xxx:6379"}}], diff --git a/tests/app/test_navigation.py b/tests/app/test_navigation.py index 59cb0f8f9..e24b4f145 100644 --- a/tests/app/test_navigation.py +++ b/tests/app/test_navigation.py @@ -352,7 +352,7 @@ def test_raises_on_invalid_navigation_item(client_request, navigation_instance): @pytest.mark.parametrize( - "endpoint, selected_nav_item", + ("endpoint", "selected_nav_item"), [ ("main.choose_template", "Send messages"), ("main.manage_users", "Team members"), @@ -392,7 +392,7 @@ def test_a_page_should_nave_selected_navigation_item( @pytest.mark.parametrize( - "endpoint, selected_nav_item", + ("endpoint", "selected_nav_item"), [ ("main.organization_dashboard", "Usage"), ("main.manage_org_users", "Team members"), diff --git a/tests/app/test_statistics_utils.py b/tests/app/test_statistics_utils.py index 1e2b585ee..91c09eb62 100644 --- a/tests/app/test_statistics_utils.py +++ b/tests/app/test_statistics_utils.py @@ -53,7 +53,7 @@ def test_sum_of_statistics_sums_inputs(): @pytest.mark.parametrize( - "emails_failed,emails_requested,expected_failure_rate", + ("emails_failed", "emails_requested", "expected_failure_rate"), [(0, 0, "0"), (0, 1, "0.0"), (1, 3, "33.3")], ) def test_add_rates_sets_email_failure_rate( @@ -72,7 +72,7 @@ def test_add_rates_sets_email_failure_rate( @pytest.mark.parametrize( - "sms_failed,sms_requested,expected_failure_rate", + ("sms_failed", "sms_requested", "expected_failure_rate"), [(0, 0, "0"), (0, 1, "0.0"), (1, 3, "33.3")], ) def test_add_rates_sets_sms_failure_rate( @@ -121,7 +121,7 @@ def test_service_statistics_by_state(): @pytest.mark.parametrize( - "failed, delivered, expected_failure_rate", + ("failed", "delivered", "expected_failure_rate"), [(0, 0, 0), (0, 1, 0), (1, 1, 50), (1, 0, 100), (1, 4, 20)], ) def test_add_rate_to_job_calculates_rate(failed, delivered, expected_failure_rate): From 72c8a46b8c5be16c6af2451f07c3c3cd1492ba15 Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Fri, 8 Sep 2023 17:58:06 -0400 Subject: [PATCH 06/14] Reformatted a handful more tests Signed-off-by: Carlo Costino --- tests/app/main/views/test_sign_in.py | 4 +- tests/app/main/views/test_template_folders.py | 38 ++++----- tests/app/main/views/test_templates.py | 79 +++++++++++-------- tests/app/main/views/test_two_factor.py | 12 +-- tests/app/main/views/test_user_profile.py | 2 +- .../app/main/views/uploads/test_upload_hub.py | 14 ++-- tests/app/models/test_base_model.py | 8 +- tests/app/models/test_event.py | 6 +- tests/app/models/test_job.py | 2 +- tests/app/models/test_organization.py | 4 +- tests/app/models/test_service.py | 4 +- tests/app/models/test_spreadsheet.py | 6 +- tests/app/models/test_template_list.py | 8 +- tests/app/models/test_user.py | 2 +- .../app/notify_client/test_billing_client.py | 2 +- tests/app/notify_client/test_job_client.py | 4 +- .../notify_client/test_notification_client.py | 4 +- .../notify_client/test_organization_client.py | 18 ++--- .../notify_client/test_service_api_client.py | 24 +++--- tests/app/notify_client/test_user_client.py | 14 ++-- tests/app/s3_client/test_s3_logo_client.py | 2 +- 21 files changed, 139 insertions(+), 118 deletions(-) diff --git a/tests/app/main/views/test_sign_in.py b/tests/app/main/views/test_sign_in.py index 9d4e2bddc..63a77f888 100644 --- a/tests/app/main/views/test_sign_in.py +++ b/tests/app/main/views/test_sign_in.py @@ -76,7 +76,7 @@ def test_doesnt_redirect_to_sign_in_if_no_session_info( @pytest.mark.parametrize( - "db_sess_id, cookie_sess_id", + ("db_sess_id", "cookie_sess_id"), [ (None, None), (None, uuid.UUID(int=1)), # BAD - cookie doesn't match db @@ -139,7 +139,7 @@ def test_logged_in_user_doesnt_do_evil_redirect(client_request): ], ) @pytest.mark.parametrize( - "email_address, password", + ("email_address", "password"), [ ("valid@example.gsa.gov", "val1dPassw0rd!"), (" valid@example.gsa.gov ", " val1dPassw0rd! "), diff --git a/tests/app/main/views/test_template_folders.py b/tests/app/main/views/test_template_folders.py index c5410a240..d1bf6c9d0 100644 --- a/tests/app/main/views/test_template_folders.py +++ b/tests/app/main/views/test_template_folders.py @@ -39,15 +39,15 @@ def _folder(name, folder_id=None, parent=None, users_with_permission=None): @pytest.mark.parametrize( ( - "expected_title_tag," - "expected_page_title," - "expected_parent_link_args," - "extra_args," - "expected_nav_links," - "expected_items, " - "expected_displayed_items, " - "expected_searchable_text, " - "expected_empty_message " + "expected_title_tag", + "expected_page_title", + "expected_parent_link_args", + "extra_args", + "expected_nav_links", + "expected_items", + "expected_displayed_items", + "expected_searchable_text", + "expected_empty_message", ), [ ( @@ -1026,10 +1026,10 @@ def test_delete_template_folder_should_detect_non_empty_folder_on_get( @pytest.mark.parametrize( "parent_folder_id", - ( + [ None, PARENT_FOLDER_ID, - ), + ], ) def test_delete_folder( client_request, @@ -1117,7 +1117,9 @@ def test_should_show_checkboxes_for_selecting_templates_assertion_error( mock_get_no_api_keys, user, ): - with pytest.raises(expected_exception=AssertionError): + with pytest.raises( # noqa: PT012 # This will require more research into refactoring. + expected_exception=AssertionError + ): client_request.login(user) page = client_request.get( @@ -1289,7 +1291,7 @@ def test_should_be_able_to_move_to_existing_folder( @pytest.mark.parametrize( - "user, expected_status, expected_called", + ("user", "expected_status", "expected_called"), [ (create_active_user_view_permissions(), 403, False), (create_active_user_with_permissions(), 302, True), @@ -1618,7 +1620,7 @@ def test_radio_button_with_no_value_shows_custom_error_message( @pytest.mark.parametrize( - "data, error_msg", + ("data", "error_msg"), [ # nothing selected when moving ( @@ -1678,10 +1680,10 @@ def test_show_custom_error_message( @pytest.mark.parametrize( ( - "extra_args," - "expected_displayed_items, " - "expected_items, " - "expected_empty_message " + "extra_args", + "expected_displayed_items", + "expected_items", + "expected_empty_message", ), [ ( diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index 71741a4c8..ac22da76c 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -28,8 +28,8 @@ from tests.conftest import ( @pytest.mark.parametrize( - "permissions, expected_message", - ( + ("permissions", "expected_message"), + [ ( ["email"], ( @@ -51,7 +51,7 @@ from tests.conftest import ( "You need a template before you can send messages." ), ), - ), + ], ) def test_should_show_empty_page_when_no_templates( client_request, @@ -100,7 +100,13 @@ def test_should_show_add_template_form_if_service_has_folder_permission( @pytest.mark.parametrize( - "user, expected_page_title, extra_args, expected_nav_links, expected_templates", + ( + "user", + "expected_page_title", + "extra_args", + "expected_nav_links", + "expected_templates", + ), [ ( create_active_user_view_permissions(), @@ -298,9 +304,9 @@ def test_should_show_live_search_if_service_has_lots_of_folders( assert count_of_templates == 4 -@pytest.mark.parametrize( - "service_permissions, expected_values, expected_labels", - ( +@pytest.mark.parametrize( # noqa: PT014 # Requires more research why there are duplicate params here. + ("service_permissions", "expected_values", "expected_labels"), + [ pytest.param( ["email", "sms"], [ @@ -327,7 +333,7 @@ def test_should_show_live_search_if_service_has_lots_of_folders( "Copy an existing template", ], ), - ), + ], ) def test_should_show_new_template_choices_if_service_has_folder_permission( client_request, @@ -363,7 +369,7 @@ def test_should_show_new_template_choices_if_service_has_folder_permission( @pytest.mark.parametrize( - "permissions,are_data_attrs_added", + ("permissions", "are_data_attrs_added"), [ (["sms"], True), (["email"], True), @@ -523,7 +529,7 @@ def test_user_with_only_send_and_view_redirected_to_set_sender_for_one_off( @pytest.mark.parametrize( - "permissions, links_to_be_shown, permissions_warning_to_be_shown", + ("permissions", "links_to_be_shown", "permissions_warning_to_be_shown"), [ ( ["view_activity"], @@ -899,8 +905,8 @@ def test_choose_a_template_to_copy_from_folder_within_service( @pytest.mark.parametrize( - "existing_template_names, expected_name", - ( + ("existing_template_names", "expected_name"), + [ (["Two week reminder"], "Two week reminder (copy)"), (["Two week reminder (copy)"], "Two week reminder (copy 2)"), ( @@ -919,7 +925,7 @@ def test_choose_a_template_to_copy_from_folder_within_service( ["Two week reminder (copy)", "Two week reminder (copy 10)"], "Two week reminder (copy 2)", ), - ), + ], ) def test_load_edit_template_with_copy_of_template( client_request, @@ -1002,8 +1008,8 @@ def test_cant_copy_template_from_non_member_service( @pytest.mark.parametrize( - "service_permissions, data, expected_error", - ( + ("service_permissions", "data", "expected_error"), + [ ( ["email"], { @@ -1012,7 +1018,7 @@ def test_cant_copy_template_from_non_member_service( }, "Sending text messages has been disabled for your service.", ), - ), + ], ) def test_should_not_allow_creation_of_template_through_form_without_correct_permission( client_request, @@ -1040,9 +1046,9 @@ def test_should_not_allow_creation_of_template_through_form_without_correct_perm ) -@pytest.mark.parametrize("method", ("get", "post")) +@pytest.mark.parametrize("method", ["get", "post"]) @pytest.mark.parametrize( - "type_of_template, expected_error", + ("type_of_template", "expected_error"), [ ("email", "Sending emails has been disabled for your service."), ("sms", "Sending text messages has been disabled for your service."), @@ -1236,7 +1242,7 @@ def test_should_403_when_create_template_with_process_type_of_priority_for_non_p @pytest.mark.parametrize( - "old_content, new_content, expected_paragraphs", + ("old_content", "new_content", "expected_paragraphs"), [ ( "my favorite color is blue", @@ -1521,7 +1527,7 @@ def test_should_show_delete_template_page_with_never_used_block( mock_get_service_template.assert_called_with(SERVICE_ONE_ID, fake_uuid, None) -@pytest.mark.parametrize("parent", (PARENT_FOLDER_ID, None)) +@pytest.mark.parametrize("parent", [PARENT_FOLDER_ID, None]) def test_should_redirect_when_deleting_a_template( mocker, client_request, @@ -1706,11 +1712,11 @@ def test_route_invalid_permissions( @pytest.mark.parametrize( - "template_type, expected", - ( + ("template_type", "expected"), + [ ("email", "New email template"), ("sms", "New text message template"), - ), + ], ) def test_add_template_page_title( client_request, @@ -1748,7 +1754,10 @@ def test_can_create_email_template_with_emoji( @pytest.mark.parametrize( - "template_type, expected_error", (("sms", ("You cannot use 🍜 in text messages.")),) + ("template_type", "expected_error"), + [ + ("sms", ("You cannot use 🍜 in text messages.")), + ], ) def test_should_not_create_sms_template_with_emoji( client_request, @@ -1776,7 +1785,10 @@ def test_should_not_create_sms_template_with_emoji( @pytest.mark.parametrize( - "template_type, expected_error", (("sms", ("You cannot use 🍔 in text messages.")),) + ("template_type", "expected_error"), + [ + ("sms", ("You cannot use 🍔 in text messages.")), + ], ) def test_should_not_update_sms_template_with_emoji( mocker, @@ -1815,7 +1827,12 @@ def test_should_not_update_sms_template_with_emoji( assert mock_update_service_template.called is False -@pytest.mark.parametrize("template_type", ("sms",)) +@pytest.mark.parametrize( + "template_type", + [ + "sms", + ], +) def test_should_create_sms_template_without_downgrading_unicode_characters( client_request, service_one, @@ -1944,8 +1961,8 @@ def test_set_template_sender( @pytest.mark.parametrize( - "template_type, prefix_sms, content, expected_message, expected_class", - ( + ("template_type", "prefix_sms", "content", "expected_message", "expected_class"), + [ ( "sms", False, @@ -2068,7 +2085,7 @@ def test_set_template_sender( "Will be charged as 1 text message (not including personalization)", None, ), - ), + ], ) def test_content_count_json_endpoint( client_request, @@ -2103,10 +2120,10 @@ def test_content_count_json_endpoint( @pytest.mark.parametrize( "template_type", - ( + [ "email", "banana", - ), + ], ) def test_content_count_json_endpoint_for_unsupported_template_types( client_request, diff --git a/tests/app/main/views/test_two_factor.py b/tests/app/main/views/test_two_factor.py index b51fbf39a..148aece98 100644 --- a/tests/app/main/views/test_two_factor.py +++ b/tests/app/main/views/test_two_factor.py @@ -9,7 +9,7 @@ from tests.conftest import ( ) -@pytest.fixture +@pytest.fixture() def mock_email_validated_recently(mocker): return mocker.patch( "app.main.views.two_factor.email_needs_revalidating", return_value=False @@ -23,7 +23,7 @@ def mock_email_validated_recently(mocker): "redirect_url", [None, f"/services/{SERVICE_ONE_ID}/templates"] ) @pytest.mark.parametrize( - "email_resent, page_title", [(None, "Check your email"), (True, "Email resent")] + ("email_resent", "page_title"), [(None, "Check your email"), (True, "Email resent")] ) def test_two_factor_email_sent_page( client_request, email_resent, page_title, redirect_url, request_url @@ -168,10 +168,10 @@ def test_should_login_user_and_not_redirect_to_external_url( @pytest.mark.parametrize( "platform_admin", - ( + [ True, False, - ), + ], ) def test_should_login_user_and_redirect_to_show_accounts( client_request, @@ -334,8 +334,8 @@ def test_two_factor_sms_should_activate_pending_user( @pytest.mark.parametrize( - "extra_args, expected_encoded_next_arg", - (({}, ""), ({"next": "https://example.com"}, "?next=https://example.com")), + ("extra_args", "expected_encoded_next_arg"), + [({}, ""), ({"next": "https://example.com"}, "?next=https://example.com")], ) def test_valid_two_factor_email_link_shows_interstitial( client_request, diff --git a/tests/app/main/views/test_user_profile.py b/tests/app/main/views/test_user_profile.py index 9b171a173..6fce5278f 100644 --- a/tests/app/main/views/test_user_profile.py +++ b/tests/app/main/views/test_user_profile.py @@ -80,7 +80,7 @@ def test_should_redirect_after_email_change( @pytest.mark.parametrize( - "email_address,error_message", + ("email_address", "error_message"), [ ( "me@example.com", diff --git a/tests/app/main/views/uploads/test_upload_hub.py b/tests/app/main/views/uploads/test_upload_hub.py index 0756c55fe..2c7140c6c 100644 --- a/tests/app/main/views/uploads/test_upload_hub.py +++ b/tests/app/main/views/uploads/test_upload_hub.py @@ -9,15 +9,17 @@ from tests.conftest import ( ) +@pytest.mark.usefixtures("_mock_get_no_uploads") @pytest.mark.parametrize( - "extra_permissions, expected_empty_message", - (([], ("You have not uploaded any files recently.")),), + ("extra_permissions", "expected_empty_message"), + [ + ([], ("You have not uploaded any files recently.")), + ], ) def test_get_upload_hub_with_no_uploads( mocker, client_request, service_one, - _mock_get_no_uploads, extra_permissions, expected_empty_message, ): @@ -56,18 +58,18 @@ def test_get_upload_hub_page( ) +@pytest.mark.usefixtures("_mock_get_no_uploads") @pytest.mark.parametrize( "user", - ( + [ create_active_caseworking_user(), create_active_user_with_permissions(), - ), + ], ) @freeze_time("2012-12-12 12:12") def test_uploads_page_shows_scheduled_jobs( mocker, client_request, - _mock_get_no_uploads, mock_get_jobs, user, ): diff --git a/tests/app/models/test_base_model.py b/tests/app/models/test_base_model.py index 00c97b361..af69d7c9b 100644 --- a/tests/app/models/test_base_model.py +++ b/tests/app/models/test_base_model.py @@ -26,10 +26,10 @@ def test_raises_when_overriding_custom_properties(): @pytest.mark.parametrize( "json_response", - ( + [ {}, {"foo": "bar"}, # Should still raise an exception - ), + ], ) def test_model_raises_for_unknown_attributes(json_response): class Custom(JSONModel): @@ -56,10 +56,10 @@ def test_model_raises_keyerror_if_item_missing_from_dict(): @pytest.mark.parametrize( "json_response", - ( + [ {}, {"foo": "bar"}, # Should be ignored - ), + ], ) def test_model_doesnt_swallow_attribute_errors(json_response): class Custom(JSONModel): diff --git a/tests/app/models/test_event.py b/tests/app/models/test_event.py index f8dbd29ca..4f64f7a32 100644 --- a/tests/app/models/test_event.py +++ b/tests/app/models/test_event.py @@ -5,8 +5,8 @@ from tests.conftest import sample_uuid @pytest.mark.parametrize( - "key, value_from, value_to, expected", - ( + ("key", "value_from", "value_to", "expected"), + [ ("restricted", True, False, ("Made this service live")), ("restricted", False, True, ("Put this service back into trial mode")), ("active", False, True, ("Unsuspended this service")), @@ -70,7 +70,7 @@ from tests.conftest import sample_uuid "bar", ("Updated the callback for delivery receipts"), ), - ), + ], ) def test_service_event( key, diff --git a/tests/app/models/test_job.py b/tests/app/models/test_job.py index 986f1ebdb..d3a028195 100644 --- a/tests/app/models/test_job.py +++ b/tests/app/models/test_job.py @@ -6,7 +6,7 @@ from tests.conftest import SERVICE_ONE_ID @pytest.mark.parametrize( - "job_status, num_notifications_created, expected_still_processing", + ("job_status", "num_notifications_created", "expected_still_processing"), [ ("scheduled", 0, True), ("cancelled", 10, True), diff --git a/tests/app/models/test_organization.py b/tests/app/models/test_organization.py index 42ee05906..f909b801d 100644 --- a/tests/app/models/test_organization.py +++ b/tests/app/models/test_organization.py @@ -5,8 +5,8 @@ from tests import organization_json @pytest.mark.parametrize( - "purchase_order_number,expected_result", - [[None, None], ["PO1234", [None, None, None, "PO1234"]]], + ("purchase_order_number", "expected_result"), + [(None, None), ("PO1234", [None, None, None, "PO1234"])], ) def test_organization_billing_details(purchase_order_number, expected_result): organization = Organization( diff --git a/tests/app/models/test_service.py b/tests/app/models/test_service.py index 39f3f8f3b..e7bdce4a9 100644 --- a/tests/app/models/test_service.py +++ b/tests/app/models/test_service.py @@ -88,8 +88,8 @@ def test_bad_permission_raises(service_one): @pytest.mark.parametrize( - "purchase_order_number,expected_result", - [[None, None], ["PO1234", [None, None, None, "PO1234"]]], + ("purchase_order_number", "expected_result"), + [(None, None), ("PO1234", [None, None, None, "PO1234"])], ) def test_service_billing_details(purchase_order_number, expected_result): service = Service(service_json(purchase_order_number=purchase_order_number)) diff --git a/tests/app/models/test_spreadsheet.py b/tests/app/models/test_spreadsheet.py index 1e921f180..c62b60b21 100644 --- a/tests/app/models/test_spreadsheet.py +++ b/tests/app/models/test_spreadsheet.py @@ -31,14 +31,14 @@ def test_can_create_spreadsheet_from_dict_with_filename(): @pytest.mark.parametrize( - "args, kwargs", - ( + ("args", "kwargs"), + [ ( ("hello", ["hello"]), {}, ), ((), {"csv_data": "hello", "rows": ["hello"]}), - ), + ], ) def test_spreadsheet_checks_for_bad_arguments(args, kwargs): with pytest.raises(TypeError) as exception: diff --git a/tests/app/models/test_template_list.py b/tests/app/models/test_template_list.py index 959ed4f70..1a620809d 100644 --- a/tests/app/models/test_template_list.py +++ b/tests/app/models/test_template_list.py @@ -12,8 +12,8 @@ VIS_PARENT_FOLDER_ID = "bbbb222b-2b22-2b22-222b-b222b22b2222" INV_CHILD_2_FOLDER_ID = "fafe723f-1d39-4a10-865f-e551e03d8886" -@pytest.fixture -def mock_get_hierarchy_of_folders( +@pytest.fixture() +def _mock_get_hierarchy_of_folders( mock_get_template_folders, active_user_with_permissions ): mock_get_template_folders.return_value = [ @@ -74,8 +74,8 @@ def mock_get_hierarchy_of_folders( ] +@pytest.mark.usefixtures("_mock_get_hierarchy_of_folders") def test_template_list_yields_folders_visible_to_user( - mock_get_hierarchy_of_folders, mock_get_service_templates, service_one, active_user_with_permissions, @@ -98,8 +98,8 @@ def test_template_list_yields_folders_visible_to_user( ) +@pytest.mark.usefixtures("_mock_get_hierarchy_of_folders") def test_template_list_yields_all_folders_without_user( - mock_get_hierarchy_of_folders, mock_get_service_templates, service_one, ): diff --git a/tests/app/models/test_user.py b/tests/app/models/test_user.py index 88df63442..4611d5ea6 100644 --- a/tests/app/models/test_user.py +++ b/tests/app/models/test_user.py @@ -57,7 +57,7 @@ def test_activate_user_already_active( @pytest.mark.parametrize( - "is_platform_admin, value_in_session, expected_result", + ("is_platform_admin", "value_in_session", "expected_result"), [ (True, True, False), (True, False, True), diff --git a/tests/app/notify_client/test_billing_client.py b/tests/app/notify_client/test_billing_client.py index 8486064d9..9bb113efa 100644 --- a/tests/app/notify_client/test_billing_client.py +++ b/tests/app/notify_client/test_billing_client.py @@ -56,7 +56,7 @@ def test_post_free_sms_fragment_limit_for_year_endpoint(mocker, api_user_active) @pytest.mark.parametrize( - "func, expected_url", + ("func", "expected_url"), [ ( BillingAPIClient.get_data_for_volumes_by_service_report, diff --git a/tests/app/notify_client/test_job_client.py b/tests/app/notify_client/test_job_client.py index 99164ed54..7cec603c6 100644 --- a/tests/app/notify_client/test_job_client.py +++ b/tests/app/notify_client/test_job_client.py @@ -327,7 +327,7 @@ def test_cancel_job(mocker): @pytest.mark.parametrize( - "job_data, expected_cache_value", + ("job_data", "expected_cache_value"), [ ( [{"data": [1, 2, 3], "statistics": []}], @@ -364,7 +364,7 @@ def test_has_jobs_sets_cache( @pytest.mark.parametrize( - "cache_value, return_value", + ("cache_value", "return_value"), [ (b"true", True), (b"false", False), diff --git a/tests/app/notify_client/test_notification_client.py b/tests/app/notify_client/test_notification_client.py index 2eee3b2fd..6166334c7 100644 --- a/tests/app/notify_client/test_notification_client.py +++ b/tests/app/notify_client/test_notification_client.py @@ -4,7 +4,7 @@ from app.notify_client.notification_api_client import NotificationApiClient @pytest.mark.parametrize( - "arguments,expected_call", + ("arguments", "expected_call"), [ ({}, {"url": "/service/abcd1234/notifications", "params": {}}), ( @@ -63,7 +63,7 @@ def test_client_gets_notifications_for_service_and_job_by_page( @pytest.mark.parametrize( - "arguments,expected_call", + ("arguments", "expected_call"), [ ( {"to": "2028675309"}, diff --git a/tests/app/notify_client/test_organization_client.py b/tests/app/notify_client/test_organization_client.py index cb63cb3e2..ca7d6839c 100644 --- a/tests/app/notify_client/test_organization_client.py +++ b/tests/app/notify_client/test_organization_client.py @@ -7,12 +7,12 @@ from app import organizations_client @pytest.mark.parametrize( ( - "client_method," - "expected_cache_get_calls," - "cache_value," - "expected_api_calls," - "expected_cache_set_calls," - "expected_return_value," + "client_method", + "expected_cache_get_calls", + "cache_value", + "expected_api_calls", + "expected_cache_set_calls", + "expected_return_value", ), [ ( @@ -132,8 +132,8 @@ def test_deletes_domain_cache( @pytest.mark.parametrize( - "post_data, expected_cache_delete_calls", - ( + ("post_data", "expected_cache_delete_calls"), + [ ( {"foo": "bar"}, [ @@ -149,7 +149,7 @@ def test_deletes_domain_cache( call("domains"), ], ), - ), + ], ) def test_update_organization_when_not_updating_org_type( mocker, diff --git a/tests/app/notify_client/test_service_api_client.py b/tests/app/notify_client/test_service_api_client.py index 75d813d31..acffa3f8a 100644 --- a/tests/app/notify_client/test_service_api_client.py +++ b/tests/app/notify_client/test_service_api_client.py @@ -109,8 +109,8 @@ def test_get_precompiled_template(mocker): @pytest.mark.parametrize( - "template_data, extra_args, expected_count", - ( + ("template_data", "extra_args", "expected_count"), + [ ( [], {}, @@ -137,7 +137,7 @@ def test_get_precompiled_template(mocker): {"template_type": "email"}, 1, ), - ), + ], ) def test_client_returns_count_of_service_templates( notify_admin, @@ -159,13 +159,13 @@ def test_client_returns_count_of_service_templates( @pytest.mark.parametrize( ( - "client_method," - "extra_args," - "expected_cache_get_calls," - "cache_value," - "expected_api_calls," - "expected_cache_set_calls," - "expected_return_value," + "client_method", + "extra_args", + "expected_cache_get_calls", + "cache_value", + "expected_api_calls", + "expected_cache_set_calls", + "expected_return_value", ), [ ( @@ -374,7 +374,7 @@ def test_returns_value_from_cache( @pytest.mark.parametrize( - "client, method, extra_args, extra_kwargs", + ("client", "method", "extra_args", "extra_kwargs"), [ (service_api_client, "update_service", [SERVICE_ONE_ID], {"name": "foo"}), ( @@ -450,7 +450,7 @@ def test_deletes_service_cache( @pytest.mark.parametrize( - "method, extra_args, expected_cache_deletes", + ("method", "extra_args", "expected_cache_deletes"), [ ( "create_service_template", diff --git a/tests/app/notify_client/test_user_client.py b/tests/app/notify_client/test_user_client.py index c2f635626..4ed5fd881 100644 --- a/tests/app/notify_client/test_user_client.py +++ b/tests/app/notify_client/test_user_client.py @@ -141,11 +141,11 @@ def test_client_converts_admin_permissions_to_db_permissions_on_add_to_service( @pytest.mark.parametrize( ( - "expected_cache_get_calls," - "cache_value," - "expected_api_calls," - "expected_cache_set_calls," - "expected_return_value," + "expected_cache_get_calls", + "cache_value", + "expected_api_calls", + "expected_cache_set_calls", + "expected_return_value", ), [ ( @@ -192,8 +192,8 @@ def test_returns_value_from_cache( assert mock_redis_set.call_args_list == expected_cache_set_calls -@pytest.mark.parametrize( - "client, method, extra_args, extra_kwargs", +@pytest.mark.parametrize( # noqa: PT014 # Duplicate add_user_to_service has different params for each + ("client", "method", "extra_args", "extra_kwargs"), [ ( user_api_client, diff --git a/tests/app/s3_client/test_s3_logo_client.py b/tests/app/s3_client/test_s3_logo_client.py index c6ec7a6f2..fd640a002 100644 --- a/tests/app/s3_client/test_s3_logo_client.py +++ b/tests/app/s3_client/test_s3_logo_client.py @@ -134,7 +134,7 @@ def test_does_not_delete_non_temp_email_file(client_request, mocker): "app.s3_client.s3_logo_client.delete_s3_object" ) - with pytest.raises(ValueError) as error: + with pytest.raises(ValueError) as error: # noqa: PT011 # Requires more research. delete_email_temp_file(filename) assert mocked_delete_s3_object.called is False From acb70b43cda6734ec7feb6254472939716ba13af Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Mon, 11 Sep 2023 16:51:30 -0400 Subject: [PATCH 07/14] Reformatted and cleaned up more tests. Signed-off-by: Carlo Costino --- tests/app/main/views/test_history.py | 6 +- tests/app/main/views/test_index.py | 22 +++-- tests/app/main/views/test_jobs.py | 10 +- tests/app/main/views/test_manage_users.py | 34 +++---- tests/app/main/views/test_notifications.py | 16 +-- tests/app/main/views/test_platform_admin.py | 20 ++-- tests/app/main/views/test_providers.py | 20 ++-- tests/app/main/views/test_register.py | 10 +- tests/app/main/views/test_send.py | 103 +++++++++++--------- 9 files changed, 126 insertions(+), 115 deletions(-) diff --git a/tests/app/main/views/test_history.py b/tests/app/main/views/test_history.py index 2535e24fd..184e0b061 100644 --- a/tests/app/main/views/test_history.py +++ b/tests/app/main/views/test_history.py @@ -5,8 +5,8 @@ from tests.conftest import SERVICE_ONE_ID, normalize_spaces @pytest.mark.parametrize( - "extra_args, expected_headings_and_events", - ( + ("extra_args", "expected_headings_and_events"), + [ ( {}, [ @@ -83,7 +83,7 @@ from tests.conftest import SERVICE_ONE_ID, normalize_spaces ), ], ), - ), + ], ) @freeze_time("2012-01-01 01:01:01") def test_history( diff --git a/tests/app/main/views/test_index.py b/tests/app/main/views/test_index.py index 405efc6fd..e9ea4dcf0 100644 --- a/tests/app/main/views/test_index.py +++ b/tests/app/main/views/test_index.py @@ -60,8 +60,8 @@ def test_robots(client_request): @pytest.mark.parametrize( - "endpoint, kwargs", - ( + ("endpoint", "kwargs"), + [ ("sign_in", {}), ("support", {}), ("support_public", {}), @@ -73,7 +73,7 @@ def test_robots(client_request): ("thanks", {}), ("register", {}), pytest.param("index", {}, marks=pytest.mark.xfail(raises=AssertionError)), - ), + ], ) @freeze_time("2012-12-12 12:12") # So we don’t go out of business hours def test_hiding_pages_from_search_engines( @@ -170,12 +170,11 @@ def test_guidance_pages_link_to_service_pages_when_signed_in( @pytest.mark.parametrize( - "view, expected_view", + ("view", "expected_view"), [ ("information_risk_management", "security"), ("old_integration_testing", "integration_testing"), ("old_roadmap", "roadmap"), - ("information_risk_management", "security"), ("old_terms", "terms"), ("information_security", "using_notify"), ("old_using_notify", "using_notify"), @@ -265,8 +264,8 @@ def test_css_is_served_from_correct_path(client_request): @pytest.mark.parametrize( - "extra_args, email_branding_retrieved", - ( + ("extra_args", "email_branding_retrieved"), + [ ( {}, False, @@ -279,7 +278,7 @@ def test_css_is_served_from_correct_path(client_request): {"branding_style": sample_uuid()}, True, ), - ), + ], ) def test_email_branding_preview( client_request, @@ -294,7 +293,12 @@ def test_email_branding_preview( assert mock_get_email_branding.called is email_branding_retrieved -@pytest.mark.parametrize("current_date, expected_rate", (("2022-05-01", "1.72"),)) +@pytest.mark.parametrize( + ("current_date", "expected_rate"), + [ + ("2022-05-01", "1.72"), + ], +) @pytest.mark.skip(reason="Currently hidden for TTS") def test_sms_price( client_request, diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index 8ad57a1f0..a4f72a318 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -37,7 +37,7 @@ def test_old_jobs_hub_redirects( ], ) @pytest.mark.parametrize( - "status_argument, expected_api_call", + ("status_argument", "expected_api_call"), [ ( "", @@ -247,8 +247,8 @@ def test_should_show_job_with_sending_limit_exceeded_status( @freeze_time("2020-01-10 1:0:0") @pytest.mark.parametrize( - "created_at, processing_started, expected_message", - ( + ("created_at", "processing_started", "expected_message"), + [ # Recently created, not yet started (datetime(2020, 1, 10, 0, 0, 0), None, ("No messages to show yet…")), # Just started @@ -284,7 +284,7 @@ def test_should_show_job_with_sending_limit_exceeded_status( "These messages have been deleted because they were sent more than 7 days ago" ), ), - ), + ], ) def test_should_show_old_job( client_request, @@ -469,7 +469,7 @@ def test_should_show_updates_for_scheduled_job_as_json( @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"), diff --git a/tests/app/main/views/test_manage_users.py b/tests/app/main/views/test_manage_users.py index 6d7278d07..99d273ab8 100644 --- a/tests/app/main/views/test_manage_users.py +++ b/tests/app/main/views/test_manage_users.py @@ -20,8 +20,8 @@ from tests.conftest import ( ) -@pytest.mark.parametrize( - "user, expected_self_text, expected_coworker_text", +@pytest.mark.parametrize( # noqa: PT014 # Duplicate parameters have different permissions. + ("user", "expected_self_text", "expected_coworker_text"), [ ( create_active_user_with_permissions(), @@ -174,10 +174,10 @@ def test_should_show_overview_page( @pytest.mark.parametrize( "state", - ( + [ "active", "pending", - ), + ], ) def test_should_show_change_details_link( client_request, @@ -220,10 +220,10 @@ def test_should_show_change_details_link( @pytest.mark.parametrize( "number_of_users", - ( + [ pytest.param(7), pytest.param(8), - ), + ], ) def test_should_show_live_search_if_more_than_7_users( client_request, @@ -324,7 +324,7 @@ def test_should_show_caseworker_on_overview_page( @pytest.mark.parametrize( - "endpoint, extra_args, service_has_email_auth, auth_options_hidden", + ("endpoint", "extra_args", "service_has_email_auth", "auth_options_hidden"), [ ("main.edit_user_permissions", {"user_id": sample_uuid()}, True, False), ("main.edit_user_permissions", {"user_id": sample_uuid()}, False, True), @@ -350,9 +350,9 @@ def test_service_with_no_email_auth_hides_auth_type_options( ) == auth_options_hidden -@pytest.mark.parametrize("service_has_caseworking", (True, False)) +@pytest.mark.parametrize("service_has_caseworking", [True, False]) @pytest.mark.parametrize( - "endpoint, extra_args", + ("endpoint", "extra_args"), [ ( "main.edit_user_permissions", @@ -385,7 +385,7 @@ def test_service_without_caseworking_doesnt_show_admin_vs_caseworker( @pytest.mark.parametrize( - "service_has_email_auth, displays_auth_type", [(True, True), (False, False)] + ("service_has_email_auth", "displays_auth_type"), [(True, True), (False, False)] ) def test_manage_users_page_shows_member_auth_type_if_service_has_email_auth_activated( client_request, @@ -403,7 +403,7 @@ def test_manage_users_page_shows_member_auth_type_if_service_has_email_auth_acti @pytest.mark.parametrize( - "sms_option_disabled, mobile_number, expected_label", + ("sms_option_disabled", "mobile_number", "expected_label"), [ ( True, @@ -455,7 +455,7 @@ def test_user_with_no_mobile_number_cant_be_set_to_sms_auth( @pytest.mark.parametrize( - "endpoint, extra_args, expected_checkboxes", + ("endpoint", "extra_args", "expected_checkboxes"), [ ( "main.edit_user_permissions", @@ -542,7 +542,7 @@ def test_should_not_show_page_for_non_team_member( @pytest.mark.parametrize( - "submitted_permissions, permissions_sent_to_api", + ("submitted_permissions", "permissions_sent_to_api"), [ ( { @@ -1045,7 +1045,7 @@ def test_should_show_folder_permission_form_if_service_has_folder_permissions_en @pytest.mark.parametrize( - "email_address, gov_user", + ("email_address", "gov_user"), [("test@example.gsa.gov", True), ("test@example.com", False)], ) def test_invite_user( @@ -1151,7 +1151,7 @@ def test_invite_user_when_email_address_is_prefilled( @pytest.mark.parametrize("auth_type", [("sms_auth"), ("email_auth")]) @pytest.mark.parametrize( - "email_address, gov_user", + ("email_address", "gov_user"), [("test@example.gsa.gov", True), ("test@example.com", False)], ) def test_invite_user_with_email_auth_service( @@ -1267,7 +1267,7 @@ def test_cancel_invited_user_doesnt_work_if_user_not_invited_to_this_service( @pytest.mark.parametrize( - "invite_status, expected_text", + ("invite_status", "expected_text"), [ ( "pending", @@ -1385,7 +1385,7 @@ def test_no_permission_manage_users_page( @pytest.mark.parametrize( - "folders_user_can_see, expected_message", + ("folders_user_can_see", "expected_message"), [ (3, "Can see all folders"), (2, "Can see 2 folders"), diff --git a/tests/app/main/views/test_notifications.py b/tests/app/main/views/test_notifications.py index 875db4ccc..3f522ae83 100644 --- a/tests/app/main/views/test_notifications.py +++ b/tests/app/main/views/test_notifications.py @@ -14,7 +14,7 @@ from tests.conftest import ( @pytest.mark.parametrize( - "key_type, notification_status, expected_status", + ("key_type", "notification_status", "expected_status"), [ (None, "created", "Sending"), ( @@ -87,7 +87,7 @@ def test_notification_status_page_shows_details( @pytest.mark.parametrize( - "notification_type, notification_status, expected_class", + ("notification_type", "notification_status", "expected_class"), [ ("sms", "failed", "error"), ("email", "failed", "error"), @@ -130,7 +130,7 @@ def test_notification_status_page_formats_email_and_sms_status_correctly( @pytest.mark.parametrize( - "template_redaction_setting, expected_content", + ("template_redaction_setting", "expected_content"), [ (False, "service one: hello Jo"), (True, "service one: hello hidden"), @@ -170,7 +170,7 @@ def test_notification_status_page_respects_redaction( @pytest.mark.parametrize( - "extra_args, expected_back_link", + ("extra_args", "expected_back_link"), [ ( {}, @@ -222,8 +222,8 @@ def test_notification_status_shows_expected_back_link( @pytest.mark.parametrize( - "time_of_viewing_page, expected_message", - ( + ("time_of_viewing_page", "expected_message"), + [ ( "2012-01-01 06:01", ("‘sample template’ was sent by Test User today at 06:01 UTC"), @@ -240,7 +240,7 @@ def test_notification_status_shows_expected_back_link( "2013-01-03 06:01", ("‘sample template’ was sent by Test User on 1 January 2012 at 06:01 UTC"), ), - ), + ], ) def test_notification_page_doesnt_link_to_template_in_tour( mocker, @@ -295,7 +295,7 @@ def test_notification_page_does_not_show_cancel_link_for_sms_or_email_notificati @pytest.mark.parametrize( - "service_permissions, template_type, link_expected", + ("service_permissions", "template_type", "link_expected"), [ ([], "", False), (["inbound_sms"], "email", False), diff --git a/tests/app/main/views/test_platform_admin.py b/tests/app/main/views/test_platform_admin.py index 7b3990901..b3859024e 100644 --- a/tests/app/main/views/test_platform_admin.py +++ b/tests/app/main/views/test_platform_admin.py @@ -52,7 +52,7 @@ def test_should_403_if_not_platform_admin( @pytest.mark.parametrize( - "endpoint, expected_services_shown", + ("endpoint", "expected_services_shown"), [ ("main.live_services", 1), ("main.trial_services", 1), @@ -87,7 +87,7 @@ def test_should_render_platform_admin_page( ], ) @pytest.mark.parametrize( - "partial_url_for, inc", + ("partial_url_for", "inc"), [ (partial(url_for), True), (partial(url_for, include_from_test_key="y", start_date="", end_date=""), True), @@ -137,7 +137,7 @@ def test_live_trial_services_with_date_filter( @pytest.mark.parametrize( - "endpoint, expected_big_numbers", + ("endpoint", "expected_big_numbers"), [ ( "main.live_services", @@ -263,7 +263,7 @@ def test_format_stats_by_service_returns_correct_values(fake_uuid): @pytest.mark.parametrize( - "endpoint, restricted, research_mode", + ("endpoint", "restricted", "research_mode"), [("main.trial_services", True, False), ("main.live_services", False, False)], ) def test_should_show_email_and_sms_stats_for_all_service_types( @@ -311,7 +311,7 @@ def test_should_show_email_and_sms_stats_for_all_service_types( @pytest.mark.parametrize( - "endpoint, restricted", + ("endpoint", "restricted"), [("main.live_services", False), ("main.trial_services", True)], ids=["live", "trial"], ) @@ -363,7 +363,7 @@ def test_should_show_archived_services_last( @pytest.mark.parametrize( - "endpoint, restricted, research_mode", + ("endpoint", "restricted", "research_mode"), [("main.trial_services", True, False), ("main.live_services", False, False)], ) def test_should_order_services_by_usage_with_inactive_last( @@ -561,7 +561,7 @@ def test_platform_admin_list_complaints_returns_404_with_invalid_page( @pytest.mark.parametrize( - "number, total, threshold, result", + ("number", "total", "threshold", "result"), [ (0, 0, 0, False), (1, 1, 0, True), @@ -763,8 +763,8 @@ def test_clear_cache_shows_form( @pytest.mark.parametrize( - "model_type, expected_calls, expected_confirmation", - ( + ("model_type", "expected_calls", "expected_confirmation"), + [ ( "template", [ @@ -793,7 +793,7 @@ def test_clear_cache_shows_form( ], "Removed 18 objects across 9 key formats for service, organization", ), - ), + ], ) def test_clear_cache_submits_and_tells_you_how_many_things_were_deleted( client_request, diff --git a/tests/app/main/views/test_providers.py b/tests/app/main/views/test_providers.py index 482e120e4..d3a79599f 100644 --- a/tests/app/main/views/test_providers.py +++ b/tests/app/main/views/test_providers.py @@ -26,7 +26,7 @@ def provider_json(overrides): return provider -@pytest.fixture +@pytest.fixture() def sms_provider_1(): return provider_json( { @@ -42,7 +42,7 @@ def sms_provider_1(): ) -@pytest.fixture +@pytest.fixture() def sms_provider_2(): return provider_json( { @@ -56,7 +56,7 @@ def sms_provider_2(): ) -@pytest.fixture +@pytest.fixture() def email_provider_1(): return provider_json( { @@ -68,7 +68,7 @@ def email_provider_1(): ) -@pytest.fixture +@pytest.fixture() def email_provider_2(): return provider_json( { @@ -80,7 +80,7 @@ def email_provider_2(): ) -@pytest.fixture +@pytest.fixture() def sms_provider_intl_1(): return provider_json( { @@ -94,7 +94,7 @@ def sms_provider_intl_1(): ) -@pytest.fixture +@pytest.fixture() def sms_provider_intl_2(): return provider_json( { @@ -108,7 +108,7 @@ def sms_provider_intl_2(): ) -@pytest.fixture +@pytest.fixture() def stub_providers( sms_provider_1, sms_provider_2, @@ -129,7 +129,7 @@ def stub_providers( } -@pytest.fixture +@pytest.fixture() def stub_provider_history(): return { "data": [ @@ -365,7 +365,7 @@ def test_edit_sms_provider_provider_ratio_only_shows_active_providers( @pytest.mark.parametrize( - "post_data, expected_calls", + ("post_data", "expected_calls"), [ ( {"sms_provider_1": 10, "sms_provider_2": 90}, @@ -407,7 +407,7 @@ def test_edit_sms_provider_ratio_submit( @pytest.mark.parametrize( - "post_data, expected_error", + ("post_data", "expected_error"), [ ({"sms_provider_1": 90, "sms_provider_2": 20}, "Must add up to 100%"), ({"sms_provider_1": 101, "sms_provider_2": 20}, "Must be between 0 and 100"), diff --git a/tests/app/main/views/test_register.py b/tests/app/main/views/test_register.py index bc6a7b4a6..fc3d24ffa 100644 --- a/tests/app/main/views/test_register.py +++ b/tests/app/main/views/test_register.py @@ -142,10 +142,10 @@ def test_should_return_200_when_email_is_not_gov_uk( @pytest.mark.parametrize( "email_address", - ( + [ "notfound@example.gsa.gov", "example@lsquo.net", - ), + ], ) def test_should_add_user_details_to_session( client_request, @@ -215,7 +215,7 @@ def test_register_with_existing_email_sends_emails( @pytest.mark.parametrize( - "email_address, expected_value", + ("email_address", "expected_value"), [ ("first.last@example.com", "First Last"), ("first.middle.last@example.com", "First Middle Last"), @@ -281,13 +281,13 @@ def test_shows_hidden_email_address_on_registration_page_from_invite( @pytest.mark.parametrize( "extra_data", - ( + [ {}, # The username field is present in the page but the POST request # should ignore it {"username": "invited@user.com"}, {"username": "anythingelse@example.com"}, - ), + ], ) def test_register_from_invite( client_request, diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index 69e68e882..674f2dbd6 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -163,7 +163,7 @@ def test_sms_sender_has_receives_replies_hint( @pytest.mark.parametrize( - "template_type, sender_data", + ("template_type", "sender_data"), [ ( "email", @@ -336,7 +336,7 @@ def test_example_spreadsheet( @pytest.mark.parametrize( - "filename, acceptable_file, expected_status", + ("filename", "acceptable_file", "expected_status"), list(zip(test_spreadsheet_files, repeat(True), repeat(302))) + list(zip(test_non_spreadsheet_files, repeat(False), repeat(200))), ) @@ -412,7 +412,7 @@ def test_send_messages_sanitises_and_truncates_file_name_for_metadata( @pytest.mark.parametrize( - "exception, expected_error_message", + ("exception", "expected_error_message"), [ ( partial(UnicodeDecodeError, "codec", b"", 1, 2, "reason"), @@ -641,7 +641,7 @@ def test_upload_csv_file_with_very_long_placeholder_shows_check_page_with_errors @pytest.mark.parametrize( - "file_contents, expected_error,", + ("file_contents", "expected_error"), [ ( """ @@ -819,7 +819,12 @@ def test_upload_valid_csv_redirects_to_check_page( @pytest.mark.parametrize( - "extra_args, expected_link_in_first_row, expected_recipient, expected_message", + ( + "extra_args", + "expected_link_in_first_row", + "expected_recipient", + "expected_message", + ), [ ( {}, @@ -995,7 +1000,7 @@ def test_show_all_columns_if_there_are_duplicate_recipient_columns( @pytest.mark.parametrize( - "row_index, expected_status", + ("row_index", "expected_status"), [ (0, 404), (1, 404), @@ -1108,10 +1113,10 @@ def test_send_one_off_does_not_send_without_the_correct_permissions( @pytest.mark.parametrize( "user", - ( + [ create_active_user_with_permissions(), create_active_caseworking_user(), - ), + ], ) def test_send_one_off_has_correct_page_title( client_request, @@ -1143,7 +1148,7 @@ def test_send_one_off_has_correct_page_title( @pytest.mark.parametrize( - "step_index, prefilled, expected_field_label", + ("step_index", "prefilled", "expected_field_label"), [ ( 0, @@ -1186,7 +1191,7 @@ def test_send_one_off_shows_placeholders_in_correct_order( @pytest.mark.parametrize( - "user, template_type, expected_link_text, expected_link_url", + ("user", "template_type", "expected_link_text", "expected_link_url"), [ ( create_active_user_with_permissions(), @@ -1244,7 +1249,7 @@ def test_send_one_off_has_skip_link( @pytest.mark.parametrize( - "template_type, expected_sticky", + ("template_type", "expected_sticky"), [ ("sms", False), ("email", True), @@ -1277,10 +1282,10 @@ def test_send_one_off_has_sticky_header_for_email( @pytest.mark.parametrize( "user", - ( + [ create_active_user_with_permissions(), create_active_caseworking_user(), - ), + ], ) def test_skip_link_will_not_show_on_sms_one_off_if_service_has_no_mobile_number( client_request, @@ -1310,10 +1315,10 @@ def test_skip_link_will_not_show_on_sms_one_off_if_service_has_no_mobile_number( @pytest.mark.parametrize( "user", - ( + [ create_active_user_with_permissions(), create_active_caseworking_user(), - ), + ], ) def test_send_one_off_offers_link_to_upload( client_request, @@ -1378,10 +1383,10 @@ def test_send_one_off_has_link_to_use_existing_list( @pytest.mark.parametrize( "user", - ( + [ create_active_user_with_permissions(), create_active_caseworking_user(), - ), + ], ) def test_link_to_upload_not_offered_when_entering_personalisation( client_request, @@ -1413,10 +1418,10 @@ def test_link_to_upload_not_offered_when_entering_personalisation( @pytest.mark.parametrize( "user", - ( + [ create_active_user_with_permissions(), create_active_caseworking_user(), - ), + ], ) def test_send_one_off_redirects_to_end_if_step_out_of_bounds( client_request, @@ -1448,10 +1453,10 @@ def test_send_one_off_redirects_to_end_if_step_out_of_bounds( @pytest.mark.parametrize( "user", - ( + [ create_active_user_with_permissions(), create_active_caseworking_user(), - ), + ], ) def test_send_one_off_redirects_to_start_if_you_skip_steps( client_request, @@ -1483,10 +1488,10 @@ def test_send_one_off_redirects_to_start_if_you_skip_steps( @pytest.mark.parametrize( "user", - ( + [ create_active_user_with_permissions(), create_active_caseworking_user(), - ), + ], ) def test_send_one_off_redirects_to_start_if_index_out_of_bounds_and_some_placeholders_empty( client_request, @@ -1520,10 +1525,10 @@ def test_send_one_off_redirects_to_start_if_index_out_of_bounds_and_some_placeho @pytest.mark.parametrize( "user", - ( + [ create_active_user_with_permissions(), create_active_caseworking_user(), - ), + ], ) def test_send_one_off_sms_message_redirects( client_request, @@ -1552,10 +1557,10 @@ def test_send_one_off_sms_message_redirects( @pytest.mark.parametrize( "user", - ( + [ create_active_user_with_permissions(), create_active_caseworking_user(), - ), + ], ) def test_send_one_off_email_to_self_without_placeholders_redirects_to_check_page( client_request, @@ -1587,8 +1592,8 @@ def test_send_one_off_email_to_self_without_placeholders_redirects_to_check_page @pytest.mark.parametrize( - "permissions, expected_back_link_endpoint, extra_args", - ( + ("permissions", "expected_back_link_endpoint", "extra_args"), + [ ( {"send_messages", "manage_templates"}, "main.view_template", @@ -1604,7 +1609,7 @@ def test_send_one_off_email_to_self_without_placeholders_redirects_to_check_page "main.choose_template", {}, ), - ), + ], ) def test_send_one_off_step_0_back_link( client_request, @@ -1819,7 +1824,7 @@ def test_upload_csvfile_with_valid_phone_shows_all_numbers( @pytest.mark.parametrize( - "international_sms_permission, should_allow_international", + ("international_sms_permission", "should_allow_international"), [ (False, False), (True, True), @@ -1975,7 +1980,7 @@ def test_create_job_should_call_api( @pytest.mark.parametrize( - "route, response_code", + ("route", "response_code"), [ ("main.send_messages", 200), ("main.get_example_csv", 200), @@ -2011,7 +2016,7 @@ def test_route_permissions( @pytest.mark.parametrize( - "route, response_code, method", + ("route", "response_code", "method"), [("main.check_notification", 200, "GET"), ("main.send_notification", 302, "POST")], ) def test_route_permissions_send_check_notifications( @@ -2043,7 +2048,7 @@ def test_route_permissions_send_check_notifications( @pytest.mark.parametrize( - "route, expected_status", + ("route", "expected_status"), [ ("main.send_messages", 403), ("main.get_example_csv", 403), @@ -2083,7 +2088,7 @@ def test_route_permissions_sending( @pytest.mark.parametrize( - "template_type, has_placeholders, extra_args, expected_url", + ("template_type", "has_placeholders", "extra_args", "expected_url"), [ ("sms", False, dict(), partial(url_for, ".send_messages")), ("sms", True, dict(), partial(url_for, ".send_messages")), @@ -2142,7 +2147,7 @@ def test_check_messages_back_link( @pytest.mark.parametrize( - "num_requested,expected_msg", + ("num_requested", "expected_msg"), [ (None, "‘example.csv’ contains 1,234 phone numbers."), ("0", "‘example.csv’ contains 1,234 phone numbers."), @@ -2245,10 +2250,10 @@ def test_check_messages_shows_trial_mode_error( @pytest.mark.parametrize( "uploaded_file_name", - ( + [ pytest.param("applicants.ods"), # normal job pytest.param("send_me_later.csv"), # should look at scheduled job - ), + ], ) def test_warns_if_file_sent_already( client_request, @@ -2289,10 +2294,10 @@ def test_warns_if_file_sent_already( @pytest.mark.parametrize( "uploaded_file_name", - ( + [ pytest.param("thisisatest.csv"), # different template version pytest.param("full_of_regret.csv"), # job is cancelled - ), + ], ) def test_warns_if_file_sent_already_errors( client_request, @@ -2315,7 +2320,9 @@ def test_warns_if_file_sent_already_errors( return_value={"original_file_name": uploaded_file_name}, ) # Should be botocore.errorfactory.NoSuchKey but for some reason can't use that - with pytest.raises(expected_exception=Exception): + with pytest.raises( # noqa: PT011,PT012 # Requires more research on how to refactor. + expected_exception=Exception + ): page = client_request.get( "main.check_messages", service_id=SERVICE_ONE_ID, @@ -2516,8 +2523,8 @@ def test_check_notification_shows_preview( @pytest.mark.parametrize( - "template, recipient, placeholders, expected_personalisation", - ( + ("template", "recipient", "placeholders", "expected_personalisation"), + [ ( mock_get_service_template, "2028675301", @@ -2530,7 +2537,7 @@ def test_check_notification_shows_preview( {}, {}, ), - ), + ], ) def test_send_notification_submits_data( client_request, @@ -2609,7 +2616,7 @@ def test_send_notification_redirects_if_missing_data( @pytest.mark.parametrize( - "extra_args, extra_redirect_args", [({}, {}), ({"help": "3"}, {"help": "3"})] + ("extra_args", "extra_redirect_args"), [({}, {}), ({"help": "3"}, {"help": "3"})] ) def test_send_notification_redirects_to_view_page( client_request, @@ -2647,7 +2654,7 @@ SERVICE_DAILY_LIMIT_MSG = "Exceeded send limits (1000) for today" @pytest.mark.parametrize( - "exception_msg, expected_h1, expected_err_details", + ("exception_msg", "expected_h1", "expected_err_details"), [ ( TRIAL_MODE_MSG, @@ -2736,7 +2743,7 @@ def test_send_notification_shows_email_error_in_trial_mode( @pytest.mark.parametrize( - "endpoint, extra_args", + ("endpoint", "extra_args"), [ ("main.check_messages", {"template_id": uuid4(), "upload_id": uuid4()}), ("main.send_one_off_step", {"template_id": uuid4(), "step_index": 0}), @@ -2791,7 +2798,7 @@ def test_reply_to_is_previewed_if_chosen( @pytest.mark.parametrize( - "endpoint, extra_args", + ("endpoint", "extra_args"), [ ("main.check_messages", {"template_id": uuid4(), "upload_id": uuid4()}), ("main.send_one_off_step", {"template_id": uuid4(), "step_index": 0}), From 9031d0cb977dd0ec0797a07eb34a24f9768d4261 Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Mon, 11 Sep 2023 17:02:56 -0400 Subject: [PATCH 08/14] A few more tests taken care of. Signed-off-by: Carlo Costino --- tests/app/main/views/test_email_branding.py | 4 +- tests/app/main/views/test_email_preview.py | 2 +- tests/app/main/views/test_feedback.py | 59 ++++++++++++--------- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/tests/app/main/views/test_email_branding.py b/tests/app/main/views/test_email_branding.py index 672d41f35..fe86c108c 100644 --- a/tests/app/main/views/test_email_branding.py +++ b/tests/app/main/views/test_email_branding.py @@ -217,7 +217,7 @@ def test_create_new_email_branding_when_branding_saved( @pytest.mark.parametrize( - "endpoint, has_data", + ("endpoint", "has_data"), [ ("main.create_email_branding", False), ("main.update_email_branding", True), @@ -416,7 +416,7 @@ def test_logo_does_not_get_persisted_if_updating_email_branding_client_throws_an @pytest.mark.parametrize( - "colour_hex, expected_status_code", + ("colour_hex", "expected_status_code"), [ ("#FF00FF", 302), ("hello", 200), diff --git a/tests/app/main/views/test_email_preview.py b/tests/app/main/views/test_email_preview.py index 082394018..60604a9f3 100644 --- a/tests/app/main/views/test_email_preview.py +++ b/tests/app/main/views/test_email_preview.py @@ -4,7 +4,7 @@ import pytest @pytest.mark.parametrize( - "query_args, result", [({}, True), ({"govuk_banner": "false"}, "false")] + ("query_args", "result"), [({}, True), ({"govuk_banner": "false"}, "false")] ) def test_renders(client_request, mocker, query_args, result): mocker.patch( diff --git a/tests/app/main/views/test_feedback.py b/tests/app/main/views/test_feedback.py index 89f757bff..e3ab37e93 100644 --- a/tests/app/main/views/test_feedback.py +++ b/tests/app/main/views/test_feedback.py @@ -68,7 +68,7 @@ def test_get_support_index_page_when_signed_out( @freeze_time("2016-12-12 12:00:00.000000") @pytest.mark.parametrize( - "support_type, expected_h1", + ("support_type", "expected_h1"), [ (PROBLEM_TICKET_TYPE, "Report a problem"), (QUESTION_TICKET_TYPE, "Ask a question or give feedback"), @@ -130,7 +130,7 @@ def test_get_support_as_member_of_public( @freeze_time("2016-12-12 12:00:00.000000") @pytest.mark.parametrize( - "ticket_type, expected_status_code", + ("ticket_type", "expected_status_code"), [(PROBLEM_TICKET_TYPE, 200), (QUESTION_TICKET_TYPE, 200), ("gripe", 404)], ) def test_get_feedback_page(client_request, ticket_type, expected_status_code): @@ -144,7 +144,7 @@ def test_get_feedback_page(client_request, ticket_type, expected_status_code): @freeze_time("2016-12-12 12:00:00.000000") @pytest.mark.parametrize( - "ticket_type, zendesk_ticket_type", + ("ticket_type", "zendesk_ticket_type"), [ (PROBLEM_TICKET_TYPE, "incident"), (QUESTION_TICKET_TYPE, "question"), @@ -202,7 +202,7 @@ def test_passed_non_logged_in_user_details_through_flow( ], ) @pytest.mark.parametrize( - "ticket_type, zendesk_ticket_type", + ("ticket_type", "zendesk_ticket_type"), [ (PROBLEM_TICKET_TYPE, "incident"), (QUESTION_TICKET_TYPE, "question"), @@ -294,7 +294,7 @@ def test_email_address_required_for_problems_and_questions( @freeze_time("2016-12-12 12:00:00.000000") -@pytest.mark.parametrize("ticket_type", (PROBLEM_TICKET_TYPE, QUESTION_TICKET_TYPE)) +@pytest.mark.parametrize("ticket_type", [PROBLEM_TICKET_TYPE, QUESTION_TICKET_TYPE]) def test_email_address_must_be_valid_if_provided_to_support_form( client_request, mocker, @@ -317,7 +317,7 @@ def test_email_address_must_be_valid_if_provided_to_support_form( @pytest.mark.parametrize( - "ticket_type, severe, is_in_business_hours, is_out_of_hours_emergency", + ("ticket_type", "severe", "is_in_business_hours", "is_out_of_hours_emergency"), [ # business hours, never an emergency (PROBLEM_TICKET_TYPE, "yes", True, False), @@ -408,8 +408,12 @@ ids, params = zip( @pytest.mark.parametrize( ( - "ticket_type, is_in_business_hours, logged_in, has_live_services," - "expected_status, expected_redirect" + "ticket_type", + "is_in_business_hours", + "logged_in", + "has_live_services", + "expected_status", + "expected_redirect", ), params, ids=ids, @@ -446,11 +450,11 @@ def test_redirects_to_triage( @pytest.mark.parametrize( - "ticket_type, expected_h1", - ( + ("ticket_type", "expected_h1"), + [ (PROBLEM_TICKET_TYPE, "Report a problem"), (GENERAL_TICKET_TYPE, "Contact Notify.gov support"), - ), + ], ) def test_options_on_triage_page( client_request, @@ -492,7 +496,7 @@ def test_doesnt_lose_message_if_post_across_closing( @pytest.mark.parametrize( - "when, is_in_business_hours", + ("when", "is_in_business_hours"), [ ("2016-06-06 09:29:59+0100", False), # opening time, summer and winter ("2016-12-12 09:29:59+0000", False), @@ -513,13 +517,13 @@ def test_in_business_hours(when, is_in_business_hours): @pytest.mark.parametrize( "ticket_type", - ( + [ GENERAL_TICKET_TYPE, PROBLEM_TICKET_TYPE, - ), + ], ) @pytest.mark.parametrize( - "choice, expected_redirect_param", + ("choice", "expected_redirect_param"), [ ("yes", "yes"), ("no", "no"), @@ -545,7 +549,7 @@ def test_triage_redirects_to_correct_url( @pytest.mark.parametrize( - "extra_args, expected_back_link", + ("extra_args", "expected_back_link"), [ ( {"severe": "yes"}, @@ -575,9 +579,12 @@ def test_back_link_from_form( @pytest.mark.parametrize( ( - "is_in_business_hours, severe," - "expected_status_code, expected_redirect," - "expected_status_code_when_logged_in, expected_redirect_when_logged_in" + "is_in_business_hours", + "severe", + "expected_status_code", + "expected_redirect", + "expected_status_code_when_logged_in", + "expected_redirect_when_logged_in", ), [ (True, "yes", 200, no_redirect(), 200, no_redirect()), @@ -658,9 +665,11 @@ def test_should_be_shown_the_bat_email( @pytest.mark.parametrize( ( - "severe," - "expected_status_code, expected_redirect," - "expected_status_code_when_logged_in, expected_redirect_when_logged_in" + "severe", + "expected_status_code", + "expected_redirect", + "expected_status_code_when_logged_in", + "expected_redirect_when_logged_in", ), [ # User hasn’t answered the triage question @@ -743,8 +752,8 @@ def test_bat_email_page( @pytest.mark.parametrize( - "out_of_hours_emergency, email_address_provided, out_of_hours, message", - ( + ("out_of_hours_emergency", "email_address_provided", "out_of_hours", "message"), + [ # Out of hours emergencies trump everything else ( True, @@ -780,7 +789,7 @@ def test_bat_email_page( "We’ll aim to read your message in the next 30 minutes and we’ll reply within one working day.", ), (False, True, True, "We’ll reply within one working day."), - ), + ], ) def test_thanks( client_request, From d2411e6cbe6e2480db225d0750a16b743a6eb655 Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Fri, 15 Sep 2023 09:48:35 -0400 Subject: [PATCH 09/14] Updated a few more tests Signed-off-by: Carlo Costino --- tests/app/main/views/test_conversation.py | 2 +- tests/app/main/views/test_dashboard.py | 32 +++++++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/tests/app/main/views/test_conversation.py b/tests/app/main/views/test_conversation.py index c0b82fda1..3e8459cd7 100644 --- a/tests/app/main/views/test_conversation.py +++ b/tests/app/main/views/test_conversation.py @@ -64,7 +64,7 @@ def test_get_user_phone_number_raises_if_both_api_requests_fail(mocker): @pytest.mark.parametrize( - "outbound_redacted, expected_outbound_content", + ("outbound_redacted", "expected_outbound_content"), [ (True, "Hello hidden"), (False, "Hello Jo"), diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index 4871caea8..1e2efd670 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -62,10 +62,10 @@ stub_template_stats = [ @pytest.mark.parametrize( "user", - ( + [ create_active_user_view_permissions(), create_active_caseworking_user(), - ), + ], ) def test_redirect_from_old_dashboard( client_request, @@ -226,7 +226,7 @@ def test_inbound_messages_shows_count_of_messages_when_there_are_no_messages( @pytest.mark.parametrize( - "index, expected_row", + ("index", "expected_row"), enumerate( [ "(202) 867-5300 message-1 1 hour ago", @@ -407,7 +407,7 @@ def test_download_inbox( @freeze_time("2016-07-01 13:00") @pytest.mark.parametrize( - "message_content, expected_cell", + ("message_content", "expected_cell"), [ ("=2+5", "2+5"), ("==2+5", "2+5"), @@ -488,7 +488,7 @@ def test_should_show_recent_templates_on_dashboard( @pytest.mark.parametrize( "stats", - ( + [ pytest.param( [stub_template_stats[0]], ), @@ -496,7 +496,7 @@ def test_should_show_recent_templates_on_dashboard( [stub_template_stats[0], stub_template_stats[1]], marks=pytest.mark.xfail(raises=AssertionError), ), - ), + ], ) def test_should_not_show_recent_templates_on_dashboard_if_only_one_template_used( client_request, @@ -716,7 +716,12 @@ def test_should_not_show_upcoming_jobs_on_dashboard_if_service_has_no_jobs( assert "files waiting to send " not in page.select_one("main").text -@pytest.mark.parametrize("permissions", (["email", "sms"],)) +@pytest.mark.parametrize( + "permissions", + [ + ("email", "sms"), + ], +) @pytest.mark.parametrize( "totals", [ @@ -899,7 +904,7 @@ def test_usage_page_monthly_breakdown( @pytest.mark.parametrize( - "now, expected_number_of_months", + ("now", "expected_number_of_months"), [ (freeze_time("2017-03-31 11:09:00.061258"), 6), (freeze_time("2017-01-01 11:09:00.061258"), 4), @@ -1243,7 +1248,7 @@ def test_get_dashboard_totals_adds_percentages(): assert get_dashboard_totals(stats)["email"]["failed_percentage"] == "0" -@pytest.mark.parametrize("failures,expected", [(2, False), (3, False), (4, True)]) +@pytest.mark.parametrize(("failures", "expected"), [(2, False), (3, False), (4, True)]) def test_get_dashboard_totals_adds_warning(failures, expected): stats = {"sms": {"requested": 100, "delivered": 0, "failed": failures}} assert get_dashboard_totals(stats)["sms"]["show_warning"] == expected @@ -1286,7 +1291,7 @@ def _stats(requested, delivered, failed): @pytest.mark.parametrize( - "dict_in, expected_failed, expected_requested", + ("dict_in", "expected_failed", "expected_requested"), [ ({}, 0, 0), ( @@ -1497,7 +1502,12 @@ def test_breadcrumb_shows_if_service_is_suspended( assert "Suspended" in page.select_one(".navigation-service-name").text -@pytest.mark.parametrize("permissions", (["email", "sms"],)) +@pytest.mark.parametrize( + "permissions", + [ + ("email", "sms"), + ], +) def test_service_dashboard_shows_usage( client_request, service_one, From 9a4afe44bb33b6d5b96cce84b8d10b09ecaacf87 Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Mon, 25 Sep 2023 17:55:42 -0400 Subject: [PATCH 10/14] 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 --- tests/app/main/views/test_accept_invite.py | 46 ++++++++++---------- tests/app/main/views/test_activity.py | 38 +++++++++------- tests/app/main/views/test_add_service.py | 22 +++++----- tests/app/main/views/test_api_integration.py | 16 +++---- 4 files changed, 64 insertions(+), 58 deletions(-) diff --git a/tests/app/main/views/test_accept_invite.py b/tests/app/main/views/test_accept_invite.py index 03fd3d920..696a3ea83 100644 --- a/tests/app/main/views/test_accept_invite.py +++ b/tests/app/main/views/test_accept_invite.py @@ -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, diff --git a/tests/app/main/views/test_activity.py b/tests/app/main/views/test_activity.py index b6acde247..ae3d44fdf 100644 --- a/tests/app/main/views/test_activity.py +++ b/tests/app/main/views/test_activity.py @@ -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), diff --git a/tests/app/main/views/test_add_service.py b/tests/app/main/views/test_add_service.py index 9247de02a..412fc475d 100644 --- a/tests/app/main/views/test_add_service.py +++ b/tests/app/main/views/test_add_service.py @@ -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", - ( + [ # User’s email address doesn’t 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"), diff --git a/tests/app/main/views/test_api_integration.py b/tests/app/main/views/test_api_integration.py index 373bd5cd5..18ff4fdcb 100644 --- a/tests/app/main/views/test_api_integration.py +++ b/tests/app/main/views/test_api_integration.py @@ -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"), ( From f5a5fbc926148295187d276880fa04ff1f9a75fd Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Fri, 29 Sep 2023 16:37:11 -0400 Subject: [PATCH 11/14] Updated more tests with linting fixes Signed-off-by: Carlo Costino --- .../service_settings/test_service_settings.py | 396 +++++++++--------- 1 file changed, 202 insertions(+), 194 deletions(-) diff --git a/tests/app/main/views/service_settings/test_service_settings.py b/tests/app/main/views/service_settings/test_service_settings.py index b290951d7..ea2818473 100644 --- a/tests/app/main/views/service_settings/test_service_settings.py +++ b/tests/app/main/views/service_settings/test_service_settings.py @@ -38,8 +38,8 @@ from tests.conftest import ( FAKE_TEMPLATE_ID = uuid4() -@pytest.fixture -def mock_get_service_settings_page_common( +@pytest.fixture() +def _mock_get_service_settings_page_common( mock_get_inbound_number_for_service, mock_get_free_sms_fragment_limit, mock_get_service_data_retention, @@ -48,8 +48,9 @@ def mock_get_service_settings_page_common( return +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") @pytest.mark.parametrize( - "user, expected_rows", + ("user", "expected_rows"), [ ( create_active_user_with_permissions(), @@ -98,7 +99,6 @@ def test_should_show_overview( single_sms_sender, user, expected_rows, - mock_get_service_settings_page_common, ): service_one = service_json( SERVICE_ONE_ID, @@ -121,13 +121,13 @@ def test_should_show_overview( app.service_api_client.get_service.assert_called_with(SERVICE_ONE_ID) +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") def test_no_go_live_link_for_service_without_organization( client_request, mocker, no_reply_to_email_addresses, single_sms_sender, platform_admin_user, - mock_get_service_settings_page_common, ): mocker.patch("app.organizations_client.get_organization", return_value=None) client_request.login(platform_admin_user) @@ -154,12 +154,12 @@ def test_no_go_live_link_for_service_without_organization( ) +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") def test_organization_name_links_to_org_dashboard( client_request, platform_admin_user, no_reply_to_email_addresses, single_sms_sender, - mock_get_service_settings_page_common, mocker, ): service_one = service_json( @@ -183,8 +183,9 @@ def test_organization_name_links_to_org_dashboard( @pytest.mark.skip(reason="Email currently deactivated") +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") @pytest.mark.parametrize( - "service_contact_link,expected_text", + ("service_contact_link", "expected_text"), [ ( "contact.me@gsa.gov", @@ -198,7 +199,6 @@ def test_send_files_by_email_row_on_settings_page( platform_admin_user, no_reply_to_email_addresses, single_sms_sender, - mock_get_service_settings_page_common, mocker, service_contact_link, expected_text, @@ -223,8 +223,9 @@ def test_send_files_by_email_row_on_settings_page( assert normalize_spaces(org_row.get_text()) == expected_text +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") @pytest.mark.parametrize( - "permissions, expected_rows", + ("permissions", "expected_rows"), [ ( ["email", "sms", "international_sms"], @@ -256,7 +257,6 @@ def test_should_show_overview_for_service_with_more_things_set( single_reply_to_email_address, single_sms_sender, mock_get_email_branding, - mock_get_service_settings_page_common, permissions, expected_rows, ): @@ -351,7 +351,7 @@ def test_should_show_service_name_with_no_prefixing( @pytest.mark.parametrize( - "name, error_message", + ("name", "error_message"), [ ("", "Cannot be empty"), (".", "Must include at least two alphanumeric characters"), @@ -374,8 +374,9 @@ def test_service_name_change_fails_if_new_name_fails_validation( assert error_message in page.find("span", {"class": "usa-error-message"}).text +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") @pytest.mark.parametrize( - "user, expected_text, expected_link", + ("user", "expected_text", "expected_link"), [ ( create_active_user_with_permissions(), @@ -394,7 +395,6 @@ def test_show_restricted_service( service_one, single_reply_to_email_address, single_sms_sender, - mock_get_service_settings_page_common, user, expected_text, expected_link, @@ -446,12 +446,12 @@ def test_switch_service_to_live( ) +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") def test_show_live_service( client_request, mock_get_live_service, single_reply_to_email_address, single_sms_sender, - mock_get_service_settings_page_common, ): page = client_request.get( "main.service_settings", @@ -485,11 +485,11 @@ def test_switch_service_to_restricted( @pytest.mark.parametrize( - "count_as_live, selected, labelled", - ( + ("count_as_live", "selected", "labelled"), + [ (True, "True", "Yes"), (False, "False", "No"), - ), + ], ) def test_show_switch_service_to_count_as_live_page( mocker, @@ -521,11 +521,11 @@ def test_show_switch_service_to_count_as_live_page( @pytest.mark.parametrize( - "post_data, expected_persisted_value", - ( + ("post_data", "expected_persisted_value"), + [ ("True", True), ("False", False), - ), + ], ) def test_switch_service_to_count_as_live( client_request, @@ -589,7 +589,7 @@ def test_should_redirect_after_service_name_change( @pytest.mark.parametrize( - "volumes, consent_to_research, expected_estimated_volumes_item", + ("volumes", "consent_to_research", "expected_estimated_volumes_item"), [ ((0, 0), None, "Tell us how many messages you expect to send Not completed"), ((1, 0), None, "Tell us how many messages you expect to send Not completed"), @@ -636,10 +636,10 @@ def test_should_check_if_estimated_volumes_provided( @pytest.mark.parametrize( ( - "volume_email," - "count_of_email_templates," - "reply_to_email_addresses," - "expected_reply_to_checklist_item" + "volume_email", + "count_of_email_templates", + "reply_to_email_addresses", + "expected_reply_to_checklist_item", ), [ (None, 1, [], "Add a reply-to email address Not completed"), @@ -698,10 +698,10 @@ def test_should_check_for_reply_to_on_go_live( @pytest.mark.parametrize( ( - "volume_email," - "count_of_email_templates," - "reply_to_email_addresses," - "expected_reply_to_checklist_item" + "volume_email", + "count_of_email_templates", + "reply_to_email_addresses", + "expected_reply_to_checklist_item", ), [ (None, 0, [], ""), @@ -744,7 +744,9 @@ def test_should_check_for_reply_to_on_go_live_index_error( return_value=volume, ) - with pytest.raises(expected_exception=IndexError): + with pytest.raises( # noqa: PT012 # This will require more research for refactoring. + expected_exception=IndexError + ): page = client_request.get("main.request_to_go_live", service_id=SERVICE_ONE_ID) assert page.h1.text == "Before you request to go live" @@ -757,9 +759,9 @@ def test_should_check_for_reply_to_on_go_live_index_error( @pytest.mark.parametrize( ( - "count_of_users_with_manage_service," - "count_of_invites_with_manage_service," - "expected_user_checklist_item" + "count_of_users_with_manage_service", + "count_of_invites_with_manage_service", + "expected_user_checklist_item", ), [ ( @@ -772,7 +774,7 @@ def test_should_check_for_reply_to_on_go_live_index_error( ], ) @pytest.mark.parametrize( - "count_of_templates, expected_templates_checklist_item", + ("count_of_templates", "expected_templates_checklist_item"), [ ( 0, @@ -850,12 +852,11 @@ def test_should_check_for_sending_things_right( @pytest.mark.parametrize( - "checklist_completed, expected_button", - ( - (True, True), + ("checklist_completed", "expected_button"), + [ (True, True), (False, False), - ), + ], ) def test_should_not_show_go_live_button_if_checklist_not_complete( client_request, @@ -907,7 +908,7 @@ def test_should_not_show_go_live_button_if_checklist_not_complete( @pytest.mark.parametrize( - "go_live_at, message", + ("go_live_at", "message"), [ (None, "‘service one’ is already live."), ("2020-10-09 13:55:20", "‘service one’ went live on 9 October 2020."), @@ -933,11 +934,11 @@ def test_request_to_go_live_redirects_if_service_already_live( @pytest.mark.parametrize( ( - "estimated_sms_volume," - "organization_type," - "count_of_sms_templates," - "sms_senders," - "expected_sms_sender_checklist_item" + "estimated_sms_volume", + "organization_type", + "count_of_sms_templates", + "sms_senders", + "expected_sms_sender_checklist_item", ), [ ( @@ -954,13 +955,6 @@ def test_request_to_go_live_redirects_if_service_already_live( [{"is_default": True, "sms_sender": "GOVUK"}], "", ), - ( - 1, - "federal", - 99, - [{"is_default": True, "sms_sender": "GOVUK"}], - "", - ), ( None, "federal", @@ -1036,7 +1030,9 @@ def test_should_check_for_sms_sender_on_go_live( return_value=volume, ) - with pytest.raises(expected_exception=IndexError): + with pytest.raises( # noqa: PT012 # Requires more research for how to refactor. + expected_exception=IndexError + ): page = client_request.get("main.request_to_go_live", service_id=SERVICE_ONE_ID) assert page.h1.text == "Before you request to go live" @@ -1084,16 +1080,16 @@ def test_non_gov_user_is_told_they_cant_go_live( @pytest.mark.parametrize( - "consent_to_research, displayed_consent", - ( + ("consent_to_research", "displayed_consent"), + [ (None, None), (True, "yes"), (False, "no"), - ), + ], ) @pytest.mark.parametrize( - "volumes, displayed_volumes", - ( + ("volumes", "displayed_volumes"), + [ ( (("email", None), ("sms", None)), (None, None), @@ -1102,7 +1098,7 @@ def test_non_gov_user_is_told_they_cant_go_live( (("email", 1234), ("sms", 0)), ("1,234", "0"), ), - ), + ], ) def test_should_show_estimate_volumes( mocker, @@ -1163,11 +1159,11 @@ def test_should_show_estimate_volumes( @pytest.mark.parametrize( - "consent_to_research, expected_persisted_consent_to_research", - ( + ("consent_to_research", "expected_persisted_consent_to_research"), + [ ("yes", True), ("no", False), - ), + ], ) def test_should_show_persist_estimated_volumes( client_request, @@ -1198,8 +1194,8 @@ def test_should_show_persist_estimated_volumes( @pytest.mark.parametrize( - "data, error_selector, expected_error_message", - ( + ("data", "error_selector", "expected_error_message"), + [ ( { "volume_email": "1234", @@ -1218,7 +1214,7 @@ def test_should_show_persist_estimated_volumes( '[data-error-label="consent_to_research"]', "Select yes or no", ), - ), + ], ) def test_should_error_if_bad_estimations_given( client_request, @@ -1295,9 +1291,10 @@ def test_non_gov_users_cant_request_to_go_live( ) +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") @pytest.mark.parametrize( - "volumes, displayed_volumes, formatted_displayed_volumes", - ( + ("volumes", "displayed_volumes", "formatted_displayed_volumes"), + [ ( (("email", None), ("sms", None)), ", ", @@ -1308,7 +1305,7 @@ def test_non_gov_users_cant_request_to_go_live( "0, 1234", # This is a different order to match the spreadsheet ("Emails in next year: 1,234\n" "Text messages in next year: 0\n"), ), - ), + ], ) @freeze_time("2012-12-21 13:12:12.12354") def test_should_redirect_after_request_to_go_live( @@ -1318,7 +1315,6 @@ def test_should_redirect_after_request_to_go_live( single_reply_to_email_address, mock_get_organizations_and_services_for_user, single_sms_sender, - mock_get_service_settings_page_common, mock_get_service_templates, mock_get_users_by_service, mock_update_service, @@ -1388,6 +1384,7 @@ def test_should_redirect_after_request_to_go_live( ) +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") def test_request_to_go_live_displays_go_live_notes_in_zendesk_ticket( client_request, mocker, @@ -1396,7 +1393,6 @@ def test_request_to_go_live_displays_go_live_notes_in_zendesk_ticket( mock_get_organizations_and_services_for_user, single_sms_sender, mock_get_service_organization, - mock_get_service_settings_page_common, mock_get_service_templates, mock_get_users_by_service, mock_update_service, @@ -1460,6 +1456,7 @@ def test_request_to_go_live_displays_go_live_notes_in_zendesk_ticket( mock_send_ticket_to_zendesk.assert_called_once() +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") def test_request_to_go_live_displays_mou_signatories( client_request, mocker, @@ -1469,7 +1466,6 @@ def test_request_to_go_live_displays_mou_signatories( mock_get_organizations_and_services_for_user, single_sms_sender, mock_get_service_organization, - mock_get_service_settings_page_common, mock_get_service_templates, mock_get_users_by_service, mock_update_service, @@ -1503,13 +1499,13 @@ def test_request_to_go_live_displays_mou_signatories( ] +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") def test_should_be_able_to_request_to_go_live_with_no_organization( client_request, mocker, single_reply_to_email_address, mock_get_organizations_and_services_for_user, single_sms_sender, - mock_get_service_settings_page_common, mock_get_service_templates, mock_get_users_by_service, mock_update_service, @@ -1536,19 +1532,19 @@ def test_should_be_able_to_request_to_go_live_with_no_organization( @pytest.mark.parametrize( ( - "has_team_members," - "has_templates," - "has_email_templates," - "has_sms_templates," - "has_email_reply_to_address," - "shouldnt_use_govuk_as_sms_sender," - "sms_sender_is_govuk," - "volume_email," - "volume_sms," - "expected_readyness," - "agreement_signed," + "has_team_members", + "has_templates", + "has_email_templates", + "has_sms_templates", + "has_email_reply_to_address", + "shouldnt_use_govuk_as_sms_sender", + "sms_sender_is_govuk", + "volume_email", + "volume_sms", + "expected_readyness", + "agreement_signed", ), - ( + [ ( # Just sending email True, True, @@ -1640,7 +1636,7 @@ def test_should_be_able_to_request_to_go_live_with_no_organization( "No", False, ), - ), + ], ) def test_ready_to_go_live( client_request, @@ -1695,6 +1691,7 @@ def test_ready_to_go_live( ) +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") @pytest.mark.parametrize( "route", [ @@ -1715,7 +1712,6 @@ def test_route_permissions( mock_get_invites_for_service, single_sms_sender, route, - mock_get_service_settings_page_common, mock_get_service_templates, ): validate_route_permission( @@ -1764,6 +1760,7 @@ def test_route_invalid_permissions( ) +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") @pytest.mark.parametrize( "route", [ @@ -1782,7 +1779,6 @@ def test_route_for_platform_admin( single_reply_to_email_address, single_sms_sender, route, - mock_get_service_settings_page_common, mock_get_service_templates, mock_get_invites_for_service, ): @@ -1799,13 +1795,10 @@ def test_route_for_platform_admin( ) +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") @pytest.mark.skip(reason="Email currently deactivated") def test_and_more_hint_appears_on_settings_with_more_than_just_a_single_sender( - client_request, - service_one, - multiple_reply_to_email_addresses, - multiple_sms_senders, - mock_get_service_settings_page_common, + client_request, service_one, multiple_reply_to_email_addresses, multiple_sms_senders ): service_one["permissions"] = ["email", "sms"] @@ -1827,7 +1820,7 @@ def test_and_more_hint_appears_on_settings_with_more_than_just_a_single_sender( @pytest.mark.parametrize( - "sender_list_page, index, expected_output", + ("sender_list_page", "index", "expected_output"), [ ( "main.service_email_reply_to", @@ -1855,7 +1848,7 @@ def test_api_ids_dont_show_on_option_pages_with_a_single_sender( @pytest.mark.parametrize( - ("sender_list_page," "endpoint_to_mock," "sample_data," "expected_items,"), + ("sender_list_page", "endpoint_to_mock", "sample_data", "expected_items"), [ ( "main.service_email_reply_to", @@ -1897,7 +1890,7 @@ def test_default_option_shows_for_default_sender( @pytest.mark.parametrize( - "sender_list_page, endpoint_to_mock, expected_output", + ("sender_list_page", "endpoint_to_mock", "expected_output"), [ ( "main.service_email_reply_to", @@ -1925,7 +1918,7 @@ def test_no_senders_message_shows( @pytest.mark.parametrize( - "reply_to_input, expected_error", + ("reply_to_input", "expected_error"), [ ("", "Cannot be empty"), ("testtest", "Enter a valid email address"), @@ -1947,7 +1940,7 @@ def test_incorrect_reply_to_email_address_input( @pytest.mark.parametrize( - "sms_sender_input, expected_error", + ("sms_sender_input", "expected_error"), [ ("elevenchars", None), ("11 chars", None), @@ -2005,7 +1998,7 @@ def test_incorrect_sms_sender_input_with_multiple_errors_only_shows_the_first( @pytest.mark.parametrize( - "reply_to_addresses, data, api_default_args", + ("reply_to_addresses", "data", "api_default_args"), [ ([], {}, True), (create_multiple_email_reply_to_addresses(), {}, False), @@ -2067,11 +2060,11 @@ def test_service_add_reply_to_email_address_without_verification_for_platform_ad @pytest.mark.parametrize( - "is_default,replace,expected_header", + ("is_default", "replace", "expected_header"), [(True, "&replace=123", "Change"), (False, "", "Add")], ) @pytest.mark.parametrize( - "status,expected_failure,expected_success", + ("status", "expected_failure", "expected_success"), [ ("delivered", 0, 1), ("sending", 0, 0), @@ -2181,7 +2174,7 @@ def test_add_reply_to_email_address_fails_if_notification_not_delivered_in_45_se @pytest.mark.parametrize( - "sms_senders, data, api_default_args", + ("sms_senders", "data", "api_default_args"), [ ([], {}, True), (create_multiple_sms_senders(), {}, False), @@ -2203,7 +2196,7 @@ def test_add_sms_sender( @pytest.mark.parametrize( - "reply_to_addresses, checkbox_present", + ("reply_to_addresses", "checkbox_present"), [ ([], False), (create_multiple_email_reply_to_addresses(), True), @@ -2225,7 +2218,7 @@ def test_default_box_doesnt_show_on_first_email_sender( @pytest.mark.parametrize( - "reply_to_address, data, api_default_args", + ("reply_to_address", "data", "api_default_args"), [ (create_reply_to_email_address(is_default=True), {"is_default": "y"}, True), (create_reply_to_email_address(is_default=True), {}, True), @@ -2291,7 +2284,7 @@ def test_service_edit_email_reply_to_updates_email_address_without_verification_ @pytest.mark.parametrize( - "reply_to_address, data, api_default_args", + ("reply_to_address", "data", "api_default_args"), [ (create_reply_to_email_address(), {"is_default": "y"}, True), (create_reply_to_email_address(), {}, True), @@ -2379,7 +2372,7 @@ def test_add_edit_reply_to_email_address_goes_straight_to_update_if_address_not_ @pytest.mark.parametrize( - "reply_to_address, default_choice_and_delete_link_expected", + ("reply_to_address", "default_choice_and_delete_link_expected"), [ ( create_reply_to_email_address(is_default=False), @@ -2430,7 +2423,11 @@ def test_shows_delete_link_for_get_request_for_edit_email_reply_to_address( @pytest.mark.parametrize( - "reply_to_address, default_choice_and_delete_link_expected, default_checkbox_checked", + ( + "reply_to_address", + "default_choice_and_delete_link_expected", + "default_checkbox_checked", + ), [ (create_reply_to_email_address(is_default=False), True, False), (create_reply_to_email_address(is_default=False), True, True), @@ -2536,7 +2533,7 @@ def test_delete_reply_to_email_address( @pytest.mark.parametrize( - "sms_sender, data, api_default_args", + ("sms_sender", "data", "api_default_args"), [ (create_sms_sender(), {"is_default": "y", "sms_sender": "test"}, True), (create_sms_sender(), {"sms_sender": "test"}, True), @@ -2575,7 +2572,14 @@ def test_edit_sms_sender( @pytest.mark.parametrize( - "sender_page, endpoint_to_mock, sender_details, default_message, params, checkbox_present", + ( + "sender_page", + "endpoint_to_mock", + "sender_details", + "default_message", + "params", + "checkbox_present", + ), [ ( "main.service_edit_email_reply_to", @@ -2636,7 +2640,7 @@ def test_default_box_shows_on_non_default_sender_details_while_editing( @pytest.mark.parametrize( - "sms_sender, expected_link_text, partial_href", + ("sms_sender", "expected_link_text", "partial_href"), [ ( create_sms_sender(is_default=False), @@ -2706,7 +2710,7 @@ def test_confirm_delete_sms_sender( @pytest.mark.parametrize( - "sms_sender, expected_link_text", + ("sms_sender", "expected_link_text"), [ (create_sms_sender(is_default=False, inbound_number_id="1234"), None), (create_sms_sender(is_default=True), None), @@ -2757,7 +2761,7 @@ def test_delete_sms_sender( @pytest.mark.parametrize( - "sms_sender, hide_textbox", + ("sms_sender", "hide_textbox"), [ (create_sms_sender(is_default=False, inbound_number_id="1234"), True), (create_sms_sender(is_default=True), False), @@ -2782,13 +2786,13 @@ def test_inbound_sms_sender_is_not_editable( ) +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") def test_shows_research_mode_indicator( client_request, service_one, mocker, single_reply_to_email_address, single_sms_sender, - mock_get_service_settings_page_common, ): service_one["research_mode"] = True mocker.patch("app.service_api_client.update_service", return_value=service_one) @@ -2802,11 +2806,9 @@ def test_shows_research_mode_indicator( assert element.text == "research mode" +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") def test_does_not_show_research_mode_indicator( - client_request, - single_reply_to_email_address, - single_sms_sender, - mock_get_service_settings_page_common, + client_request, single_reply_to_email_address, single_sms_sender ): page = client_request.get( "main.service_settings", @@ -2818,7 +2820,7 @@ def test_does_not_show_research_mode_indicator( @pytest.mark.parametrize( - "current_branding, expected_values, expected_labels", + ("current_branding", "expected_values", "expected_labels"), [ ( None, @@ -2854,8 +2856,8 @@ def test_does_not_show_research_mode_indicator( ], ) @pytest.mark.parametrize( - "endpoint, extra_args", - ( + ("endpoint", "extra_args"), + [ ( "main.service_set_email_branding", {"service_id": SERVICE_ONE_ID}, @@ -2864,7 +2866,7 @@ def test_does_not_show_research_mode_indicator( "main.edit_organization_email_branding", {"org_id": ORGANISATION_ID}, ), - ), + ], ) def test_should_show_branding_styles( mocker, @@ -2920,8 +2922,8 @@ def test_should_show_branding_styles( @pytest.mark.parametrize( - "endpoint, extra_args, expected_redirect", - ( + ("endpoint", "extra_args", "expected_redirect"), + [ ( "main.service_set_email_branding", {"service_id": SERVICE_ONE_ID}, @@ -2932,7 +2934,7 @@ def test_should_show_branding_styles( {"org_id": ORGANISATION_ID}, "main.organization_preview_email_branding", ), - ), + ], ) def test_should_send_branding_and_organizations_to_preview( client_request, @@ -2958,8 +2960,8 @@ def test_should_send_branding_and_organizations_to_preview( @pytest.mark.parametrize( - "endpoint, extra_args", - ( + ("endpoint", "extra_args"), + [ ( "main.service_preview_email_branding", {"service_id": SERVICE_ONE_ID}, @@ -2968,7 +2970,7 @@ def test_should_send_branding_and_organizations_to_preview( "main.organization_preview_email_branding", {"org_id": ORGANISATION_ID}, ), - ), + ], ) def test_should_preview_email_branding( client_request, @@ -2992,16 +2994,16 @@ def test_should_preview_email_branding( @pytest.mark.parametrize( - "posted_value, submitted_value", - ( + ("posted_value", "submitted_value"), + [ ("1", "1"), ("__NONE__", None), pytest.param("None", None, marks=pytest.mark.xfail(raises=AssertionError)), - ), + ], ) @pytest.mark.parametrize( - "endpoint, extra_args, expected_redirect", - ( + ("endpoint", "extra_args", "expected_redirect"), + [ ( "main.service_preview_email_branding", {"service_id": SERVICE_ONE_ID}, @@ -3012,7 +3014,7 @@ def test_should_preview_email_branding( {"org_id": ORGANISATION_ID}, "main.organization_settings", ), - ), + ], ) def test_should_set_branding_and_organizations( client_request, @@ -3095,7 +3097,7 @@ def test_should_show_page_to_set_sms_allowance( @freeze_time("2017-04-01 11:09:00.061258") @pytest.mark.parametrize( - "given_allowance, expected_api_argument", + ("given_allowance", "expected_api_argument"), [ ("0", 0), ("1", 1), @@ -3130,7 +3132,7 @@ def test_should_set_sms_allowance( @freeze_time("2017-04-01 11:09:00.061258") @pytest.mark.parametrize( - "given_allowance, expected_api_argument", + ("given_allowance", "expected_api_argument"), [ pytest.param("foo", "foo"), ], @@ -3143,7 +3145,9 @@ def test_should_set_sms_allowance_fails( mock_get_free_sms_fragment_limit, mock_create_or_update_free_sms_fragment_limit, ): - with pytest.raises(expected_exception=AssertionError): + with pytest.raises( # noqa: PT012 # Needs more research for refactoring. + expected_exception=AssertionError + ): client_request.login(platform_admin_user) client_request.post( "main.set_free_sms_allowance", @@ -3183,14 +3187,14 @@ def test_should_show_page_to_set_rate_limit( @pytest.mark.parametrize( - "endpoint, field_name", - ( + ("endpoint", "field_name"), + [ ("main.set_message_limit", "message_limit"), ("main.set_rate_limit", "rate_limit"), - ), + ], ) @pytest.mark.parametrize( - "new_limit, expected_api_argument", + ("new_limit", "expected_api_argument"), [ ("1", 1), ("250000", 250000), @@ -3233,13 +3237,13 @@ def test_unknown_channel_404s( @pytest.mark.parametrize( ( - "channel," - "expected_first_para," - "expected_legend," - "initial_permissions," - "expected_initial_value," - "posted_value," - "expected_updated_permissions" + "channel", + "expected_first_para", + "expected_legend", + "initial_permissions", + "expected_initial_value", + "posted_value", + "expected_updated_permissions", ), [ ( @@ -3318,7 +3322,7 @@ def test_switch_service_channels_on_and_off( @pytest.mark.parametrize( - "permission, permissions, expected_checked", + ("permission", "permissions", "expected_checked"), [ ("international_sms", ["international_sms"], "True"), ("international_sms", [""], "False"), @@ -3343,9 +3347,9 @@ def test_show_international_sms_as_radio_button( assert checked_radios[0]["value"] == expected_checked -@pytest.mark.parametrize("permission", ("international_sms",)) +@pytest.mark.parametrize("permission", ["international_sms"]) @pytest.mark.parametrize( - "post_value, permission_expected_in_api_call", + ("post_value", "permission_expected_in_api_call"), [ ("True", True), ("False", False), @@ -3380,12 +3384,12 @@ def test_switch_service_enable_international_sms( @pytest.mark.parametrize( - "user, is_trial_service", - ( - [create_platform_admin_user(), True], - [create_platform_admin_user(), False], - [create_active_user_with_permissions(), True], - ), + ("user", "is_trial_service"), + [ + (create_platform_admin_user(), True), + (create_platform_admin_user(), False), + (create_active_user_with_permissions(), True), + ], ) def test_archive_service_after_confirm( client_request, @@ -3432,11 +3436,11 @@ def test_archive_service_after_confirm( @pytest.mark.parametrize( - "user, is_trial_service", - ( + ("user", "is_trial_service"), + [ pytest.param(create_active_user_with_permissions(), False), pytest.param(create_active_user_no_settings_permission(), True), - ), + ], ) def test_archive_service_after_confirm_error( client_request, @@ -3456,7 +3460,9 @@ def test_archive_service_after_confirm_error( mocker.patch("app.notify_client.service_api_client.redis_client.delete") mocker.patch("app.notify_client.service_api_client.redis_client.delete_by_pattern") - with pytest.raises(expected_exception=AssertionError): + with pytest.raises( # noqa: PT012 # Needs more research for refactoring. + expected_exception=AssertionError + ): client_request.login(user) client_request.post( "main.archive_service", @@ -3465,13 +3471,14 @@ def test_archive_service_after_confirm_error( ) +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") @pytest.mark.parametrize( - "user, is_trial_service", - ( - [create_platform_admin_user(), True], - [create_platform_admin_user(), False], - [create_active_user_with_permissions(), True], - ), + ("user", "is_trial_service"), + [ + (create_platform_admin_user(), True), + (create_platform_admin_user(), False), + (create_active_user_with_permissions(), True), + ], ) def test_archive_service_prompts_user( client_request, @@ -3479,7 +3486,6 @@ def test_archive_service_prompts_user( single_reply_to_email_address, service_one, single_sms_sender, - mock_get_service_settings_page_common, user, is_trial_service, ): @@ -3509,12 +3515,13 @@ def test_archive_service_prompts_user( assert mock_api.called is False +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") @pytest.mark.parametrize( - "user, is_trial_service", - ( + ("user", "is_trial_service"), + [ pytest.param(create_active_user_with_permissions(), False), pytest.param(create_active_user_no_settings_permission(), True), - ), + ], ) def test_archive_service_prompts_user_error( client_request, @@ -3522,7 +3529,6 @@ def test_archive_service_prompts_user_error( single_reply_to_email_address, service_one, single_sms_sender, - mock_get_service_settings_page_common, user, is_trial_service, ): @@ -3534,13 +3540,13 @@ def test_archive_service_prompts_user_error( client_request.get("main.archive_service", service_id=SERVICE_ONE_ID) +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") def test_cant_archive_inactive_service( client_request, platform_admin_user, service_one, single_reply_to_email_address, single_sms_sender, - mock_get_service_settings_page_common, ): service_one["active"] = False @@ -3553,7 +3559,7 @@ def test_cant_archive_inactive_service( assert "Delete service" not in {a.text for a in page.find_all("a", class_="button")} -@pytest.mark.parametrize("user", (create_platform_admin_user(),)) +@pytest.mark.parametrize("user", [create_platform_admin_user()]) def test_suspend_service_after_confirm( client_request, user, @@ -3582,7 +3588,7 @@ def test_suspend_service_after_confirm( ) -@pytest.mark.parametrize("user", (pytest.param(create_active_user_with_permissions()),)) +@pytest.mark.parametrize("user", [pytest.param(create_active_user_with_permissions())]) def test_suspend_service_after_confirm_error( client_request, user, @@ -3590,7 +3596,9 @@ def test_suspend_service_after_confirm_error( ): mocker.patch("app.service_api_client.post") mocker.patch("app.main.views.service_settings.create_suspend_service_event") - with pytest.raises(expected_exception=AssertionError): + with pytest.raises( # noqa: PT012 # Needs more research for refactoring. + expected_exception=AssertionError + ): client_request.login(user) client_request.post( "main.suspend_service", @@ -3602,12 +3610,13 @@ def test_suspend_service_after_confirm_error( ) +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") @pytest.mark.parametrize( "user", - ( + [ create_platform_admin_user(), pytest.param(create_active_user_with_permissions()), - ), + ], ) def test_suspend_service_prompts_user( client_request, @@ -3616,7 +3625,6 @@ def test_suspend_service_prompts_user( mocker, single_reply_to_email_address, single_sms_sender, - mock_get_service_settings_page_common, ): mock_api = mocker.patch("app.service_api_client.post") @@ -3636,13 +3644,13 @@ def test_suspend_service_prompts_user( assert mock_api.called is False +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") def test_cant_suspend_inactive_service( client_request, platform_admin_user, service_one, single_reply_to_email_address, single_sms_sender, - mock_get_service_settings_page_common, ): service_one["active"] = False @@ -3659,10 +3667,10 @@ def test_cant_suspend_inactive_service( @pytest.mark.parametrize( "user", - ( + [ create_platform_admin_user(), create_active_user_with_permissions(), - ), + ], ) def test_resume_service_after_confirm( mocker, @@ -3702,12 +3710,13 @@ def test_resume_service_after_confirm( ) +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") @pytest.mark.parametrize( "user", - ( + [ create_platform_admin_user(), pytest.param(create_active_user_with_permissions(), marks=pytest.mark.xfail), - ), + ], ) def test_resume_service_prompts_user( client_request, @@ -3716,7 +3725,6 @@ def test_resume_service_prompts_user( single_reply_to_email_address, single_sms_sender, mocker, - mock_get_service_settings_page_common, ): service_one["active"] = False mock_api = mocker.patch("app.service_api_client.post") @@ -3731,13 +3739,13 @@ def test_resume_service_prompts_user( assert mock_api.called is False +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") def test_cant_resume_active_service( client_request, platform_admin_user, service_one, single_reply_to_email_address, single_sms_sender, - mock_get_service_settings_page_common, ): client_request.login(platform_admin_user) page = client_request.get( @@ -3748,7 +3756,7 @@ def test_cant_resume_active_service( @pytest.mark.parametrize( - "contact_details_type, contact_details_value", + ("contact_details_type", "contact_details_value"), [ ("url", "http://example.com/"), ("email_address", "me@example.com"), @@ -3775,8 +3783,9 @@ def test_send_files_by_email_contact_details_prefills_the_form_with_the_existing ) +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") @pytest.mark.parametrize( - "contact_details_type, old_value, new_value", + ("contact_details_type", "old_value", "new_value"), [ ("url", "http://example.com/", "http://new-link.com/"), ("email_address", "old@example.com", "new@example.com"), @@ -3787,7 +3796,6 @@ def test_send_files_by_email_contact_details_updates_contact_details_and_redirec client_request, service_one, mock_update_service, - mock_get_service_settings_page_common, no_reply_to_email_addresses, single_sms_sender, contact_details_type, @@ -3810,11 +3818,11 @@ def test_send_files_by_email_contact_details_updates_contact_details_and_redirec mock_update_service.assert_called_once_with(SERVICE_ONE_ID, contact_link=new_value) +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") def test_send_files_by_email_contact_details_uses_the_selected_field_when_multiple_textboxes_contain_data( client_request, service_one, mock_update_service, - mock_get_service_settings_page_common, no_reply_to_email_addresses, single_sms_sender, ): @@ -3839,7 +3847,7 @@ def test_send_files_by_email_contact_details_uses_the_selected_field_when_multip @pytest.mark.parametrize( - "contact_link, subheader, button_selected", + ("contact_link", "subheader", "button_selected"), [ ( "contact.me@gsa.gov", @@ -3900,7 +3908,7 @@ def test_send_files_by_email_contact_details_displays_error_message_when_no_radi @pytest.mark.parametrize( - "contact_details_type, invalid_value, error", + ("contact_details_type", "invalid_value", "error"), [ ("url", "invalid.com/", "Must be a valid URL"), ("email_address", "me@co", "Enter a valid email address"), @@ -3933,7 +3941,7 @@ def test_send_files_by_email_contact_details_does_not_update_invalid_contact_det @pytest.mark.parametrize( - "endpoint, permissions, expected_p", + ("endpoint", "permissions", "expected_p"), [ ("main.service_set_auth_type", [], ("Text message code")), ( @@ -3999,7 +4007,7 @@ def test_set_inbound_sms_when_inbound_number_is_not_set( @pytest.mark.parametrize( - "user, expected_paragraphs", + ("user", "expected_paragraphs"), [ ( create_active_user_with_permissions(), @@ -4166,7 +4174,7 @@ def test_update_service_organization_does_not_update_if_same_value( @pytest.mark.skip(reason="Email currently deactivated") @pytest.mark.parametrize( - "single_branding_option, expected_href", + ("single_branding_option", "expected_href"), [ ( True, @@ -4302,6 +4310,7 @@ def test_update_service_data_retention_populates_form( assert page.find("input", attrs={"name": "days_of_retention"})["value"] == "5" +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") def test_service_settings_links_to_edit_service_notes_page_for_platform_admins( mocker, service_one, @@ -4309,7 +4318,6 @@ def test_service_settings_links_to_edit_service_notes_page_for_platform_admins( platform_admin_user, no_reply_to_email_addresses, single_sms_sender, - mock_get_service_settings_page_common, ): client_request.login(platform_admin_user) page = client_request.get( @@ -4357,6 +4365,7 @@ def test_update_service_notes( mock_update_service.assert_called_with(SERVICE_ONE_ID, notes="Very fluffy") +@pytest.mark.usefixtures("_mock_get_service_settings_page_common") def test_service_settings_links_to_edit_service_billing_details_page_for_platform_admins( mocker, service_one, @@ -4364,7 +4373,6 @@ def test_service_settings_links_to_edit_service_billing_details_page_for_platfor platform_admin_user, no_reply_to_email_addresses, single_sms_sender, - mock_get_service_settings_page_common, ): client_request.login(platform_admin_user) page = client_request.get( From 35ecd7006a1e4865ff0f2475ebf8b98336b19391 Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Fri, 29 Sep 2023 17:28:58 -0400 Subject: [PATCH 12/14] Finally finished linting all the tests! ...Now to fix the ones I broke... :lolsob: Signed-off-by: Carlo Costino --- tests/app/main/forms/test_create_key_form.py | 8 +- tests/app/main/forms/test_placeholder_form.py | 8 +- .../test_service_contact_details_form.py | 4 +- .../forms/test_service_sms_senders_form.py | 2 +- tests/app/main/forms/test_two_factor_form.py | 6 +- tests/app/main/test_formatters.py | 18 ++--- tests/app/main/test_permissions.py | 8 +- tests/app/main/test_request_header.py | 2 +- tests/app/main/test_validators.py | 2 +- .../views/accounts/test_choose_accounts.py | 12 +-- .../test_show_accounts_or_dashboard.py | 2 +- .../test_organization_invites.py | 10 +-- .../views/organizations/test_organizations.py | 73 ++++++++++--------- .../test_email_branding_requests.py | 21 +++--- .../test_service_setting_permissions.py | 18 +++-- 15 files changed, 100 insertions(+), 94 deletions(-) diff --git a/tests/app/main/forms/test_create_key_form.py b/tests/app/main/forms/test_create_key_form.py index 0768c271a..3539d29b4 100644 --- a/tests/app/main/forms/test_create_key_form.py +++ b/tests/app/main/forms/test_create_key_form.py @@ -5,11 +5,11 @@ from app.main.forms import CreateKeyForm @pytest.mark.parametrize( - "expiry_date, expected_errors", - ( + ("expiry_date", "expected_errors"), + [ (None, ["A key with this name already exists"]), ("2001-01-01 01:01:01", None), - ), + ], ) def test_return_validation_error_when_key_name_exists( client_request, @@ -35,7 +35,7 @@ def test_return_validation_error_when_key_name_exists( @pytest.mark.parametrize( - "key_type, expected_error", + ("key_type", "expected_error"), [("", "Select the type of key"), ("invalid", "Select the type of key")], ) def test_return_validation_error_when_key_type_not_chosen( diff --git a/tests/app/main/forms/test_placeholder_form.py b/tests/app/main/forms/test_placeholder_form.py index babd5c640..40a12ae56 100644 --- a/tests/app/main/forms/test_placeholder_form.py +++ b/tests/app/main/forms/test_placeholder_form.py @@ -24,7 +24,13 @@ def test_form_class_not_mutated(notify_admin): @pytest.mark.parametrize( - "service_can_send_international_sms, placeholder_name, template_type, value, expected_error", + ( + "service_can_send_international_sms", + "placeholder_name", + "template_type", + "value", + "expected_error", + ), [ (False, "email address", "email", "", "Cannot be empty"), (False, "email address", "email", "12345", "Enter a valid email address"), diff --git a/tests/app/main/forms/test_service_contact_details_form.py b/tests/app/main/forms/test_service_contact_details_form.py index 02695cb28..4521fe3bc 100644 --- a/tests/app/main/forms/test_service_contact_details_form.py +++ b/tests/app/main/forms/test_service_contact_details_form.py @@ -13,7 +13,7 @@ def test_form_fails_validation_with_no_radio_buttons_selected(notify_admin): @pytest.mark.parametrize( - "selected_radio_button, selected_text_box, text_box_data", + ("selected_radio_button", "selected_text_box", "text_box_data"), [ ("email_address", "url", "http://www.example.com"), ("phone_number", "url", "http://www.example.com"), @@ -40,7 +40,7 @@ def test_form_fails_validation_when_radio_button_selected_and_text_box_filled_in @pytest.mark.parametrize( - "selected_field, url, email_address, phone_number", + ("selected_field", "url", "email_address", "phone_number"), [ ("url", "http://www.example.com", "invalid-email.com", "phone"), ("email_address", "www.invalid-url.com", "me@example.com", "phone"), diff --git a/tests/app/main/forms/test_service_sms_senders_form.py b/tests/app/main/forms/test_service_sms_senders_form.py index fff10c5ca..4268b3c2d 100644 --- a/tests/app/main/forms/test_service_sms_senders_form.py +++ b/tests/app/main/forms/test_service_sms_senders_form.py @@ -4,7 +4,7 @@ from app.main.forms import ServiceSmsSenderForm @pytest.mark.parametrize( - "sms_sender,error_expected,error_message", + ("sms_sender", "error_expected", "error_message"), [ ("", True, "Cannot be empty"), ("22", True, "Enter 3 characters or more"), diff --git a/tests/app/main/forms/test_two_factor_form.py b/tests/app/main/forms/test_two_factor_form.py index 54eb1f6b7..4c9d583e2 100644 --- a/tests/app/main/forms/test_two_factor_form.py +++ b/tests/app/main/forms/test_two_factor_form.py @@ -30,8 +30,8 @@ def test_form_is_valid_returns_no_errors( @pytest.mark.parametrize( - "post_data, expected_error", - ( + ("post_data", "expected_error"), + [ ( {"sms_code": "1234"}, "Not enough numbers", @@ -52,7 +52,7 @@ def test_form_is_valid_returns_no_errors( {"sms_code": " ! 2 3 4 5 6"}, "Numbers only", ), - ), + ], ) def test_check_verify_code_returns_errors( notify_admin, diff --git a/tests/app/main/test_formatters.py b/tests/app/main/test_formatters.py index a77b182e4..e388db654 100644 --- a/tests/app/main/test_formatters.py +++ b/tests/app/main/test_formatters.py @@ -16,8 +16,8 @@ from app.formatters import ( @pytest.mark.parametrize( - "status, notification_type, expected", - ( + ("status", "notification_type", "expected"), + [ # Successful statuses aren’t linked ("created", "email", lambda: None), ("sending", "email", lambda: None), @@ -53,7 +53,7 @@ from app.formatters import ( "sms", partial(url_for, "main.message_status", _anchor="text-message-statuses"), ), - ), + ], ) def test_format_notification_status_as_url( client_request, @@ -65,7 +65,7 @@ def test_format_notification_status_as_url( @pytest.mark.parametrize( - "input_number, formatted_number", + ("input_number", "formatted_number"), [ (0, "0p"), (0.01, "1p"), @@ -84,7 +84,7 @@ def test_format_number_in_pounds_as_currency(input_number, formatted_number): @pytest.mark.parametrize( - "time, human_readable_datetime", + ("time", "human_readable_datetime"), [ # incoming in UTC, outgoing in "human formatted" UTC ("2018-03-14 09:00", "14 March at 09:00 UTC"), @@ -127,8 +127,8 @@ def test_format_datetime_relative(time, human_readable_datetime): @pytest.mark.parametrize( - "value, significant_figures, expected_result", - ( + ("value", "significant_figures", "expected_result"), + [ (0, 1, 0), (0, 2, 0), (12_345, 1, 10_000), @@ -138,14 +138,14 @@ def test_format_datetime_relative(time, human_readable_datetime): (12_345.6789, 1, 10_000), (12_345.6789, 9, 12_345), (-12_345, 1, -10_000), - ), + ], ) def test_round_to_significant_figures(value, significant_figures, expected_result): assert round_to_significant_figures(value, significant_figures) == expected_result @pytest.mark.parametrize( - "service_name, safe_email", + ("service_name", "safe_email"), [ ("name with spaces", "name.with.spaces"), ("singleword", "singleword"), diff --git a/tests/app/main/test_permissions.py b/tests/app/main/test_permissions.py index f2f015e27..a0104924e 100644 --- a/tests/app/main/test_permissions.py +++ b/tests/app/main/test_permissions.py @@ -15,8 +15,8 @@ from tests.conftest import ( @pytest.mark.parametrize( - "user_services, user_organizations, expected_status, organization_checked", - ( + ("user_services", "user_organizations", "expected_status", "organization_checked"), + [ ([SERVICE_ONE_ID], [], 200, False), ([SERVICE_ONE_ID, SERVICE_TWO_ID], [], 200, False), ([], [ORGANISATION_ID], 200, True), @@ -27,7 +27,7 @@ from tests.conftest import ( ([SERVICE_ONE_ID, SERVICE_TWO_ID], [ORGANISATION_ID], 200, False), ([], [ORGANISATION_TWO_ID], 403, True), ([], [ORGANISATION_ID, ORGANISATION_TWO_ID], 200, True), - ), + ], ) def test_services_pages_that_org_users_are_allowed_to_see( client_request, @@ -117,7 +117,7 @@ def test_service_navigation_for_org_user( @pytest.mark.parametrize( - "user_organizations, expected_menu_items, expected_status", + ("user_organizations", "expected_menu_items", "expected_status"), [ ( [], diff --git a/tests/app/main/test_request_header.py b/tests/app/main/test_request_header.py index 665ed689e..70d3d9ac9 100644 --- a/tests/app/main/test_request_header.py +++ b/tests/app/main/test_request_header.py @@ -4,7 +4,7 @@ from tests.conftest import set_config_values @pytest.mark.parametrize( - "check_proxy_header,header_value,expected_code", + ("check_proxy_header", "header_value,expected_code"), [ (True, "key_1", 200), (True, "wrong_key", 403), diff --git a/tests/app/main/test_validators.py b/tests/app/main/test_validators.py index d5962110e..09100f710 100644 --- a/tests/app/main/test_validators.py +++ b/tests/app/main/test_validators.py @@ -66,7 +66,7 @@ def test_sms_character_validation(client_request, msg): @pytest.mark.parametrize( - "data, err_msg", + ("data", "err_msg"), [ ( "∆ abc 📲 def 📵 ghi", diff --git a/tests/app/main/views/accounts/test_choose_accounts.py b/tests/app/main/views/accounts/test_choose_accounts.py index 6976b3aea..7d47c2a95 100644 --- a/tests/app/main/views/accounts/test_choose_accounts.py +++ b/tests/app/main/views/accounts/test_choose_accounts.py @@ -67,7 +67,7 @@ SAMPLE_DATA = { } -@pytest.fixture +@pytest.fixture() def mock_get_orgs_and_services(mocker): return mocker.patch( "app.user_api_client.get_organizations_and_services_for_user", @@ -177,8 +177,8 @@ def test_choose_account_should_show_choose_accounts_page_if_no_services( @pytest.mark.parametrize( - "orgs_and_services, expected_headings", - ( + ("orgs_and_services", "expected_headings"), + [ ( {"organizations": [], "services": []}, [ @@ -227,7 +227,7 @@ def test_choose_account_should_show_choose_accounts_page_if_no_services( "Trial mode services", ], ), - ), + ], ) def test_choose_account_should_should_organizations_link_for_platform_admin( client_request, @@ -302,10 +302,10 @@ def test_choose_account_should_not_show_back_to_service_link_if_not_signed_in( @pytest.mark.parametrize( "active", - ( + [ False, pytest.param(True), - ), + ], ) def test_choose_account_should_not_show_back_to_service_link_if_service_archived( client_request, diff --git a/tests/app/main/views/accounts/test_show_accounts_or_dashboard.py b/tests/app/main/views/accounts/test_show_accounts_or_dashboard.py index a57b582d2..d28d58f22 100644 --- a/tests/app/main/views/accounts/test_show_accounts_or_dashboard.py +++ b/tests/app/main/views/accounts/test_show_accounts_or_dashboard.py @@ -14,7 +14,7 @@ def user_with_orgs_and_services(num_orgs, num_services, platform_admin=False): @pytest.mark.parametrize( - "num_orgs,num_services,endpoint,endpoint_kwargs", + ("num_orgs", "num_services", "endpoint", "endpoint_kwargs"), [ (0, 0, ".choose_account", {}), (0, 2, ".choose_account", {}), diff --git a/tests/app/main/views/organizations/test_organization_invites.py b/tests/app/main/views/organizations/test_organization_invites.py index ac2e7fb56..3eca5ae49 100644 --- a/tests/app/main/views/organizations/test_organization_invites.py +++ b/tests/app/main/views/organizations/test_organization_invites.py @@ -256,24 +256,24 @@ def test_registration_from_org_invite_404s_if_user_not_in_session( @pytest.mark.parametrize( - "data, error", + ("data", "error"), [ - [ + ( { "name": "Bad Mobile", "mobile_number": "not good", "password": "validPassword!", }, "The string supplied did not seem to be a phone number", - ], - [ + ), + ( { "name": "Bad Password", "mobile_number": "+12021234123", "password": "password", }, "Choose a password that’s harder to guess", - ], + ), ], ) def test_registration_from_org_invite_has_bad_data( diff --git a/tests/app/main/views/organizations/test_organizations.py b/tests/app/main/views/organizations/test_organizations.py index 3abffc2fb..0b330b5a9 100644 --- a/tests/app/main/views/organizations/test_organizations.py +++ b/tests/app/main/views/organizations/test_organizations.py @@ -168,7 +168,7 @@ def test_create_new_organization_validates( @pytest.mark.parametrize( - "name, error_message", + ("name", "error_message"), [ ("", "Cannot be empty"), ("a", "at least two alphanumeric characters"), @@ -229,12 +229,12 @@ def test_create_new_organization_fails_with_duplicate_name( @pytest.mark.parametrize( - "organization_type, organization, expected_status", - ( + ("organization_type", "organization", "expected_status"), + [ ("nhs_gp", None, 200), ("central", None, 403), ("nhs_gp", organization_json(organization_type="nhs_gp"), 403), - ), + ], ) @pytest.mark.skip(reason="Update for TTS") def test_gps_can_create_own_organizations( @@ -265,8 +265,8 @@ def test_gps_can_create_own_organizations( @pytest.mark.parametrize( - "data, expected_service_name", - ( + ("data", "expected_service_name"), + [ ( { "same_as_service_name": False, @@ -281,7 +281,7 @@ def test_gps_can_create_own_organizations( }, "service one", ), - ), + ], ) @pytest.mark.skip(reason="Update for TTS") def test_gps_can_name_their_organization( @@ -315,8 +315,8 @@ def test_gps_can_name_their_organization( @pytest.mark.parametrize( - "data, expected_error", - ( + ("data", "expected_error"), + [ ( { "name": "Dr. Example", @@ -330,7 +330,7 @@ def test_gps_can_name_their_organization( }, "Cannot be empty", ), - ), + ], ) @pytest.mark.skip(reason="Update for TTS") def test_validation_of_gps_creating_organizations( @@ -457,12 +457,12 @@ def test_organization_services_shows_live_services_and_usage_with_count_of_1( @freeze_time("2020-02-20 20:20") @pytest.mark.parametrize( - "financial_year, expected_selected", - ( + ("financial_year", "expected_selected"), + [ (2017, "2017 to 2018 fiscal year"), (2018, "2018 to 2019 fiscal year"), (2019, "2019 to 2020 fiscal year"), - ), + ], ) def test_organization_services_filters_by_financial_year( client_request, @@ -784,10 +784,10 @@ def test_manage_org_users_shows_no_link_for_cancelled_users( @pytest.mark.parametrize( "number_of_users", - ( + [ pytest.param(8), pytest.param(800), - ), + ], ) def test_manage_org_users_should_show_live_search_if_more_than_7_users( client_request, @@ -831,10 +831,10 @@ def test_manage_org_users_should_show_live_search_if_more_than_7_users( @pytest.mark.parametrize( "number_of_users", - ( + [ pytest.param(3), pytest.param(7), - ), + ], ) def test_manage_org_users_should_show_live_search_if_7_users_or_less( client_request, @@ -947,8 +947,8 @@ def test_organization_settings_for_platform_admin( @pytest.mark.parametrize( - "endpoint, expected_options, expected_selected", - ( + ("endpoint", "expected_options", "expected_selected"), + [ ( ".edit_organization_type", ( @@ -958,16 +958,16 @@ def test_organization_settings_for_platform_admin( ), "federal", ), - ), + ], ) @pytest.mark.parametrize( "user", - ( + [ pytest.param( create_platform_admin_user(), ), pytest.param(create_active_user_with_permissions(), marks=pytest.mark.xfail), - ), + ], ) def test_view_organization_settings( client_request, @@ -1007,8 +1007,8 @@ def test_view_organization_settings( @pytest.mark.parametrize( - "endpoint, post_data, expected_persisted", - ( + ("endpoint", "post_data", "expected_persisted"), + [ ( ".edit_organization_type", {"organization_type": "federal"}, @@ -1019,18 +1019,18 @@ def test_view_organization_settings( {"organization_type": "state"}, {"cached_service_ids": [], "organization_type": "state"}, ), - ), + ], ) @pytest.mark.parametrize( "user", - ( + [ pytest.param( create_platform_admin_user(), ), pytest.param( create_active_user_with_permissions(), ), - ), + ], ) def test_update_organization_settings( mocker, @@ -1101,12 +1101,12 @@ def test_update_organization_sector_sends_service_id_data_to_api_client( @pytest.mark.parametrize( "user", - ( + [ pytest.param( create_platform_admin_user(), ), pytest.param(create_active_user_with_permissions(), marks=pytest.mark.xfail), - ), + ], ) def test_view_organization_domains( mocker, @@ -1155,8 +1155,8 @@ def test_view_organization_domains( @pytest.mark.parametrize( - "post_data, expected_persisted", - ( + ("post_data", "expected_persisted"), + [ ( { "domains-0": "example.gsa.gov", @@ -1179,18 +1179,18 @@ def test_view_organization_domains( }, {"domains": []}, ), - ), + ], ) @pytest.mark.parametrize( "user", - ( + [ pytest.param( create_platform_admin_user(), ), pytest.param( create_active_user_with_permissions(), ), - ), + ], ) def test_update_organization_domains( client_request, @@ -1291,7 +1291,7 @@ def test_update_organization_name( @pytest.mark.parametrize( - "name, error_message", + ("name", "error_message"), [ ("", "Cannot be empty"), ("a", "at least two alphanumeric characters"), @@ -1362,7 +1362,8 @@ def test_get_edit_organization_go_live_notes_page( @pytest.mark.parametrize( - "input_note,saved_note", [("Needs permission", "Needs permission"), (" ", None)] + ("input_note", "saved_note"), + [("Needs permission", "Needs permission"), (" ", None)], ) def test_post_edit_organization_go_live_notes_updates_go_live_notes( client_request, diff --git a/tests/app/main/views/service_settings/test_email_branding_requests.py b/tests/app/main/views/service_settings/test_email_branding_requests.py index 55e7df8ee..ccab8a87a 100644 --- a/tests/app/main/views/service_settings/test_email_branding_requests.py +++ b/tests/app/main/views/service_settings/test_email_branding_requests.py @@ -9,15 +9,15 @@ from tests.conftest import ORGANISATION_ID, SERVICE_ONE_ID, normalize_spaces @pytest.mark.parametrize( - "organization_type, expected_options", - ( + ("organization_type", "expected_options"), + [ ( "other", [ ("something_else", "Something else"), ], ), - ), + ], ) def test_email_branding_request_page_when_no_branding_is_set( service_one, @@ -86,8 +86,8 @@ def test_email_branding_request_page_back_link( @pytest.mark.parametrize( - "data, org_type, endpoint", - ( + ("data", "org_type", "endpoint"), + [ ( { "options": "govuk", @@ -109,7 +109,7 @@ def test_email_branding_request_page_back_link( "federal", "main.email_branding_something_else", ), - ), + ], ) def test_email_branding_request_submit( client_request, @@ -162,7 +162,7 @@ def test_email_branding_request_submit_when_no_radio_button_is_selected( @pytest.mark.parametrize( - "endpoint, expected_heading", + ("endpoint", "expected_heading"), [ ("main.email_branding_govuk_and_org", "Before you request new branding"), ], @@ -196,11 +196,8 @@ def test_email_branding_description_pages_for_org_branding( @pytest.mark.parametrize( - "endpoint, service_org_type, branding_preview_id", - [ - ("main.email_branding_govuk", "central", "__NONE__"), - # ('main.email_branding_nhs', 'nhs_local', NHS_EMAIL_BRANDING_ID), - ], + ("endpoint", "service_org_type", "branding_preview_id"), + [("main.email_branding_govuk", "central", "__NONE__")], ) @pytest.mark.skip(reason="Update for TTS") def test_email_branding_govuk_and_nhs_pages( diff --git a/tests/app/main/views/service_settings/test_service_setting_permissions.py b/tests/app/main/views/service_settings/test_service_setting_permissions.py index f2673cb15..42c50b8be 100644 --- a/tests/app/main/views/service_settings/test_service_setting_permissions.py +++ b/tests/app/main/views/service_settings/test_service_setting_permissions.py @@ -7,7 +7,7 @@ from app.main.views.service_settings import PLATFORM_ADMIN_SERVICE_PERMISSIONS from tests.conftest import normalize_spaces -@pytest.fixture +@pytest.fixture() def get_service_settings_page( client_request, platform_admin_user, @@ -41,7 +41,7 @@ def test_service_set_permission_requires_platform_admin( @pytest.mark.parametrize( - "initial_permissions, permission, form_data, expected_update", + ("initial_permissions", "permission", "form_data", "expected_update"), [ ( [], @@ -102,7 +102,7 @@ def test_service_set_permission( @pytest.mark.parametrize( - "service_fields, endpoint, kwargs, text", + ("service_fields", "endpoint", "kwargs", "text"), [ ( {"restricted": True}, @@ -146,7 +146,7 @@ def test_service_setting_toggles_show( @pytest.mark.parametrize( - "service_fields, endpoint, index, text", + ("service_fields", "endpoint", "index", "text"), [ ({"active": True}, ".archive_service", 0, "Delete this service"), ({"active": True}, ".suspend_service", 1, "Suspend service"), @@ -172,7 +172,7 @@ def test_service_setting_link_toggles( @pytest.mark.parametrize( - "service_fields, endpoint, index, text", + ("service_fields", "endpoint", "index", "text"), [ pytest.param( {"active": False}, @@ -190,7 +190,9 @@ def test_service_setting_link_toggles_index_error( index, text, ): - with pytest.raises(expected_exception=IndexError): + with pytest.raises( # noqa: PT012 # Requires more research to refactor. + expected_exception=IndexError + ): url_for(endpoint, service_id=service_one["id"]) service_one.update(service_fields) page = get_service_settings_page() @@ -198,7 +200,7 @@ def test_service_setting_link_toggles_index_error( @pytest.mark.parametrize( - "permissions,permissions_text,visible", + ("permissions", "permissions_text,visible"), [ ("sms", "inbound SMS", True), ("inbound_sms", "inbound SMS", False), # no sms parent permission @@ -216,7 +218,7 @@ def test_service_settings_doesnt_show_option_if_parent_permission_disabled( @pytest.mark.parametrize( - "service_fields, link_text", + ("service_fields", "link_text"), [ # can't archive or suspend inactive service. Can't resume active service. ({"active": False}, "Archive service"), From 7163f813ce9921f908d69f75604a33245bfc5a6f Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Fri, 29 Sep 2023 17:40:28 -0400 Subject: [PATCH 13/14] Fix malformed tuples Signed-off-by: Carlo Costino --- tests/app/main/test_request_header.py | 2 +- .../views/service_settings/test_service_setting_permissions.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/app/main/test_request_header.py b/tests/app/main/test_request_header.py index 70d3d9ac9..68a3ac84c 100644 --- a/tests/app/main/test_request_header.py +++ b/tests/app/main/test_request_header.py @@ -4,7 +4,7 @@ from tests.conftest import set_config_values @pytest.mark.parametrize( - ("check_proxy_header", "header_value,expected_code"), + ("check_proxy_header", "header_value", "expected_code"), [ (True, "key_1", 200), (True, "wrong_key", 403), diff --git a/tests/app/main/views/service_settings/test_service_setting_permissions.py b/tests/app/main/views/service_settings/test_service_setting_permissions.py index 42c50b8be..e64c6c829 100644 --- a/tests/app/main/views/service_settings/test_service_setting_permissions.py +++ b/tests/app/main/views/service_settings/test_service_setting_permissions.py @@ -200,7 +200,7 @@ def test_service_setting_link_toggles_index_error( @pytest.mark.parametrize( - ("permissions", "permissions_text,visible"), + ("permissions", "permissions_text", "visible"), [ ("sms", "inbound SMS", True), ("inbound_sms", "inbound SMS", False), # no sms parent permission From 85f0a31505f5d08fceb7b44677419e20e35784c2 Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Thu, 12 Oct 2023 10:27:26 -0400 Subject: [PATCH 14/14] Updated poetry.lock file after rebasing with more dependency updates. Signed-off-by: Carlo Costino --- poetry.lock | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/poetry.lock b/poetry.lock index 808d4432b..dd900a5ab 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1621,16 +1621,6 @@ files = [ {file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:5bbe06f8eeafd38e5d0a4894ffec89378b6c6a625ff57e3028921f8ff59318ac"}, {file = "MarkupSafe-2.1.3-cp311-cp311-win32.whl", hash = "sha256:dd15ff04ffd7e05ffcb7fe79f1b98041b8ea30ae9234aed2a9168b5797c3effb"}, {file = "MarkupSafe-2.1.3-cp311-cp311-win_amd64.whl", hash = "sha256:134da1eca9ec0ae528110ccc9e48041e0828d79f24121a1a146161103c76e686"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:f698de3fd0c4e6972b92290a45bd9b1536bffe8c6759c62471efaa8acb4c37bc"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aa57bd9cf8ae831a362185ee444e15a93ecb2e344c8e52e4d721ea3ab6ef1823"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ffcc3f7c66b5f5b7931a5aa68fc9cecc51e685ef90282f4a82f0f5e9b704ad11"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:47d4f1c5f80fc62fdd7777d0d40a2e9dda0a05883ab11374334f6c4de38adffd"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1f67c7038d560d92149c060157d623c542173016c4babc0c1913cca0564b9939"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:9aad3c1755095ce347e26488214ef77e0485a3c34a50c5a5e2471dff60b9dd9c"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:14ff806850827afd6b07a5f32bd917fb7f45b046ba40c57abdb636674a8b559c"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8f9293864fe09b8149f0cc42ce56e3f0e54de883a9de90cd427f191c346eb2e1"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-win32.whl", hash = "sha256:715d3562f79d540f251b99ebd6d8baa547118974341db04f5ad06d5ea3eb8007"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-win_amd64.whl", hash = "sha256:1b8dd8c3fd14349433c79fa8abeb573a55fc0fdd769133baac1f5e07abf54aeb"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8e254ae696c88d98da6555f5ace2279cf7cd5b3f52be2b5cf97feafe883b58d2"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cb0932dc158471523c9637e807d9bfb93e06a95cbf010f1a38b98623b929ef2b"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9402b03f1a1b4dc4c19845e5c749e3ab82d5078d16a2a4c2cd2df62d57bb0707"}, @@ -3529,4 +3519,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "76dec28e50e44e8fd06d55116388f86b252e779884fe034c50b8c800aaf8bc3d" +content-hash = "a6d88cdfee13c817eed778af541bd6cd6d2fb217ce7bafc4fff2f790cd5d9836"