From df10c4693c861dca489ef5cf19abed878f251649 Mon Sep 17 00:00:00 2001 From: Cliff Hill Date: Thu, 18 Jan 2024 10:27:31 -0500 Subject: [PATCH] Formatting goodness. Signed-off-by: Cliff Hill --- tests/app/celery/test_nightly_tasks.py | 4 +- tests/app/conftest.py | 3 +- .../notification_dao/test_notification_dao.py | 14 ++++++- .../dao/test_fact_notification_status_dao.py | 28 +++++++++---- tests/app/dao/test_jobs_dao.py | 4 +- tests/app/dao/test_service_permissions_dao.py | 3 +- tests/app/dao/test_uploads_dao.py | 2 +- .../test_process_notification.py | 7 +++- .../test_receive_notification.py | 2 +- tests/app/notifications/test_validators.py | 41 +++++++++++++------ .../test_send_notification.py | 16 +++++--- .../test_send_one_off_notification.py | 4 +- tests/app/service/test_rest.py | 4 +- tests/app/service/test_sender.py | 4 +- tests/app/service/test_service_guest_list.py | 4 +- tests/app/template/test_rest.py | 2 +- tests/app/user/test_rest_verify.py | 8 +--- .../notifications/test_post_notifications.py | 6 ++- 18 files changed, 110 insertions(+), 46 deletions(-) diff --git a/tests/app/celery/test_nightly_tasks.py b/tests/app/celery/test_nightly_tasks.py index 9caef3532..83d74660c 100644 --- a/tests/app/celery/test_nightly_tasks.py +++ b/tests/app/celery/test_nightly_tasks.py @@ -98,7 +98,9 @@ def test_will_remove_csv_files_for_jobs_older_than_retention_period( service=service_1, notification_type=NotificationType.SMS, days_of_retention=3 ) create_service_data_retention( - service=service_2, notification_type=NotificationType.EMAIL, days_of_retention=30 + service=service_2, + notification_type=NotificationType.EMAIL, + days_of_retention=30, ) sms_template_service_1 = create_template(service=service_1) email_template_service_1 = create_template(service=service_1, template_type="email") diff --git a/tests/app/conftest.py b/tests/app/conftest.py index db1b3914c..5d7280c90 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -247,7 +247,8 @@ def _sample_service_full_permissions(notify_db_session): @pytest.fixture(scope="function") def sample_template(sample_user): service = create_service( - service_permissions=[ServicePermissionType.EMAIL, ServicePermissionType.SMS], check_if_service_exists=True + service_permissions=[ServicePermissionType.EMAIL, ServicePermissionType.SMS], + check_if_service_exists=True, ) data = { diff --git a/tests/app/dao/notification_dao/test_notification_dao.py b/tests/app/dao/notification_dao/test_notification_dao.py index f167ca65f..bf8005626 100644 --- a/tests/app/dao/notification_dao/test_notification_dao.py +++ b/tests/app/dao/notification_dao/test_notification_dao.py @@ -1762,8 +1762,18 @@ def test_get_service_ids_with_notifications_on_date_checks_ft_status( create_ft_notification_status(template=sample_template, local_date="2022-01-02") assert ( - len(get_service_ids_with_notifications_on_date(NotificationType.SMS, date(2022, 1, 1))) == 1 + len( + get_service_ids_with_notifications_on_date( + NotificationType.SMS, date(2022, 1, 1) + ) + ) + == 1 ) assert ( - len(get_service_ids_with_notifications_on_date(NotificationType.SMS, date(2022, 1, 2))) == 1 + len( + get_service_ids_with_notifications_on_date( + NotificationType.SMS, date(2022, 1, 2) + ) + ) + == 1 ) diff --git a/tests/app/dao/test_fact_notification_status_dao.py b/tests/app/dao/test_fact_notification_status_dao.py index 1f0e6ab84..bf9772fae 100644 --- a/tests/app/dao/test_fact_notification_status_dao.py +++ b/tests/app/dao/test_fact_notification_status_dao.py @@ -169,7 +169,9 @@ def test_fetch_notification_status_for_service_for_today_and_7_previous_days( service_1 = create_service(service_name="service_1") sms_template = create_template(service=service_1, template_type=TemplateType.SMS) sms_template_2 = create_template(service=service_1, template_type=TemplateType.SMS) - email_template = create_template(service=service_1, template_type=TemplateType.EMAIL) + email_template = create_template( + service=service_1, template_type=TemplateType.EMAIL + ) create_ft_notification_status(date(2018, 10, 29), "sms", service_1, count=10) create_ft_notification_status(date(2018, 10, 25), "sms", service_1, count=8) @@ -222,12 +224,18 @@ def test_fetch_notification_status_by_template_for_service_for_today_and_7_previ ): service_1 = create_service(service_name="service_1") sms_template = create_template( - template_name="sms Template 1", service=service_1, template_type=TemplateType.SMS + template_name="sms Template 1", + service=service_1, + template_type=TemplateType.SMS, ) sms_template_2 = create_template( - template_name="sms Template 2", service=service_1, template_type=TemplateType.SMS + template_name="sms Template 2", + service=service_1, + template_type=TemplateType.SMS, + ) + email_template = create_template( + service=service_1, template_type=TemplateType.EMAIL ) - email_template = create_template(service=service_1, template_type=TemplateType.EMAIL) # create unused email template create_template(service=service_1, template_type=TemplateType.EMAIL) @@ -324,7 +332,9 @@ def test_fetch_notification_status_totals_for_all_services_works_in_est( ): service_1 = create_service(service_name="service_1") sms_template = create_template(service=service_1, template_type=TemplateType.SMS) - email_template = create_template(service=service_1, template_type=TemplateType.EMAIL) + email_template = create_template( + service=service_1, template_type=TemplateType.EMAIL + ) create_notification( sms_template, created_at=datetime(2018, 4, 20, 12, 0, 0), status="delivered" @@ -368,7 +378,9 @@ def set_up_data(): service_2 = create_service(service_name="service_2") service_1 = create_service(service_name="service_1") sms_template = create_template(service=service_1, template_type=TemplateType.SMS) - email_template = create_template(service=service_1, template_type=TemplateType.EMAIL) + email_template = create_template( + service=service_1, template_type=TemplateType.EMAIL + ) create_ft_notification_status(date(2018, 10, 24), "sms", service_1, count=8) create_ft_notification_status(date(2018, 10, 29), "sms", service_1, count=10) create_ft_notification_status( @@ -854,7 +866,9 @@ def test_update_fact_notification_status_respects_gmt_bst( expected_count, ): create_notification(template=sample_template, created_at=created_at_utc) - update_fact_notification_status(process_day, NotificationType.SMS, sample_service.id) + update_fact_notification_status( + process_day, NotificationType.SMS, sample_service.id + ) assert ( FactNotificationStatus.query.filter_by( diff --git a/tests/app/dao/test_jobs_dao.py b/tests/app/dao/test_jobs_dao.py index b7afa713c..0f1cc394a 100644 --- a/tests/app/dao/test_jobs_dao.py +++ b/tests/app/dao/test_jobs_dao.py @@ -352,7 +352,9 @@ def test_should_get_jobs_seven_days_old_by_scheduled_for_date(sample_service): sms_template, created_at=eight_days_ago, scheduled_for=six_days_ago ) - jobs = dao_get_jobs_older_than_data_retention(notification_types=[NotificationType.SMS]) + jobs = dao_get_jobs_older_than_data_retention( + notification_types=[NotificationType.SMS] + ) assert len(jobs) == 2 assert job_to_remain.id not in [job.id for job in jobs] diff --git a/tests/app/dao/test_service_permissions_dao.py b/tests/app/dao/test_service_permissions_dao.py index df87575ae..cf550b2b0 100644 --- a/tests/app/dao/test_service_permissions_dao.py +++ b/tests/app/dao/test_service_permissions_dao.py @@ -41,7 +41,8 @@ def test_fetch_service_permissions_gets_service_permissions( sp.service_id == service_without_permissions.id for sp in service_permissions ) assert all( - sp.permission in { + sp.permission + in { ServicePermissionType.INTERNATIONAL_SMS, ServicePermissionType.SMS, } diff --git a/tests/app/dao/test_uploads_dao.py b/tests/app/dao/test_uploads_dao.py index 016d7a92e..d444c38fe 100644 --- a/tests/app/dao/test_uploads_dao.py +++ b/tests/app/dao/test_uploads_dao.py @@ -3,7 +3,7 @@ from datetime import datetime, timedelta from freezegun import freeze_time from app.dao.uploads_dao import dao_get_uploads_by_service_id -from app.models import JOB_STATUS_IN_PROGRESS +from app.models import JOB_STATUS_IN_PROGRESS, TemplateType from tests.app.db import ( create_job, create_notification, diff --git a/tests/app/notifications/test_process_notification.py b/tests/app/notifications/test_process_notification.py index d0ea87574..fde2291f8 100644 --- a/tests/app/notifications/test_process_notification.py +++ b/tests/app/notifications/test_process_notification.py @@ -11,7 +11,12 @@ from notifications_utils.recipients import ( ) from sqlalchemy.exc import SQLAlchemyError -from app.models import Notification, NotificationHistory, ServicePermissionType, TemplateType +from app.models import ( + Notification, + NotificationHistory, + ServicePermissionType, + TemplateType, +) from app.notifications.process_notifications import ( create_content_for_notification, persist_notification, diff --git a/tests/app/notifications/test_receive_notification.py b/tests/app/notifications/test_receive_notification.py index fdc1450f2..4e12e5536 100644 --- a/tests/app/notifications/test_receive_notification.py +++ b/tests/app/notifications/test_receive_notification.py @@ -268,7 +268,7 @@ def test_receive_notification_error_if_not_single_matching_service( service_permissions=[ ServicePermissionType.EMAIL, ServicePermissionType.SMS, - ServicePermissionType.INBOUND_SMS + ServicePermissionType.INBOUND_SMS, ], ) diff --git a/tests/app/notifications/test_validators.py b/tests/app/notifications/test_validators.py index a3a098e4d..8eeb858c0 100644 --- a/tests/app/notifications/test_validators.py +++ b/tests/app/notifications/test_validators.py @@ -5,7 +5,12 @@ from notifications_utils import SMS_CHAR_COUNT_LIMIT import app from app.dao import templates_dao -from app.models import KEY_TYPE_NORMAL, NotificationType, ServicePermissionType, TemplateType +from app.models import ( + KEY_TYPE_NORMAL, + NotificationType, + ServicePermissionType, + TemplateType, +) from app.notifications.process_notifications import create_content_for_notification from app.notifications.sns_cert_validator import ( VALID_SNS_TOPICS, @@ -93,7 +98,7 @@ def test_check_application_over_retention_limit_fails( [ (TemplateType.EMAIL, NotificationType.EMAIL), (TemplateType.SMS, NotificationType.SMS), - ] + ], ) def test_check_template_is_for_notification_type_pass(template_type, notification_type): assert ( @@ -109,7 +114,7 @@ def test_check_template_is_for_notification_type_pass(template_type, notificatio [ (TemplateType.SMS, NotificationType.EMAIL), (TemplateType.EMAIL, NotificationType.SMS), - ] + ], ) def test_check_template_is_for_notification_type_fails_when_template_type_does_not_match_notification_type( template_type, notification_type @@ -583,7 +588,9 @@ def test_validate_and_format_recipient_succeeds_with_international_numbers_if_se def test_validate_and_format_recipient_fails_when_no_recipient(): with pytest.raises(BadRequestError) as e: - validate_and_format_recipient(None, "key_type", "service", "NotificationType.SMS") + validate_and_format_recipient( + None, "key_type", "service", "NotificationType.SMS" + ) assert e.value.status_code == 400 assert e.value.message == "Recipient can't be empty" @@ -608,7 +615,9 @@ def test_check_service_email_reply_to_id_where_service_id_is_not_found( ): reply_to_address = create_reply_to_email(sample_service, "test@test.com") with pytest.raises(BadRequestError) as e: - check_service_email_reply_to_id(fake_uuid, reply_to_address.id, NotificationType.EMAIL) + check_service_email_reply_to_id( + fake_uuid, reply_to_address.id, NotificationType.EMAIL + ) assert e.value.status_code == 400 assert ( e.value.message @@ -622,7 +631,9 @@ def test_check_service_email_reply_to_id_where_reply_to_id_is_not_found( sample_service, fake_uuid ): with pytest.raises(BadRequestError) as e: - check_service_email_reply_to_id(sample_service.id, fake_uuid, NotificationType.EMAIL) + check_service_email_reply_to_id( + sample_service.id, fake_uuid, NotificationType.EMAIL + ) assert e.value.status_code == 400 assert ( e.value.message @@ -639,11 +650,14 @@ def test_check_service_sms_sender_id_where_sms_sender_id_is_none(notification_ty def test_check_service_sms_sender_id_where_sms_sender_id_is_found(sample_service): sms_sender = create_service_sms_sender(service=sample_service, sms_sender="123456") - assert check_service_sms_sender_id( - sample_service.id, - sms_sender.id, - NotificationType.SMS, - ) == "123456" + assert ( + check_service_sms_sender_id( + sample_service.id, + sms_sender.id, + NotificationType.SMS, + ) + == "123456" + ) def test_check_service_sms_sender_id_where_service_id_is_not_found( @@ -690,7 +704,10 @@ def test_check_reply_to_email_type(sample_service): def test_check_reply_to_sms_type(sample_service): sms_sender = create_service_sms_sender(service=sample_service, sms_sender="123456") - assert check_reply_to(sample_service.id, sms_sender.id, NotificationType.SMS) == "123456" + assert ( + check_reply_to(sample_service.id, sms_sender.id, NotificationType.SMS) + == "123456" + ) def test_check_if_service_can_send_files_by_email_raises_if_no_contact_link_set( diff --git a/tests/app/service/send_notification/test_send_notification.py b/tests/app/service/send_notification/test_send_notification.py index 254886bf4..c3468a2c5 100644 --- a/tests/app/service/send_notification/test_send_notification.py +++ b/tests/app/service/send_notification/test_send_notification.py @@ -100,7 +100,7 @@ def test_should_reject_bad_phone_numbers(notify_api, sample_template, mocker): [ (TemplateType.SMS, "+447700900855"), (TemplateType.EMAIL, "ok@ok.com"), - ] + ], ) def test_send_notification_invalid_template_id( notify_api, sample_template, mocker, fake_uuid, template_type, to @@ -339,7 +339,9 @@ def test_should_send_notification_if_restricted_and_a_service_user( ) template = ( - sample_template if template_type == TemplateType.SMS else sample_email_template + sample_template + if template_type == TemplateType.SMS + else sample_email_template ) to = ( template.service.created_by.mobile_number @@ -769,7 +771,9 @@ def test_should_persist_notification( "app.notifications.process_notifications.uuid.uuid4", return_value=fake_uuid ) - template = sample_template if template_type == TemplateType.SMS else sample_email_template + template = ( + sample_template if template_type == TemplateType.SMS else sample_email_template + ) to = ( sample_template.service.created_by.mobile_number if template_type == TemplateType.SMS @@ -826,7 +830,9 @@ def test_should_delete_notification_and_return_error_if_redis_fails( "app.notifications.process_notifications.uuid.uuid4", return_value=fake_uuid ) - template = sample_template if template_type == TemplateType.SMS else sample_email_template + template = ( + sample_template if template_type == TemplateType.SMS else sample_email_template + ) to = ( sample_template.service.created_by.mobile_number if template_type == TemplateType.SMS @@ -1086,7 +1092,7 @@ def test_create_template_doesnt_raise_with_too_much_personalisation( [ (TemplateType.SMS, True), (TemplateType.EMAIL, False), - ] + ], ) def test_create_template_raises_invalid_request_when_content_too_large( sample_service, template_type, should_error diff --git a/tests/app/service/send_notification/test_send_one_off_notification.py b/tests/app/service/send_notification/test_send_one_off_notification.py index c7b369444..9f4ccfbc1 100644 --- a/tests/app/service/send_notification/test_send_one_off_notification.py +++ b/tests/app/service/send_notification/test_send_one_off_notification.py @@ -203,7 +203,9 @@ def test_send_one_off_notification_raises_if_cant_send_to_recipient( template = create_template(service=service) dao_add_and_commit_guest_list_contacts( [ - ServiceGuestList.from_string(service.id, GuestListRecipientType.MOBILE, "2028765309"), + ServiceGuestList.from_string( + service.id, GuestListRecipientType.MOBILE, "2028765309" + ), ] ) diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index d9ab3fd07..9b3fd378a 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -1723,7 +1723,9 @@ def test_get_all_notifications_for_service_filters_notifications_when_using_post service_2 = create_service(service_name="2") service_1_sms_template = create_template(service_1) - service_1_email_template = create_template(service_1, template_type=TemplateType.EMAIL) + service_1_email_template = create_template( + service_1, template_type=TemplateType.EMAIL + ) service_2_sms_template = create_template(service_2) returned_notification = create_notification( diff --git a/tests/app/service/test_sender.py b/tests/app/service/test_sender.py index 5f28fefed..dc17e1eb8 100644 --- a/tests/app/service/test_sender.py +++ b/tests/app/service/test_sender.py @@ -7,7 +7,9 @@ from app.service.sender import send_notification_to_service_users from tests.app.db import create_service, create_template, create_user -@pytest.mark.parametrize("notification_type", [NotificationType.EMAIL, NotificationType.SMS]) +@pytest.mark.parametrize( + "notification_type", [NotificationType.EMAIL, NotificationType.SMS] +) def test_send_notification_to_service_users_persists_notifications_correctly( notify_service, notification_type, sample_service, mocker ): diff --git a/tests/app/service/test_service_guest_list.py b/tests/app/service/test_service_guest_list.py index 918a8e399..cd8ec7c1d 100644 --- a/tests/app/service/test_service_guest_list.py +++ b/tests/app/service/test_service_guest_list.py @@ -28,7 +28,9 @@ def test_get_guest_list_separates_emails_and_phones(client, sample_service): GuestListRecipientType.EMAIL, "service@example.com", ), - ServiceGuestList.from_string(sample_service.id, GuestListRecipientType.MOBILE, "2028675309"), + ServiceGuestList.from_string( + sample_service.id, GuestListRecipientType.MOBILE, "2028675309" + ), ServiceGuestList.from_string( sample_service.id, GuestListRecipientType.MOBILE, diff --git a/tests/app/template/test_rest.py b/tests/app/template/test_rest.py index cc145ca0b..bca08034a 100644 --- a/tests/app/template/test_rest.py +++ b/tests/app/template/test_rest.py @@ -223,7 +223,7 @@ def test_should_raise_error_on_create_if_no_permission( ), ( TemplateType.EMAIL, - [ServicePErmissionType.SMS], + [ServicePermissionType.SMS], {"template_type": ["Updating email templates is not allowed"]}, ), ], diff --git a/tests/app/user/test_rest_verify.py b/tests/app/user/test_rest_verify.py index 7744a8316..4c063e7b5 100644 --- a/tests/app/user/test_rest_verify.py +++ b/tests/app/user/test_rest_verify.py @@ -10,13 +10,7 @@ import app.celery.tasks from app import db from app.dao.services_dao import dao_fetch_service_by_id from app.dao.users_dao import create_user_code -from app.models import ( - USER_AUTH_TYPES, - Notification, - User, - VerifyCode, - VerifyCodeType, -) +from app.models import USER_AUTH_TYPES, Notification, User, VerifyCode, VerifyCodeType from tests import create_admin_authorization_header diff --git a/tests/app/v2/notifications/test_post_notifications.py b/tests/app/v2/notifications/test_post_notifications.py index 36bfb5d67..d683895ee 100644 --- a/tests/app/v2/notifications/test_post_notifications.py +++ b/tests/app/v2/notifications/test_post_notifications.py @@ -761,7 +761,11 @@ def test_post_sms_notification_returns_400_if_number_not_in_guest_list( notify_db_session, client, restricted ): service = create_service( - restricted=restricted, service_permissions=[ServicePermissionType.SMS, ServicePermissionType.INTERNATIONAL_SMS] + restricted=restricted, + service_permissions=[ + ServicePermissionType.SMS, + ServicePermissionType.INTERNATIONAL_SMS, + ], ) template = create_template(service=service) create_api_key(service=service, key_type="team")