From 908d695b54b7d900b72e2a75da93739429bb4732 Mon Sep 17 00:00:00 2001 From: Cliff Hill Date: Wed, 10 Jan 2024 09:48:32 -0500 Subject: [PATCH] More cleanup. Signed-off-by: Cliff Hill --- app/models.py | 1 - app/service/statistics.py | 8 ++++---- app/template/template_schemas.py | 6 +++--- app/v2/notifications/notification_schemas.py | 7 +++++-- app/v2/template/template_schemas.py | 6 +++--- app/v2/templates/templates_schemas.py | 4 ++-- tests/app/celery/test_reporting_tasks.py | 3 +-- tests/app/conftest.py | 3 +-- tests/app/test_utils.py | 6 ++++-- 9 files changed, 23 insertions(+), 21 deletions(-) diff --git a/app/models.py b/app/models.py index a656a926c..29fde4ffd 100644 --- a/app/models.py +++ b/app/models.py @@ -33,7 +33,6 @@ from app.utils import ( class TemplateType(Enum): SMS = "sms" EMAIL = "email" - LETTER = "letter" class NotificationType(Enum): diff --git a/app/service/statistics.py b/app/service/statistics.py index c61a3c55f..37e66f362 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.models import NOTIFICATION_STATUS_TYPES, NOTIFICATION_TYPES +from app.models import NOTIFICATION_STATUS_TYPES, TemplateType def format_statistics(statistics): @@ -40,7 +40,7 @@ def format_admin_stats(statistics): def create_stats_dict(): stats_dict = {} - for template in NOTIFICATION_TYPES: + for template in TemplateType: stats_dict[template] = {} for status in ("total", "test-key"): @@ -78,7 +78,7 @@ def format_monthly_template_notification_stats(year, rows): def create_zeroed_stats_dicts(): return { template_type: {status: 0 for status in ("requested", "delivered", "failed")} - for template_type in NOTIFICATION_TYPES + for template_type in TemplateType } @@ -103,7 +103,7 @@ def create_empty_monthly_notification_status_stats_dict(year): # nested dicts - data[month][template type][status] = count return { start.strftime("%Y-%m"): { - template_type: defaultdict(int) for template_type in NOTIFICATION_TYPES + template_type: defaultdict(int) for template_type in TemplateType } for start in utc_month_starts } diff --git a/app/template/template_schemas.py b/app/template/template_schemas.py index c8843a343..c19c7fe75 100644 --- a/app/template/template_schemas.py +++ b/app/template/template_schemas.py @@ -1,4 +1,4 @@ -from app.models import TEMPLATE_PROCESS_TYPE, TEMPLATE_TYPES +from app.models import TEMPLATE_PROCESS_TYPE, TemplateType from app.schema_validation.definitions import nullable_uuid, uuid post_create_template_schema = { @@ -8,7 +8,7 @@ post_create_template_schema = { "title": "payload for POST /service//template", "properties": { "name": {"type": "string"}, - "template_type": {"enum": TEMPLATE_TYPES}, + "template_type": {"enum": [e.value for e in TemplateType]}, "service": uuid, "process_type": {"enum": TEMPLATE_PROCESS_TYPE}, "content": {"type": "string"}, @@ -29,7 +29,7 @@ post_update_template_schema = { "properties": { "id": uuid, "name": {"type": "string"}, - "template_type": {"enum": TEMPLATE_TYPES}, + "template_type": {"enum": [e.value for e in TemplateType]}, "service": uuid, "process_type": {"enum": TEMPLATE_PROCESS_TYPE}, "content": {"type": "string"}, diff --git a/app/v2/notifications/notification_schemas.py b/app/v2/notifications/notification_schemas.py index 91671bf23..d64c38d86 100644 --- a/app/v2/notifications/notification_schemas.py +++ b/app/v2/notifications/notification_schemas.py @@ -1,4 +1,4 @@ -from app.models import NOTIFICATION_STATUS_TYPES, NOTIFICATION_TYPES +from app.models import NOTIFICATION_STATUS_TYPES, TemplateType from app.schema_validation.definitions import personalisation, uuid template = { @@ -81,7 +81,10 @@ get_notifications_request = { "properties": { "reference": {"type": "string"}, "status": {"type": "array", "items": {"enum": NOTIFICATION_STATUS_TYPES}}, - "template_type": {"type": "array", "items": {"enum": NOTIFICATION_TYPES}}, + "template_type": { + "type": "array", + "items": {"enum": [e.value for e in 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 1865a561e..d6799e458 100644 --- a/app/v2/template/template_schemas.py +++ b/app/v2/template/template_schemas.py @@ -1,4 +1,4 @@ -from app.models import TEMPLATE_TYPES +from app.models import TemplateType from app.schema_validation.definitions import personalisation, uuid get_template_by_id_request = { @@ -17,7 +17,7 @@ get_template_by_id_response = { "title": "reponse v2/template", "properties": { "id": uuid, - "type": {"enum": TEMPLATE_TYPES}, + "type": {"enum": [e.value for e in 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": TEMPLATE_TYPES}, + "type": {"enum": [e.value for e in 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 e5496a90d..57dd8a08f 100644 --- a/app/v2/templates/templates_schemas.py +++ b/app/v2/templates/templates_schemas.py @@ -1,11 +1,11 @@ -from app.models import TEMPLATE_TYPES +from app.models import TemplateType from app.v2.template.template_schemas import get_template_by_id_response as template 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": TEMPLATE_TYPES}}, + "properties": {"type": {"enum": [e.value for e in TemplateType]}}, "additionalProperties": False, } diff --git a/tests/app/celery/test_reporting_tasks.py b/tests/app/celery/test_reporting_tasks.py index 70eb44b8b..d4d57da4f 100644 --- a/tests/app/celery/test_reporting_tasks.py +++ b/tests/app/celery/test_reporting_tasks.py @@ -17,7 +17,6 @@ from app.models import ( KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST, - NOTIFICATION_TYPES, FactBilling, FactNotificationStatus, Notification, @@ -109,7 +108,7 @@ def test_create_nightly_notification_status_triggers_relevant_tasks( "app.celery.reporting_tasks.create_nightly_notification_status_for_service_and_day" ).apply_async - for notification_type in NOTIFICATION_TYPES: + for notification_type in NotificationType: template = create_template(sample_service, template_type=notification_type) create_notification(template=template, created_at=notification_date) diff --git a/tests/app/conftest.py b/tests/app/conftest.py index 5d7280c90..e0bc81bdd 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -23,7 +23,6 @@ from app.models import ( KEY_TYPE_TEAM, KEY_TYPE_TEST, NOTIFICATION_STATUS_TYPES_COMPLETED, - SERVICE_PERMISSION_TYPES, ApiKey, GuestListRecipientType, InvitedUser, @@ -237,7 +236,7 @@ def sample_service(sample_user): def _sample_service_full_permissions(notify_db_session): service = create_service( service_name="sample service full permissions", - service_permissions=set(SERVICE_PERMISSION_TYPES), + service_permissions=set(ServicePermissionType), check_if_service_exists=True, ) create_inbound_number("12345", service_id=service.id) diff --git a/tests/app/test_utils.py b/tests/app/test_utils.py index dff502c4a..c78620e7f 100644 --- a/tests/app/test_utils.py +++ b/tests/app/test_utils.py @@ -4,7 +4,7 @@ from datetime import date, datetime import pytest from freezegun import freeze_time -from app.models import UPLOAD_DOCUMENT +from app.models import ServicePermissionType from app.utils import ( format_sequential_number, get_midnight_for_day_before, @@ -89,7 +89,9 @@ def test_get_uuid_string_or_none(): def test_get_public_notify_type_text(): - assert get_public_notify_type_text(UPLOAD_DOCUMENT) == "document" + assert ( + get_public_notify_type_text(ServicePermissionType.UPLOAD_DOCUMENT) == "document" + ) # This method is used for simulating bulk sends. We use localstack and run on a developer's machine to do the