diff --git a/app/performance_dashboard/rest.py b/app/performance_dashboard/rest.py index a225e9798..747c8964d 100644 --- a/app/performance_dashboard/rest.py +++ b/app/performance_dashboard/rest.py @@ -32,18 +32,18 @@ def get_performance_dashboard(): today = str(datetime.utcnow().date()) start_date = datetime.strptime( - request.args.get("start_date", today), "%Y-%m-%d" + request.args.get("start_date", today), "%Y-%m-%d", ).date() - end_date = datetime.strptime(request.args.get("end_date", today), "%Y-%m-%d").date() + end_date = datetime.strptime(request.args.get("end_date", today), "%Y-%m-%d",).date() total_for_all_time = get_total_notifications_for_date_range( - start_date=None, end_date=None + start_date=None, end_date=None, ) total_notifications, emails, sms = transform_results_into_totals(total_for_all_time) totals_for_date_range = get_total_notifications_for_date_range( - start_date=start_date, end_date=end_date + start_date=start_date, end_date=end_date, ) processing_time_results = get_processing_time_percentage_for_date_range( - start_date=start_date, end_date=end_date + start_date=start_date, end_date=end_date, ) services = get_live_services_with_organization() stats = { diff --git a/tests/__init__.py b/tests/__init__.py index 1105a427e..eeb1c2ae2 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -39,7 +39,7 @@ def create_admin_authorization_header(): def create_internal_authorization_header(client_id): secret = current_app.config["INTERNAL_CLIENT_API_KEYS"][client_id][0] token = create_jwt_token(secret=secret, client_id=client_id) - return "Authorization", "Bearer {}".format(token) + return "Authorization", f"Bearer {token}" def unwrap_function(fn): diff --git a/tests/app/conftest.py b/tests/app/conftest.py index fef9e0406..e96ed1069 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -1,7 +1,6 @@ import json import uuid from datetime import datetime, timedelta -from types import CodeType import pytest import pytz @@ -19,6 +18,8 @@ from app.dao.services_dao import dao_add_user_to_service, dao_create_service from app.dao.templates_dao import dao_create_template from app.dao.users_dao import create_secret_code, create_user_code from app.enums import ( + CodeType, + InvitedUserStatus, JobStatus, KeyType, NotificationStatus, @@ -132,9 +133,9 @@ def create_sample_notification( "api_key_id": api_key and api_key.id, "key_type": api_key.key_type if api_key else key_type, "sent_by": sent_by, - "updated_at": created_at - if status in NotificationStatus.completed_types() - else None, + "updated_at": ( + created_at if status in NotificationStatus.completed_types() else None + ), "client_reference": client_reference, "rate_multiplier": rate_multiplier, "normalised_to": normalised_to, @@ -575,7 +576,7 @@ def sample_expired_user(notify_db_session): "permissions": "send_messages,manage_service,manage_api_keys", "folder_permissions": ["folder_1_id", "folder_2_id"], "created_at": datetime.utcnow() - timedelta(days=3), - "status": NotificationStatus.EXPIRED, + "status": InvitedUserStatus.EXPIRED, } expired_user = InvitedUser(**data) save_invited_user(expired_user) diff --git a/tests/app/dao/notification_dao/test_notification_dao.py b/tests/app/dao/notification_dao/test_notification_dao.py index 849adfb45..feb380568 100644 --- a/tests/app/dao/notification_dao/test_notification_dao.py +++ b/tests/app/dao/notification_dao/test_notification_dao.py @@ -644,7 +644,7 @@ def test_get_all_notifications_for_job_by_status(sample_job): assert len(notifications(filter_dict={"status": status}).items) == 1 - assert len(notifications(filter_dict={"status": NotificationStatus[:3]}).items) == 3 + assert len(notifications(filter_dict={"status": list(NotificationStatus)[:3]}).items) == 3 def test_dao_get_notification_count_for_job_id(notify_db_session): diff --git a/tests/app/dao/test_invited_user_dao.py b/tests/app/dao/test_invited_user_dao.py index 5331f1851..cedee16ea 100644 --- a/tests/app/dao/test_invited_user_dao.py +++ b/tests/app/dao/test_invited_user_dao.py @@ -26,7 +26,7 @@ def test_create_invited_user(notify_db_session, sample_service): "service": sample_service, "email_address": email_address, "from_user": invite_from, - "permissions": "send_messages,manage_service", + "permissions": "send_emails,manage_settings", "folder_permissions": [], } diff --git a/tests/app/dao/test_service_callback_api_dao.py b/tests/app/dao/test_service_callback_api_dao.py index eb7ac0548..ac7fe2b46 100644 --- a/tests/app/dao/test_service_callback_api_dao.py +++ b/tests/app/dao/test_service_callback_api_dao.py @@ -99,8 +99,10 @@ def test_update_service_callback_can_add_two_api_of_different_types(sample_servi save_service_callback_api(complaint) results = ServiceCallbackApi.query.order_by(ServiceCallbackApi.callback_type).all() assert len(results) == 2 - assert results[0].serialize() == complaint.serialize() - assert results[1].serialize() == delivery_status.serialize() + + callbacks = [complaint.serialize(), delivery_status.serialize()] + assert results[0].serialize() in callbacks + assert results[1].serialize() in callbacks def test_update_service_callback_api(sample_service): diff --git a/tests/app/dao/test_service_data_retention_dao.py b/tests/app/dao/test_service_data_retention_dao.py index 529281b61..1d60c619b 100644 --- a/tests/app/dao/test_service_data_retention_dao.py +++ b/tests/app/dao/test_service_data_retention_dao.py @@ -31,8 +31,9 @@ def test_fetch_service_data_retention(sample_service): list_of_data_retention = fetch_service_data_retention(sample_service.id) assert len(list_of_data_retention) == 2 - assert list_of_data_retention[0] == email_data_retention - assert list_of_data_retention[1] == sms_data_retention + data_retentions = [email_data_retention, sms_data_retention] + assert list_of_data_retention[0] in data_retentions + assert list_of_data_retention[1] in data_retentions def test_fetch_service_data_retention_only_returns_row_for_service(sample_service): diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index 2686b7977..565bc52e9 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -1275,7 +1275,7 @@ def test_dao_fetch_todays_stats_for_all_services_groups_correctly(notify_db_sess service2.active, service2.created_at, NotificationType.SMS, - NotificationType.CREATED, + NotificationStatus.CREATED, 1, ) in stats @@ -1517,7 +1517,7 @@ def test_dao_find_services_with_high_failure_rates(notify_db_session, fake_uuid) create_notification(template, status=NotificationStatus.PERMANENT_FAILURE) create_notification(template, status=NotificationStatus.DELIVERED) create_notification(template, status=NotificationStatus.SENDING) - create_notification(template, status=NotificationStatus.TEMPORART_FAILURE) + create_notification(template, status=NotificationStatus.TEMPORARY_FAILURE) service_6 = create_service(service_name="Service 6") with freeze_time("2019-11-30 15:00:00.000000"): @@ -1538,7 +1538,7 @@ def test_dao_find_services_with_high_failure_rates(notify_db_session, fake_uuid) ) # test key type is excluded create_notification( template_2, - status=NotificationStatus.PERMANET_FAILURE, + status=NotificationStatus.PERMANENT_FAILURE, ) # below threshold is excluded start_date = datetime.utcnow() - timedelta(days=1) diff --git a/tests/app/dao/test_users_dao.py b/tests/app/dao/test_users_dao.py index 91c52c170..57ed65619 100644 --- a/tests/app/dao/test_users_dao.py +++ b/tests/app/dao/test_users_dao.py @@ -1,6 +1,5 @@ import uuid from datetime import datetime, timedelta -from types import CodeType import pytest from freezegun import freeze_time @@ -25,7 +24,7 @@ from app.dao.users_dao import ( update_user_password, user_can_be_archived, ) -from app.enums import AuthType, PermissionType +from app.enums import AuthType, CodeType, PermissionType from app.errors import InvalidRequest from app.models import User, VerifyCode from tests.app.db import ( diff --git a/tests/app/email_branding/test_rest.py b/tests/app/email_branding/test_rest.py index 0b68e9a4d..08b65ede4 100644 --- a/tests/app/email_branding/test_rest.py +++ b/tests/app/email_branding/test_rest.py @@ -247,7 +247,7 @@ def test_create_email_branding_reject_invalid_brand_type(admin_request): assert ( response["errors"][0]["message"] - == "brand_type NOT A TYPE is not one of [org, both, org_banner]" + == f"brand_type NOT A TYPE is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in BrandType])}]" ) @@ -265,5 +265,5 @@ def test_update_email_branding_reject_invalid_brand_type( assert ( response["errors"][0]["message"] - == "brand_type NOT A TYPE is not one of [org, both, org_banner]" + == f"brand_type NOT A TYPE is not one of [{', '.join([f'<{type(e).__name__}.{e.name}: {e.value}>'for e in BrandType])}]" ) diff --git a/tests/app/notifications/test_validators.py b/tests/app/notifications/test_validators.py index 56c5e8e33..f2d9cabb8 100644 --- a/tests/app/notifications/test_validators.py +++ b/tests/app/notifications/test_validators.py @@ -505,7 +505,8 @@ def test_check_service_over_api_rate_limit_when_exceed_rate_limit_request_fails_ ) assert e.value.status_code == 429 assert e.value.message == ( - f"Exceeded rate limit for key type {key_type.upper()} of " + f"Exceeded rate limit for key type " + f"{key_type.name if key_type != KeyType.NORMAL else 'LIVE'} of " f"{sample_service.rate_limit} requests per {60} seconds" ) assert e.value.fields == [] @@ -636,7 +637,7 @@ def test_check_service_email_reply_to_id_where_service_id_is_not_found( ) assert e.value.status_code == 400 assert e.value.message == ( - f"email_reply_to_id {reply_to_address.id} does not exist in database for i" + f"email_reply_to_id {reply_to_address.id} does not exist in database for " f"service id {fake_uuid}" )