diff --git a/app/celery/process_ses_receipts_tasks.py b/app/celery/process_ses_receipts_tasks.py index 8c5de1f62..63a337ed5 100644 --- a/app/celery/process_ses_receipts_tasks.py +++ b/app/celery/process_ses_receipts_tasks.py @@ -170,22 +170,22 @@ def get_aws_responses(ses_message): "Permanent": { "message": "Hard bounced", "success": False, - "notification_status": "permanent-failure", + "notification_status": NotificationStatus.PERMANENT_FAILURE, }, "Temporary": { "message": "Soft bounced", "success": False, - "notification_status": "temporary-failure", + "notification_status": NotificationStatus.TEMPORARY_FAILURE, }, "Delivery": { "message": "Delivered", "success": True, - "notification_status": "delivered", + "notification_status": NotificationStatus.DELIVERED, }, "Complaint": { "message": "Complaint", "success": True, - "notification_status": "delivered", + "notification_status": NotificationStatus.DELIVERED, }, }[status] diff --git a/app/clients/__init__.py b/app/clients/__init__.py index 66e014354..9c1f4af68 100644 --- a/app/clients/__init__.py +++ b/app/clients/__init__.py @@ -14,9 +14,6 @@ AWS_CLIENT_CONFIG = Config( }, use_fips_endpoint=True, ) -STATISTICS_REQUESTED = "requested" -STATISTICS_DELIVERED = "delivered" -STATISTICS_FAILURE = "failure" class ClientException(Exception): diff --git a/app/clients/email/aws_ses.py b/app/clients/email/aws_ses.py index 7bd68a924..a5c404c2b 100644 --- a/app/clients/email/aws_ses.py +++ b/app/clients/email/aws_ses.py @@ -4,38 +4,39 @@ import botocore from boto3 import client from flask import current_app -from app.clients import AWS_CLIENT_CONFIG, STATISTICS_DELIVERED, STATISTICS_FAILURE +from app.clients import AWS_CLIENT_CONFIG from app.clients.email import ( EmailClient, EmailClientException, EmailClientNonRetryableException, ) from app.cloudfoundry_config import cloud_config +from app.enums import NotificationStatus, StatisticsType ses_response_map = { "Permanent": { "message": "Hard bounced", "success": False, - "notification_status": "permanent-failure", - "notification_statistics_status": STATISTICS_FAILURE, + "notification_status": NotificationStatus.PERMANENT_FAILURE, + "notification_statistics_status": StatisticsType.FAILURE, }, "Temporary": { "message": "Soft bounced", "success": False, - "notification_status": "temporary-failure", - "notification_statistics_status": STATISTICS_FAILURE, + "notification_status": NotificationStatus.TEMPORARY_FAILURE, + "notification_statistics_status": StatisticsType.FAILURE, }, "Delivery": { "message": "Delivered", "success": True, - "notification_status": "delivered", - "notification_statistics_status": STATISTICS_DELIVERED, + "notification_status": NotificationStatus.DELIVERED, + "notification_statistics_status": StatisticsType.DELIVERED, }, "Complaint": { "message": "Complaint", "success": True, - "notification_status": "delivered", - "notification_statistics_status": STATISTICS_DELIVERED, + "notification_status": NotificationStatus.DELIVERED, + "notification_statistics_status": StatisticsType.DELIVERED, }, } diff --git a/app/enums.py b/app/enums.py index a5090463f..709fdf323 100644 --- a/app/enums.py +++ b/app/enums.py @@ -209,3 +209,9 @@ class AgreementType(StrEnum): class AgreementStatus(StrEnum): ACTIVE = "active" EXPIRED = "expired" + + +class StatisticsType(StrEnum): + REQUESTED = "requested" + DELIVERED = "delivered" + FAILURE = "failure" diff --git a/app/service/statistics.py b/app/service/statistics.py index 78359fd6c..c8d882e8b 100644 --- a/app/service/statistics.py +++ b/app/service/statistics.py @@ -2,7 +2,7 @@ from collections import defaultdict from datetime import datetime from app.dao.date_util import get_months_for_financial_year -from app.enums import NotificationStatus, TemplateType +from app.enums import NotificationStatus, StatisticsType, TemplateType def format_statistics(statistics): @@ -77,16 +77,16 @@ def format_monthly_template_notification_stats(year, rows): def create_zeroed_stats_dicts(): return { - template_type: {status: 0 for status in ("requested", "delivered", "failed")} + template_type: {status: 0 for status in StatisticsType} for template_type in (TemplateType.SMS, TemplateType.EMAIL) } def _update_statuses_from_row(update_dict, row): if row.status != NotificationStatus.CANCELLED: - update_dict["requested"] += row.count + update_dict[StatisticsType.REQUESTED] += row.count if row.status in (NotificationStatus.DELIVERED, NotificationStatus.SENT): - update_dict["delivered"] += row.count + update_dict[StatisticsType.DELIVERED] += row.count elif row.status in ( NotificationStatus.FAILED, NotificationStatus.TECHNICAL_FAILURE, @@ -95,7 +95,7 @@ def _update_statuses_from_row(update_dict, row): NotificationStatus.VALIDATION_FAILED, NotificationStatus.VIRUS_SCAN_FAILED, ): - update_dict["failed"] += row.count + update_dict[StatisticsType.FAILED] += row.count def create_empty_monthly_notification_status_stats_dict(year): diff --git a/tests/app/celery/test_process_ses_receipts_tasks.py b/tests/app/celery/test_process_ses_receipts_tasks.py index 2977f034e..7edfc91ac 100644 --- a/tests/app/celery/test_process_ses_receipts_tasks.py +++ b/tests/app/celery/test_process_ses_receipts_tasks.py @@ -16,6 +16,7 @@ from app.celery.test_key_tasks import ( ses_soft_bounce_callback, ) from app.dao.notifications_dao import get_notification_by_id +from app.enums import NotificationStatus from app.models import Complaint from tests.app.conftest import create_sample_notification from tests.app.db import ( @@ -136,7 +137,7 @@ def test_process_ses_results(sample_email_template): sample_email_template, reference="ref1", sent_at=datetime.utcnow(), - status="sending", + status=NotificationStatus.SENDING, ) assert process_ses_results(response=ses_notification_callback(reference="ref1")) @@ -147,7 +148,7 @@ def test_process_ses_results_retry_called(sample_email_template, mocker): sample_email_template, reference="ref1", sent_at=datetime.utcnow(), - status="sending", + status=NotificationStatus.SENDING, ) mocker.patch( "app.dao.notifications_dao._update_notification_status", @@ -196,15 +197,20 @@ def test_ses_callback_should_update_notification_status( notify_db_session, template=sample_email_template, reference="ref", - status="sending", + status=NotificationStatus.SENDING, sent_at=datetime.utcnow(), ) create_service_callback_api( service=sample_email_template.service, url="https://original_url.com" ) - assert get_notification_by_id(notification.id).status == "sending" + assert ( + get_notification_by_id(notification.id).status == NotificationStatus.SENDING + ) assert process_ses_results(ses_notification_callback(reference="ref")) - assert get_notification_by_id(notification.id).status == "delivered" + assert ( + get_notification_by_id(notification.id).status + == NotificationStatus.DELIVERED + ) send_mock.assert_called_once_with( [str(notification.id), ANY], queue="service-callbacks" ) @@ -222,11 +228,15 @@ def test_ses_callback_should_not_update_notification_status_if_already_delivered "app.celery.process_ses_receipts_tasks.notifications_dao._update_notification_status" ) notification = create_notification( - template=sample_email_template, reference="ref", status="delivered" + template=sample_email_template, + reference="ref", + status=NotificationStatus.DELIVERED, ) assert process_ses_results(ses_notification_callback(reference="ref")) is None - assert get_notification_by_id(notification.id).status == "delivered" - mock_dup.assert_called_once_with(notification, "delivered") + assert ( + get_notification_by_id(notification.id).status == NotificationStatus.DELIVERED + ) + mock_dup.assert_called_once_with(notification, NotificationStatus.DELIVERED) assert mock_upd.call_count == 0 @@ -283,12 +293,17 @@ def test_ses_callback_does_not_call_send_delivery_status_if_no_db_entry( notify_db_session, template=sample_email_template, reference="ref", - status="sending", + status=NotificationStatus.SENDING, sent_at=datetime.utcnow(), ) - assert get_notification_by_id(notification.id).status == "sending" + assert ( + get_notification_by_id(notification.id).status == NotificationStatus.SENDING + ) assert process_ses_results(ses_notification_callback(reference="ref")) - assert get_notification_by_id(notification.id).status == "delivered" + assert ( + get_notification_by_id(notification.id).status + == NotificationStatus.DELIVERED + ) send_mock.assert_not_called() @@ -304,7 +319,7 @@ def test_ses_callback_should_update_multiple_notification_status_sent( template=sample_email_template, reference="ref1", sent_at=datetime.utcnow(), - status="sending", + status=NotificationStatus.SENDING, ) create_sample_notification( _notify_db, @@ -312,7 +327,7 @@ def test_ses_callback_should_update_multiple_notification_status_sent( template=sample_email_template, reference="ref2", sent_at=datetime.utcnow(), - status="sending", + status=NotificationStatus.SENDING, ) create_sample_notification( _notify_db, @@ -320,7 +335,7 @@ def test_ses_callback_should_update_multiple_notification_status_sent( template=sample_email_template, reference="ref3", sent_at=datetime.utcnow(), - status="sending", + status=NotificationStatus.SENDING, ) create_service_callback_api( service=sample_email_template.service, url="https://original_url.com" @@ -342,15 +357,18 @@ def test_ses_callback_should_set_status_to_temporary_failure( notify_db_session, template=sample_email_template, reference="ref", - status="sending", + status=NotificationStatus.SENDING, sent_at=datetime.utcnow(), ) create_service_callback_api( service=notification.service, url="https://original_url.com" ) - assert get_notification_by_id(notification.id).status == "sending" + assert get_notification_by_id(notification.id).status == NotificationStatus.SENDING assert process_ses_results(ses_soft_bounce_callback(reference="ref")) - assert get_notification_by_id(notification.id).status == "temporary-failure" + assert ( + get_notification_by_id(notification.id).status + == NotificationStatus.TEMPORARY_FAILURE + ) assert send_mock.called @@ -365,15 +383,18 @@ def test_ses_callback_should_set_status_to_permanent_failure( notify_db_session, template=sample_email_template, reference="ref", - status="sending", + status=NotificationStatus.SENDING, sent_at=datetime.utcnow(), ) create_service_callback_api( service=sample_email_template.service, url="https://original_url.com" ) - assert get_notification_by_id(notification.id).status == "sending" + assert get_notification_by_id(notification.id).status == NotificationStatus.SENDING assert process_ses_results(ses_hard_bounce_callback(reference="ref")) - assert get_notification_by_id(notification.id).status == "permanent-failure" + assert ( + get_notification_by_id(notification.id).status + == NotificationStatus.PERMANENT_FAILURE + ) assert send_mock.called @@ -392,7 +413,7 @@ def test_ses_callback_should_send_on_complaint_to_user_callback_api( template=sample_email_template, reference="ref1", sent_at=datetime.utcnow(), - status="sending", + status=NotificationStatus.SENDING, ) response = ses_complaint_callback() assert process_ses_results(response) diff --git a/tests/app/celery/test_service_callback_tasks.py b/tests/app/celery/test_service_callback_tasks.py index f1e4db462..2e050e9f8 100644 --- a/tests/app/celery/test_service_callback_tasks.py +++ b/tests/app/celery/test_service_callback_tasks.py @@ -161,7 +161,7 @@ def test__send_data_to_service_callback_api_does_not_retry_if_request_returns_40 created_at=datestr, updated_at=datestr, sent_at=datestr, - status="sent", + status=NotificationStatus.SENT, ) encrypted_data = _set_up_data_for_status_update(callback_api, notification) mocked = mocker.patch( diff --git a/tests/app/celery/test_test_key_tasks.py b/tests/app/celery/test_test_key_tasks.py index 9d2b3109c..dd18c31a2 100644 --- a/tests/app/celery/test_test_key_tasks.py +++ b/tests/app/celery/test_test_key_tasks.py @@ -36,7 +36,10 @@ def test_make_sns_callback(notify_api, rmock, mocker): assert rmock.called assert rmock.request_history[0].url == endpoint - assert json.loads(rmock.request_history[0].text)["status"] == "delivered" + assert ( + json.loads(rmock.request_history[0].text)["status"] + == NotificationStatus.DELIVERED + ) def test_callback_logs_on_api_call_failure(notify_api, rmock, mocker): @@ -86,5 +89,5 @@ def test_delivered_sns_callback(mocker): get_notification_by_id.return_value = n data = json.loads(sns_callback("1234")) - assert data["status"] == "delivered" + assert data["status"] == NotificationStatus.DELIVERED assert data["CID"] == "1234" diff --git a/tests/app/clients/test_aws_ses.py b/tests/app/clients/test_aws_ses.py index 98cbc532f..302fe2dd9 100644 --- a/tests/app/clients/test_aws_ses.py +++ b/tests/app/clients/test_aws_ses.py @@ -12,37 +12,38 @@ from app.clients.email.aws_ses import ( AwsSesClientThrottlingSendRateException, get_aws_responses, ) +from app.enums import NotificationStatus, StatisticsType def test_should_return_correct_details_for_delivery(): response_dict = get_aws_responses("Delivery") assert response_dict["message"] == "Delivered" - assert response_dict["notification_status"] == "delivered" - assert response_dict["notification_statistics_status"] == "delivered" + assert response_dict["notification_status"] == NotificationStatus.DELIVERED + assert response_dict["notification_statistics_status"] == StatisticsType.DELIVERED assert response_dict["success"] def test_should_return_correct_details_for_hard_bounced(): response_dict = get_aws_responses("Permanent") assert response_dict["message"] == "Hard bounced" - assert response_dict["notification_status"] == "permanent-failure" - assert response_dict["notification_statistics_status"] == "failure" + assert response_dict["notification_status"] == NotificationStatus.PERMANENT_FAILURE + assert response_dict["notification_statistics_status"] == StatisticsType.FAILURE assert not response_dict["success"] def test_should_return_correct_details_for_soft_bounced(): response_dict = get_aws_responses("Temporary") assert response_dict["message"] == "Soft bounced" - assert response_dict["notification_status"] == "temporary-failure" - assert response_dict["notification_statistics_status"] == "failure" + assert response_dict["notification_status"] == NotificationStatus.TEMPORARY_FAILURE + assert response_dict["notification_statistics_status"] == StatisticsType.FAILURE assert not response_dict["success"] def test_should_return_correct_details_for_complaint(): response_dict = get_aws_responses("Complaint") assert response_dict["message"] == "Complaint" - assert response_dict["notification_status"] == "delivered" - assert response_dict["notification_statistics_status"] == "delivered" + assert response_dict["notification_status"] == NotificationStatus.DELIVERED + assert response_dict["notification_statistics_status"] == StatisticsType.DELIVERED assert response_dict["success"] diff --git a/tests/app/dao/test_fact_billing_dao.py b/tests/app/dao/test_fact_billing_dao.py index 85d40c3e6..c717aa730 100644 --- a/tests/app/dao/test_fact_billing_dao.py +++ b/tests/app/dao/test_fact_billing_dao.py @@ -116,8 +116,8 @@ def test_fetch_billing_data_for_day_only_calls_query_for_permission_type( service = create_service(service_permissions=[notification_type]) email_template = create_template(service=service, template_type=TemplateType.EMAIL) sms_template = create_template(service=service, template_type=TemplateType.SMS) - create_notification(template=email_template, status="delivered") - create_notification(template=sms_template, status="delivered") + create_notification(template=email_template, status=NotificationStatus.DELIVERED) + create_notification(template=sms_template, status=NotificationStatus.DELIVERED) today = datetime.utcnow() results = fetch_billing_data_for_day( process_day=today.date(), check_permissions=True diff --git a/tests/app/notifications/test_notifications_ses_callback.py b/tests/app/notifications/test_notifications_ses_callback.py index 0260f7665..ec61004d6 100644 --- a/tests/app/notifications/test_notifications_ses_callback.py +++ b/tests/app/notifications/test_notifications_ses_callback.py @@ -7,6 +7,7 @@ from app.celery.process_ses_receipts_tasks import ( handle_complaint, ) from app.dao.notifications_dao import get_notification_by_id +from app.enums import NotificationStatus from app.models import Complaint from tests.app.db import ( create_notification, @@ -23,10 +24,12 @@ def test_ses_callback_should_not_set_status_once_status_is_delivered( ): notification = create_notification( sample_email_template, - status="delivered", + status=NotificationStatus.DELIVERED, ) - assert get_notification_by_id(notification.id).status == "delivered" + assert ( + get_notification_by_id(notification.id).status == NotificationStatus.DELIVERED + ) def test_process_ses_results_in_complaint(sample_email_template): diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 4a5d60941..d7f8e169c 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -21,6 +21,7 @@ from app.enums import ( OrganizationType, PermissionType, ServicePermissionType, + StatisticsType, TemplateType, ) from app.models import ( @@ -1775,10 +1776,14 @@ def test_get_all_notifications_for_service_filters_notifications_when_using_post ) create_notification( - service_1_sms_template, to_field="+447700900000", normalised_to="447700900000" + service_1_sms_template, + to_field="+447700900000", + normalised_to="447700900000", ) create_notification( - service_1_sms_template, status="delivered", normalised_to="447700900855" + service_1_sms_template, + status=NotificationStatus.DELIVERED, + normalised_to="447700900855", ) create_notification(service_1_email_template, normalised_to="447700900855") # create notification for service_2 @@ -2089,8 +2094,22 @@ def test_set_sms_prefixing_for_service_cant_be_none( @pytest.mark.parametrize( "today_only,stats", [ - ("False", {"requested": 2, "delivered": 1, "failed": 0}), - ("True", {"requested": 1, "delivered": 0, "failed": 0}), + ( + "False", + { + StatisticsType.REQUESTED: 2, + StatisticsType.DELIVERED: 1, + StatisticsType.FAILED: 0, + }, + ), + ( + "True", + { + StatisticsType.REQUESTED: 1, + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + }, + ), ], ids=["seven_days", "today"], ) @@ -2134,8 +2153,16 @@ 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: {"delivered": 0, "failed": 0, "requested": 0}, - NotificationType.SMS: {"delivered": 0, "failed": 0, "requested": 3}, + NotificationType.EMAIL: { + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + StatisticsType.REQUESTED: 0, + }, + NotificationType.SMS: { + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + StatisticsType.REQUESTED: 3, + }, } @@ -2157,8 +2184,16 @@ 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: {"delivered": 0, "failed": 0, "requested": 0}, - NotificationType.SMS: {"delivered": 0, "failed": 0, "requested": 2}, + NotificationType.EMAIL: { + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + StatisticsType.REQUESTED: 0, + }, + NotificationType.SMS: { + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + StatisticsType.REQUESTED: 2, + }, } @@ -2228,27 +2263,27 @@ def test_get_detailed_services_groups_by_service(notify_db_session): assert data[0]["id"] == str(service_1.id) assert data[0]["statistics"] == { NotificationType.EMAIL: { - "delivered": 0, - "failed": 0, - "requested": 0, + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + StatisticsType.REQUESTED: 0, }, NotificationType.SMS: { - "delivered": 1, - "failed": 0, - "requested": 3, + StatisticsType.DELIVERED: 1, + StatisticsType.FAILED: 0, + StatisticsType.REQUESTED: 3, }, } assert data[1]["id"] == str(service_2.id) assert data[1]["statistics"] == { NotificationType.EMAIL: { - "delivered": 0, - "failed": 0, - "requested": 0, + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + StatisticsType.REQUESTED: 0, }, NotificationType.SMS: { - "delivered": 0, - "failed": 0, - "requested": 1, + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + StatisticsType.REQUESTED: 1, }, } @@ -2273,27 +2308,27 @@ def test_get_detailed_services_includes_services_with_no_notifications( assert data[0]["id"] == str(service_1.id) assert data[0]["statistics"] == { NotificationType.EMAIL: { - "delivered": 0, - "failed": 0, - "requested": 0, + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + StatisticsType.REQUESTED: 0, }, NotificationType.SMS: { - "delivered": 0, - "failed": 0, - "requested": 1, + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + StatisticsType.REQUESTED: 1, }, } assert data[1]["id"] == str(service_2.id) assert data[1]["statistics"] == { NotificationType.EMAIL: { - "delivered": 0, - "failed": 0, - "requested": 0, + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + StatisticsType.REQUESTED: 0, }, NotificationType.SMS: { - "delivered": 0, - "failed": 0, - "requested": 0, + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + StatisticsType.REQUESTED: 0, }, } @@ -2315,14 +2350,14 @@ def test_get_detailed_services_only_includes_todays_notifications(sample_templat assert len(data) == 1 assert data[0]["statistics"] == { NotificationType.EMAIL: { - "delivered": 0, - "failed": 0, - "requested": 0, + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + StatisticsType.REQUESTED: 0, }, NotificationType.SMS: { - "delivered": 0, - "failed": 0, - "requested": 3, + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + StatisticsType.REQUESTED: 3, }, } @@ -2368,14 +2403,14 @@ def test_get_detailed_services_for_date_range( assert len(data) == 1 assert data[0]["statistics"][NotificationType.EMAIL] == { - "delivered": 0, - "failed": 0, - "requested": 0, + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + StatisticsType.REQUESTED: 0, } assert data[0]["statistics"][NotificationType.SMS] == { - "delivered": 2, - "failed": 0, - "requested": 2, + StatisticsType.DELIVERED: 2, + StatisticsType.FAILED: 0, + StatisticsType.REQUESTED: 2, } @@ -2598,13 +2633,13 @@ def test_search_for_notification_by_to_field_filters_by_status(client, sample_te notification1 = create_notification( sample_template, to_field="+447700900855", - status="delivered", + status=NotificationStatus.DELIVERED, normalised_to="447700900855", ) create_notification( sample_template, to_field="+447700900855", - status="sending", + status=NotificationStatus.SENDING, normalised_to="447700900855", ) @@ -2630,13 +2665,13 @@ def test_search_for_notification_by_to_field_filters_by_statuses( notification1 = create_notification( sample_template, to_field="+447700900855", - status="delivered", + status=NotificationStatus.DELIVERED, normalised_to="447700900855", ) notification2 = create_notification( sample_template, to_field="+447700900855", - status="sending", + status=NotificationStatus.SENDING, normalised_to="447700900855", ) diff --git a/tests/app/service/test_statistics_rest.py b/tests/app/service/test_statistics_rest.py index 6216f2ab2..a220231ce 100644 --- a/tests/app/service/test_statistics_rest.py +++ b/tests/app/service/test_statistics_rest.py @@ -4,7 +4,13 @@ from datetime import date, datetime import pytest from freezegun import freeze_time -from app.enums import KeyType, NotificationStatus, NotificationType, TemplateType +from app.enums import ( + KeyType, + NotificationStatus, + NotificationType, + StatisticsType, + TemplateType, +) from tests.app.db import ( create_ft_notification_status, create_notification, @@ -106,8 +112,22 @@ def test_get_template_usage_by_month_returns_two_templates( @pytest.mark.parametrize( "today_only, stats", [ - (False, {"requested": 2, "delivered": 1, "failed": 0}), - (True, {"requested": 1, "delivered": 0, "failed": 0}), + ( + False, + { + StatisticsType.REQUESTED: 2, + StatisticsType.DELIVERED: 1, + StatisticsType.FAILED: 0, + }, + ), + ( + True, + { + StatisticsType.REQUESTED: 1, + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + }, + ), ], ids=["seven_days", "today"], ) @@ -138,8 +158,16 @@ def test_get_service_notification_statistics_with_unknown_service(admin_request) ) assert resp["data"] == { - NotificationType.SMS: {"requested": 0, "delivered": 0, "failed": 0}, - NotificationType.EMAIL: {"requested": 0, "delivered": 0, "failed": 0}, + NotificationType.SMS: { + StatisticsType.REQUESTED: 0, + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + }, + NotificationType.EMAIL: { + StatisticsType.REQUESTED: 0, + StatisticsType.DELIVERED: 0, + StatisticsType.FAILED: 0, + }, } @@ -237,7 +265,7 @@ def test_get_monthly_notification_stats_returns_stats(admin_request, sample_serv NotificationStatus.CREATED: 1, NotificationStatus.DELIVERED: 2, }, - NotificationType.EMAIL: {"delivered": 1}, + NotificationType.EMAIL: {StatisticsType.DELIVERED: 1}, } diff --git a/tests/app/test_model.py b/tests/app/test_model.py index 95039b6a3..bbd670412 100644 --- a/tests/app/test_model.py +++ b/tests/app/test_model.py @@ -152,21 +152,29 @@ def test_notification_for_csv_returns_correct_job_row_number(sample_job): @pytest.mark.parametrize( "template_type, status, expected_status", [ - (TemplateType.EMAIL, "failed", "Failed"), - (TemplateType.EMAIL, "technical-failure", "Technical failure"), + (TemplateType.EMAIL, NotificationStatus.FAILED, "Failed"), + (TemplateType.EMAIL, NotificationStatus.TECHNICAL_FAILURE, "Technical failure"), ( TemplateType.EMAIL, - "temporary-failure", + NotificationStatus.TEMPORARY_FAILURE, "Inbox not accepting messages right now", ), - (TemplateType.EMAIL, "permanent-failure", "Email address doesn’t exist"), + ( + TemplateType.EMAIL, + NotificationStatus.PERMANENT_FAILURE, + "Email address doesn’t exist", + ), ( TemplateType.SMS, - "temporary-failure", + NotificationStatus.TEMPORARY_FAILURE, "Unable to find carrier response -- still looking", ), - (TemplateType.SMS, "permanent-failure", "Unable to find carrier response."), - (TemplateType.SMS, "sent", "Sent internationally"), + ( + TemplateType.SMS, + NotificationStatus.PERMANENT_FAILURE, + "Unable to find carrier response.", + ), + (TemplateType.SMS, NotificationStatus.SENT, "Sent internationally"), ], ) def test_notification_for_csv_returns_formatted_status( diff --git a/tests/app/v2/notifications/test_get_notifications.py b/tests/app/v2/notifications/test_get_notifications.py index 79fba95be..e551ca4f8 100644 --- a/tests/app/v2/notifications/test_get_notifications.py +++ b/tests/app/v2/notifications/test_get_notifications.py @@ -630,7 +630,8 @@ def test_get_all_notifications_filter_multiple_query_parameters( # TODO had to change pending to sending. Is that correct? # this is the notification we are looking for older_notification = create_notification( - template=sample_email_template, status="sending" + template=sample_email_template, + status=NotificationStatus.SENDING, ) # wrong status @@ -639,13 +640,16 @@ def test_get_all_notifications_filter_multiple_query_parameters( sample_email_template.service, template_type=TemplateType.SMS ) # wrong template - create_notification(template=wrong_template, status="sending") + create_notification(template=wrong_template, status=NotificationStatus.SENDING) # we only want notifications created before this one newer_notification = create_notification(template=sample_email_template) # this notification was created too recently - create_notification(template=sample_email_template, status="sending") + create_notification( + template=sample_email_template, + status=NotificationStatus.SENDING, + ) auth_header = create_service_authorization_header( service_id=newer_notification.service_id