From e8f659837aac0c51c192d4148ae1ee9a72e59139 Mon Sep 17 00:00:00 2001 From: venusbb Date: Wed, 25 Oct 2017 12:50:13 +0100 Subject: [PATCH] remove unused codes --- app/dao/annual_billing_dao.py | 4 +- app/service/rest.py | 3 -- tests/app/billing/test_billing.py | 51 +++++------------------- tests/app/dao/test_annual_billing_dao.py | 3 +- tests/app/dao/test_services_dao.py | 3 +- tests/app/db.py | 1 - 6 files changed, 16 insertions(+), 49 deletions(-) diff --git a/app/dao/annual_billing_dao.py b/app/dao/annual_billing_dao.py index 8e8f7c886..6e76f6ce5 100644 --- a/app/dao/annual_billing_dao.py +++ b/app/dao/annual_billing_dao.py @@ -11,7 +11,7 @@ from app.service.utils import get_current_financial_year_start_year def dao_get_annual_billing(service_id): return AnnualBilling.query.filter_by( service_id=service_id, - ).all() + ).order_by(AnnualBilling.financial_year_start).all() def dao_create_or_update_annual_billing_for_year(annual_billing): @@ -31,7 +31,7 @@ def dao_get_all_free_sms_fragment_limit(service_id): return AnnualBilling.query.filter_by( service_id=service_id, - ).all() + ).order_by(AnnualBilling.financial_year_start).all() def insert_annual_billing(service): diff --git a/app/service/rest.py b/app/service/rest.py index be08e5028..3c19fb4ed 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -98,7 +98,6 @@ from app.schemas import ( detailed_service_schema ) from app.utils import pagination_links -from app.dao.notifications_dao import get_financial_year service_blueprint = Blueprint('service', __name__) @@ -170,8 +169,6 @@ def create_service(): raise InvalidRequest(errors, status_code=400) # TODO: to be removed when front-end is updated - # if 'free_sms_fragment_limit' not in data: - # data['free_sms_fragment_limit'] = current_app.config['FREE_SMS_TIER_FRAGMENT_COUNT'] # validate json with marshmallow service_schema.load(request.get_json()) diff --git a/tests/app/billing/test_billing.py b/tests/app/billing/test_billing.py index 86bfcc6d6..fdd797242 100644 --- a/tests/app/billing/test_billing.py +++ b/tests/app/billing/test_billing.py @@ -256,46 +256,6 @@ def test_transform_billing_calculates_with_different_rate_multipliers(sample_ser }) -def test_get_free_sms_fragment_limit(client, sample_service): - years = [2016, 2017, 2018] - sms_allowance = [1000, 2000, 3000] - - for i in range(0, len(years)): - y = years[i] - sms_l = sms_allowance[i] - annual_billing = dao_get_free_sms_fragment_limit_for_year(sample_service.id, years[i]) - if annual_billing: - annual_billing.free_sms_fragment_limit = sms_allowance[i] - else: - annual_billing = AnnualBilling(service_id=sample_service.id, - financial_year_start=years[i], - free_sms_fragment_limit=sms_allowance[i]) - - dao_create_or_update_annual_billing_for_year(annual_billing) - - response = client.get('service/{}/billing/free-sms-fragment-limit?financial_year_start=2017' - .format(sample_service.id), - headers=[('Content-Type', 'application/json'), create_authorization_header()]) - - json_resp = json.loads(response.get_data(as_text=True)) - assert response.status_code == 200 - - assert json_resp['data']['free_sms_fragment_limit'] == 2000 - assert json_resp['data']['financial_year_start'] == 2017 - - response = client.get( - 'service/{}/billing/free-sms-fragment-limit'.format(sample_service.id), - headers=[('Content-Type', 'application/json'), create_authorization_header()]) - - json_resp = json.loads(response.get_data(as_text=True)) - - assert len(json_resp['data']) == 3 - assert response.status_code == 200 - for i in range(0, len(years)): - assert json_resp['data'][i]['free_sms_fragment_limit'] == sms_allowance[i] - assert json_resp['data'][i]['financial_year_start'] == years[i] - - def test_create_update_free_sms_fragment_limit_invalid_schema(client, sample_service): response = client.post('service/{}/billing/free-sms-fragment-limit'.format(sample_service.id), @@ -385,6 +345,17 @@ def test_get_free_sms_fragment_limit_for_all_years(client, sample_service): json_resp = json.loads(response_get.get_data(as_text=True)) assert response_get.status_code == 200 assert len(json_resp['data']) == 3 + print(json_resp) for i in [0, 1, 2]: assert json_resp['data'][i]['free_sms_fragment_limit'] == limits[i] assert json_resp['data'][i]['financial_year_start'] == years[i] + + +def test_get_free_sms_fragment_limit_no_year_data_return_404(client, sample_service): + + response_get = client.get( + 'service/{}/billing/free-sms-fragment-limit?financial_year_start={}'.format(sample_service.id, 1999), + headers=[('Content-Type', 'application/json'), create_authorization_header()]) + json_resp = json.loads(response_get.get_data(as_text=True)) + + assert response_get.status_code == 404 diff --git a/tests/app/dao/test_annual_billing_dao.py b/tests/app/dao/test_annual_billing_dao.py index e971c6460..b356687c7 100644 --- a/tests/app/dao/test_annual_billing_dao.py +++ b/tests/app/dao/test_annual_billing_dao.py @@ -8,6 +8,7 @@ from app.dao.annual_billing_dao import ( def test_sample_service_has_free_sms_fragment_limit(notify_db_session, sample_service): + # when sample_service was created, it automatically create an entry in the annual_billing table free_limit = dao_get_free_sms_fragment_limit_for_year(sample_service.id, get_current_financial_year_start_year()) assert free_limit.free_sms_fragment_limit == 250000 @@ -16,7 +17,7 @@ def test_sample_service_has_free_sms_fragment_limit(notify_db_session, sample_se def test_dao_update_free_sms_fragment_limit(notify_db_session, sample_service): - year = 2016 + year = 1999 old_limit = 1000 new_limit = 9999 diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index a38d81b24..9edec2feb 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -171,8 +171,7 @@ def test_should_remove_user_from_service(sample_user): email_from="email_from", message_limit=1000, restricted=False, - created_by=sample_user, - free_sms_fragment_limit=9999) + created_by=sample_user) dao_create_service(service, sample_user) new_user = User( name='Test User', diff --git a/tests/app/db.py b/tests/app/db.py index 74d2033e2..0cdf7cfee 100644 --- a/tests/app/db.py +++ b/tests/app/db.py @@ -68,7 +68,6 @@ def create_service( service = Service( name=service_name, message_limit=1000, - free_sms_fragment_limit=7777, restricted=restricted, email_from=email_from if email_from else service_name.lower().replace(' ', '.'), created_by=user or create_user(email='{}@digital.cabinet-office.gov.uk'.format(uuid.uuid4())),