mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-10 10:03:38 -04:00
Fixing things is fun.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
@@ -125,11 +125,7 @@ def get_jobs_by_service(service_id):
|
|||||||
try:
|
try:
|
||||||
limit_days = int(request.args["limit_days"])
|
limit_days = int(request.args["limit_days"])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
errors = {
|
errors = {"limit_days": [f"{request.args['limit_days']} is not an integer"]}
|
||||||
"limit_days": [
|
|
||||||
f"{request.args['limit_days']} is not an integer"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
raise InvalidRequest(errors, status_code=400)
|
raise InvalidRequest(errors, status_code=400)
|
||||||
else:
|
else:
|
||||||
limit_days = None
|
limit_days = None
|
||||||
|
|||||||
@@ -85,7 +85,13 @@ def transform_results_into_totals(total_notifications_results):
|
|||||||
def transform_into_notification_by_type_json(total_notifications):
|
def transform_into_notification_by_type_json(total_notifications):
|
||||||
j = []
|
j = []
|
||||||
for x in total_notifications:
|
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
|
return j
|
||||||
|
|
||||||
|
|||||||
@@ -475,39 +475,43 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio
|
|||||||
|
|
||||||
assert len(new_fact_data) == 4
|
assert len(new_fact_data) == 4
|
||||||
|
|
||||||
email_delivered_row = new_fact_data[0]
|
email_delivered = (NotificationType.EMAIL, NotificationStatus.DELIVERED)
|
||||||
assert email_delivered_row.template_id == second_template.id
|
email_sending = (NotificationType.EMAIL, NotificationStatus.SENDING)
|
||||||
assert email_delivered_row.service_id == second_service.id
|
email_failure = (NotificationType.EMAIL, NotificationStatus.FAILED)
|
||||||
assert email_delivered_row.notification_type == NotificationType.EMAIL
|
sms_delivered = (NotificationType.SMS, NotificationStatus.DELIVERED)
|
||||||
assert email_delivered_row.notification_status == NotificationStatus.DELIVERED
|
|
||||||
assert email_delivered_row.notification_count == 1
|
|
||||||
assert email_delivered_row.key_type == KeyType.NORMAL
|
|
||||||
|
|
||||||
email_sending_row = new_fact_data[1]
|
for row in new_fact_data:
|
||||||
assert email_sending_row.template_id == second_template.id
|
current = (row.notification_type, row.notification_status)
|
||||||
assert email_sending_row.service_id == second_service.id
|
if current == email_delivered:
|
||||||
assert email_sending_row.notification_type == NotificationType.EMAIL
|
assert row.template_id == second_template.id
|
||||||
assert email_sending_row.notification_status == NotificationStatus.FAILED
|
assert row.service_id == second_service.id
|
||||||
assert email_sending_row.notification_count == 1
|
assert row.notification_type == NotificationType.EMAIL
|
||||||
assert email_sending_row.key_type == KeyType.NORMAL
|
assert row.notification_status == NotificationStatus.DELIVERED
|
||||||
|
assert row.notification_count == 1
|
||||||
email_failure_row = new_fact_data[2]
|
assert row.key_type == KeyType.NORMAL
|
||||||
assert email_failure_row.local_date == process_day
|
elif current == email_failure:
|
||||||
assert email_failure_row.template_id == second_template.id
|
assert row.template_id == second_template.id
|
||||||
assert email_failure_row.service_id == second_service.id
|
assert row.service_id == second_service.id
|
||||||
assert email_failure_row.job_id == UUID("00000000-0000-0000-0000-000000000000")
|
assert row.notification_type == NotificationType.EMAIL
|
||||||
assert email_failure_row.notification_type == NotificationType.EMAIL
|
assert row.notification_status == NotificationStatus.FAILED
|
||||||
assert email_failure_row.notification_status == NotificationStatus.SENDING
|
assert row.notification_count == 1
|
||||||
assert email_failure_row.notification_count == 1
|
assert row.key_type == KeyType.NORMAL
|
||||||
assert email_failure_row.key_type == KeyType.TEAM
|
elif current == email_sending:
|
||||||
|
assert row.local_date == process_day
|
||||||
sms_delivered_row = new_fact_data[3]
|
assert row.template_id == second_template.id
|
||||||
assert sms_delivered_row.template_id == first_template.id
|
assert row.service_id == second_service.id
|
||||||
assert sms_delivered_row.service_id == first_service.id
|
assert row.job_id == UUID("00000000-0000-0000-0000-000000000000")
|
||||||
assert sms_delivered_row.notification_type == NotificationType.SMS
|
assert row.notification_type == NotificationType.EMAIL
|
||||||
assert sms_delivered_row.notification_status == NotificationStatus.DELIVERED
|
assert row.notification_status == NotificationStatus.SENDING
|
||||||
assert sms_delivered_row.notification_count == 1
|
assert row.notification_count == 1
|
||||||
assert sms_delivered_row.key_type == KeyType.NORMAL
|
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(
|
def test_create_nightly_notification_status_for_service_and_day_overwrites_old_data(
|
||||||
|
|||||||
@@ -871,67 +871,72 @@ def test_fetch_monthly_notification_statuses_per_service(notify_db_session):
|
|||||||
assert len(results) == 5
|
assert len(results) == 5
|
||||||
# column order: date, service_id, service_name, notifaction_type, count_sending, count_delivered,
|
# column order: date, service_id, service_name, notifaction_type, count_sending, count_delivered,
|
||||||
# count_technical_failure, count_temporary_failure, count_permanent_failure, count_sent
|
# count_technical_failure, count_temporary_failure, count_permanent_failure, count_sent
|
||||||
assert [x for x in results[0]] == [
|
expected = [
|
||||||
date(2019, 3, 1),
|
[
|
||||||
service_two.id,
|
date(2019, 3, 1),
|
||||||
"service two",
|
service_two.id,
|
||||||
NotificationType.SMS,
|
"service two",
|
||||||
0,
|
NotificationType.SMS,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
2,
|
0,
|
||||||
0,
|
2,
|
||||||
]
|
0,
|
||||||
assert [x for x in results[1]] == [
|
],
|
||||||
date(2019, 3, 1),
|
[
|
||||||
service_one.id,
|
date(2019, 3, 1),
|
||||||
"service one",
|
service_one.id,
|
||||||
NotificationType.EMAIL,
|
"service one",
|
||||||
5,
|
NotificationType.EMAIL,
|
||||||
0,
|
5,
|
||||||
3,
|
0,
|
||||||
0,
|
3,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
]
|
0,
|
||||||
assert [x for x in results[2]] == [
|
],
|
||||||
date(2019, 3, 1),
|
[
|
||||||
service_one.id,
|
date(2019, 3, 1),
|
||||||
"service one",
|
service_one.id,
|
||||||
NotificationType.SMS,
|
"service one",
|
||||||
0,
|
NotificationType.SMS,
|
||||||
1,
|
0,
|
||||||
0,
|
1,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
1,
|
0,
|
||||||
]
|
1,
|
||||||
assert [x for x in results[3]] == [
|
],
|
||||||
date(2019, 4, 1),
|
[
|
||||||
service_two.id,
|
date(2019, 4, 1),
|
||||||
"service two",
|
service_two.id,
|
||||||
NotificationType.SMS,
|
"service two",
|
||||||
0,
|
NotificationType.SMS,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
10,
|
0,
|
||||||
0,
|
10,
|
||||||
0,
|
0,
|
||||||
]
|
0,
|
||||||
assert [x for x in results[4]] == [
|
],
|
||||||
date(2019, 4, 1),
|
[
|
||||||
service_one.id,
|
date(2019, 4, 1),
|
||||||
"service one",
|
service_one.id,
|
||||||
NotificationType.SMS,
|
"service one",
|
||||||
0,
|
NotificationType.SMS,
|
||||||
1,
|
0,
|
||||||
0,
|
1,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
0,
|
||||||
|
],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
for row in results:
|
||||||
|
assert [x for x in row] in expected
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2019-04-10 14:00")
|
@freeze_time("2019-04-10 14:00")
|
||||||
def test_fetch_monthly_notification_statuses_per_service_for_rows_that_should_be_excluded(
|
def test_fetch_monthly_notification_statuses_per_service_for_rows_that_should_be_excluded(
|
||||||
|
|||||||
@@ -276,9 +276,21 @@ def test_send_notification_to_queue_throws_exception_deletes_notification(
|
|||||||
[
|
[
|
||||||
("+14254147755", NotificationType.SMS, True),
|
("+14254147755", NotificationType.SMS, True),
|
||||||
("+14254147167", 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@notifications.service.gov.uk",
|
||||||
("simulate-delivered-3@notifications.service.gov.uk", NotificationType.EMAIL, True),
|
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),
|
("2028675309", NotificationType.SMS, False),
|
||||||
("valid_email@test.com", NotificationType.EMAIL, False),
|
("valid_email@test.com", NotificationType.EMAIL, False),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user