Latest and greatest.

Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
Cliff Hill
2024-02-02 11:40:25 -05:00
parent 544bf35c06
commit 689ff10b71
6 changed files with 84 additions and 51 deletions

View File

@@ -17,8 +17,8 @@ from app.dao.fact_notification_status_dao import (
get_total_notifications_for_date_range,
update_fact_notification_status,
)
from app.enums import KeyType, NotificationStatus
from app.models import FactNotificationStatus, NotificationType, TemplateType
from app.enums import KeyType, NotificationStatus, NotificationType, TemplateType
from app.models import FactNotificationStatus
from tests.app.db import (
create_ft_notification_status,
create_job,
@@ -32,24 +32,31 @@ def test_fetch_notification_status_for_service_by_month(notify_db_session):
service_1 = create_service(service_name="service_1")
service_2 = create_service(service_name="service_2")
create_ft_notification_status(date(2018, 1, 1), "sms", service_1, count=4)
create_ft_notification_status(date(2018, 1, 2), "sms", service_1, count=10)
create_ft_notification_status(
date(2018, 1, 2), "sms", service_1, notification_status="created"
date(2018, 1, 1), NotificationType.SMS, service_1, count=4
)
create_ft_notification_status(date(2018, 1, 3), "email", service_1)
create_ft_notification_status(
date(2018, 1, 2), NotificationType.SMS, service_1, count=10
)
create_ft_notification_status(
date(2018, 1, 2),
NotificationType.SMS,
service_1,
notification_status=NotificationStatus.CREATED,
)
create_ft_notification_status(date(2018, 1, 3), NotificationType.EMAIL, service_1)
create_ft_notification_status(date(2018, 2, 2), "sms", service_1)
create_ft_notification_status(date(2018, 2, 2), NotificationType.SMS, service_1)
# not included - too early
create_ft_notification_status(date(2017, 12, 31), "sms", service_1)
create_ft_notification_status(date(2017, 12, 31), NotificationType.SMS, service_1)
# not included - too late
create_ft_notification_status(date(2017, 3, 1), "sms", service_1)
create_ft_notification_status(date(2017, 3, 1), NotificationType.SMS, service_1)
# not included - wrong service
create_ft_notification_status(date(2018, 1, 3), "sms", service_2)
create_ft_notification_status(date(2018, 1, 3), NotificationType.SMS, service_2)
# not included - test keys
create_ft_notification_status(
date(2018, 1, 3), "sms", service_1, key_type=KeyType.TEST
date(2018, 1, 3), NotificationType.SMS, service_1, key_type=KeyType.TEST
)
results = sorted(
@@ -62,23 +69,23 @@ def test_fetch_notification_status_for_service_by_month(notify_db_session):
assert len(results) == 4
assert results[0].month.date() == date(2018, 1, 1)
assert results[0].notification_type == "email"
assert results[0].notification_status == "delivered"
assert results[0].notification_type == NotificationType.EMAIL
assert results[0].notification_status == NotificationStatus.DELIVERED
assert results[0].count == 1
assert results[1].month.date() == date(2018, 1, 1)
assert results[1].notification_type == "sms"
assert results[1].notification_status == "created"
assert results[1].notification_type == NotificationType.SMS
assert results[1].notification_status == NotificationStatus.CREATED
assert results[1].count == 1
assert results[2].month.date() == date(2018, 1, 1)
assert results[2].notification_type == "sms"
assert results[2].notification_status == "delivered"
assert results[2].notification_type == NotificationType.SMS
assert results[2].notification_status == NotificationStatus.DELIVERED
assert results[2].count == 14
assert results[3].month.date() == date(2018, 2, 1)
assert results[3].notification_type == "sms"
assert results[3].notification_status == "delivered"
assert results[3].notification_type == NotificationType.SMS
assert results[3].notification_status == NotificationStatus.DELIVERED
assert results[3].count == 1
@@ -109,7 +116,7 @@ def test_fetch_notification_status_for_service_for_day(notify_db_session):
create_notification(
service_1.templates[0],
created_at=datetime(2018, 6, 1, 12, 0, 0),
status="delivered",
status=NotificationStatus.DELIVERED,
)
# test key
@@ -138,13 +145,13 @@ def test_fetch_notification_status_for_service_for_day(notify_db_session):
assert len(results) == 2
assert results[0].month == datetime(2018, 6, 1, 0, 0)
assert results[0].notification_type == "sms"
assert results[0].notification_status == "created"
assert results[0].notification_type == NotificationType.SMS
assert results[0].notification_status == NotificationStatus.CREATED
assert results[0].count == 3
assert results[1].month == datetime(2018, 6, 1, 0, 0)
assert results[1].notification_type == "sms"
assert results[1].notification_status == "delivered"
assert results[1].notification_type == NotificationType.SMS
assert results[1].notification_status == NotificationStatus.DELIVERED
assert results[1].count == 1
@@ -159,20 +166,42 @@ def test_fetch_notification_status_for_service_for_today_and_7_previous_days(
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, 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, 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_2, 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,
)
# too early, shouldn't be included
@@ -299,16 +328,16 @@ def test_fetch_notification_status_totals_for_all_services(
assert len(results) == 3
assert results[0].notification_type == "email"
assert results[0].status == "delivered"
assert results[0].notification_type == NotificationType.EMAIL
assert results[0].status == NotificationStatus.DELIVERED
assert results[0].count == expected_email
assert results[1].notification_type == "sms"
assert results[1].status == "created"
assert results[1].notification_type == NotificationType.SMS
assert results[1].status == NotificationStatus.CREATED
assert results[1].count == expected_created_sms
assert results[2].notification_type == "sms"
assert results[2].status == "delivered"
assert results[2].notification_type == NotificationType.SMS
assert results[2].status == NotificationStatus.DELIVERED
assert results[2].count == expected_sms

View File

@@ -929,7 +929,9 @@ def set_up_usage_data(start_date):
# service with emails only:
service_with_emails = create_service(service_name="b - emails")
email_template = create_template(service=service_with_emails, template_type=TemplateType.EMAIL)
email_template = create_template(
service=service_with_emails, template_type=TemplateType.EMAIL
)
org_2 = create_organization(
name="Org for {}".format(service_with_emails.name),
)