diff --git a/app/enums.py b/app/enums.py index a09325fb7..a5090463f 100644 --- a/app/enums.py +++ b/app/enums.py @@ -1,4 +1,5 @@ from strenum import StrEnum # type: ignore [import-not-found] + # In 3.11 this is in the enum library. We will not need this external library any more. # The line will simply change from importing from strenum to importing from enum. # And the strenum library can then be removed from poetry. diff --git a/app/service/statistics.py b/app/service/statistics.py index ef538b45f..e781854bd 100644 --- a/app/service/statistics.py +++ b/app/service/statistics.py @@ -78,7 +78,7 @@ def format_monthly_template_notification_stats(year, rows): def create_zeroed_stats_dicts(): return { template_type: {status: 0 for status in ("requested", "delivered", "failed")} - for template_type in TemplateType + for template_type in (TemplateType.SMS, TemplateType.EMAIL) } @@ -103,7 +103,8 @@ def create_empty_monthly_notification_status_stats_dict(year): # nested dicts - data[month][template type][status] = count return { start.strftime("%Y-%m"): { - template_type: defaultdict(int) for template_type in TemplateType + template_type: defaultdict(int) + for template_type in (TemplateType.SMS, TemplateType.EMAIL) } for start in utc_month_starts } diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index b6cc6fd04..189cc2f4b 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -1212,7 +1212,9 @@ def test_default_permissions_are_added_for_user_service( ] from app.dao.permissions_dao import default_service_permissions - assert sorted(ServicePermissionType.defaults()) == sorted(service_permissions) + assert sorted(ServicePermissionType.defaults()) == sorted( + service_permissions + ) def test_add_existing_user_to_another_service_with_all_permissions( diff --git a/tests/app/service/test_statistics_rest.py b/tests/app/service/test_statistics_rest.py index f0d8eda4a..5e88702a6 100644 --- a/tests/app/service/test_statistics_rest.py +++ b/tests/app/service/test_statistics_rest.py @@ -108,7 +108,9 @@ def test_get_template_usage_by_month_returns_two_templates( def test_get_service_notification_statistics( admin_request, sample_service, sample_template, today_only, stats ): - create_ft_notification_status(date(2000, 1, 1), "sms", sample_service, count=1) + create_ft_notification_status( + date(2000, 1, 1), NotificationType.SMS, sample_service, count=1 + ) with freeze_time("2000-01-02T12:00:00"): create_notification(sample_template, status="created") resp = admin_request.get( diff --git a/tests/app/user/test_rest.py b/tests/app/user/test_rest.py index 3f4f22d67..c24b950d8 100644 --- a/tests/app/user/test_rest.py +++ b/tests/app/user/test_rest.py @@ -457,11 +457,7 @@ def test_set_user_permissions(admin_request, sample_user, sample_service): "user.set_permissions", user_id=str(sample_user.id), service_id=str(sample_service.id), - _data={ - "permissions": [ - {"permission": PermissionType.PermissionType.MANAGE_SETTINGS} - ] - }, + _data={"permissions": [{"permission": PermissionType.MANAGE_SETTINGS}]}, _expected_status=204, ) diff --git a/tests/app/v2/notifications/test_get_notifications.py b/tests/app/v2/notifications/test_get_notifications.py index 82b589e4c..a68ed3ac7 100644 --- a/tests/app/v2/notifications/test_get_notifications.py +++ b/tests/app/v2/notifications/test_get_notifications.py @@ -1,6 +1,7 @@ import pytest from flask import json, url_for +from app.enums import NotificationType, TemplateType from app.utils import DATETIME_FORMAT from tests import create_service_authorization_header from tests.app.db import create_notification, create_template @@ -239,7 +240,7 @@ def test_get_notification_by_id_invalid_id(client, sample_notification, id): } -@pytest.mark.parametrize("template_type", ["sms", "email"]) +@pytest.mark.parametrize("template_type", [TemplateType.SMS, TemplateType.EMAIL]) def test_get_notification_doesnt_have_delivery_estimate_for_non_letters( client, sample_service, template_type ): @@ -290,7 +291,7 @@ def test_get_all_notifications_except_job_notifications_returns_200( "version": 1, } assert json_response["notifications"][0]["phone_number"] == "1" - assert json_response["notifications"][0]["type"] == "sms" + assert json_response["notifications"][0]["type"] == NotificationType.SMS assert not json_response["notifications"][0]["scheduled_for"] @@ -348,8 +349,12 @@ def test_get_all_notifications_no_notifications_if_no_notifications( def test_get_all_notifications_filter_by_template_type(client, sample_service): - email_template = create_template(service=sample_service, template_type="email") - sms_template = create_template(service=sample_service, template_type="sms") + email_template = create_template( + service=sample_service, template_type=TemplateType.EMAIL + ) + sms_template = create_template( + service=sample_service, template_type=TemplateType.SMS + ) notification = create_notification( template=email_template, to_field="don.draper@scdp.biz" @@ -382,7 +387,7 @@ def test_get_all_notifications_filter_by_template_type(client, sample_service): "version": 1, } assert json_response["notifications"][0]["email_address"] == "1" - assert json_response["notifications"][0]["type"] == "email" + assert json_response["notifications"][0]["type"] == NotificationType.EMAIL def test_get_all_notifications_filter_by_template_type_invalid_template_type( @@ -405,7 +410,7 @@ def test_get_all_notifications_filter_by_template_type_invalid_template_type( assert len(json_response["errors"]) == 1 assert ( json_response["errors"][0]["message"] - == "template_type orange is not one of [sms, email]" + == "template_type orange is not one of [sms, email, letter]" ) @@ -625,7 +630,9 @@ def test_get_all_notifications_filter_multiple_query_parameters( # wrong status create_notification(template=sample_email_template) - wrong_template = create_template(sample_email_template.service, template_type="sms") + wrong_template = create_template( + sample_email_template.service, template_type=TemplateType.SMS + ) # wrong template create_notification(template=wrong_template, status="sending") @@ -681,7 +688,10 @@ def test_get_all_notifications_renames_letter_statuses( assert response.status_code == 200 for noti in json_response["notifications"]: - if noti["type"] == "sms" or noti["type"] == "email": + if ( + noti["type"] == NotificationType.SMS + or noti["type"] == NotificationType.EMAIL + ): assert noti["status"] == "created" else: pytest.fail() diff --git a/tests/app/v2/template/test_post_template.py b/tests/app/v2/template/test_post_template.py index 57c9bb868..00d3aabfe 100644 --- a/tests/app/v2/template/test_post_template.py +++ b/tests/app/v2/template/test_post_template.py @@ -59,7 +59,7 @@ valid_post = [ ] -@pytest.mark.parametrize("tmp_type", TemplateType) +@pytest.mark.parametrize("tmp_type", (TemplateType.SMS, TemplateType.EMAIL)) @pytest.mark.parametrize( "subject,content,post_data,expected_subject,expected_content,expected_html", valid_post, @@ -125,7 +125,7 @@ def test_email_templates_not_rendered_into_content(client, sample_service): assert resp_json["body"] == template.content -@pytest.mark.parametrize("tmp_type", TemplateType) +@pytest.mark.parametrize("tmp_type", (TemplateType.SMS, TemplateType.EMAIL)) def test_invalid_post_template_returns_400(client, sample_service, tmp_type): template = create_template( sample_service, diff --git a/tests/app/v2/templates/test_templates_schemas.py b/tests/app/v2/templates/test_templates_schemas.py index f133b5760..08236d8b1 100644 --- a/tests/app/v2/templates/test_templates_schemas.py +++ b/tests/app/v2/templates/test_templates_schemas.py @@ -278,7 +278,10 @@ def test_get_all_template_request_schema_against_invalid_args_is_invalid(templat assert errors["status_code"] == 400 assert len(errors["errors"]) == 1 - assert errors["errors"][0]["message"] == "type unknown is not one of [sms, email, letter]" + assert ( + errors["errors"][0]["message"] + == "type unknown is not one of [sms, email, letter]" + ) @pytest.mark.parametrize("response", valid_json_get_all_response)