Add endpoint to get billable units/financial year

`/services/ef7a665d-11a4-425a-a180-a67ca00b69d7/billable-units?year=2016`

Pretty much just passes through to the DAO layer. Validates that year
is:

- present (there’s no need for unbounded queries on this endpoint)
- an integer
This commit is contained in:
Chris Hill-Scott
2016-09-30 19:44:13 +01:00
parent 6a5e947220
commit def1d253aa
2 changed files with 34 additions and 0 deletions

View File

@@ -310,3 +310,13 @@ def update_whitelist(service_id):
else:
dao_add_and_commit_whitelisted_contacts(whitelist_objs)
return '', 204
@service_blueprint.route('/<uuid:service_id>/billable-units')
def get_billable_unit_count(service_id):
try:
return jsonify(notifications_dao.get_notification_billable_unit_count_per_month(
service_id, int(request.args.get('year'))
))
except TypeError:
return jsonify(result='error', message='No valid year provided'), 400

View File

@@ -1300,3 +1300,27 @@ def test_get_detailed_services_only_includes_todays_notifications(notify_db, not
'email': {'delivered': 0, 'failed': 0, 'requested': 0},
'sms': {'delivered': 0, 'failed': 0, 'requested': 2}
}
@freeze_time('2012-12-12T12:00:01')
def test_get_notification_billable_unit_count(client, notify_db, notify_db_session):
notification = create_sample_notification(notify_db, notify_db_session)
response = client.get(
'/service/{}/billable-units?year=2012'.format(notification.service_id),
headers=[create_authorization_header(service_id=notification.service_id)]
)
assert response.status_code == 200
assert json.loads(response.get_data(as_text=True)) == {
'December': 1
}
def test_get_notification_billable_unit_count_missing_year(client, sample_service):
response = client.get(
'/service/{}/billable-units'.format(sample_service.id),
headers=[create_authorization_header(service_id=sample_service.id)]
)
assert response.status_code == 400
assert json.loads(response.get_data(as_text=True)) == {
'message': 'No valid year provided', 'result': 'error'
}