diff --git a/app/email_branding/email_branding_schema.py b/app/email_branding/email_branding_schema.py index 805835724..fa3b7f60e 100644 --- a/app/email_branding/email_branding_schema.py +++ b/app/email_branding/email_branding_schema.py @@ -9,7 +9,7 @@ post_create_email_branding_schema = { "name": {"type": "string"}, "text": {"type": ["string", "null"]}, "logo": {"type": ["string", "null"]}, - "brand_type": {"enum": [e.value for e in BrandType]}, + "brand_type": {"enum": list(BrandType)}, }, "required": ["name"], } @@ -23,7 +23,7 @@ post_update_email_branding_schema = { "name": {"type": ["string", "null"]}, "text": {"type": ["string", "null"]}, "logo": {"type": ["string", "null"]}, - "brand_type": {"enum": [e.value for e in BrandType]}, + "brand_type": {"enum": list(BrandType)}, }, "required": [], } diff --git a/app/service/service_data_retention_schema.py b/app/service/service_data_retention_schema.py index da732c284..2aeb7f92a 100644 --- a/app/service/service_data_retention_schema.py +++ b/app/service/service_data_retention_schema.py @@ -7,9 +7,7 @@ add_service_data_retention_request = { "type": "object", "properties": { "days_of_retention": {"type": "integer"}, - "notification_type": { - "enum": [NotificationType.SMS.value, NotificationType.EMAIL.value] - }, + "notification_type": {"enum": [NotificationType.SMS, NotificationType.EMAIL]}, }, "required": ["days_of_retention", "notification_type"], } diff --git a/app/service/statistics.py b/app/service/statistics.py index bf230f164..78359fd6c 100644 --- a/app/service/statistics.py +++ b/app/service/statistics.py @@ -68,7 +68,7 @@ def format_monthly_template_notification_stats(year, rows): stats[formatted_month][str(row.template_id)] = { "name": row.name, "type": row.template_type, - "counts": dict.fromkeys([e.value for e in NotificationStatus], 0), + "counts": dict.fromkeys(list(NotificationStatus), 0), } stats[formatted_month][str(row.template_id)]["counts"][row.status] += row.count @@ -83,17 +83,17 @@ def create_zeroed_stats_dicts(): def _update_statuses_from_row(update_dict, row): - if row.status != "cancelled": + if row.status != NotificationStatus.CANCELLED: update_dict["requested"] += row.count - if row.status in ("delivered", "sent"): + if row.status in (NotificationStatus.DELIVERED, NotificationStatus.SENT): update_dict["delivered"] += row.count elif row.status in ( - "failed", - "technical-failure", - "temporary-failure", - "permanent-failure", - "validation-failed", - "virus-scan-failed", + NotificationStatus.FAILED, + NotificationStatus.TECHNICAL_FAILURE, + NotificationStatus.TEMPORARY_FAILURE, + NotificationStatus.PERMANENT_FAILURE, + NotificationStatus.VALIDATION_FAILED, + NotificationStatus.VIRUS_SCAN_FAILED, ): update_dict["failed"] += row.count diff --git a/app/template/template_schemas.py b/app/template/template_schemas.py index d03a83b93..899572d37 100644 --- a/app/template/template_schemas.py +++ b/app/template/template_schemas.py @@ -8,15 +8,15 @@ post_create_template_schema = { "title": "payload for POST /service//template", "properties": { "name": {"type": "string"}, - "template_type": {"enum": [e.value for e in TemplateType]}, + "template_type": {"enum": list(TemplateType)}, "service": uuid, - "process_type": {"enum": [e.value for e in TemplateProcessType]}, + "process_type": {"enum": list(TemplateProcessType)}, "content": {"type": "string"}, "subject": {"type": "string"}, "created_by": uuid, "parent_folder_id": uuid, }, - "if": {"properties": {"template_type": {"enum": [TemplateType.EMAIL.value]}}}, + "if": {"properties": {"template_type": {"enum": [TemplateType.EMAIL]}}}, "then": {"required": ["subject"]}, "required": ["name", "template_type", "content", "service", "created_by"], } @@ -29,9 +29,9 @@ post_update_template_schema = { "properties": { "id": uuid, "name": {"type": "string"}, - "template_type": {"enum": [e.value for e in TemplateType]}, + "template_type": {"enum": list(TemplateType)}, "service": uuid, - "process_type": {"enum": [e.value for e in TemplateProcessType]}, + "process_type": {"enum": list(TemplateProcessType)}, "content": {"type": "string"}, "subject": {"type": "string"}, "reply_to": nullable_uuid, diff --git a/app/v2/notifications/notification_schemas.py b/app/v2/notifications/notification_schemas.py index 0d737407e..c66ecf6c2 100644 --- a/app/v2/notifications/notification_schemas.py +++ b/app/v2/notifications/notification_schemas.py @@ -41,7 +41,7 @@ get_notification_response = { "line_5": {"type": ["string", "null"]}, "line_6": {"type": ["string", "null"]}, "postcode": {"type": ["string", "null"]}, - "type": {"enum": [e.value for e in TemplateType]}, + "type": {"enum": list(TemplateType)}, "status": {"type": "string"}, "template": template, "body": {"type": "string"}, @@ -82,11 +82,11 @@ get_notifications_request = { "reference": {"type": "string"}, "status": { "type": "array", - "items": {"enum": [e.value for e in NotificationStatus]}, + "items": {"enum": list(NotificationStatus)}, }, "template_type": { "type": "array", - "items": {"enum": [e.value for e in TemplateType]}, + "items": {"enum": list(TemplateType)}, }, "include_jobs": {"enum": ["true", "True"]}, "older_than": uuid, diff --git a/app/v2/template/template_schemas.py b/app/v2/template/template_schemas.py index 8d0cf300d..7461f3fe4 100644 --- a/app/v2/template/template_schemas.py +++ b/app/v2/template/template_schemas.py @@ -17,7 +17,7 @@ get_template_by_id_response = { "title": "reponse v2/template", "properties": { "id": uuid, - "type": {"enum": [e.value for e in TemplateType]}, + "type": {"enum": list(TemplateType)}, "created_at": { "format": "date-time", "type": "string", @@ -62,7 +62,7 @@ post_template_preview_response = { "title": "reponse v2/template/{id}/preview", "properties": { "id": uuid, - "type": {"enum": [e.value for e in TemplateType]}, + "type": {"enum": list(TemplateType)}, "version": {"type": "integer"}, "body": {"type": "string"}, "subject": {"type": ["string", "null"]}, diff --git a/app/v2/templates/templates_schemas.py b/app/v2/templates/templates_schemas.py index 70aea7522..90cb6e01d 100644 --- a/app/v2/templates/templates_schemas.py +++ b/app/v2/templates/templates_schemas.py @@ -5,7 +5,7 @@ get_all_template_request = { "$schema": "http://json-schema.org/draft-07/schema#", "description": "request schema for parameters allowed when getting all templates", "type": "object", - "properties": {"type": {"enum": [e.value for e in TemplateType]}}, + "properties": {"type": {"enum": list(TemplateType)}}, "additionalProperties": False, } diff --git a/tests/app/notifications/test_rest.py b/tests/app/notifications/test_rest.py index 6e8142e7c..0b7f711ce 100644 --- a/tests/app/notifications/test_rest.py +++ b/tests/app/notifications/test_rest.py @@ -272,13 +272,19 @@ def test_only_normal_api_keys_can_return_job_notifications( key_type, ): normal_notification = create_notification( - template=sample_template, api_key=sample_api_key, key_type=KeyType.NORMAL + template=sample_template, + api_key=sample_api_key, + key_type=KeyType.NORMAL, ) team_notification = create_notification( - template=sample_template, api_key=sample_team_api_key, key_type=KeyType.TEAM + template=sample_template, + api_key=sample_team_api_key, + key_type=KeyType.TEAM, ) test_notification = create_notification( - template=sample_template, api_key=sample_test_api_key, key_type=KeyType.TEST + template=sample_template, + api_key=sample_test_api_key, + key_type=KeyType.TEST, ) notification_objs = { diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 94cf5d8d6..4a5d60941 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -1231,9 +1231,7 @@ def test_default_permissions_are_added_for_user_service( str(sample_service.id) ] - assert sorted(i.value for i in PermissionType.defaults()) == sorted( - service_permissions - ) + assert sorted(PermissionType.defaults()) == sorted(service_permissions) def test_add_existing_user_to_another_service_with_all_permissions( @@ -1790,7 +1788,7 @@ def test_get_all_notifications_for_service_filters_notifications_when_using_post data = { "page": 1, "template_type": [TemplateType.SMS], - "status": ["created", "sending"], + "status": [NotificationStatus.CREATED, NotificationStatus.SENDING], "to": "0855", } @@ -2103,7 +2101,7 @@ def test_get_detailed_service( date(2000, 1, 1), NotificationType.SMS, sample_service, count=1 ) with freeze_time("2000-01-02T12:00:00"): - create_notification(template=sample_template, status="created") + create_notification(template=sample_template, status=NotificationStatus.CREATED) resp = client.get( f"/service/{sample_service.id}?detailed=True&today_only={today_only}", headers=[create_admin_authorization_header()], @@ -2114,10 +2112,10 @@ def test_get_detailed_service( assert service["id"] == str(sample_service.id) assert "statistics" in service.keys() assert set(service["statistics"].keys()) == { - NotificationType.SMS.value, - NotificationType.EMAIL.value, + NotificationType.SMS, + NotificationType.EMAIL, } - assert service["statistics"][NotificationType.SMS.value] == stats + assert service["statistics"][NotificationType.SMS] == stats def test_get_services_with_detailed_flag(client, sample_template): @@ -2136,8 +2134,8 @@ def test_get_services_with_detailed_flag(client, sample_template): assert data[0]["name"] == "Sample service" assert data[0]["id"] == str(notifications[0].service_id) assert data[0]["statistics"] == { - NotificationType.EMAIL.value: {"delivered": 0, "failed": 0, "requested": 0}, - NotificationType.SMS.value: {"delivered": 0, "failed": 0, "requested": 3}, + NotificationType.EMAIL: {"delivered": 0, "failed": 0, "requested": 0}, + NotificationType.SMS: {"delivered": 0, "failed": 0, "requested": 3}, } @@ -2159,8 +2157,8 @@ def test_get_services_with_detailed_flag_excluding_from_test_key( data = resp.json["data"] assert len(data) == 1 assert data[0]["statistics"] == { - NotificationType.EMAIL.value: {"delivered": 0, "failed": 0, "requested": 0}, - NotificationType.SMS.value: {"delivered": 0, "failed": 0, "requested": 2}, + NotificationType.EMAIL: {"delivered": 0, "failed": 0, "requested": 0}, + NotificationType.SMS: {"delivered": 0, "failed": 0, "requested": 2}, } @@ -2229,27 +2227,27 @@ def test_get_detailed_services_groups_by_service(notify_db_session): assert len(data) == 2 assert data[0]["id"] == str(service_1.id) assert data[0]["statistics"] == { - NotificationType.EMAIL.value: { - NotificationStatus.DELIVERED: 0, - NotificationStatus.FAILED: 0, + NotificationType.EMAIL: { + "delivered": 0, + "failed": 0, "requested": 0, }, - NotificationType.SMS.value: { - NotificationStatus.DELIVERED: 1, - NotificationStatus.FAILED: 0, + NotificationType.SMS: { + "delivered": 1, + "failed": 0, "requested": 3, }, } assert data[1]["id"] == str(service_2.id) assert data[1]["statistics"] == { - NotificationType.EMAIL.value: { - NotificationStatus.DELIVERED: 0, - NotificationStatus.FAILED: 0, + NotificationType.EMAIL: { + "delivered": 0, + "failed": 0, "requested": 0, }, - NotificationType.SMS.value: { - NotificationStatus.DELIVERED: 0, - NotificationStatus.FAILED: 0, + NotificationType.SMS: { + "delivered": 0, + "failed": 0, "requested": 1, }, } @@ -2274,27 +2272,27 @@ def test_get_detailed_services_includes_services_with_no_notifications( assert len(data) == 2 assert data[0]["id"] == str(service_1.id) assert data[0]["statistics"] == { - NotificationType.EMAIL.value: { - NotificationStatus.DELIVERED: 0, - NotificationStatus.FAILED: 0, + NotificationType.EMAIL: { + "delivered": 0, + "failed": 0, "requested": 0, }, - NotificationType.SMS.value: { - NotificationStatus.DELIVERED: 0, - NotificationStatus.FAILED: 0, + NotificationType.SMS: { + "delivered": 0, + "failed": 0, "requested": 1, }, } assert data[1]["id"] == str(service_2.id) assert data[1]["statistics"] == { - NotificationType.EMAIL.value: { - NotificationStatus.DELIVERED: 0, - NotificationStatus.FAILED: 0, + NotificationType.EMAIL: { + "delivered": 0, + "failed": 0, "requested": 0, }, - NotificationType.SMS.value: { - NotificationStatus.DELIVERED: 0, - NotificationStatus.FAILED: 0, + NotificationType.SMS: { + "delivered": 0, + "failed": 0, "requested": 0, }, } @@ -2316,14 +2314,14 @@ def test_get_detailed_services_only_includes_todays_notifications(sample_templat assert len(data) == 1 assert data[0]["statistics"] == { - NotificationType.EMAIL.value: { - NotificationStatus.DELIVERED: 0, - NotificationStatus.FAILED: 0, + NotificationType.EMAIL: { + "delivered": 0, + "failed": 0, "requested": 0, }, - NotificationType.SMS.value: { - NotificationStatus.DELIVERED: 0, - NotificationStatus.FAILED: 0, + NotificationType.SMS: { + "delivered": 0, + "failed": 0, "requested": 3, }, } @@ -2369,14 +2367,14 @@ def test_get_detailed_services_for_date_range( ) assert len(data) == 1 - assert data[0]["statistics"][NotificationType.EMAIL.value] == { - NotificationStatus.DELIVERED: 0, - NotificationStatus.FAILED: 0, + assert data[0]["statistics"][NotificationType.EMAIL] == { + "delivered": 0, + "failed": 0, "requested": 0, } - assert data[0]["statistics"][NotificationType.SMS.value] == { - NotificationStatus.DELIVERED: 2, - NotificationStatus.FAILED: 0, + assert data[0]["statistics"][NotificationType.SMS] == { + "delivered": 2, + "failed": 0, "requested": 2, } diff --git a/tests/app/test_commands.py b/tests/app/test_commands.py index b147f3a0f..a96eae599 100644 --- a/tests/app/test_commands.py +++ b/tests/app/test_commands.py @@ -265,7 +265,8 @@ def test_populate_annual_billing_with_defaults( notify_db_session, notify_api, organization_type, expected_allowance ): service = create_service( - service_name=organization_type.value, organization_type=organization_type + service_name=organization_type, + organization_type=organization_type, ) notify_api.test_cli_runner().invoke( @@ -289,7 +290,8 @@ def test_populate_annual_billing_with_the_previous_years_allowance( notify_db_session, notify_api, organization_type, expected_allowance ): service = create_service( - service_name=organization_type.value, organization_type=organization_type + service_name=organization_type, + organization_type=organization_type, ) notify_api.test_cli_runner().invoke( diff --git a/tests/app/v2/notifications/test_get_notifications.py b/tests/app/v2/notifications/test_get_notifications.py index a68ed3ac7..79fba95be 100644 --- a/tests/app/v2/notifications/test_get_notifications.py +++ b/tests/app/v2/notifications/test_get_notifications.py @@ -1,7 +1,7 @@ import pytest from flask import json, url_for -from app.enums import NotificationType, TemplateType +from app.enums import NotificationStatus, NotificationType, TemplateType from app.utils import DATETIME_FORMAT from tests import create_service_authorization_header from tests.app.db import create_notification, create_template @@ -284,7 +284,7 @@ def test_get_all_notifications_except_job_notifications_returns_200( assert len(json_response["notifications"]) == 2 assert json_response["notifications"][0]["id"] == str(notification.id) - assert json_response["notifications"][0]["status"] == "created" + assert json_response["notifications"][0]["status"] == NotificationStatus.CREATED assert json_response["notifications"][0]["template"] == { "id": str(notification.template.id), "uri": notification.template.get_link(), @@ -380,7 +380,7 @@ def test_get_all_notifications_filter_by_template_type(client, sample_service): assert len(json_response["notifications"]) == 1 assert json_response["notifications"][0]["id"] == str(notification.id) - assert json_response["notifications"][0]["status"] == "created" + assert json_response["notifications"][0]["status"] == NotificationStatus.CREATED assert json_response["notifications"][0]["template"] == { "id": str(email_template.id), "uri": notification.template.get_link(), @@ -469,7 +469,11 @@ def test_get_all_notifications_filter_by_status_invalid_status( def test_get_all_notifications_filter_by_multiple_statuses(client, sample_template): notifications = [ create_notification(template=sample_template, status=_status) - for _status in ["created", "pending", "sending"] + for _status in [ + NotificationStatus.CREATED, + NotificationStatus.PENDING, + NotificationStatus.SENDING, + ] ] failed_notification = create_notification( template=sample_template, status="permanent-failure" @@ -502,7 +506,8 @@ def test_get_all_notifications_filter_by_multiple_statuses(client, sample_templa def test_get_all_notifications_filter_by_failed_status(client, sample_template): created_notification = create_notification( - template=sample_template, status="created" + template=sample_template, + status=NotificationStatus.CREATED, ) failed_notifications = [ create_notification(template=sample_template, status="failed") @@ -692,6 +697,6 @@ def test_get_all_notifications_renames_letter_statuses( noti["type"] == NotificationType.SMS or noti["type"] == NotificationType.EMAIL ): - assert noti["status"] == "created" + assert noti["status"] == NotificationStatus.CREATED else: pytest.fail() diff --git a/tests/app/v2/notifications/test_notification_schemas.py b/tests/app/v2/notifications/test_notification_schemas.py index 0c6595c20..4d7df0af6 100644 --- a/tests/app/v2/notifications/test_notification_schemas.py +++ b/tests/app/v2/notifications/test_notification_schemas.py @@ -39,7 +39,7 @@ def test_get_notifications_valid_json(input): # multiple invalid statuses (["elephant", "giraffe", "cheetah"], []), # one bad status and one good status - (["elephant"], ["created"]), + (["elephant"], [NotificationStatus.CREATED]), ], ) def test_get_notifications_request_invalid_statuses(invalid_statuses, valid_statuses):