mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-26 09:13:40 -04:00
@@ -255,23 +255,52 @@ def test_fetch_notification_status_by_template_for_service_for_today_and_7_previ
|
||||
# create unused email template
|
||||
create_template(service=service_1, template_type=TemplateType.EMAIL)
|
||||
|
||||
create_ft_notification_status(date(2018, 10, 29), NotificationType.SMS, service_1, count=10,)
|
||||
create_ft_notification_status(date(2018, 10, 29), NotificationType.SMS, service_1, count=11,)
|
||||
create_ft_notification_status(date(2018, 10, 25), NotificationType.SMS, service_1, count=8,)
|
||||
create_ft_notification_status(
|
||||
date(2018, 10, 29), NotificationType.SMS, service_1, notification_status=NotificationStatus.CREATED,
|
||||
date(2018, 10, 29),
|
||||
NotificationType.SMS,
|
||||
service_1,
|
||||
count=10,
|
||||
)
|
||||
create_ft_notification_status(
|
||||
date(2018, 10, 29),
|
||||
NotificationType.SMS,
|
||||
service_1,
|
||||
count=11,
|
||||
)
|
||||
create_ft_notification_status(
|
||||
date(2018, 10, 25),
|
||||
NotificationType.SMS,
|
||||
service_1,
|
||||
count=8,
|
||||
)
|
||||
create_ft_notification_status(
|
||||
date(2018, 10, 29),
|
||||
NotificationType.SMS,
|
||||
service_1,
|
||||
notification_status=NotificationStatus.CREATED,
|
||||
)
|
||||
create_ft_notification_status(
|
||||
date(2018, 10, 29),
|
||||
NotificationType.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, 12, 0, 0), status=NotificationStatus.DELIVERED,
|
||||
sms_template,
|
||||
created_at=datetime(2018, 10, 31, 12, 0, 0),
|
||||
status=NotificationStatus.DELIVERED,
|
||||
)
|
||||
create_notification(
|
||||
sms_template_2, created_at=datetime(2018, 10, 31, 12, 0, 0), status=NotificationStatus.DELIVERED,
|
||||
sms_template_2,
|
||||
created_at=datetime(2018, 10, 31, 12, 0, 0),
|
||||
status=NotificationStatus.DELIVERED,
|
||||
)
|
||||
create_notification(
|
||||
email_template, created_at=datetime(2018, 10, 31, 13, 0, 0), status=NotificationStatus.DELIVERED,
|
||||
email_template,
|
||||
created_at=datetime(2018, 10, 31, 13, 0, 0),
|
||||
status=NotificationStatus.DELIVERED,
|
||||
)
|
||||
|
||||
# too early, shouldn't be included
|
||||
@@ -282,19 +311,83 @@ def test_fetch_notification_status_by_template_for_service_for_today_and_7_previ
|
||||
)
|
||||
|
||||
results = fetch_notification_status_for_service_for_today_and_7_previous_days(
|
||||
service_1.id, by_template=True,
|
||||
service_1.id,
|
||||
by_template=True,
|
||||
)
|
||||
|
||||
assert [
|
||||
("email Template Name", False, mock.ANY, NotificationType.EMAIL, NotificationStatus.DELIVERED, 1,),
|
||||
("email Template Name", False, mock.ANY, NotificationType.EMAIL, NotificationStatus.DELIVERED, 3,),
|
||||
("sms Template 1", False, mock.ANY, NotificationType.SMS, NotificationStatus.CREATED, 1,),
|
||||
("sms Template Name", False, mock.ANY, NotificationType.SMS, NotificationStatus.CREATED, 1,),
|
||||
("sms Template 1", False, mock.ANY, NotificationType.SMS, NotificationStatus.DELIVERED, 1,),
|
||||
("sms Template 2", False, mock.ANY, NotificationType.SMS, NotificationStatus.DELIVERED, 1,),
|
||||
("sms Template Name", False, mock.ANY, NotificationType.SMS, NotificationStatus.DELIVERED, 8,),
|
||||
("sms Template Name", False, mock.ANY, NotificationType.SMS, NotificationStatus.DELIVERED, 10,),
|
||||
("sms Template Name", False, mock.ANY, NotificationType.SMS, NotificationStatus.DELIVERED, 11,),
|
||||
(
|
||||
"email Template Name",
|
||||
False,
|
||||
mock.ANY,
|
||||
NotificationType.EMAIL,
|
||||
NotificationStatus.DELIVERED,
|
||||
1,
|
||||
),
|
||||
(
|
||||
"email Template Name",
|
||||
False,
|
||||
mock.ANY,
|
||||
NotificationType.EMAIL,
|
||||
NotificationStatus.DELIVERED,
|
||||
3,
|
||||
),
|
||||
(
|
||||
"sms Template 1",
|
||||
False,
|
||||
mock.ANY,
|
||||
NotificationType.SMS,
|
||||
NotificationStatus.CREATED,
|
||||
1,
|
||||
),
|
||||
(
|
||||
"sms Template Name",
|
||||
False,
|
||||
mock.ANY,
|
||||
NotificationType.SMS,
|
||||
NotificationStatus.CREATED,
|
||||
1,
|
||||
),
|
||||
(
|
||||
"sms Template 1",
|
||||
False,
|
||||
mock.ANY,
|
||||
NotificationType.SMS,
|
||||
NotificationStatus.DELIVERED,
|
||||
1,
|
||||
),
|
||||
(
|
||||
"sms Template 2",
|
||||
False,
|
||||
mock.ANY,
|
||||
NotificationType.SMS,
|
||||
NotificationStatus.DELIVERED,
|
||||
1,
|
||||
),
|
||||
(
|
||||
"sms Template Name",
|
||||
False,
|
||||
mock.ANY,
|
||||
NotificationType.SMS,
|
||||
NotificationStatus.DELIVERED,
|
||||
8,
|
||||
),
|
||||
(
|
||||
"sms Template Name",
|
||||
False,
|
||||
mock.ANY,
|
||||
NotificationType.SMS,
|
||||
NotificationStatus.DELIVERED,
|
||||
10,
|
||||
),
|
||||
(
|
||||
"sms Template Name",
|
||||
False,
|
||||
mock.ANY,
|
||||
NotificationType.SMS,
|
||||
NotificationStatus.DELIVERED,
|
||||
11,
|
||||
),
|
||||
] == sorted(
|
||||
results, key=lambda x: (x.notification_type, x.status, x.template_name, x.count)
|
||||
)
|
||||
@@ -352,19 +445,29 @@ def test_fetch_notification_status_totals_for_all_services_works_in_est(
|
||||
)
|
||||
|
||||
create_notification(
|
||||
sms_template, created_at=datetime(2018, 4, 20, 12, 0, 0), status=NotificationStatus.DELIVERED,
|
||||
sms_template,
|
||||
created_at=datetime(2018, 4, 20, 12, 0, 0),
|
||||
status=NotificationStatus.DELIVERED,
|
||||
)
|
||||
create_notification(
|
||||
sms_template, created_at=datetime(2018, 4, 21, 11, 0, 0), status=NotificationStatus.CREATED,
|
||||
sms_template,
|
||||
created_at=datetime(2018, 4, 21, 11, 0, 0),
|
||||
status=NotificationStatus.CREATED,
|
||||
)
|
||||
create_notification(
|
||||
sms_template, created_at=datetime(2018, 4, 21, 12, 0, 0), status=NotificationStatus.DELIVERED,
|
||||
sms_template,
|
||||
created_at=datetime(2018, 4, 21, 12, 0, 0),
|
||||
status=NotificationStatus.DELIVERED,
|
||||
)
|
||||
create_notification(
|
||||
email_template, created_at=datetime(2018, 4, 21, 13, 0, 0), status=NotificationStatus.DELIVERED,
|
||||
email_template,
|
||||
created_at=datetime(2018, 4, 21, 13, 0, 0),
|
||||
status=NotificationStatus.DELIVERED,
|
||||
)
|
||||
create_notification(
|
||||
email_template, created_at=datetime(2018, 4, 21, 14, 0, 0), status=NotificationStatus.DELIVERED,
|
||||
email_template,
|
||||
created_at=datetime(2018, 4, 21, 14, 0, 0),
|
||||
status=NotificationStatus.DELIVERED,
|
||||
)
|
||||
|
||||
results = sorted(
|
||||
@@ -396,12 +499,27 @@ def set_up_data():
|
||||
email_template = create_template(
|
||||
service=service_1, template_type=TemplateType.EMAIL
|
||||
)
|
||||
create_ft_notification_status(date(2018, 10, 24), NotificationType.SMS, service_1, count=8,)
|
||||
create_ft_notification_status(date(2018, 10, 29), NotificationType.SMS, service_1, count=10,)
|
||||
create_ft_notification_status(
|
||||
date(2018, 10, 29), NotificationType.SMS, service_1, notification_status=NotificationStatus.CREATED,
|
||||
date(2018, 10, 24),
|
||||
NotificationType.SMS,
|
||||
service_1,
|
||||
count=8,
|
||||
)
|
||||
create_ft_notification_status(
|
||||
date(2018, 10, 29),
|
||||
NotificationType.SMS,
|
||||
service_1,
|
||||
count=10,
|
||||
)
|
||||
create_ft_notification_status(
|
||||
date(2018, 10, 29),
|
||||
NotificationType.SMS,
|
||||
service_1,
|
||||
notification_status=NotificationStatus.CREATED,
|
||||
)
|
||||
create_ft_notification_status(
|
||||
date(2018, 10, 29), NotificationType.EMAIL, service_1, count=3
|
||||
)
|
||||
create_ft_notification_status(date(2018, 10, 29), NotificationType.EMAIL, service_1, count=3)
|
||||
|
||||
create_notification(
|
||||
service_1.templates[0],
|
||||
@@ -410,10 +528,14 @@ def set_up_data():
|
||||
)
|
||||
create_notification(sms_template, created_at=datetime(2018, 10, 31, 11, 0, 0))
|
||||
create_notification(
|
||||
sms_template, created_at=datetime(2018, 10, 31, 12, 0, 0), status=NotificationStatus.DELIVERED,
|
||||
sms_template,
|
||||
created_at=datetime(2018, 10, 31, 12, 0, 0),
|
||||
status=NotificationStatus.DELIVERED,
|
||||
)
|
||||
create_notification(
|
||||
email_template, created_at=datetime(2018, 10, 31, 13, 0, 0), status=NotificationStatus.DELIVERED,
|
||||
email_template,
|
||||
created_at=datetime(2018, 10, 31, 13, 0, 0),
|
||||
status=NotificationStatus.DELIVERED,
|
||||
)
|
||||
return service_1, service_2
|
||||
|
||||
@@ -423,16 +545,28 @@ def test_fetch_notification_statuses_for_job(sample_template):
|
||||
j2 = create_job(sample_template)
|
||||
|
||||
create_ft_notification_status(
|
||||
date(2018, 10, 1), job=j1, notification_status=NotificationStatus.CREATED, count=1,
|
||||
date(2018, 10, 1),
|
||||
job=j1,
|
||||
notification_status=NotificationStatus.CREATED,
|
||||
count=1,
|
||||
)
|
||||
create_ft_notification_status(
|
||||
date(2018, 10, 1), job=j1, notification_status=NotificationStatus.DELIVERED, count=2,
|
||||
date(2018, 10, 1),
|
||||
job=j1,
|
||||
notification_status=NotificationStatus.DELIVERED,
|
||||
count=2,
|
||||
)
|
||||
create_ft_notification_status(
|
||||
date(2018, 10, 2), job=j1, notification_status=NotificationStatus.CREATED, count=4,
|
||||
date(2018, 10, 2),
|
||||
job=j1,
|
||||
notification_status=NotificationStatus.CREATED,
|
||||
count=4,
|
||||
)
|
||||
create_ft_notification_status(
|
||||
date(2018, 10, 1), job=j2, notification_status=NotificationStatus.CREATED, count=8,
|
||||
date(2018, 10, 1),
|
||||
job=j2,
|
||||
notification_status=NotificationStatus.CREATED,
|
||||
count=8,
|
||||
)
|
||||
|
||||
assert {x.status: x.count for x in fetch_notification_statuses_for_job(j1.id)} == {
|
||||
@@ -473,10 +607,14 @@ def test_fetch_stats_for_all_services_by_date_range(notify_db_session):
|
||||
@freeze_time("2018-03-30 14:00")
|
||||
def test_fetch_monthly_template_usage_for_service(sample_service):
|
||||
template_one = create_template(
|
||||
service=sample_service, template_type=TemplateType.SMS, template_name="a",
|
||||
service=sample_service,
|
||||
template_type=TemplateType.SMS,
|
||||
template_name="a",
|
||||
)
|
||||
template_two = create_template(
|
||||
service=sample_service, template_type=TemplateType.EMAIL, template_name="b",
|
||||
service=sample_service,
|
||||
template_type=TemplateType.EMAIL,
|
||||
template_name="b",
|
||||
)
|
||||
|
||||
create_ft_notification_status(
|
||||
@@ -548,10 +686,14 @@ def test_fetch_monthly_template_usage_for_service_does_join_to_notifications_if_
|
||||
sample_service,
|
||||
):
|
||||
template_one = create_template(
|
||||
service=sample_service, template_type=TemplateType.SMS, template_name="a",
|
||||
service=sample_service,
|
||||
template_type=TemplateType.SMS,
|
||||
template_name="a",
|
||||
)
|
||||
template_two = create_template(
|
||||
service=sample_service, template_type=TmplateType.EMAIL, template_name="b",
|
||||
service=sample_service,
|
||||
template_type=TemplateType.EMAIL,
|
||||
template_name="b",
|
||||
)
|
||||
create_ft_notification_status(
|
||||
local_date=date(2018, 2, 1),
|
||||
@@ -604,7 +746,9 @@ def test_fetch_monthly_template_usage_for_service_does_not_include_cancelled_sta
|
||||
count=15,
|
||||
)
|
||||
create_notification(
|
||||
template=sample_template, created_at=datetime.utcnow(), status=NotificationStatus.CANCELLED,
|
||||
template=sample_template,
|
||||
created_at=datetime.utcnow(),
|
||||
status=NotificationStatus.CANCELLED,
|
||||
)
|
||||
results = fetch_monthly_template_usage_for_service(
|
||||
datetime(2018, 1, 1), datetime(2018, 3, 31), sample_template.service_id
|
||||
@@ -632,7 +776,9 @@ def test_fetch_monthly_template_usage_for_service_does_not_include_test_notifica
|
||||
key_type=KeyType.TEST,
|
||||
)
|
||||
results = fetch_monthly_template_usage_for_service(
|
||||
datetime(2018, 1, 1), datetime(2018, 3, 31), sample_template.service_id,
|
||||
datetime(2018, 1, 1),
|
||||
datetime(2018, 3, 31),
|
||||
sample_template.service_id,
|
||||
)
|
||||
|
||||
assert len(results) == 0
|
||||
@@ -821,10 +967,14 @@ def test_fetch_monthly_notification_statuses_per_service_for_rows_that_should_be
|
||||
|
||||
def test_get_total_notifications_for_date_range(sample_service):
|
||||
template_sms = create_template(
|
||||
service=sample_service, template_type=TemplateType.SMS, template_name="a",
|
||||
service=sample_service,
|
||||
template_type=TemplateType.SMS,
|
||||
template_name="a",
|
||||
)
|
||||
template_email = create_template(
|
||||
service=sample_service, template_type=TemplateType.EMAIL, template_name="b",
|
||||
service=sample_service,
|
||||
template_type=TemplateType.EMAIL,
|
||||
template_name="b",
|
||||
)
|
||||
create_ft_notification_status(
|
||||
local_date=date(2021, 2, 28),
|
||||
|
||||
Reference in New Issue
Block a user