diff --git a/app/service/rest.py b/app/service/rest.py index 423d5dc9b..f52b18174 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -444,13 +444,13 @@ def get_monthly_template_stats(service_id): raise InvalidRequest('Year must be a number', status_code=400) -@service_blueprint.route('//yearly-usage-count') -def get_yearly_usage_count(service_id): +@service_blueprint.route('//yearly-sms-billable-units') +def get_yearly_sms_billable_units(service_id): try: cache_key = sms_billable_units_cache_key(service_id) cached_value = redis_store.get(cache_key) if cached_value: - return jsonify({'billable_sms_units': cached_value}) + return jsonify({'billable_sms_units': int(cached_value)}) else: start_date, end_date = get_financial_year(int(request.args.get('year'))) billable_units = get_total_billable_units_for_sent_sms_notifications_in_date_range( @@ -460,7 +460,7 @@ def get_yearly_usage_count(service_id): redis_store.set(cache_key, billable_units, ex=60) return jsonify({'billable_sms_units': billable_units}) - except (ValueError, TypeError): + except (ValueError, TypeError) as e: return jsonify(result='error', message='No valid year provided'), 400 diff --git a/tests/app/dao/test_notification_usage_dao.py b/tests/app/dao/test_notification_usage_dao.py index 81cbd0202..7dfd4bdfb 100644 --- a/tests/app/dao/test_notification_usage_dao.py +++ b/tests/app/dao/test_notification_usage_dao.py @@ -438,4 +438,3 @@ def test_returns_zero_if_no_matching_rows_when_returning_billable_units_for_sms_ start = datetime.utcnow() - timedelta(minutes=10) end = datetime.utcnow() + timedelta(minutes=10) assert get_total_billable_units_for_sent_sms_notifications_in_date_range(start, end, sample_service.id) == 0 - diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index c7ad9495c..57d152b9b 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -1202,19 +1202,19 @@ def test_get_detailed_service(notify_db, notify_db_session, notify_api, sample_s @pytest.mark.parametrize( 'url, expected_status, expected_json', [ ( - '/service/{}/notifications/monthly?year=2001', - 200, - {'data': {'foo': 'bar'}}, + '/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?year=baz', + 400, + {'message': 'Year must be a number', 'result': 'error'}, ), ( - '/service/{}/notifications/monthly', - 400, - {'message': 'Year must be a number', 'result': 'error'}, + '/service/{}/notifications/monthly', + 400, + {'message': 'Year must be a number', 'result': 'error'}, ), ] ) @@ -1724,7 +1724,7 @@ def test_update_service_does_not_call_send_notification_when_restricted_not_chan def test_get_yearly_billing_usage_count_returns_400_if_missing_year(client, sample_service): response = client.get( - '/service/{}/yearly-usage-count'.format(sample_service.id), + '/service/{}/yearly-sms-billable-units'.format(sample_service.id), headers=[create_authorization_header()] ) assert response.status_code == 400 @@ -1738,7 +1738,7 @@ def test_get_yearly_billing_usage_count_returns_400_if_invalid_year(client, samp redis_set_mock = mocker.patch('app.service.rest.redis_store.set') response = client.get( - '/service/{}/yearly-usage-count?year=HAHAHAHAH'.format(sample_service.id), + '/service/{}/yearly-sms-billable-units?year=HAHAHAHAH'.format(sample_service.id), headers=[create_authorization_header()] ) assert response.status_code == 400 @@ -1760,7 +1760,7 @@ def test_get_yearly_billing_usage_count_returns_200_if_year_provided(client, sam ) mock_year = mocker.patch('app.service.rest.get_financial_year', return_value=(start, end)) response = client.get( - '/service/{}/yearly-usage-count?year=2016'.format(sample_service.id), + '/service/{}/yearly-sms-billable-units?year=2016'.format(sample_service.id), headers=[create_authorization_header()] ) assert response.status_code == 200 @@ -1785,7 +1785,7 @@ def test_get_yearly_billing_usage_count_returns_from_cache_if_present(client, sa mock_year = mocker.patch('app.service.rest.get_financial_year', return_value=(start, end)) response = client.get( - '/service/{}/yearly-usage-count?year=2016'.format(sample_service.id), + '/service/{}/yearly-sms-billable-units?year=2016'.format(sample_service.id), headers=[create_authorization_header()] ) assert response.status_code == 200