"sms" entries cleaned up.

Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
Cliff Hill
2024-02-21 08:36:42 -05:00
parent 4429e48221
commit 9fde1f30ea
3 changed files with 87 additions and 44 deletions

View File

@@ -18,7 +18,9 @@ def test_get_template_usage_by_month_returns_correct_data(
admin_request, sample_template
):
create_ft_notification_status(
local_date=date(2017, 4, 2), template=sample_template, count=3
local_date=date(2017, 4, 2),
template=sample_template,
count=3,
)
create_notification(sample_template, created_at=datetime.utcnow())
@@ -57,10 +59,14 @@ def test_get_template_usage_by_month_returns_two_templates(
hidden=True,
)
create_ft_notification_status(
local_date=datetime(2017, 4, 2), template=template_one, count=1
local_date=datetime(2017, 4, 2),
template=template_one,
count=1,
)
create_ft_notification_status(
local_date=datetime(2017, 4, 2), template=sample_template, count=3
local_date=datetime(2017, 4, 2),
template=sample_template,
count=3,
)
create_notification(sample_template, created_at=datetime.utcnow())
@@ -191,7 +197,7 @@ def test_get_monthly_notification_stats_returns_empty_stats_with_correct_dates(
]
assert sorted(response["data"].keys()) == keys
for val in response["data"].values():
assert val == {"sms": {}, "email": {}}
assert val == {NotificationType.SMS: {}, NotificationType.EMAIL: {}}
def test_get_monthly_notification_stats_returns_stats(admin_request, sample_service):
@@ -205,7 +211,9 @@ def test_get_monthly_notification_stats_returns_stats(admin_request, sample_serv
create_ft_notification_status(datetime(2016, 7, 1), template=sms_t1)
create_ft_notification_status(datetime(2016, 7, 1), template=sms_t2)
create_ft_notification_status(
datetime(2016, 7, 1), template=sms_t1, notification_status="created"
datetime(2016, 7, 1),
template=sms_t1,
notification_status=NotificationStatus.CREATED,
)
create_ft_notification_status(datetime(2016, 7, 1), template=email_template)
@@ -217,19 +225,19 @@ def test_get_monthly_notification_stats_returns_stats(admin_request, sample_serv
assert len(response["data"]) == 12
assert response["data"]["2016-06"] == {
"sms": {
NotificationType.SMS: {
# it combines the two days
"delivered": 2
NotificationStatus.DELIVERED: 2
},
"email": {},
NotificationType.EMAIL: {},
}
assert response["data"]["2016-07"] == {
# it combines the two template types
"sms": {
"created": 1,
"delivered": 2,
NotificationType.SMS: {
NotificationStatus.CREATED: 1,
NotificationStatus.DELIVERED: 2,
},
"email": {"delivered": 1},
NotificationType.EMAIL: {"delivered": 1},
}
@@ -274,14 +282,17 @@ def test_get_monthly_notification_stats_combines_todays_data_and_historic_stats(
)
assert len(response["data"]) == 6 # January to June
assert response["data"]["2016-05"] == {"sms": {"delivered": 1}, "email": {}}
assert response["data"]["2016-05"] == {
NotificationType.SMS: {NotificationStatus.DELIVERED: 1},
NotificationType.EMAIL: {},
}
assert response["data"]["2016-06"] == {
"sms": {
NotificationType.SMS: {
# combines the stats from the historic ft_notification_status and the current notifications
"created": 3,
"delivered": 1,
NotificationStatus.CREATED: 3,
NotificationStatus.DELIVERED: 1,
},
"email": {},
NotificationType.EMAIL: {},
}
@@ -289,13 +300,22 @@ def test_get_monthly_notification_stats_ignores_test_keys(
admin_request, sample_service
):
create_ft_notification_status(
datetime(2016, 6, 1), service=sample_service, key_type=KeyType.NORMAL, count=1
datetime(2016, 6, 1),
service=sample_service,
key_type=KeyType.NORMAL,
count=1,
)
create_ft_notification_status(
datetime(2016, 6, 1), service=sample_service, key_type=KeyType.TEAM, count=2
datetime(2016, 6, 1),
service=sample_service,
key_type=KeyType.TEAM,
count=2,
)
create_ft_notification_status(
datetime(2016, 6, 1), service=sample_service, key_type=KeyType.TEST, count=4
datetime(2016, 6, 1),
service=sample_service,
key_type=KeyType.TEST,
count=4,
)
response = admin_request.get(
@@ -304,20 +324,28 @@ def test_get_monthly_notification_stats_ignores_test_keys(
year=2016,
)
assert response["data"]["2016-06"]["sms"] == {"delivered": 3}
assert response["data"]["2016-06"][NotificationType.SMS] == {
NotificationStatus.DELIVERED: 3,
}
def test_get_monthly_notification_stats_checks_dates(admin_request, sample_service):
t = create_template(sample_service)
# create_ft_notification_status(datetime(2016, 3, 31), template=t, notification_status='created')
create_ft_notification_status(
datetime(2016, 4, 2), template=t, notification_status="sending"
datetime(2016, 4, 2),
template=t,
notification_status=NotificationStatus.SENDING,
)
create_ft_notification_status(
datetime(2017, 3, 31), template=t, notification_status="delivered"
datetime(2017, 3, 31),
template=t,
notification_status=NotificationStatus.DELIVERED,
)
create_ft_notification_status(
datetime(2017, 4, 11), template=t, notification_status="permanent-failure"
datetime(2017, 4, 11),
template=t,
notification_status=NotificationStatus.PERMANENT_FAILURE,
)
response = admin_request.get(
@@ -327,8 +355,12 @@ def test_get_monthly_notification_stats_checks_dates(admin_request, sample_servi
)
assert "2016-04" in response["data"]
assert "2017-04" not in response["data"]
assert response["data"]["2016-04"]["sms"] == {"sending": 1}
assert response["data"]["2016-04"]["sms"] == {"sending": 1}
assert response["data"]["2016-04"][NotificationType.SMS] == {
NotificationStatus.SENDING: 1,
}
assert response["data"]["2016-04"][NotificationType.SMS] == {
NotificationStatus.SENDING: 1,
}
def test_get_monthly_notification_stats_only_gets_for_one_service(
@@ -339,14 +371,23 @@ def test_get_monthly_notification_stats_only_gets_for_one_service(
templates = [create_template(services[0]), create_template(services[1])]
create_ft_notification_status(
datetime(2016, 6, 1), template=templates[0], notification_status="created"
datetime(2016, 6, 1),
template=templates[0],
notification_status=NotificationStatus.CREATED,
)
create_ft_notification_status(
datetime(2016, 6, 1), template=templates[1], notification_status="delivered"
datetime(2016, 6, 1),
template=templates[1],
notification_status=NotificationStatus.DELIVERED,
)
response = admin_request.get(
"service.get_monthly_notification_stats", service_id=services[0].id, year=2016
"service.get_monthly_notification_stats",
service_id=services[0].id,
year=2016,
)
assert response["data"]["2016-06"] == {"sms": {"created": 1}, "email": {}}
assert response["data"]["2016-06"] == {
NotificationType.SMS: {NotificationStatus.CREATED: 1},
NotificationType.EMAIL: {},
}