mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 05:58:53 -04:00
@@ -1,4 +1,5 @@
|
|||||||
from strenum import StrEnum # In 3.11 this is in the enum library.
|
from strenum import StrEnum # In 3.11 this is in the enum library. We will not need
|
||||||
|
# this external library any more.
|
||||||
|
|
||||||
|
|
||||||
class TemplateType(StrEnum):
|
class TemplateType(StrEnum):
|
||||||
|
|||||||
@@ -1860,7 +1860,9 @@ class InvitedUser(db.Model):
|
|||||||
)
|
)
|
||||||
permissions = db.Column(db.String, nullable=False)
|
permissions = db.Column(db.String, nullable=False)
|
||||||
auth_type = enum_column(AuthType, index=True, nullable=False, default=AuthType.SMS)
|
auth_type = enum_column(AuthType, index=True, nullable=False, default=AuthType.SMS)
|
||||||
folder_permissions = db.Column(JSONB(none_as_null=True), nullable=False, default=list)
|
folder_permissions = db.Column(
|
||||||
|
JSONB(none_as_null=True), nullable=False, default=list
|
||||||
|
)
|
||||||
|
|
||||||
# would like to have used properties for this but haven't found a way to make them
|
# would like to have used properties for this but haven't found a way to make them
|
||||||
# play nice with marshmallow yet
|
# play nice with marshmallow yet
|
||||||
|
|||||||
@@ -159,27 +159,27 @@ def test_fetch_notification_status_for_service_for_today_and_7_previous_days(
|
|||||||
service=service_1, template_type=TemplateType.EMAIL
|
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), NotificationType.SMS, service_1, count=10,)
|
||||||
create_ft_notification_status(date(2018, 10, 25), "sms", service_1, count=8)
|
create_ft_notification_status(date(2018, 10, 25), NotificationType.SMS, service_1, count=8,)
|
||||||
create_ft_notification_status(
|
create_ft_notification_status(
|
||||||
date(2018, 10, 29), "sms", service_1, notification_status="created"
|
date(2018, 10, 29), NotificationType.SMS, service_1, notification_status=NotificationStatus.CREATED,
|
||||||
)
|
)
|
||||||
create_ft_notification_status(date(2018, 10, 29), "email", service_1, count=3)
|
create_ft_notification_status(date(2018, 10, 29), NotificationType.EMAIL, service_1, count=3,)
|
||||||
|
|
||||||
create_notification(sms_template, created_at=datetime(2018, 10, 31, 11, 0, 0))
|
create_notification(sms_template, created_at=datetime(2018, 10, 31, 11, 0, 0))
|
||||||
create_notification(sms_template_2, created_at=datetime(2018, 10, 31, 11, 0, 0))
|
create_notification(sms_template_2, created_at=datetime(2018, 10, 31, 11, 0, 0))
|
||||||
create_notification(
|
create_notification(
|
||||||
sms_template, created_at=datetime(2018, 10, 31, 12, 0, 0), status="delivered"
|
sms_template, created_at=datetime(2018, 10, 31, 12, 0, 0), status=NotificationStatus.DELIVERED,
|
||||||
)
|
)
|
||||||
create_notification(
|
create_notification(
|
||||||
email_template, created_at=datetime(2018, 10, 31, 13, 0, 0), status="delivered"
|
email_template, created_at=datetime(2018, 10, 31, 13, 0, 0), status=NotificationStatus.DELIVERED,
|
||||||
)
|
)
|
||||||
|
|
||||||
# too early, shouldn't be included
|
# too early, shouldn't be included
|
||||||
create_notification(
|
create_notification(
|
||||||
service_1.templates[0],
|
service_1.templates[0],
|
||||||
created_at=datetime(2018, 10, 30, 12, 0, 0),
|
created_at=datetime(2018, 10, 30, 12, 0, 0),
|
||||||
status="delivered",
|
status=NotificationStatus.DELIVERED,
|
||||||
)
|
)
|
||||||
|
|
||||||
results = sorted(
|
results = sorted(
|
||||||
@@ -191,16 +191,16 @@ def test_fetch_notification_status_for_service_for_today_and_7_previous_days(
|
|||||||
|
|
||||||
assert len(results) == 3
|
assert len(results) == 3
|
||||||
|
|
||||||
assert results[0].notification_type == "email"
|
assert results[0].notification_type == NotificationType.EMAIL
|
||||||
assert results[0].status == "delivered"
|
assert results[0].status == NotificationStatus.DELIVERED
|
||||||
assert results[0].count == 4
|
assert results[0].count == 4
|
||||||
|
|
||||||
assert results[1].notification_type == "sms"
|
assert results[1].notification_type == NotificationType.SMS
|
||||||
assert results[1].status == "created"
|
assert results[1].status == NotificationStatus.CREATED
|
||||||
assert results[1].count == 3
|
assert results[1].count == 3
|
||||||
|
|
||||||
assert results[2].notification_type == "sms"
|
assert results[2].notification_type == NotificationType.SMS
|
||||||
assert results[2].status == "delivered"
|
assert results[2].status == NotificationStatus.DELIVERED
|
||||||
assert results[2].count == 19
|
assert results[2].count == 19
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,10 +27,14 @@ 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.templates_dao import dao_create_template, dao_update_template
|
||||||
from app.dao.users_dao import save_model_user
|
from app.dao.users_dao import save_model_user
|
||||||
from app.enums import (
|
from app.enums import (
|
||||||
|
JobStatus,
|
||||||
KeyType,
|
KeyType,
|
||||||
|
NotificationStatus,
|
||||||
|
NotificationType,
|
||||||
OrganizationType,
|
OrganizationType,
|
||||||
RecipientType,
|
RecipientType,
|
||||||
ServicePermissionType,
|
ServicePermissionType,
|
||||||
|
TemplateProcessType,
|
||||||
TemplateType,
|
TemplateType,
|
||||||
)
|
)
|
||||||
from app.models import (
|
from app.models import (
|
||||||
@@ -204,7 +208,7 @@ def create_template(
|
|||||||
hidden=False,
|
hidden=False,
|
||||||
archived=False,
|
archived=False,
|
||||||
folder=None,
|
folder=None,
|
||||||
process_type="normal",
|
process_type=TemplateProcessType.NORMAL,
|
||||||
contact_block_id=None,
|
contact_block_id=None,
|
||||||
):
|
):
|
||||||
data = {
|
data = {
|
||||||
@@ -235,7 +239,7 @@ def create_notification(
|
|||||||
job=None,
|
job=None,
|
||||||
job_row_number=None,
|
job_row_number=None,
|
||||||
to_field=None,
|
to_field=None,
|
||||||
status="created",
|
status=NotificationStatus.CREATED,
|
||||||
reference=None,
|
reference=None,
|
||||||
created_at=None,
|
created_at=None,
|
||||||
sent_at=None,
|
sent_at=None,
|
||||||
@@ -326,7 +330,7 @@ def create_notification_history(
|
|||||||
template=None,
|
template=None,
|
||||||
job=None,
|
job=None,
|
||||||
job_row_number=None,
|
job_row_number=None,
|
||||||
status="created",
|
status=NotificationStatus.CREATED,
|
||||||
reference=None,
|
reference=None,
|
||||||
created_at=None,
|
created_at=None,
|
||||||
sent_at=None,
|
sent_at=None,
|
||||||
@@ -390,7 +394,7 @@ def create_job(
|
|||||||
template,
|
template,
|
||||||
notification_count=1,
|
notification_count=1,
|
||||||
created_at=None,
|
created_at=None,
|
||||||
job_status="pending",
|
job_status=JobStatus.PENDING,
|
||||||
scheduled_for=None,
|
scheduled_for=None,
|
||||||
processing_started=None,
|
processing_started=None,
|
||||||
processing_finished=None,
|
processing_finished=None,
|
||||||
@@ -681,12 +685,12 @@ def create_ft_billing(
|
|||||||
|
|
||||||
def create_ft_notification_status(
|
def create_ft_notification_status(
|
||||||
local_date,
|
local_date,
|
||||||
notification_type="sms",
|
notification_type=NotificationType.SMS,
|
||||||
service=None,
|
service=None,
|
||||||
template=None,
|
template=None,
|
||||||
job=None,
|
job=None,
|
||||||
key_type="normal",
|
key_type=KeyType.NORMAL,
|
||||||
notification_status="delivered",
|
notification_status=NotificationStatus.DELIVERED,
|
||||||
count=1,
|
count=1,
|
||||||
):
|
):
|
||||||
if job:
|
if job:
|
||||||
@@ -842,7 +846,7 @@ def ses_notification_callback():
|
|||||||
|
|
||||||
|
|
||||||
def create_service_data_retention(
|
def create_service_data_retention(
|
||||||
service, notification_type="sms", days_of_retention=3
|
service, notification_type=NotificationType.SMS, days_of_retention=3
|
||||||
):
|
):
|
||||||
data_retention = insert_service_data_retention(
|
data_retention = insert_service_data_retention(
|
||||||
service_id=service.id,
|
service_id=service.id,
|
||||||
@@ -925,7 +929,7 @@ def set_up_usage_data(start_date):
|
|||||||
|
|
||||||
# service with emails only:
|
# service with emails only:
|
||||||
service_with_emails = create_service(service_name="b - emails")
|
service_with_emails = create_service(service_name="b - emails")
|
||||||
email_template = create_template(service=service_with_emails, template_type="email")
|
email_template = create_template(service=service_with_emails, template_type=TemplateType.EMAIL)
|
||||||
org_2 = create_organization(
|
org_2 = create_organization(
|
||||||
name="Org for {}".format(service_with_emails.name),
|
name="Org for {}".format(service_with_emails.name),
|
||||||
)
|
)
|
||||||
@@ -951,7 +955,7 @@ def set_up_usage_data(start_date):
|
|||||||
billing_reference="sms billing reference",
|
billing_reference="sms billing reference",
|
||||||
)
|
)
|
||||||
sms_template = create_template(
|
sms_template = create_template(
|
||||||
service=service_with_sms_without_org, template_type="sms"
|
service=service_with_sms_without_org, template_type=TemplateType.SMS
|
||||||
)
|
)
|
||||||
create_annual_billing(
|
create_annual_billing(
|
||||||
service_id=service_with_sms_without_org.id,
|
service_id=service_with_sms_without_org.id,
|
||||||
@@ -971,7 +975,7 @@ def set_up_usage_data(start_date):
|
|||||||
service_name="e - sms within allowance"
|
service_name="e - sms within allowance"
|
||||||
)
|
)
|
||||||
sms_template_2 = create_template(
|
sms_template_2 = create_template(
|
||||||
service=service_with_sms_within_allowance, template_type="sms"
|
service=service_with_sms_within_allowance, template_type=TemplateType.SMS
|
||||||
)
|
)
|
||||||
create_annual_billing(
|
create_annual_billing(
|
||||||
service_id=service_with_sms_within_allowance.id,
|
service_id=service_with_sms_within_allowance.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user