mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
Add endpoint for breakdown of activity by month
This endpoint will eventualy replace the weekly breakdown one. By month for a given financial year is better, because it gives us consistency with the breakdown of financial usage (and eventually consistency with the template usage). The code to do this is a bit convoluted, in order to fill out the counts for months and statuses where we don’t have notifications. This will make the admin side of this easier, because we can rely on there always being numbers available. The admin side will deal with summing the statuses (eg `temporary-failure` > `failed`) because this is presentational. This commit also modifies the usage count to use `.between()` for consistency.
This commit is contained in:
@@ -20,6 +20,7 @@ from app.dao.services_dao import (
|
||||
dao_fetch_stats_for_service,
|
||||
dao_fetch_todays_stats_for_service,
|
||||
dao_fetch_weekly_historical_stats_for_service,
|
||||
dao_fetch_monthly_historical_stats_for_service,
|
||||
fetch_todays_total_message_count,
|
||||
dao_fetch_todays_stats_for_all_services,
|
||||
fetch_stats_by_date_range_for_all_services,
|
||||
@@ -507,6 +508,50 @@ def test_fetch_weekly_historical_stats_separates_weeks(notify_db, notify_db_sess
|
||||
assert ret[-1].count == 1
|
||||
|
||||
|
||||
def test_fetch_monthly_historical_stats_separates_weeks(notify_db, notify_db_session, sample_template):
|
||||
notification_history = functools.partial(
|
||||
create_notification_history,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template
|
||||
)
|
||||
_before_start_of_financial_year = notification_history(created_at=datetime(2016, 3, 31))
|
||||
start_of_financial_year = notification_history(created_at=datetime(2016, 4, 1))
|
||||
start_of_summer = notification_history(created_at=datetime(2016, 6, 20))
|
||||
start_of_autumn = notification_history(created_at=datetime(2016, 9, 22))
|
||||
start_of_winter = notification_history(created_at=datetime(2016, 12, 1), status='delivered')
|
||||
start_of_spring = notification_history(created_at=datetime(2017, 3, 11))
|
||||
end_of_financial_year = notification_history(created_at=datetime(2017, 3, 31))
|
||||
_after_end_of_financial_year = notification_history(created_at=datetime(2017, 4, 1))
|
||||
|
||||
result = dao_fetch_monthly_historical_stats_for_service(sample_template.service_id, 2016)
|
||||
|
||||
assert result['2016-04']['sms']['created'] == 1
|
||||
assert result['2016-04']['sms']['sending'] == 0
|
||||
assert result['2016-04']['sms']['delivered'] == 0
|
||||
assert result['2016-04']['sms']['pending'] == 0
|
||||
assert result['2016-04']['sms']['failed'] == 0
|
||||
assert result['2016-04']['sms']['technical-failure'] == 0
|
||||
assert result['2016-04']['sms']['temporary-failure'] == 0
|
||||
assert result['2016-04']['sms']['permanent-failure'] == 0
|
||||
|
||||
assert result['2016-06']['sms']['created'] == 1
|
||||
|
||||
assert result['2016-09']['sms']['created'] == 1
|
||||
|
||||
assert result['2016-12']['sms']['created'] == 0
|
||||
assert result['2016-12']['sms']['delivered'] == 1
|
||||
|
||||
assert result['2017-03']['sms']['created'] == 2
|
||||
|
||||
assert result.keys() == {
|
||||
'2016-04', '2016-05', '2016-06',
|
||||
'2016-07', '2016-08', '2016-09',
|
||||
'2016-10', '2016-11', '2016-12',
|
||||
'2017-01', '2017-02', '2017-03',
|
||||
}
|
||||
|
||||
|
||||
def test_fetch_weekly_historical_stats_ignores_second_service(notify_db, notify_db_session, service_factory):
|
||||
template_1 = service_factory.get('1').templates[0]
|
||||
template_2 = service_factory.get('2').templates[0]
|
||||
|
||||
Reference in New Issue
Block a user