mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-16 02:02:13 -05:00
fix platform admin stats row-order bug
now that we're reading from two tables (ft_notification_status and notifications) for stats, we'll get a couple of rows for each notification type. If a service doesn't have any rows in one of those tables, the query will return a row with nulls for the notification types and counts. Some services will have history but no stats from today, others will have data from today but no history. This commit acknowledges that any row might have nulls, not just the first row.
This commit is contained in:
@@ -478,10 +478,7 @@ def get_detailed_services(start_date, end_date, only_active=False, include_from_
|
||||
results = []
|
||||
for service_id, rows in itertools.groupby(stats, lambda x: x.service_id):
|
||||
rows = list(rows)
|
||||
if rows[0].count is None:
|
||||
s = statistics.create_zeroed_stats_dicts()
|
||||
else:
|
||||
s = statistics.format_statistics(rows)
|
||||
s = statistics.format_statistics(rows)
|
||||
results.append({
|
||||
'id': str(rows[0].service_id),
|
||||
'name': rows[0].name,
|
||||
|
||||
@@ -13,7 +13,10 @@ def format_statistics(statistics):
|
||||
# so we can return emails/sms * created, sent, and failed
|
||||
counts = create_zeroed_stats_dicts()
|
||||
for row in statistics:
|
||||
_update_statuses_from_row(counts[row.notification_type], row)
|
||||
# any row could be null, if the service either has no notifications in the notifications table,
|
||||
# or no historical data in the ft_notification_status table.
|
||||
if row.notification_type:
|
||||
_update_statuses_from_row(counts[row.notification_type], row)
|
||||
|
||||
return counts
|
||||
|
||||
|
||||
@@ -45,6 +45,10 @@ NewStatsRow = collections.namedtuple('row', ('notification_type', 'status', 'key
|
||||
StatsRow('sms', 'delivered', 1),
|
||||
StatsRow('sms', 'sent', 1),
|
||||
], [0, 0, 0], [3, 2, 0], [0, 0, 0]),
|
||||
'handles_none_rows': ([
|
||||
StatsRow('sms', 'sending', 1),
|
||||
StatsRow(None, None, None)
|
||||
], [0, 0, 0], [1, 0, 0], [0, 0, 0])
|
||||
})
|
||||
def test_format_statistics(stats, email_counts, sms_counts, letter_counts):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user