diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index c3333fc5a..805cb1e17 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -270,27 +270,6 @@ def get_notifications_for_job(service_id, job_id, filter_dict=None, page=1, page ) -@statsd(namespace="dao") -def get_notification_billable_unit_count_per_month(service_id, year): - month = get_london_month_from_utc_column(NotificationHistory.created_at) - - start_date, end_date = get_financial_year(year) - notifications = db.session.query( - month, - func.sum(NotificationHistory.billable_units) - ).filter( - NotificationHistory.billable_units != 0, - NotificationHistory.service_id == service_id, - NotificationHistory.created_at.between(start_date, end_date) - ).group_by( - month - ).order_by( - month - ).all() - - return [(datetime.strftime(x[0], "%B"), x[1]) for x in notifications] - - @statsd(namespace="dao") def get_notification_with_personalisation(service_id, notification_id, key_type): filter_dict = {'service_id': service_id, 'id': notification_id} diff --git a/app/service/rest.py b/app/service/rest.py index 25a4052df..485806ea9 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -450,16 +450,6 @@ def resume_service(service_id): return '', 204 -@service_blueprint.route('//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 - - @service_blueprint.route('//notifications/templates/monthly', methods=['GET']) def get_monthly_template_stats(service_id): service = dao_fetch_service_by_id(service_id) diff --git a/tests/app/celery/test_tasks.py b/tests/app/celery/test_tasks.py index 102da6298..717dc7b82 100644 --- a/tests/app/celery/test_tasks.py +++ b/tests/app/celery/test_tasks.py @@ -1184,10 +1184,13 @@ def test_send_inbound_sms_to_service_retries_if_request_returns_500(notify_api, status_code=500) send_inbound_sms_to_service(inbound_sms.id, inbound_sms.service_id) - mocked.assert_called_with( - exc='Unable to send_inbound_sms_to_service for service_id: {} ' - 'and url: {url}. \n500 Server Error: None for url: {url}'.format(sample_service.id, url=inbound_api.url), - queue="retry-tasks") + exc_msg = 'Unable to send_inbound_sms_to_service for service_id: {} and url: {url}'.format( + sample_service.id, + url=inbound_api.url + ) + assert mocked.call_count == 1 + assert mocked.call_args[1]['queue'] == 'retry-tasks' + assert exc_msg in mocked.call_args[1]['exc'] def test_send_inbound_sms_to_service_does_not_retries_if_request_returns_404(notify_api, sample_service, mocker): diff --git a/tests/app/dao/test_notification_dao.py b/tests/app/dao/test_notification_dao.py index 58680f39d..2adfe3dd9 100644 --- a/tests/app/dao/test_notification_dao.py +++ b/tests/app/dao/test_notification_dao.py @@ -31,7 +31,6 @@ from app.dao.notifications_dao import ( delete_notifications_created_more_than_a_week_ago_by_type, get_notification_by_id, get_notification_for_job, - get_notification_billable_unit_count_per_month, get_notification_with_personalisation, get_notifications_for_job, get_notifications_for_service, @@ -914,38 +913,6 @@ def test_get_all_notifications_for_job_by_status(notify_db, notify_db_session, s assert len(notifications(filter_dict={'status': NOTIFICATION_STATUS_TYPES[:3]}).items) == 3 -def test_get_notification_billable_unit_count_per_month(notify_db, notify_db_session, sample_service): - - for year, month, day, hour, minute, second in ( - (2017, 1, 15, 23, 59, 59), # ↓ 2016 financial year - (2016, 9, 30, 23, 59, 59), # counts in October with BST conversion - (2016, 6, 30, 23, 50, 20), - (2016, 7, 15, 9, 20, 25), - (2016, 4, 1, 1, 1, 00), - (2016, 4, 1, 0, 0, 00), - (2016, 3, 31, 23, 00, 1), # counts in April with BST conversion - (2015, 4, 1, 13, 8, 59), # ↓ 2015 financial year - (2015, 11, 20, 22, 40, 45), - (2016, 1, 31, 23, 30, 40) # counts in January no BST conversion in winter - ): - sample_notification( - notify_db, notify_db_session, service=sample_service, - created_at=datetime( - year, month, day, hour, minute, second, 0 - ) - ) - - for financial_year, months in ( - (2017, []), - (2016, [('April', 3), ('July', 2), ('October', 1), ('January', 1)]), - (2015, [('April', 1), ('November', 1), ('January', 1)]), - (2014, []) - ): - assert get_notification_billable_unit_count_per_month( - sample_service.id, financial_year - ) == months - - def test_update_notification_sets_status(sample_notification): assert sample_notification.status == 'created' sample_notification.status = 'failed' diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 48225ab2f..0c6397cbb 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -1665,30 +1665,6 @@ def test_get_detailed_services_for_date_range(notify_db, notify_db_session, set_ } -@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()] - ) - 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()] - ) - assert response.status_code == 400 - assert json.loads(response.get_data(as_text=True)) == { - 'message': 'No valid year provided', 'result': 'error' - } - - @pytest.mark.parametrize('query_string, expected_status, expected_json', [ ('', 200, {'data': {'email_count': 0, 'sms_count': 0}}), ('?year=2000', 200, {'data': {'email_count': 0, 'sms_count': 0}}),