Fixing things is fun.

Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
Cliff Hill
2024-02-28 15:54:35 -05:00
parent c49e1fa5f0
commit 11992be740
5 changed files with 123 additions and 100 deletions

View File

@@ -125,11 +125,7 @@ def get_jobs_by_service(service_id):
try:
limit_days = int(request.args["limit_days"])
except ValueError:
errors = {
"limit_days": [
f"{request.args['limit_days']} is not an integer"
]
}
errors = {"limit_days": [f"{request.args['limit_days']} is not an integer"]}
raise InvalidRequest(errors, status_code=400)
else:
limit_days = None

View File

@@ -85,7 +85,13 @@ def transform_results_into_totals(total_notifications_results):
def transform_into_notification_by_type_json(total_notifications):
j = []
for x in total_notifications:
j.append({"date": x.local_date.strftime("%Y-%m-%d"), "emails": x.emails, "sms": x.sms})
j.append(
{
"date": x.local_date.strftime("%Y-%m-%d"),
"emails": x.emails,
"sms": x.sms,
}
)
return j

View File

@@ -475,39 +475,43 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio
assert len(new_fact_data) == 4
email_delivered_row = new_fact_data[0]
assert email_delivered_row.template_id == second_template.id
assert email_delivered_row.service_id == second_service.id
assert email_delivered_row.notification_type == NotificationType.EMAIL
assert email_delivered_row.notification_status == NotificationStatus.DELIVERED
assert email_delivered_row.notification_count == 1
assert email_delivered_row.key_type == KeyType.NORMAL
email_delivered = (NotificationType.EMAIL, NotificationStatus.DELIVERED)
email_sending = (NotificationType.EMAIL, NotificationStatus.SENDING)
email_failure = (NotificationType.EMAIL, NotificationStatus.FAILED)
sms_delivered = (NotificationType.SMS, NotificationStatus.DELIVERED)
email_sending_row = new_fact_data[1]
assert email_sending_row.template_id == second_template.id
assert email_sending_row.service_id == second_service.id
assert email_sending_row.notification_type == NotificationType.EMAIL
assert email_sending_row.notification_status == NotificationStatus.FAILED
assert email_sending_row.notification_count == 1
assert email_sending_row.key_type == KeyType.NORMAL
email_failure_row = new_fact_data[2]
assert email_failure_row.local_date == process_day
assert email_failure_row.template_id == second_template.id
assert email_failure_row.service_id == second_service.id
assert email_failure_row.job_id == UUID("00000000-0000-0000-0000-000000000000")
assert email_failure_row.notification_type == NotificationType.EMAIL
assert email_failure_row.notification_status == NotificationStatus.SENDING
assert email_failure_row.notification_count == 1
assert email_failure_row.key_type == KeyType.TEAM
sms_delivered_row = new_fact_data[3]
assert sms_delivered_row.template_id == first_template.id
assert sms_delivered_row.service_id == first_service.id
assert sms_delivered_row.notification_type == NotificationType.SMS
assert sms_delivered_row.notification_status == NotificationStatus.DELIVERED
assert sms_delivered_row.notification_count == 1
assert sms_delivered_row.key_type == KeyType.NORMAL
for row in new_fact_data:
current = (row.notification_type, row.notification_status)
if current == email_delivered:
assert row.template_id == second_template.id
assert row.service_id == second_service.id
assert row.notification_type == NotificationType.EMAIL
assert row.notification_status == NotificationStatus.DELIVERED
assert row.notification_count == 1
assert row.key_type == KeyType.NORMAL
elif current == email_failure:
assert row.template_id == second_template.id
assert row.service_id == second_service.id
assert row.notification_type == NotificationType.EMAIL
assert row.notification_status == NotificationStatus.FAILED
assert row.notification_count == 1
assert row.key_type == KeyType.NORMAL
elif current == email_sending:
assert row.local_date == process_day
assert row.template_id == second_template.id
assert row.service_id == second_service.id
assert row.job_id == UUID("00000000-0000-0000-0000-000000000000")
assert row.notification_type == NotificationType.EMAIL
assert row.notification_status == NotificationStatus.SENDING
assert row.notification_count == 1
assert row.key_type == KeyType.TEAM
elif current == sms_delivered:
assert row.template_id == first_template.id
assert row.service_id == first_service.id
assert row.notification_type == NotificationType.SMS
assert row.notification_status == NotificationStatus.DELIVERED
assert row.notification_count == 1
assert row.key_type == KeyType.NORMAL
def test_create_nightly_notification_status_for_service_and_day_overwrites_old_data(

View File

@@ -871,67 +871,72 @@ def test_fetch_monthly_notification_statuses_per_service(notify_db_session):
assert len(results) == 5
# column order: date, service_id, service_name, notifaction_type, count_sending, count_delivered,
# count_technical_failure, count_temporary_failure, count_permanent_failure, count_sent
assert [x for x in results[0]] == [
date(2019, 3, 1),
service_two.id,
"service two",
NotificationType.SMS,
0,
0,
0,
0,
2,
0,
]
assert [x for x in results[1]] == [
date(2019, 3, 1),
service_one.id,
"service one",
NotificationType.EMAIL,
5,
0,
3,
0,
0,
0,
]
assert [x for x in results[2]] == [
date(2019, 3, 1),
service_one.id,
"service one",
NotificationType.SMS,
0,
1,
0,
0,
0,
1,
]
assert [x for x in results[3]] == [
date(2019, 4, 1),
service_two.id,
"service two",
NotificationType.SMS,
0,
0,
0,
10,
0,
0,
]
assert [x for x in results[4]] == [
date(2019, 4, 1),
service_one.id,
"service one",
NotificationType.SMS,
0,
1,
0,
0,
0,
0,
expected = [
[
date(2019, 3, 1),
service_two.id,
"service two",
NotificationType.SMS,
0,
0,
0,
0,
2,
0,
],
[
date(2019, 3, 1),
service_one.id,
"service one",
NotificationType.EMAIL,
5,
0,
3,
0,
0,
0,
],
[
date(2019, 3, 1),
service_one.id,
"service one",
NotificationType.SMS,
0,
1,
0,
0,
0,
1,
],
[
date(2019, 4, 1),
service_two.id,
"service two",
NotificationType.SMS,
0,
0,
0,
10,
0,
0,
],
[
date(2019, 4, 1),
service_one.id,
"service one",
NotificationType.SMS,
0,
1,
0,
0,
0,
0,
],
]
for row in results:
assert [x for x in row] in expected
@freeze_time("2019-04-10 14:00")
def test_fetch_monthly_notification_statuses_per_service_for_rows_that_should_be_excluded(

View File

@@ -276,9 +276,21 @@ def test_send_notification_to_queue_throws_exception_deletes_notification(
[
("+14254147755", NotificationType.SMS, True),
("+14254147167", NotificationType.SMS, True),
("simulate-delivered@notifications.service.gov.uk", NotificationType.EMAIL, True),
("simulate-delivered-2@notifications.service.gov.uk", NotificationType.EMAIL, True),
("simulate-delivered-3@notifications.service.gov.uk", NotificationType.EMAIL, True),
(
"simulate-delivered@notifications.service.gov.uk",
NotificationType.EMAIL,
True,
),
(
"simulate-delivered-2@notifications.service.gov.uk",
NotificationType.EMAIL,
True,
),
(
"simulate-delivered-3@notifications.service.gov.uk",
NotificationType.EMAIL,
True,
),
("2028675309", NotificationType.SMS, False),
("valid_email@test.com", NotificationType.EMAIL, False),
],