diff --git a/app/celery/nightly_tasks.py b/app/celery/nightly_tasks.py
index 678c9bfa1..f3ee22bf6 100644
--- a/app/celery/nightly_tasks.py
+++ b/app/celery/nightly_tasks.py
@@ -25,7 +25,7 @@ from app.dao.notifications_dao import (
from app.dao.service_data_retention_dao import (
fetch_service_data_retention_for_all_services_by_notification_type,
)
-from app.models import NotificationType, FactProcessingTime
+from app.models import FactProcessingTime, NotificationType
from app.utils import get_midnight_in_utc
diff --git a/app/celery/scheduled_tasks.py b/app/celery/scheduled_tasks.py
index 6ec3370cb..314e1f310 100644
--- a/app/celery/scheduled_tasks.py
+++ b/app/celery/scheduled_tasks.py
@@ -38,8 +38,8 @@ from app.models import (
JOB_STATUS_ERROR,
JOB_STATUS_IN_PROGRESS,
JOB_STATUS_PENDING,
- NotificationType,
Job,
+ NotificationType,
)
from app.notifications.process_notifications import send_notification_to_queue
diff --git a/app/commands.py b/app/commands.py
index 26c48c45b..4d084e845 100644
--- a/app/commands.py
+++ b/app/commands.py
@@ -52,11 +52,11 @@ from app.dao.users_dao import (
from app.models import (
KEY_TYPE_TEST,
NOTIFICATION_CREATED,
- NotificationType,
AnnualBilling,
Domain,
EmailBranding,
Notification,
+ NotificationType,
Organization,
Service,
Template,
diff --git a/app/dao/fact_billing_dao.py b/app/dao/fact_billing_dao.py
index b2f53dbc2..06b537643 100644
--- a/app/dao/fact_billing_dao.py
+++ b/app/dao/fact_billing_dao.py
@@ -13,11 +13,11 @@ from app.models import (
KEY_TYPE_TEAM,
NOTIFICATION_STATUS_TYPES_BILLABLE_SMS,
NOTIFICATION_STATUS_TYPES_SENT_EMAILS,
- NotificationType,
AnnualBilling,
FactBilling,
NotificationAllTimeView,
NotificationHistory,
+ NotificationType,
Organization,
Rate,
Service,
@@ -483,7 +483,9 @@ def get_service_ids_that_need_billing_populated(start_date, end_date):
.filter(
NotificationHistory.created_at >= start_date,
NotificationHistory.created_at <= end_date,
- NotificationHistory.notification_type.in_([NotificationType.SMS, NotificationType.EMAIL]),
+ NotificationHistory.notification_type.in_(
+ [NotificationType.SMS, NotificationType.EMAIL]
+ ),
NotificationHistory.billable_units != 0,
)
.distinct()
diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py
index 2b5767caa..5143746d9 100644
--- a/app/dao/inbound_sms_dao.py
+++ b/app/dao/inbound_sms_dao.py
@@ -6,9 +6,9 @@ from sqlalchemy.orm import aliased
from app import db
from app.dao.dao_utils import autocommit
from app.models import (
- NotificationType,
InboundSms,
InboundSmsHistory,
+ NotificationType,
Service,
ServiceDataRetention,
)
diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py
index c903de270..42ac8671c 100644
--- a/app/dao/notifications_dao.py
+++ b/app/dao/notifications_dao.py
@@ -26,10 +26,10 @@ from app.models import (
NOTIFICATION_SENDING,
NOTIFICATION_SENT,
NOTIFICATION_TEMPORARY_FAILURE,
- NotificationType,
FactNotificationStatus,
Notification,
NotificationHistory,
+ NotificationType,
)
from app.utils import (
escape_special_characters,
@@ -444,7 +444,9 @@ def dao_timeout_notifications(cutoff_time, limit=100000):
Notification.query.filter(
Notification.created_at < cutoff_time,
Notification.status.in_(current_statuses),
- Notification.notification_type.in_([NotificationType.SMS, NotificationType.EMAIL]),
+ Notification.notification_type.in_(
+ [NotificationType.SMS, NotificationType.EMAIL]
+ ),
)
.limit(limit)
.all()
@@ -506,7 +508,9 @@ def dao_get_notifications_by_recipient_or_reference(
normalised = "".join(search_term.split()).lower()
else:
- raise TypeError(f"Notification type must be {NotificationType.EMAIL}, {NotificationType.SMS}, or None")
+ raise TypeError(
+ f"Notification type must be {NotificationType.EMAIL}, {NotificationType.SMS}, or None"
+ )
normalised = escape_special_characters(normalised)
search_term = escape_special_characters(search_term)
diff --git a/app/dao/provider_details_dao.py b/app/dao/provider_details_dao.py
index 3497e8398..270f8731e 100644
--- a/app/dao/provider_details_dao.py
+++ b/app/dao/provider_details_dao.py
@@ -6,8 +6,8 @@ from sqlalchemy import asc, desc, func
from app import db
from app.dao.dao_utils import autocommit
from app.models import (
- NotificationType,
FactBilling,
+ NotificationType,
ProviderDetails,
ProviderDetailsHistory,
User,
diff --git a/app/dao/uploads_dao.py b/app/dao/uploads_dao.py
index 6ef166edd..200d41805 100644
--- a/app/dao/uploads_dao.py
+++ b/app/dao/uploads_dao.py
@@ -8,10 +8,10 @@ from app import db
from app.models import (
JOB_STATUS_CANCELLED,
JOB_STATUS_SCHEDULED,
- NotificationType,
NOTIFICATION_CANCELLED,
Job,
Notification,
+ NotificationType,
ServiceDataRetention,
Template,
)
diff --git a/app/models.py b/app/models.py
index 92b2871a6..29fde4ffd 100644
--- a/app/models.py
+++ b/app/models.py
@@ -44,6 +44,8 @@ class NotificationType(Enum):
NORMAL = "normal"
PRIORITY = "priority"
TEMPLATE_PROCESS_TYPE = [NORMAL, PRIORITY]
+
+
class TemplateProcessType(Enum):
# TODO: Should Template.process_type be changed to use this?
NORMAL = "normal"
@@ -54,6 +56,8 @@ SMS_AUTH_TYPE = "sms_auth"
EMAIL_AUTH_TYPE = "email_auth"
WEBAUTHN_AUTH_TYPE = "webauthn_auth"
USER_AUTH_TYPES = [SMS_AUTH_TYPE, EMAIL_AUTH_TYPE, WEBAUTHN_AUTH_TYPE]
+
+
class UserAuthType(Enum):
# TODO: Should User.auth_type be changed to use this?
SMS = "sms_auth"
@@ -64,10 +68,13 @@ class UserAuthType(Enum):
DELIVERY_STATUS_CALLBACK_TYPE = "delivery_status"
COMPLAINT_CALLBACK_TYPE = "complaint"
SERVICE_CALLBACK_TYPES = [DELIVERY_STATUS_CALLBACK_TYPE, COMPLAINT_CALLBACK_TYPE]
-class ServiceCallbackType(Enum):
- # TODO: Should ServiceCallbackApi.callback_type be changed to use this?
- DELIVERY_STATUS = "delivery_status"
- COMPLAINT = "complaint"
+
+
+# class ServiceCallbackType(Enum):
+# # TODO: Should ServiceCallbackApi.callback_type be changed to use this?
+# DELIVERY_STATUS = "delivery_status"
+# COMPLAINT = "complaint"
+
def filter_null_value_fields(obj):
return dict(filter(lambda x: x[1] is not None, obj.items()))
@@ -287,6 +294,8 @@ BRANDING_ORG = "org"
BRANDING_BOTH = "both"
BRANDING_ORG_BANNER = "org_banner"
BRANDING_TYPES = [BRANDING_ORG, BRANDING_BOTH, BRANDING_ORG_BANNER]
+
+
class BrandingType(Enum):
# TODO: Should EmailBranding.branding_type be changed to use this?
GOVUK = "govuk" # Deprecated outside migrations
@@ -295,7 +304,6 @@ class BrandingType(Enum):
ORG_BANNER = "org_banner"
-
class BrandingTypes(db.Model):
__tablename__ = "branding_type"
name = db.Column(db.String(255), primary_key=True)
@@ -805,10 +813,12 @@ class ServicePermission(db.Model):
# MOBILE_TYPE = "mobile"
# EMAIL_TYPE = "email"
+
class GuestListRecipientType(Enum):
MOBILE = "mobile"
EMAIL = "email"
+
guest_list_recipient_types = db.Enum(GuestListRecipientType, name="recipient_type")
@@ -999,6 +1009,8 @@ class ApiKey(db.Model, Versioned):
KEY_TYPE_NORMAL = "normal"
KEY_TYPE_TEAM = "team"
KEY_TYPE_TEST = "test"
+
+
class KeyType(Enum):
# TODO: Should Key Types be rewritten to use this?
NORMAL = "normal"
@@ -1006,7 +1018,6 @@ class KeyType(Enum):
TEST = "test"
-
class KeyTypes(db.Model):
__tablename__ = "key_types"
@@ -1100,7 +1111,9 @@ class TemplateBase(db.Model):
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
name = db.Column(db.String(255), nullable=False)
- template_type = db.Column(db.Enum(TemplateType, name="template_type"), nullable=False)
+ template_type = db.Column(
+ db.Enum(TemplateType, name="template_type"), nullable=False
+ )
created_at = db.Column(
db.DateTime, nullable=False, default=datetime.datetime.utcnow
)
@@ -1184,7 +1197,9 @@ class TemplateBase(db.Model):
"created_by": self.created_by.email_address,
"version": self.version,
"body": self.content,
- "subject": self.subject if self.template_type == TemplateType.EMAIL else None,
+ "subject": self.subject
+ if self.template_type == TemplateType.EMAIL
+ else None,
"name": self.name,
"personalisation": {
key: {
@@ -1355,6 +1370,8 @@ JOB_STATUS_TYPES = [
JOB_STATUS_SENT_TO_DVLA,
JOB_STATUS_ERROR,
]
+
+
class JobStatusType(Enum):
# TODO: Should Job.job_status be changed to use this?
PENDING = "pending"
@@ -1850,8 +1867,12 @@ class Notification(db.Model):
serialized = {
"id": self.id,
"reference": self.client_reference,
- "email_address": self.to if self.notification_type == NotificationType.EMAIL else None,
- "phone_number": self.to if self.notification_type == NotificationType.SMS else None,
+ "email_address": self.to
+ if self.notification_type == NotificationType.EMAIL
+ else None,
+ "phone_number": self.to
+ if self.notification_type == NotificationType.SMS
+ else None,
"line_1": None,
"line_2": None,
"line_3": None,
diff --git a/app/notifications/process_notifications.py b/app/notifications/process_notifications.py
index 8d02795f1..24a24bc8d 100644
--- a/app/notifications/process_notifications.py
+++ b/app/notifications/process_notifications.py
@@ -122,7 +122,9 @@ def persist_notification(
notification.phone_prefix = recipient_info.country_prefix
notification.rate_multiplier = recipient_info.billable_units
elif notification_type == NotificationType.EMAIL:
- current_app.logger.info(f"Persisting notification with type: {NotificationType.EMAIL}")
+ current_app.logger.info(
+ f"Persisting notification with type: {NotificationType.EMAIL}"
+ )
redis_store.set(
f"email-address-{notification.id}",
format_email_address(notification.to),
diff --git a/app/notifications/receive_notifications.py b/app/notifications/receive_notifications.py
index 04e652ebd..c1031417b 100644
--- a/app/notifications/receive_notifications.py
+++ b/app/notifications/receive_notifications.py
@@ -125,4 +125,6 @@ def fetch_potential_service(inbound_number, provider_name):
def has_inbound_sms_permissions(permissions):
str_permissions = [p.permission for p in permissions]
- return {ServicePermissionType.INBOUND_SMS, ServicePermissionType.SMS}.issubset(set(str_permissions))
+ return {ServicePermissionType.INBOUND_SMS, ServicePermissionType.SMS}.issubset(
+ set(str_permissions)
+ )
diff --git a/app/service/rest.py b/app/service/rest.py
index ec7002990..355978b5d 100644
--- a/app/service/rest.py
+++ b/app/service/rest.py
@@ -643,10 +643,14 @@ def get_guest_list(service_id):
guest_list = dao_fetch_service_guest_list(service.id)
return jsonify(
email_addresses=[
- item.recipient for item in guest_list if item.recipient_type == GuestListRecipientType.EMAIL
+ item.recipient
+ for item in guest_list
+ if item.recipient_type == GuestListRecipientType.EMAIL
],
phone_numbers=[
- item.recipient for item in guest_list if item.recipient_type == GuestListRecipientType.MOBILE
+ item.recipient
+ for item in guest_list
+ if item.recipient_type == GuestListRecipientType.MOBILE
],
)
diff --git a/app/service/utils.py b/app/service/utils.py
index c323bdc06..3b21b90ee 100644
--- a/app/service/utils.py
+++ b/app/service/utils.py
@@ -20,8 +20,12 @@ def get_guest_list_objects(service_id, request_json):
return [
ServiceGuestList.from_string(service_id, type, recipient)
for type, recipient in (
- get_recipients_from_request(request_json, "phone_numbers", GuestListRecipientType.MOBILE)
- + get_recipients_from_request(request_json, "email_addresses", GuestListRecipientType.EMAIL)
+ get_recipients_from_request(
+ request_json, "phone_numbers", GuestListRecipientType.MOBILE
+ )
+ + get_recipients_from_request(
+ request_json, "email_addresses", GuestListRecipientType.EMAIL
+ )
)
]
diff --git a/app/user/rest.py b/app/user/rest.py
index 3192613e6..278eaf396 100644
--- a/app/user/rest.py
+++ b/app/user/rest.py
@@ -33,7 +33,13 @@ from app.dao.users_dao import (
use_user_code,
)
from app.errors import InvalidRequest, register_errors
-from app.models import KEY_TYPE_NORMAL, Notification, NotificationType, Permission, Service, TemplateType
+from app.models import (
+ KEY_TYPE_NORMAL,
+ NotificationType,
+ Permission,
+ Service,
+ TemplateType,
+)
from app.notifications.process_notifications import (
persist_notification,
send_notification_to_queue,
diff --git a/app/utils.py b/app/utils.py
index e922a34f4..eea303250 100644
--- a/app/utils.py
+++ b/app/utils.py
@@ -46,9 +46,7 @@ def get_template_instance(template, values):
return {
TemplateType.SMS: SMSMessageTemplate,
TemplateType.EMAIL: HTMLEmailTemplate,
- }[
- template["template_type"]
- ](template, values)
+ }[template["template_type"]](template, values)
def get_midnight_in_utc(date):
@@ -80,7 +78,7 @@ def get_month_from_utc_column(column):
def get_public_notify_type_text(notify_type, plural=False):
- from app.models import NotificationType, UPLOAD_DOCUMENT
+ from app.models import UPLOAD_DOCUMENT, NotificationType
notify_type_text = notify_type
if notify_type == NotificationType.SMS:
diff --git a/tests/app/celery/test_nightly_tasks.py b/tests/app/celery/test_nightly_tasks.py
index 63f4b22fd..9caef3532 100644
--- a/tests/app/celery/test_nightly_tasks.py
+++ b/tests/app/celery/test_nightly_tasks.py
@@ -17,7 +17,7 @@ from app.celery.nightly_tasks import (
save_daily_notification_processing_time,
timeout_notifications,
)
-from app.models import EMAIL_TYPE, SMS_TYPE, FactProcessingTime, Job
+from app.models import FactProcessingTime, Job, NotificationType
from tests.app.db import (
create_job,
create_notification,
@@ -95,10 +95,10 @@ def test_will_remove_csv_files_for_jobs_older_than_retention_period(
service_1 = create_service(service_name="service 1")
service_2 = create_service(service_name="service 2")
create_service_data_retention(
- service=service_1, notification_type=SMS_TYPE, days_of_retention=3
+ service=service_1, notification_type=NotificationType.SMS, days_of_retention=3
)
create_service_data_retention(
- service=service_2, notification_type=EMAIL_TYPE, 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/celery/test_reporting_tasks.py b/tests/app/celery/test_reporting_tasks.py
index 2dee56c27..70eb44b8b 100644
--- a/tests/app/celery/test_reporting_tasks.py
+++ b/tests/app/celery/test_reporting_tasks.py
@@ -14,15 +14,14 @@ from app.celery.reporting_tasks import (
from app.config import QueueNames
from app.dao.fact_billing_dao import get_rate
from app.models import (
- EMAIL_TYPE,
KEY_TYPE_NORMAL,
KEY_TYPE_TEAM,
KEY_TYPE_TEST,
NOTIFICATION_TYPES,
- SMS_TYPE,
FactBilling,
FactNotificationStatus,
Notification,
+ NotificationType,
)
from tests.app.db import (
create_notification,
@@ -36,9 +35,9 @@ from tests.app.db import (
def mocker_get_rate(
non_letter_rates, notification_type, local_date, rate_multiplier=None
):
- if notification_type == SMS_TYPE:
+ if notification_type == NotificationType.SMS:
return Decimal(1.33)
- elif notification_type == EMAIL_TYPE:
+ elif notification_type == NotificationType.EMAIL:
return Decimal(0)
@@ -83,7 +82,7 @@ def test_create_nightly_notification_status_triggers_tasks(
kwargs={
"service_id": sample_service.id,
"process_day": "2019-07-31",
- "notification_type": SMS_TYPE,
+ "notification_type": NotificationType.SMS,
},
queue=QueueNames.REPORTING,
)
@@ -94,8 +93,8 @@ def test_create_nightly_notification_status_triggers_tasks(
"notification_date, expected_types_aggregated",
[
("2019-08-01", set()),
- ("2019-07-31", {EMAIL_TYPE, SMS_TYPE}),
- ("2019-07-28", {EMAIL_TYPE, SMS_TYPE}),
+ ("2019-07-31", {NotificationType.EMAIL, NotificationType.SMS}),
+ ("2019-07-28", {NotificationType.EMAIL, NotificationType.SMS}),
("2019-07-21", set()),
],
)
@@ -148,7 +147,7 @@ def test_create_nightly_billing_for_day_checks_history(
assert len(records) == 1
record = records[0]
- assert record.notification_type == SMS_TYPE
+ assert record.notification_type == NotificationType.SMS
assert record.notifications_sent == 2
@@ -321,14 +320,14 @@ def test_create_nightly_billing_for_day_null_sent_by_sms(
def test_get_rate_for_sms_and_email(notify_db_session):
non_letter_rates = [
- create_rate(datetime(2017, 12, 1), 0.15, SMS_TYPE),
- create_rate(datetime(2017, 12, 1), 0, EMAIL_TYPE),
+ create_rate(datetime(2017, 12, 1), 0.15, NotificationType.SMS),
+ create_rate(datetime(2017, 12, 1), 0, NotificationType.EMAIL),
]
- rate = get_rate(non_letter_rates, SMS_TYPE, date(2018, 1, 1))
+ rate = get_rate(non_letter_rates, NotificationType.SMS, date(2018, 1, 1))
assert rate == Decimal(0.15)
- rate = get_rate(non_letter_rates, EMAIL_TYPE, date(2018, 1, 1))
+ rate = get_rate(non_letter_rates, NotificationType.EMAIL, date(2018, 1, 1))
assert rate == Decimal(0)
diff --git a/tests/app/celery/test_tasks.py b/tests/app/celery/test_tasks.py
index 41c613563..b9e08ce30 100644
--- a/tests/app/celery/test_tasks.py
+++ b/tests/app/celery/test_tasks.py
@@ -30,15 +30,15 @@ from app.celery.tasks import (
from app.config import QueueNames
from app.dao import jobs_dao, service_email_reply_to_dao, service_sms_sender_dao
from app.models import (
- EMAIL_TYPE,
JOB_STATUS_ERROR,
JOB_STATUS_FINISHED,
JOB_STATUS_IN_PROGRESS,
KEY_TYPE_NORMAL,
NOTIFICATION_CREATED,
- SMS_TYPE,
Job,
Notification,
+ NotificationType,
+ TemplateType,
)
from app.serialised_models import SerialisedService, SerialisedTemplate
from app.utils import DATETIME_FORMAT
@@ -305,8 +305,8 @@ def test_should_process_all_sms_job(sample_job_with_placeholdered_template, mock
@pytest.mark.parametrize(
"template_type, expected_function, expected_queue",
[
- (SMS_TYPE, "save_sms", "database-tasks"),
- (EMAIL_TYPE, "save_email", "database-tasks"),
+ (TemplateType.SMS, "save_sms", "database-tasks"),
+ (TemplateType.EMAIL, "save_email", "database-tasks"),
],
)
def test_process_row_sends_letter_task(
@@ -362,7 +362,7 @@ def test_process_row_when_sender_id_is_provided(mocker, fake_uuid):
mocker.patch("app.celery.tasks.create_uuid", return_value="noti_uuid")
task_mock = mocker.patch("app.celery.tasks.save_sms.apply_async")
encrypt_mock = mocker.patch("app.celery.tasks.encryption.encrypt")
- template = Mock(id="template_id", template_type=SMS_TYPE)
+ template = Mock(id="template_id", template_type=TemplateType.SMS)
job = Mock(id="job_id", template_version="temp_vers")
service = Mock(id="service_id", research_mode=False)
@@ -1384,8 +1384,8 @@ def test_process_incomplete_jobs_sets_status_to_in_progress_and_resets_processin
def test_save_api_email_or_sms(mocker, sample_service, notification_type):
template = (
create_template(sample_service)
- if notification_type == SMS_TYPE
- else create_template(sample_service, template_type=EMAIL_TYPE)
+ if notification_type == NotificationType.SMS
+ else create_template(sample_service, template_type=TemplateType.EMAIL)
)
mock_provider_task = mocker.patch(
f"app.celery.provider_tasks.deliver_{notification_type}.apply_async"
@@ -1407,7 +1407,7 @@ def test_save_api_email_or_sms(mocker, sample_service, notification_type):
"created_at": datetime.utcnow().strftime(DATETIME_FORMAT),
}
- if notification_type == EMAIL_TYPE:
+ if notification_type == NotificationType.EMAIL:
data.update({"to": "jane.citizen@example.com"})
expected_queue = QueueNames.SEND_EMAIL
else:
@@ -1417,7 +1417,7 @@ def test_save_api_email_or_sms(mocker, sample_service, notification_type):
encrypted = encryption.encrypt(data)
assert len(Notification.query.all()) == 0
- if notification_type == EMAIL_TYPE:
+ if notification_type == NotificationType.EMAIL:
save_api_email(encrypted_notification=encrypted)
else:
save_api_sms(encrypted_notification=encrypted)
@@ -1436,8 +1436,8 @@ def test_save_api_email_dont_retry_if_notification_already_exists(
):
template = (
create_template(sample_service)
- if notification_type == SMS_TYPE
- else create_template(sample_service, template_type=EMAIL_TYPE)
+ if notification_type == NotificationType.SMS
+ else create_template(sample_service, template_type=TemplateType.EMAIL)
)
mock_provider_task = mocker.patch(
f"app.celery.provider_tasks.deliver_{notification_type}.apply_async"
@@ -1459,7 +1459,7 @@ def test_save_api_email_dont_retry_if_notification_already_exists(
"created_at": datetime.utcnow().strftime(DATETIME_FORMAT),
}
- if notification_type == EMAIL_TYPE:
+ if notification_type == NotificationType.EMAIL:
data.update({"to": "jane.citizen@example.com"})
expected_queue = QueueNames.SEND_EMAIL
else:
@@ -1469,14 +1469,14 @@ def test_save_api_email_dont_retry_if_notification_already_exists(
encrypted = encryption.encrypt(data)
assert len(Notification.query.all()) == 0
- if notification_type == EMAIL_TYPE:
+ if notification_type == NotificationType.EMAIL:
save_api_email(encrypted_notification=encrypted)
else:
save_api_sms(encrypted_notification=encrypted)
notifications = Notification.query.all()
assert len(notifications) == 1
# call the task again with the same notification
- if notification_type == EMAIL_TYPE:
+ if notification_type == NotificationType.EMAIL:
save_api_email(encrypted_notification=encrypted)
else:
save_api_sms(encrypted_notification=encrypted)
diff --git a/tests/app/conftest.py b/tests/app/conftest.py
index 249dcdcf8..db1b3914c 100644
--- a/tests/app/conftest.py
+++ b/tests/app/conftest.py
@@ -19,14 +19,13 @@ from app.dao.templates_dao import dao_create_template
from app.dao.users_dao import create_secret_code, create_user_code
from app.history_meta import create_history
from app.models import (
- EMAIL_TYPE,
KEY_TYPE_NORMAL,
KEY_TYPE_TEAM,
KEY_TYPE_TEST,
NOTIFICATION_STATUS_TYPES_COMPLETED,
SERVICE_PERMISSION_TYPES,
- SMS_TYPE,
ApiKey,
+ GuestListRecipientType,
InvitedUser,
Job,
Notification,
@@ -38,8 +37,10 @@ from app.models import (
Service,
ServiceEmailReplyTo,
ServiceGuestList,
+ ServicePermissionType,
Template,
TemplateHistory,
+ TemplateType,
)
from tests import create_admin_authorization_header
from tests.app.db import (
@@ -246,7 +247,7 @@ def _sample_service_full_permissions(notify_db_session):
@pytest.fixture(scope="function")
def sample_template(sample_user):
service = create_service(
- service_permissions=[EMAIL_TYPE, SMS_TYPE], check_if_service_exists=True
+ service_permissions=[ServicePermissionType.EMAIL, ServicePermissionType.SMS], check_if_service_exists=True
)
data = {
@@ -268,9 +269,9 @@ def sample_template(sample_user):
@pytest.fixture(scope="function")
def sample_template_without_sms_permission(notify_db_session):
service = create_service(
- service_permissions=[EMAIL_TYPE], check_if_service_exists=True
+ service_permissions=[ServicePermissionType.EMAIL], check_if_service_exists=True
)
- return create_template(service, template_type=SMS_TYPE)
+ return create_template(service, template_type=TemplateType.SMS)
@pytest.fixture(scope="function")
@@ -293,12 +294,12 @@ def sample_sms_template_with_html(sample_service):
def sample_email_template(sample_user):
service = create_service(
user=sample_user,
- service_permissions=[EMAIL_TYPE, SMS_TYPE],
+ service_permissions=[ServicePermissionType.EMAIL, ServicePermissionType.SMS],
check_if_service_exists=True,
)
data = {
"name": "Email Template Name",
- "template_type": EMAIL_TYPE,
+ "template_type": TemplateType.EMAIL,
"content": "This is a template",
"service": service,
"created_by": sample_user,
@@ -312,16 +313,16 @@ def sample_email_template(sample_user):
@pytest.fixture(scope="function")
def sample_template_without_email_permission(notify_db_session):
service = create_service(
- service_permissions=[SMS_TYPE], check_if_service_exists=True
+ service_permissions=[ServicePermissionType.SMS], check_if_service_exists=True
)
- return create_template(service, template_type=EMAIL_TYPE)
+ return create_template(service, template_type=TemplateType.EMAIL)
@pytest.fixture(scope="function")
def sample_email_template_with_placeholders(sample_service):
return create_template(
sample_service,
- template_type=EMAIL_TYPE,
+ template_type=TemplateType.EMAIL,
subject="((name))",
content="Hello ((name))\nThis is an email from GOV.UK",
)
@@ -331,7 +332,7 @@ def sample_email_template_with_placeholders(sample_service):
def sample_email_template_with_html(sample_service):
return create_template(
sample_service,
- template_type=EMAIL_TYPE,
+ template_type=TemplateType.EMAIL,
subject="((name)) some HTML",
content="Hello ((name))\nThis is an email from GOV.UK with some HTML",
)
@@ -480,7 +481,7 @@ def sample_notification(notify_db_session):
def sample_email_notification(notify_db_session):
created_at = datetime.utcnow()
service = create_service(check_if_service_exists=True)
- template = create_template(service, template_type=EMAIL_TYPE)
+ template = create_template(service, template_type=TemplateType.EMAIL)
job = create_job(template)
notification_id = uuid.uuid4()
@@ -843,7 +844,7 @@ def notify_service(notify_db_session, sample_user):
def sample_service_guest_list(notify_db_session):
service = create_service(check_if_service_exists=True)
guest_list_user = ServiceGuestList.from_string(
- service.id, EMAIL_TYPE, "guest_list_user@digital.fake.gov"
+ service.id, GuestListRecipientType.EMAIL, "guest_list_user@digital.fake.gov"
)
notify_db_session.add(guest_list_user)
diff --git a/tests/app/dao/test_fact_notification_status_dao.py b/tests/app/dao/test_fact_notification_status_dao.py
index a38d3e3ec..c5586be34 100644
--- a/tests/app/dao/test_fact_notification_status_dao.py
+++ b/tests/app/dao/test_fact_notification_status_dao.py
@@ -18,7 +18,6 @@ from app.dao.fact_notification_status_dao import (
update_fact_notification_status,
)
from app.models import (
- EMAIL_TYPE,
KEY_TYPE_TEAM,
KEY_TYPE_TEST,
NOTIFICATION_CREATED,
@@ -30,8 +29,8 @@ from app.models import (
NOTIFICATION_SENT,
NOTIFICATION_TECHNICAL_FAILURE,
NOTIFICATION_TEMPORARY_FAILURE,
- SMS_TYPE,
FactNotificationStatus,
+ TemplateType,
)
from tests.app.db import (
create_ft_notification_status,
@@ -167,9 +166,9 @@ def test_fetch_notification_status_for_service_for_today_and_7_previous_days(
notify_db_session,
):
service_1 = create_service(service_name="service_1")
- sms_template = create_template(service=service_1, template_type=SMS_TYPE)
- sms_template_2 = create_template(service=service_1, template_type=SMS_TYPE)
- email_template = create_template(service=service_1, template_type=EMAIL_TYPE)
+ 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)
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,15 +221,15 @@ 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=SMS_TYPE
+ 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=SMS_TYPE
+ template_name="sms Template 2", service=service_1, template_type=TemplateType.SMS
)
- email_template = create_template(service=service_1, template_type=EMAIL_TYPE)
+ email_template = create_template(service=service_1, template_type=TemplateType.EMAIL)
# create unused email template
- create_template(service=service_1, template_type=EMAIL_TYPE)
+ 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, 29), "sms", service_1, count=11)
@@ -323,8 +322,8 @@ def test_fetch_notification_status_totals_for_all_services_works_in_est(
notify_db_session,
):
service_1 = create_service(service_name="service_1")
- sms_template = create_template(service=service_1, template_type=SMS_TYPE)
- email_template = create_template(service=service_1, template_type=EMAIL_TYPE)
+ sms_template = create_template(service=service_1, template_type=TemplateType.SMS)
+ 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"
@@ -367,8 +366,8 @@ def test_fetch_notification_status_totals_for_all_services_works_in_est(
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=SMS_TYPE)
- email_template = create_template(service=service_1, template_type=EMAIL_TYPE)
+ sms_template = create_template(service=service_1, template_type=TemplateType.SMS)
+ 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(
diff --git a/tests/app/dao/test_service_guest_list_dao.py b/tests/app/dao/test_service_guest_list_dao.py
index 5d8e97bd3..3fdd88227 100644
--- a/tests/app/dao/test_service_guest_list_dao.py
+++ b/tests/app/dao/test_service_guest_list_dao.py
@@ -5,7 +5,7 @@ from app.dao.service_guest_list_dao import (
dao_fetch_service_guest_list,
dao_remove_service_guest_list,
)
-from app.models import EMAIL_TYPE, ServiceGuestList
+from app.models import GuestListRecipientType, ServiceGuestList
from tests.app.db import create_service
@@ -21,7 +21,7 @@ def test_fetch_service_guest_list_ignores_other_service(sample_service_guest_lis
def test_add_and_commit_guest_list_contacts_saves_data(sample_service):
guest_list = ServiceGuestList.from_string(
- sample_service.id, EMAIL_TYPE, "foo@example.com"
+ sample_service.id, GuestListRecipientType.EMAIL, "foo@example.com"
)
dao_add_and_commit_guest_list_contacts([guest_list])
@@ -37,10 +37,10 @@ def test_remove_service_guest_list_only_removes_for_my_service(notify_db_session
dao_add_and_commit_guest_list_contacts(
[
ServiceGuestList.from_string(
- service_1.id, EMAIL_TYPE, "service1@example.com"
+ service_1.id, GuestListRecipientType.EMAIL, "service1@example.com"
),
ServiceGuestList.from_string(
- service_2.id, EMAIL_TYPE, "service2@example.com"
+ service_2.id, GuestListRecipientType.EMAIL, "service2@example.com"
),
]
)
diff --git a/tests/app/db.py b/tests/app/db.py
index 56a33335f..b8bcbc539 100644
--- a/tests/app/db.py
+++ b/tests/app/db.py
@@ -27,10 +27,7 @@ from app.dao.services_dao import dao_add_user_to_service, dao_create_service
from app.dao.templates_dao import dao_create_template, dao_update_template
from app.dao.users_dao import save_model_user
from app.models import (
- EMAIL_TYPE,
KEY_TYPE_NORMAL,
- MOBILE_TYPE,
- SMS_TYPE,
AnnualBilling,
ApiKey,
Complaint,
@@ -39,6 +36,7 @@ from app.models import (
FactBilling,
FactNotificationStatus,
FactProcessingTime,
+ GuestListRecipientType,
InboundNumber,
InboundSms,
InvitedOrganizationUser,
@@ -55,9 +53,11 @@ from app.models import (
ServiceGuestList,
ServiceInboundApi,
ServicePermission,
+ ServicePermissionType,
ServiceSmsSender,
Template,
TemplateFolder,
+ TemplateType,
User,
WebauthnCredential,
)
@@ -193,7 +193,7 @@ def create_service_with_defined_sms_sender(sms_sender_value="1234567", *args, **
def create_template(
service,
- template_type=SMS_TYPE,
+ template_type=TemplateType.SMS,
template_name=None,
subject="Template subject",
content="Dear Sir/Madam, Hello. Yours Truly, The Government.",
@@ -215,7 +215,7 @@ def create_template(
"folder": folder,
"process_type": process_type,
}
- if template_type != SMS_TYPE:
+ if template_type != TemplateType.SMS:
data["subject"] = subject
template = Template(**data)
dao_create_template(template)
@@ -262,7 +262,7 @@ def create_notification(
if to_field is None:
to_field = (
"+447700900855"
- if template.template_type == SMS_TYPE
+ if template.template_type == TemplateType.SMS
else "test@example.com"
)
@@ -415,9 +415,10 @@ def create_job(
return job
-def create_service_permission(service_id, permission=EMAIL_TYPE):
+def create_service_permission(service_id, permission=ServicePermissionType.EMAIL):
dao_add_service_permission(
- service_id if service_id else create_service().id, permission
+ service_id if service_id else create_service().id,
+ permission,
)
service_permissions = ServicePermission.query.all()
@@ -724,15 +725,15 @@ def create_process_time(
def create_service_guest_list(service, email_address=None, mobile_number=None):
if email_address:
guest_list_user = ServiceGuestList.from_string(
- service.id, EMAIL_TYPE, email_address
+ service.id, GuestListRecipientType.EMAIL, email_address
)
elif mobile_number:
guest_list_user = ServiceGuestList.from_string(
- service.id, MOBILE_TYPE, mobile_number
+ service.id, GuestListRecipientType.MOBILE, mobile_number
)
else:
guest_list_user = ServiceGuestList.from_string(
- service.id, EMAIL_TYPE, "guest_list_user@digital.fake.gov"
+ service.id, GuestListRecipientType.EMAIL, "guest_list_user@digital.fake.gov"
)
db.session.add(guest_list_user)
diff --git a/tests/app/test_commands.py b/tests/app/test_commands.py
index c13ac3dd3..45d836105 100644
--- a/tests/app/test_commands.py
+++ b/tests/app/test_commands.py
@@ -23,10 +23,10 @@ from app.dao.users_dao import get_user_by_email
from app.models import (
KEY_TYPE_NORMAL,
NOTIFICATION_DELIVERED,
- SMS_TYPE,
AnnualBilling,
Job,
Notification,
+ NotificationType,
Organization,
Service,
Template,
@@ -314,7 +314,7 @@ def test_fix_billable_units(notify_db_session, notify_api, sample_template):
create_notification(template=sample_template)
notification = Notification.query.one()
notification.billable_units = 0
- notification.notification_type = SMS_TYPE
+ notification.notification_type = NotificationType.SMS
notification.status = NOTIFICATION_DELIVERED
notification.sent_at = None
notification.key_type = KEY_TYPE_NORMAL
diff --git a/tests/app/test_model.py b/tests/app/test_model.py
index faab07182..f893ab14c 100644
--- a/tests/app/test_model.py
+++ b/tests/app/test_model.py
@@ -6,23 +6,22 @@ from sqlalchemy.exc import IntegrityError
from app import encryption
from app.models import (
- EMAIL_TYPE,
- MOBILE_TYPE,
NOTIFICATION_CREATED,
NOTIFICATION_FAILED,
NOTIFICATION_PENDING,
NOTIFICATION_STATUS_TYPES_FAILED,
NOTIFICATION_TECHNICAL_FAILURE,
- SMS_TYPE,
Agreement,
AgreementStatus,
AgreementType,
AnnualBilling,
+ GuestListRecipientType,
Notification,
NotificationHistory,
Service,
ServiceGuestList,
ServicePermission,
+ TemplateType,
User,
VerifyCode,
filter_null_value_fields,
@@ -43,7 +42,7 @@ from tests.app.db import (
@pytest.mark.parametrize("mobile_number", ["+447700900855", "+12348675309"])
def test_should_build_service_guest_list_from_mobile_number(mobile_number):
service_guest_list = ServiceGuestList.from_string(
- "service_id", MOBILE_TYPE, mobile_number
+ "service_id", GuestListRecipientType.MOBILE, mobile_number
)
assert service_guest_list.recipient == mobile_number
@@ -52,7 +51,7 @@ def test_should_build_service_guest_list_from_mobile_number(mobile_number):
@pytest.mark.parametrize("email_address", ["test@example.com"])
def test_should_build_service_guest_list_from_email_address(email_address):
service_guest_list = ServiceGuestList.from_string(
- "service_id", EMAIL_TYPE, email_address
+ "service_id", GuestListRecipientType.EMAIL, email_address
)
assert service_guest_list.recipient == email_address
@@ -60,7 +59,11 @@ def test_should_build_service_guest_list_from_email_address(email_address):
@pytest.mark.parametrize(
"contact, recipient_type",
- [("", None), ("07700dsadsad", MOBILE_TYPE), ("gmail.com", EMAIL_TYPE)],
+ [
+ ("", None),
+ ("07700dsadsad", GuestListRecipientType.MOBILE),
+ ("gmail.com", GuestListRecipientType.EMAIL),
+ ],
)
def test_should_not_build_service_guest_list_from_invalid_contact(
recipient_type, contact
@@ -201,7 +204,7 @@ def test_notification_personalisation_setter_always_sets_empty_dict(
def test_notification_subject_is_none_for_sms(sample_service):
- template = create_template(service=sample_service, template_type=SMS_TYPE)
+ template = create_template(service=sample_service, template_type=TemplateType.SMS)
notification = create_notification(template=template)
assert notification.subject is None