mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 07:46:06 -04:00
fix testing
This commit is contained in:
@@ -458,11 +458,9 @@ def dao_fetch_stats_for_service_from_days(service_id, start_date, end_date):
|
|||||||
total_substmt = (
|
total_substmt = (
|
||||||
select(
|
select(
|
||||||
func.date_trunc("day", NotificationAllTimeView.created_at).label("day"),
|
func.date_trunc("day", NotificationAllTimeView.created_at).label("day"),
|
||||||
Job.notification_count.label("notification_count")
|
Job.notification_count.label("notification_count"),
|
||||||
)
|
|
||||||
.join(
|
|
||||||
Job, NotificationAllTimeView.job_id == Job.id
|
|
||||||
)
|
)
|
||||||
|
.join(Job, NotificationAllTimeView.job_id == Job.id)
|
||||||
.where(
|
.where(
|
||||||
NotificationAllTimeView.service_id == service_id,
|
NotificationAllTimeView.service_id == service_id,
|
||||||
NotificationAllTimeView.key_type != KeyType.TEST,
|
NotificationAllTimeView.key_type != KeyType.TEST,
|
||||||
@@ -480,9 +478,7 @@ def dao_fetch_stats_for_service_from_days(service_id, start_date, end_date):
|
|||||||
total_stmt = select(
|
total_stmt = select(
|
||||||
total_substmt.c.day,
|
total_substmt.c.day,
|
||||||
func.sum(total_substmt.c.notification_count).label("total_notifications"),
|
func.sum(total_substmt.c.notification_count).label("total_notifications"),
|
||||||
).group_by(
|
).group_by(total_substmt.c.day)
|
||||||
total_substmt.c.day
|
|
||||||
)
|
|
||||||
|
|
||||||
total_notifications = {
|
total_notifications = {
|
||||||
row.day: row.total_notifications for row in db.session.execute(total_stmt).all()
|
row.day: row.total_notifications for row in db.session.execute(total_stmt).all()
|
||||||
@@ -756,7 +752,9 @@ def fetch_notification_stats_for_service_by_month_by_user(
|
|||||||
return db.session.execute(stmt).all()
|
return db.session.execute(stmt).all()
|
||||||
|
|
||||||
|
|
||||||
def get_specific_days_stats(data, start_date, days=None, end_date=None, total_notifications=None):
|
def get_specific_days_stats(
|
||||||
|
data, start_date, days=None, end_date=None, total_notifications=None
|
||||||
|
):
|
||||||
if days is not None and end_date is not None:
|
if days is not None and end_date is not None:
|
||||||
raise ValueError("Only set days OR set end_date, not both.")
|
raise ValueError("Only set days OR set end_date, not both.")
|
||||||
elif days is not None:
|
elif days is not None:
|
||||||
|
|||||||
@@ -2200,6 +2200,7 @@ def test_set_sms_prefixing_for_service_cant_be_none(
|
|||||||
StatisticsType.REQUESTED: 2,
|
StatisticsType.REQUESTED: 2,
|
||||||
StatisticsType.DELIVERED: 1,
|
StatisticsType.DELIVERED: 1,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
|
StatisticsType.PENDING: 0,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
@@ -2208,6 +2209,7 @@ def test_set_sms_prefixing_for_service_cant_be_none(
|
|||||||
StatisticsType.REQUESTED: 1,
|
StatisticsType.REQUESTED: 1,
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
|
StatisticsType.PENDING: 0,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -2256,11 +2258,13 @@ def test_get_services_with_detailed_flag(client, sample_template):
|
|||||||
NotificationType.EMAIL: {
|
NotificationType.EMAIL: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
|
StatisticsType.PENDING: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
},
|
},
|
||||||
NotificationType.SMS: {
|
NotificationType.SMS: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
|
StatisticsType.PENDING: 0,
|
||||||
StatisticsType.REQUESTED: 3,
|
StatisticsType.REQUESTED: 3,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -2287,11 +2291,13 @@ def test_get_services_with_detailed_flag_excluding_from_test_key(
|
|||||||
NotificationType.EMAIL: {
|
NotificationType.EMAIL: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
|
StatisticsType.PENDING: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
},
|
},
|
||||||
NotificationType.SMS: {
|
NotificationType.SMS: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
|
StatisticsType.PENDING: 0,
|
||||||
StatisticsType.REQUESTED: 2,
|
StatisticsType.REQUESTED: 2,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -2363,11 +2369,13 @@ def test_get_detailed_services_groups_by_service(notify_db_session):
|
|||||||
NotificationType.EMAIL: {
|
NotificationType.EMAIL: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
|
StatisticsType.PENDING: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
},
|
},
|
||||||
NotificationType.SMS: {
|
NotificationType.SMS: {
|
||||||
StatisticsType.DELIVERED: 1,
|
StatisticsType.DELIVERED: 1,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
|
StatisticsType.PENDING: 0,
|
||||||
StatisticsType.REQUESTED: 3,
|
StatisticsType.REQUESTED: 3,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -2376,11 +2384,13 @@ def test_get_detailed_services_groups_by_service(notify_db_session):
|
|||||||
NotificationType.EMAIL: {
|
NotificationType.EMAIL: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
|
StatisticsType.PENDING: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
},
|
},
|
||||||
NotificationType.SMS: {
|
NotificationType.SMS: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
|
StatisticsType.PENDING: 0,
|
||||||
StatisticsType.REQUESTED: 1,
|
StatisticsType.REQUESTED: 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -2406,11 +2416,13 @@ def test_get_detailed_services_includes_services_with_no_notifications(
|
|||||||
NotificationType.EMAIL: {
|
NotificationType.EMAIL: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
|
StatisticsType.PENDING: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
},
|
},
|
||||||
NotificationType.SMS: {
|
NotificationType.SMS: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
|
StatisticsType.PENDING: 0,
|
||||||
StatisticsType.REQUESTED: 1,
|
StatisticsType.REQUESTED: 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -2419,11 +2431,13 @@ def test_get_detailed_services_includes_services_with_no_notifications(
|
|||||||
NotificationType.EMAIL: {
|
NotificationType.EMAIL: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
|
StatisticsType.PENDING: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
},
|
},
|
||||||
NotificationType.SMS: {
|
NotificationType.SMS: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
|
StatisticsType.PENDING: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -2448,12 +2462,15 @@ def test_get_detailed_services_only_includes_todays_notifications(sample_templat
|
|||||||
NotificationType.EMAIL: {
|
NotificationType.EMAIL: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.PENDING: 0,
|
||||||
|
StatisticsType.REQUESTED: 0
|
||||||
|
|
||||||
},
|
},
|
||||||
NotificationType.SMS: {
|
NotificationType.SMS: {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
StatisticsType.REQUESTED: 3,
|
StatisticsType.PENDING: 0,
|
||||||
|
StatisticsType.REQUESTED: 3
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2501,11 +2518,13 @@ def test_get_detailed_services_for_date_range(
|
|||||||
assert data[0]["statistics"][NotificationType.EMAIL] == {
|
assert data[0]["statistics"][NotificationType.EMAIL] == {
|
||||||
StatisticsType.DELIVERED: 0,
|
StatisticsType.DELIVERED: 0,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
|
StatisticsType.PENDING: 0,
|
||||||
StatisticsType.REQUESTED: 0,
|
StatisticsType.REQUESTED: 0,
|
||||||
}
|
}
|
||||||
assert data[0]["statistics"][NotificationType.SMS] == {
|
assert data[0]["statistics"][NotificationType.SMS] == {
|
||||||
StatisticsType.DELIVERED: 2,
|
StatisticsType.DELIVERED: 2,
|
||||||
StatisticsType.FAILURE: 0,
|
StatisticsType.FAILURE: 0,
|
||||||
|
StatisticsType.PENDING: 0,
|
||||||
StatisticsType.REQUESTED: 2,
|
StatisticsType.REQUESTED: 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user