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:
Chris Hill-Scott
2017-01-30 15:17:26 +00:00
parent 3113f49271
commit 56ba653f48
5 changed files with 148 additions and 4 deletions

View File

@@ -1221,6 +1221,38 @@ def test_get_weekly_notification_stats(notify_api, notify_db, notify_db_session)
}
@pytest.mark.parametrize(
'url, expected_status, expected_json', [
(
'/service/{}/notifications/monthly?year=2001',
200,
{'data': {'foo': 'bar'}},
),
(
'/service/{}/notifications/monthly?year=baz',
400,
{'message': 'Year must be a number', 'result': 'error'},
),
(
'/service/{}/notifications/monthly',
400,
{'message': 'Year must be a number', 'result': 'error'},
),
]
)
def test_get_monthly_notification_stats(mocker, client, sample_service, url, expected_status, expected_json):
mock_dao = mocker.patch(
'app.service.rest.dao_fetch_monthly_historical_stats_for_service',
return_value={'foo': 'bar'},
)
response = client.get(
url.format(sample_service.id),
headers=[create_authorization_header()]
)
assert response.status_code == expected_status
assert json.loads(response.get_data(as_text=True)) == expected_json
def test_get_services_with_detailed_flag(notify_api, notify_db, notify_db_session):
notifications = [
create_sample_notification(notify_db, notify_db_session),