diff --git a/tests/app/billing/test_rest.py b/tests/app/billing/test_rest.py index dd2781f90..5d503b019 100644 --- a/tests/app/billing/test_rest.py +++ b/tests/app/billing/test_rest.py @@ -6,6 +6,7 @@ from freezegun import freeze_time from app.billing.rest import update_free_sms_fragment_limit_data from app.dao.annual_billing_dao import dao_get_free_sms_fragment_limit_for_year from app.dao.date_util import get_current_calendar_year_start_year +from app.enums import NotificationType, TemplateType from tests.app.db import ( create_annual_billing, create_ft_billing, @@ -153,7 +154,7 @@ def test_get_yearly_usage_by_monthly_from_ft_billing(admin_request, notify_db_se service_id=service.id, free_sms_fragment_limit=1, financial_year_start=2016 ) - sms_template = create_template(service=service, template_type="sms") + sms_template = create_template(service=service, template_type=TemplateType.SMS) email_template = create_template(service=service, template_type="email") for dt in (date(2016, 1, 28), date(2016, 8, 10), date(2016, 12, 26)): @@ -173,10 +174,10 @@ def test_get_yearly_usage_by_monthly_from_ft_billing(admin_request, notify_db_se email_rows = [row for row in json_response if row["notification_type"] == "email"] assert len(email_rows) == 0 - sms_row = next(x for x in json_response if x["notification_type"] == "sms") + sms_row = next(x for x in json_response if x["notification_type"] == NotificationType.SMS) assert sms_row["month"] == "January" - assert sms_row["notification_type"] == "sms" + assert sms_row["notification_type"] == NotificationType.SMS assert sms_row["chargeable_units"] == 1 assert sms_row["notifications_sent"] == 1 assert sms_row["rate"] == 0.0162 @@ -216,8 +217,8 @@ def test_get_yearly_billing_usage_summary_from_ft_billing( service_id=service.id, free_sms_fragment_limit=1, financial_year_start=2016 ) - sms_template = create_template(service=service, template_type="sms") - email_template = create_template(service=service, template_type="email") + sms_template = create_template(service=service, template_type=TemplateType.SMS) + email_template = create_template(service=service, template_type=TemplateType.EMAIL) for dt in (date(2016, 1, 28), date(2016, 8, 10), date(2016, 12, 26)): create_ft_billing(local_date=dt, template=sms_template, rate=0.0162) @@ -233,7 +234,7 @@ def test_get_yearly_billing_usage_summary_from_ft_billing( assert len(json_response) == 2 - assert json_response[0]["notification_type"] == "email" + assert json_response[0]["notification_type"] == NotificationType.EMAIL assert json_response[0]["chargeable_units"] == 0 assert json_response[0]["notifications_sent"] == 3 assert json_response[0]["rate"] == 0 @@ -241,7 +242,7 @@ def test_get_yearly_billing_usage_summary_from_ft_billing( assert json_response[0]["free_allowance_used"] == 0 assert json_response[0]["charged_units"] == 0 - assert json_response[1]["notification_type"] == "sms" + assert json_response[1]["notification_type"] == NotificationType.SMS assert json_response[1]["chargeable_units"] == 3 assert json_response[1]["notifications_sent"] == 3 assert json_response[1]["rate"] == 0.0162 diff --git a/tests/app/celery/test_nightly_tasks.py b/tests/app/celery/test_nightly_tasks.py index 83d74660c..f4eddc58b 100644 --- a/tests/app/celery/test_nightly_tasks.py +++ b/tests/app/celery/test_nightly_tasks.py @@ -17,7 +17,8 @@ from app.celery.nightly_tasks import ( save_daily_notification_processing_time, timeout_notifications, ) -from app.models import FactProcessingTime, Job, NotificationType +from app.enums import NotificationType, TemplateType +from app.models import FactProcessingTime, Job from tests.app.db import ( create_job, create_notification, @@ -142,7 +143,7 @@ def test_delete_sms_notifications_older_than_retention_calls_child_task( "app.celery.nightly_tasks._delete_notifications_older_than_retention_by_type" ) delete_sms_notifications_older_than_retention() - mocked.assert_called_once_with("sms") + mocked.assert_called_once_with(NotificationType.SMS) def test_delete_email_notifications_older_than_retentions_calls_child_task( @@ -276,21 +277,21 @@ def test_delete_notifications_task_calls_task_for_services_with_data_retention_o email_service = create_service(service_name="b") letter_service = create_service(service_name="c") - create_service_data_retention(sms_service, notification_type="sms") - create_service_data_retention(email_service, notification_type="email") - create_service_data_retention(letter_service, notification_type="letter") + create_service_data_retention(sms_service, notification_type=NotificationType.SMS) + create_service_data_retention(email_service, notification_type=NotificationType.EMAIL) + create_service_data_retention(letter_service, notification_type=NotificationType.LETTER) mock_subtask = mocker.patch( "app.celery.nightly_tasks.delete_notifications_for_service_and_type" ) - _delete_notifications_older_than_retention_by_type("sms") + _delete_notifications_older_than_retention_by_type(NotificationType.SMS) mock_subtask.apply_async.assert_called_once_with( queue="reporting-tasks", kwargs={ "service_id": sms_service.id, - "notification_type": "sms", + "notification_type": NotificationType.SMS, # three days of retention, its morn of 5th, so we want to keep all messages from 4th, 3rd and 2nd. "datetime_to_delete_before": date(2021, 6, 2), }, @@ -310,7 +311,7 @@ def test_delete_notifications_task_calls_task_for_services_with_data_retention_b "app.celery.nightly_tasks.delete_notifications_for_service_and_type" ) - _delete_notifications_older_than_retention_by_type("sms") + _delete_notifications_older_than_retention_by_type(NotificationType.SMS) assert mock_subtask.apply_async.call_count == 2 mock_subtask.apply_async.assert_has_calls( @@ -320,7 +321,7 @@ def test_delete_notifications_task_calls_task_for_services_with_data_retention_b queue=ANY, kwargs={ "service_id": service_14_days.id, - "notification_type": "sms", + "notification_type": NotificationType.SMS, "datetime_to_delete_before": date(2021, 3, 21), }, ), @@ -328,7 +329,7 @@ def test_delete_notifications_task_calls_task_for_services_with_data_retention_b queue=ANY, kwargs={ "service_id": service_3_days.id, - "notification_type": "sms", + "notification_type": NotificationType.SMS, "datetime_to_delete_before": date(2021, 4, 1), }, ), @@ -347,7 +348,7 @@ def test_delete_notifications_task_calls_task_for_services_that_have_sent_notifi create_template(service_will_delete_1) create_template(service_will_delete_2) nothing_to_delete_sms_template = create_template( - service_nothing_to_delete, template_type="sms" + service_nothing_to_delete, template_type=TemplateType.SMS ) nothing_to_delete_email_template = create_template( service_nothing_to_delete, template_type="email" @@ -377,7 +378,7 @@ def test_delete_notifications_task_calls_task_for_services_that_have_sent_notifi "app.celery.nightly_tasks.delete_notifications_for_service_and_type" ) - _delete_notifications_older_than_retention_by_type("sms") + _delete_notifications_older_than_retention_by_type(NotificationType.SMS) assert mock_subtask.apply_async.call_count == 2 mock_subtask.apply_async.assert_has_calls( @@ -387,7 +388,7 @@ def test_delete_notifications_task_calls_task_for_services_that_have_sent_notifi queue=ANY, kwargs={ "service_id": service_will_delete_1.id, - "notification_type": "sms", + "notification_type": NotificationType.SMS, "datetime_to_delete_before": date(2021, 3, 26), }, ), @@ -395,7 +396,7 @@ def test_delete_notifications_task_calls_task_for_services_that_have_sent_notifi queue=ANY, kwargs={ "service_id": service_will_delete_2.id, - "notification_type": "sms", + "notification_type": NotificationType.SMS, "datetime_to_delete_before": date(2021, 3, 26), }, ), diff --git a/tests/app/celery/test_reporting_tasks.py b/tests/app/celery/test_reporting_tasks.py index 7045ce1a7..cec90c473 100644 --- a/tests/app/celery/test_reporting_tasks.py +++ b/tests/app/celery/test_reporting_tasks.py @@ -13,7 +13,7 @@ from app.celery.reporting_tasks import ( ) from app.config import QueueNames from app.dao.fact_billing_dao import get_rate -from app.enums import KeyType, NotificationType +from app.enums import KeyType, NotificationStatus, NotificationType, TemplateType from app.models import FactBilling, FactNotificationStatus, Notification from tests.app.db import ( create_notification, @@ -122,13 +122,13 @@ def test_create_nightly_billing_for_day_checks_history( create_notification( created_at=yesterday, template=sample_template, - status="sending", + status=NotificationStatus.SENDING, ) create_notification_history( created_at=yesterday, template=sample_template, - status="delivered", + status=NotificationStatus.DELIVERED, ) records = FactBilling.query.all() @@ -164,7 +164,7 @@ def test_create_nightly_billing_for_day_sms_rate_multiplier( create_notification( created_at=yesterday, template=sample_template, - status="delivered", + status=NotificationStatus.DELIVERED, sent_by="sns", international=False, rate_multiplier=1.0, @@ -173,7 +173,7 @@ def test_create_nightly_billing_for_day_sms_rate_multiplier( create_notification( created_at=yesterday, template=sample_template, - status="delivered", + status=NotificationStatus.DELIVERED, sent_by="sns", international=False, rate_multiplier=second_rate, @@ -204,7 +204,7 @@ def test_create_nightly_billing_for_day_different_templates( create_notification( created_at=yesterday, template=sample_template, - status="delivered", + status=NotificationStatus.DELIVERED, sent_by="sns", international=False, rate_multiplier=1.0, @@ -213,7 +213,7 @@ def test_create_nightly_billing_for_day_different_templates( create_notification( created_at=yesterday, template=sample_email_template, - status="delivered", + status=NotificationStatus.DELIVERED, sent_by="sns", international=False, rate_multiplier=0, @@ -248,7 +248,7 @@ def test_create_nightly_billing_for_day_same_sent_by( create_notification( created_at=yesterday, template=sample_template, - status="delivered", + status=NotificationStatus.DELIVERED, sent_by="sns", international=False, rate_multiplier=1.0, @@ -257,7 +257,7 @@ def test_create_nightly_billing_for_day_same_sent_by( create_notification( created_at=yesterday, template=sample_template, - status="delivered", + status=NotificationStatus.DELIVERED, sent_by="sns", international=False, rate_multiplier=1.0, @@ -288,7 +288,7 @@ def test_create_nightly_billing_for_day_null_sent_by_sms( create_notification( created_at=yesterday, template=sample_template, - status="delivered", + status=NotificationStatus.DELIVERED, sent_by=None, international=False, rate_multiplier=1.0, @@ -334,7 +334,7 @@ def test_create_nightly_billing_for_day_use_BST( create_notification( created_at=datetime(2018, 3, 26, 4, 1), template=sample_template, - status="delivered", + status=NotificationStatus.DELIVERED, rate_multiplier=1.0, billable_units=1, ) @@ -342,7 +342,7 @@ def test_create_nightly_billing_for_day_use_BST( create_notification( created_at=datetime(2018, 3, 25, 23, 59), template=sample_template, - status="delivered", + status=NotificationStatus.DELIVERED, rate_multiplier=1.0, billable_units=2, ) @@ -351,7 +351,7 @@ def test_create_nightly_billing_for_day_use_BST( create_notification( created_at=datetime(2018, 3, 24, 23, 59), template=sample_template, - status="delivered", + status=NotificationStatus.DELIVERED, rate_multiplier=1.0, billable_units=4, ) @@ -376,7 +376,7 @@ def test_create_nightly_billing_for_day_update_when_record_exists( create_notification( created_at=datetime.now() - timedelta(days=1), template=sample_template, - status="delivered", + status=NotificationStatus.DELIVERED, sent_by=None, international=False, rate_multiplier=1.0, @@ -397,7 +397,7 @@ def test_create_nightly_billing_for_day_update_when_record_exists( create_notification( created_at=datetime.now() - timedelta(days=1), template=sample_template, - status="delivered", + status=NotificationStatus.DELIVERED, sent_by=None, international=False, rate_multiplier=1.0, @@ -415,25 +415,25 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio first_service = create_service(service_name="First Service") first_template = create_template(service=first_service) second_service = create_service(service_name="second Service") - second_template = create_template(service=second_service, template_type="email") + second_template = create_template(service=second_service, template_type=TemplateType.EMAIL,) process_day = datetime.utcnow().date() - timedelta(days=5) with freeze_time(datetime.combine(process_day, time.max)): - create_notification(template=first_template, status="delivered") - create_notification(template=second_template, status="failed") + create_notification(template=first_template, status=NotificationStatus.DELIVERED,) + create_notification(template=second_template, status=NotificationStatus.FAILED) # team API key notifications are included create_notification( - template=second_template, status="sending", key_type=KeyType.TEAM + template=second_template, status=NotificationStatus.SENDING, key_type=KeyType.TEAM, ) # test notifications are ignored create_notification( - template=second_template, status="sending", key_type=KeyType.TEST + template=second_template, status=NotificationStatus.SENDING, key_type=KeyType.TEST, ) # historical notifications are included - create_notification_history(template=second_template, status="delivered") + create_notification_history(template=second_template, status=NotificationStatus.DELIVERED,) # these created notifications from a different day get ignored with freeze_time( @@ -445,10 +445,10 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio assert len(FactNotificationStatus.query.all()) == 0 create_nightly_notification_status_for_service_and_day( - str(process_day), first_service.id, "sms" + str(process_day), first_service.id, NotificationType.SMS, ) create_nightly_notification_status_for_service_and_day( - str(process_day), second_service.id, "email" + str(process_day), second_service.id, NotificationType.EMAIL, ) new_fact_data = FactNotificationStatus.query.order_by( @@ -461,16 +461,16 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio email_delivered_row = new_fact_data[0] assert email_delivered_row.template_id == second_template.id assert email_delivered_row.service_id == second_service.id - assert email_delivered_row.notification_type == "email" - assert email_delivered_row.notification_status == "delivered" + assert email_delivered_row.notification_type == NotificationType.EMAIL + assert email_delivered_row.notification_status == NotificationStatus.DELIVERED assert email_delivered_row.notification_count == 1 assert email_delivered_row.key_type == KeyType.NORMAL email_sending_row = new_fact_data[1] assert email_sending_row.template_id == second_template.id assert email_sending_row.service_id == second_service.id - assert email_sending_row.notification_type == "email" - assert email_sending_row.notification_status == "failed" + assert email_sending_row.notification_type == NotificationType.EMAIL + assert email_sending_row.notification_status == NotificationStatus.FAILED assert email_sending_row.notification_count == 1 assert email_sending_row.key_type == KeyType.NORMAL @@ -479,16 +479,16 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio assert email_failure_row.template_id == second_template.id assert email_failure_row.service_id == second_service.id assert email_failure_row.job_id == UUID("00000000-0000-0000-0000-000000000000") - assert email_failure_row.notification_type == "email" - assert email_failure_row.notification_status == "sending" + assert email_failure_row.notification_type == NotificationType.EMAIL + assert email_failure_row.notification_status == NotificationStatus.SENDING assert email_failure_row.notification_count == 1 assert email_failure_row.key_type == KeyType.TEAM sms_delivered_row = new_fact_data[3] assert sms_delivered_row.template_id == first_template.id assert sms_delivered_row.service_id == first_service.id - assert sms_delivered_row.notification_type == "sms" - assert sms_delivered_row.notification_status == "delivered" + assert sms_delivered_row.notification_type == NotificationType.SMS + assert sms_delivered_row.notification_status == NotificationStatus.DELIVERED assert sms_delivered_row.notification_count == 1 assert sms_delivered_row.key_type == KeyType.NORMAL @@ -501,22 +501,22 @@ def test_create_nightly_notification_status_for_service_and_day_overwrites_old_d process_day = datetime.utcnow().date() # first run: one notification, expect one row (just one status) - notification = create_notification(template=first_template, status="sending") + notification = create_notification(template=first_template, status=NotificationStatus.SENDING) create_nightly_notification_status_for_service_and_day( - str(process_day), first_service.id, "sms" + str(process_day), first_service.id, NotificationType.SMS, ) new_fact_data = FactNotificationStatus.query.all() assert len(new_fact_data) == 1 assert new_fact_data[0].notification_count == 1 - assert new_fact_data[0].notification_status == "sending" + assert new_fact_data[0].notification_status == NotificationStatus.SENDING # second run: status changed, still expect one row (one status) - notification.status = "delivered" - create_notification(template=first_template, status="created") + notification.status = NotificationStatus.DELIVERED + create_notification(template=first_template, status=NotificationStatus.CREATED) create_nightly_notification_status_for_service_and_day( - str(process_day), first_service.id, "sms" + str(process_day), first_service.id, NotificationType.SMS, ) updated_fact_data = FactNotificationStatus.query.order_by( @@ -525,9 +525,9 @@ def test_create_nightly_notification_status_for_service_and_day_overwrites_old_d assert len(updated_fact_data) == 2 assert updated_fact_data[0].notification_count == 1 - assert updated_fact_data[0].notification_status == "created" + assert updated_fact_data[0].notification_status == NotificationStatus.CREATED assert updated_fact_data[1].notification_count == 1 - assert updated_fact_data[1].notification_status == "delivered" + assert updated_fact_data[1].notification_status == NotificationStatus.DELIVERED # the job runs at 04:30am EST time. @@ -536,22 +536,22 @@ def test_create_nightly_notification_status_for_service_and_day_respects_bst( sample_template, ): create_notification( - sample_template, status="delivered", created_at=datetime(2019, 4, 2, 5, 0) + sample_template, status=NotificationStatus.DELIVERED, created_at=datetime(2019, 4, 2, 5, 0), ) # too new create_notification( - sample_template, status="created", created_at=datetime(2019, 4, 2, 5, 59) + sample_template, status=NotificationStatus.CREATED, created_at=datetime(2019, 4, 2, 5, 59), ) create_notification( - sample_template, status="created", created_at=datetime(2019, 4, 1, 4, 0) + sample_template, status=NotificationStatus.CREATED, created_at=datetime(2019, 4, 1, 4, 0), ) create_notification( - sample_template, status="delivered", created_at=datetime(2019, 3, 21, 17, 59) + sample_template, status=NotificationStatus.DELIVERED, created_at=datetime(2019, 3, 21, 17, 59), ) # too old create_nightly_notification_status_for_service_and_day( - "2019-04-01", sample_template.service_id, "sms" + "2019-04-01", sample_template.service_id, NotificationType.SMS, ) noti_status = FactNotificationStatus.query.order_by( @@ -560,4 +560,4 @@ def test_create_nightly_notification_status_for_service_and_day_respects_bst( assert len(noti_status) == 1 assert noti_status[0].local_date == date(2019, 4, 1) - assert noti_status[0].notification_status == "created" + assert noti_status[0].notification_status == NotificationStatus.CREATED diff --git a/tests/app/celery/test_scheduled_tasks.py b/tests/app/celery/test_scheduled_tasks.py index e140c58cf..0472e9fdb 100644 --- a/tests/app/celery/test_scheduled_tasks.py +++ b/tests/app/celery/test_scheduled_tasks.py @@ -19,7 +19,7 @@ from app.celery.scheduled_tasks import ( ) from app.config import QueueNames, Test from app.dao.jobs_dao import dao_get_job_by_id -from app.enums import JobStatus +from app.enums import JobStatus, NotificationStatus, TemplateType from tests.app import load_example_csv from tests.app.db import create_job, create_notification, create_template @@ -101,13 +101,13 @@ def test_should_update_scheduled_jobs_and_put_on_queue(mocker, sample_template): one_minute_in_the_past = datetime.utcnow() - timedelta(minutes=1) job = create_job( - sample_template, job_status="scheduled", scheduled_for=one_minute_in_the_past + sample_template, job_status=JobStatus.SCHEDULED, scheduled_for=one_minute_in_the_past ) run_scheduled_jobs() updated_job = dao_get_job_by_id(job.id) - assert updated_job.job_status == "pending" + assert updated_job.job_status == JobStatus.PENDING mocked.assert_called_with([str(job.id)], queue="job-tasks") @@ -118,22 +118,22 @@ def test_should_update_all_scheduled_jobs_and_put_on_queue(sample_template, mock ten_minutes_in_the_past = datetime.utcnow() - timedelta(minutes=10) twenty_minutes_in_the_past = datetime.utcnow() - timedelta(minutes=20) job_1 = create_job( - sample_template, job_status="scheduled", scheduled_for=one_minute_in_the_past + sample_template, job_status=JobStatus.SCHEDULED, scheduled_for=one_minute_in_the_past, ) job_2 = create_job( - sample_template, job_status="scheduled", scheduled_for=ten_minutes_in_the_past + sample_template, job_status=JobStatus.SCHEDULED, scheduled_for=ten_minutes_in_the_past, ) job_3 = create_job( sample_template, - job_status="scheduled", + job_status=JobStatus.SCHEDULED, scheduled_for=twenty_minutes_in_the_past, ) run_scheduled_jobs() - assert dao_get_job_by_id(job_1.id).job_status == "pending" - assert dao_get_job_by_id(job_2.id).job_status == "pending" - assert dao_get_job_by_id(job_2.id).job_status == "pending" + assert dao_get_job_by_id(job_1.id).job_status == JobStatus.PENDING + assert dao_get_job_by_id(job_2.id).job_status == JobStatus.PENDING + assert dao_get_job_by_id(job_2.id).job_status == JobStatus.PENDING mocked.assert_has_calls( [ @@ -299,36 +299,36 @@ def test_replay_created_notifications(notify_db_session, sample_service, mocker) "app.celery.provider_tasks.deliver_sms.apply_async" ) - sms_template = create_template(service=sample_service, template_type="sms") - email_template = create_template(service=sample_service, template_type="email") + sms_template = create_template(service=sample_service, template_type=TemplateType.SMS) + email_template = create_template(service=sample_service, template_type=TemplateType.EMAIL) older_than = (60 * 60) + (60 * 15) # 1 hour 15 minutes # notifications expected to be resent old_sms = create_notification( template=sms_template, created_at=datetime.utcnow() - timedelta(seconds=older_than), - status="created", + status=NotificationStatus.CREATED, ) old_email = create_notification( template=email_template, created_at=datetime.utcnow() - timedelta(seconds=older_than), - status="created", + status=NotificationStatus.CREATED, ) # notifications that are not to be resent create_notification( template=sms_template, created_at=datetime.utcnow() - timedelta(seconds=older_than), - status="sending", + status=NotificationStatus.SENDING, ) create_notification( template=email_template, created_at=datetime.utcnow() - timedelta(seconds=older_than), - status="delivered", + status=NotificationStatus.DELIVERED, ) create_notification( - template=sms_template, created_at=datetime.utcnow(), status="created" + template=sms_template, created_at=datetime.utcnow(), status=NotificationStatus.CREATED, ) create_notification( - template=email_template, created_at=datetime.utcnow(), status="created" + template=email_template, created_at=datetime.utcnow(), status=NotificationStatus.CREATED, ) replay_created_notifications() diff --git a/tests/app/conftest.py b/tests/app/conftest.py index a47bf23b1..2f550c1d4 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -1,4 +1,5 @@ import json +from types import CodeType import uuid from datetime import datetime, timedelta @@ -170,7 +171,7 @@ def service_factory(sample_user): create_template( service, template_name="Template Name", - template_type="sms", + template_type=TemplateType.SMS, ) return service @@ -203,7 +204,7 @@ def create_code(notify_db_session, code_type): @pytest.fixture(scope="function") def sample_sms_code(notify_db_session): - code, txt_code = create_code(notify_db_session, code_type="sms") + code, txt_code = create_code(notify_db_session, code_type=CodeType.SMS) code.txt_code = txt_code return code @@ -252,7 +253,7 @@ def sample_template(sample_user): data = { "name": "Template Name", - "template_type": "sms", + "template_type": TemplateType.SMS, "content": "This is a template:\nwith a newline", "service": service, "created_by": sample_user, @@ -621,7 +622,7 @@ def sms_code_template(notify_service): user=notify_service.users[0], template_config_name="SMS_CODE_TEMPLATE_ID", content="((verify_code))", - template_type="sms", + template_type=TemplateType.SMS, ) @@ -723,7 +724,7 @@ def team_member_mobile_edit_template(notify_service): user=notify_service.users[0], template_config_name="TEAM_MEMBER_EDIT_MOBILE_TEMPLATE_ID", content="Your mobile number was changed by ((servicemanagername)).", - template_type="sms", + template_type=TemplateType.SMS, ) diff --git a/tests/app/db.py b/tests/app/db.py index 5fdc70b3c..9de87ba48 100644 --- a/tests/app/db.py +++ b/tests/app/db.py @@ -899,7 +899,7 @@ def set_up_usage_data(start_date): billing_reference="service billing reference", ) sms_template_1 = create_template( - service=service_1_sms_and_letter, template_type="sms" + service=service_1_sms_and_letter, template_type=TemplateType.SMS ) create_annual_billing( service_id=service_1_sms_and_letter.id, diff --git a/tests/app/test_commands.py b/tests/app/test_commands.py index 586faaee7..b147f3a0f 100644 --- a/tests/app/test_commands.py +++ b/tests/app/test_commands.py @@ -358,7 +358,7 @@ def test_update_template(notify_db_session, email_2fa_code_template): _update_template( "299726d2-dba6-42b8-8209-30e1d66ea164", "Example text message template!", - "sms", + TemplateType.SMS, [ "Hi, I’m trying out Notify.gov! Today is ((day of week)) and my favorite color is ((color))." ], diff --git a/tests/app/test_model.py b/tests/app/test_model.py index 549d95c9a..461056a26 100644 --- a/tests/app/test_model.py +++ b/tests/app/test_model.py @@ -10,6 +10,7 @@ from app.enums import ( AgreementType, AuthType, NotificationStatus, + NotificationType, RecipientType, TemplateType, ) @@ -119,8 +120,8 @@ def test_status_conversion(initial_statuses, expected_statuses): @pytest.mark.parametrize( "template_type, recipient", [ - ("sms", "+12028675309"), - ("email", "foo@bar.com"), + (TemplateType.SMS, "+12028675309"), + (TemplateType.EMAIL, "foo@bar.com"), ], ) def test_notification_for_csv_returns_correct_type( @@ -147,17 +148,17 @@ def test_notification_for_csv_returns_correct_job_row_number(sample_job): @pytest.mark.parametrize( "template_type, status, expected_status", [ - ("email", "failed", "Failed"), - ("email", "technical-failure", "Technical failure"), - ("email", "temporary-failure", "Inbox not accepting messages right now"), - ("email", "permanent-failure", "Email address doesn’t exist"), + (TemplateType.EMAIL, "failed", "Failed"), + (TemplateType.EMAIL, "technical-failure", "Technical failure"), + (TemplateType.EMAIL, "temporary-failure", "Inbox not accepting messages right now",), + (TemplateType.EMAIL, "permanent-failure", "Email address doesn’t exist"), ( - "sms", + TemplateType.SMS, "temporary-failure", "Unable to find carrier response -- still looking", ), - ("sms", "permanent-failure", "Unable to find carrier response."), - ("sms", "sent", "Sent internationally"), + (TemplateType.SMS, "permanent-failure", "Unable to find carrier response."), + (TemplateType.SMS, "sent", "Sent internationally"), ], ) def test_notification_for_csv_returns_formatted_status( @@ -419,7 +420,7 @@ def test_notification_history_from_original(sample_notification): def test_rate_str(): - rate = create_rate("2023-01-01 00:00:00", 1.5, "sms") + rate = create_rate("2023-01-01 00:00:00", 1.5, NotificationType.SMS) assert rate.__str__() == "1.5 sms 2023-01-01 00:00:00"