From e1ef0e85c66592b99eb4c8fcdf28c6ec2941c815 Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Mon, 21 Aug 2017 14:16:25 +0100 Subject: [PATCH] Remove monthly usage dao methods --- app/service/rest.py | 18 --------- tests/app/service/test_rest.py | 72 +--------------------------------- 2 files changed, 1 insertion(+), 89 deletions(-) diff --git a/app/service/rest.py b/app/service/rest.py index 4658c2efc..ca818aa46 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -458,24 +458,6 @@ def get_monthly_template_stats(service_id): raise InvalidRequest('Year must be a number', status_code=400) -@service_blueprint.route('//monthly-usage') -def get_yearly_monthly_usage(service_id): - try: - year = int(request.args.get('year')) - results = notification_usage_dao.get_monthly_billing_data(service_id, year) - json_results = [{ - "month": x[0], - "billing_units": x[1], - "rate_multiplier": x[2], - "international": x[3], - "notification_type": x[4], - "rate": x[5] - } for x in results] - return json.dumps(json_results) - except TypeError: - return jsonify(result='error', message='No valid year provided'), 400 - - @service_blueprint.route('//inbound-api', methods=['POST']) def create_service_inbound_api(service_id): data = request.get_json() diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index ca1ceca49..eaf34219a 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -8,12 +8,11 @@ import pytest from flask import url_for, current_app from freezegun import freeze_time -from app.dao.monthly_billing_dao import create_or_update_monthly_billing from app.dao.services_dao import dao_remove_user_from_service from app.dao.templates_dao import dao_redact_template from app.dao.users_dao import save_model_user from app.models import ( - User, Organisation, Rate, Service, ServicePermission, Notification, + User, Organisation, Service, ServicePermission, Notification, DVLA_ORG_LAND_REGISTRY, KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST, EMAIL_TYPE, SMS_TYPE, LETTER_TYPE, INTERNATIONAL_SMS_TYPE, INBOUND_SMS_TYPE, @@ -1730,75 +1729,6 @@ def test_get_template_stats_by_month_returns_error_for_incorrect_year( assert json.loads(response.get_data(as_text=True)) == expected_json -def test_get_monthly_billing_usage(client, notify_db, notify_db_session, sample_service): - rate = Rate(id=uuid.uuid4(), valid_from=datetime(2016, 3, 31, 23, 00), rate=0.0158, notification_type=SMS_TYPE) - notify_db.session.add(rate) - notification = create_sample_notification(notify_db, notify_db_session, created_at=datetime(2016, 6, 5), - sent_at=datetime(2016, 6, 5), - status='sending') - create_sample_notification(notify_db, notify_db_session, created_at=datetime(2016, 6, 5), - sent_at=datetime(2016, 6, 5), - status='sending', rate_multiplier=2) - create_sample_notification(notify_db, notify_db_session, created_at=datetime(2016, 7, 5), - sent_at=datetime(2016, 7, 5), - status='sending') - - template = create_template(sample_service, template_type=EMAIL_TYPE) - create_sample_notification(notify_db, notify_db_session, created_at=datetime(2016, 6, 5), - sent_at=datetime(2016, 6, 5), - status='sending', - template=template) - response = client.get( - '/service/{}/monthly-usage?year=2016'.format(notification.service_id), - headers=[create_authorization_header()] - ) - assert response.status_code == 200 - actual = json.loads(response.get_data(as_text=True)) - assert len(actual) == 3 - assert actual == [{'month': 'June', - 'international': False, - 'rate_multiplier': 1, - 'notification_type': SMS_TYPE, - 'rate': 0.0158, - 'billing_units': 1}, - {'month': 'June', - 'international': False, - 'rate_multiplier': 2, - 'notification_type': SMS_TYPE, - 'rate': 0.0158, - 'billing_units': 1}, - {'month': 'July', - 'international': False, - 'rate_multiplier': 1, - 'notification_type': SMS_TYPE, - 'rate': 0.0158, - 'billing_units': 1}] - - -def test_get_monthly_billing_usage_returns_400_if_missing_year(client, sample_service): - response = client.get( - '/service/{}/monthly-usage'.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' - } - - -def test_get_monthly_billing_usage_returns_empty_list_if_no_notifications(client, notify_db, sample_service): - rate = Rate(id=uuid.uuid4(), valid_from=datetime(2016, 3, 31, 23, 00), rate=0.0158, notification_type=SMS_TYPE) - notify_db.session.add(rate) - response = client.get( - '/service/{}/monthly-usage?year=2016'.format(sample_service.id), - headers=[create_authorization_header()] - ) - assert response.status_code == 200 - - results = json.loads(response.get_data(as_text=True)) - assert results == [] - - def test_search_for_notification_by_to_field(client, notify_db, notify_db_session): create_notification = partial(create_sample_notification, notify_db, notify_db_session) notification1 = create_notification(to_field='+447700900855', normalised_to='447700900855')