From f29e08c7781be702abc6946421e6e55e6fcd9fed Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Wed, 6 Dec 2017 14:41:32 +0000 Subject: [PATCH] don't update current year twice --- app/billing/rest.py | 4 ++-- app/dao/annual_billing_dao.py | 4 ++-- tests/app/dao/test_annual_billing_dao.py | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/billing/rest.py b/app/billing/rest.py index 73e742229..66726bb5a 100644 --- a/app/billing/rest.py +++ b/app/billing/rest.py @@ -14,7 +14,7 @@ from app.utils import convert_utc_to_bst from app.dao.annual_billing_dao import (dao_get_free_sms_fragment_limit_for_year, dao_get_all_free_sms_fragment_limit, dao_create_or_update_annual_billing_for_year, - dao_update_annual_billing_for_current_and_future_years) + dao_update_annual_billing_for_future_years) from app.billing.billing_schemas import create_or_update_free_sms_fragment_limit_schema from app.errors import InvalidRequest from app.schema_validation import validate @@ -155,7 +155,7 @@ def update_free_sms_fragment_limit_data(service_id, free_sms_fragment_limit, fin # if we're trying to update historical data, don't touch other rows. # Otherwise, make sure that future years will get the new updated value. if financial_year_start >= current_year: - dao_update_annual_billing_for_current_and_future_years( + dao_update_annual_billing_for_future_years( service_id, free_sms_fragment_limit, financial_year_start diff --git a/app/dao/annual_billing_dao.py b/app/dao/annual_billing_dao.py index 6e43be2d6..744fc6106 100644 --- a/app/dao/annual_billing_dao.py +++ b/app/dao/annual_billing_dao.py @@ -26,10 +26,10 @@ def dao_get_annual_billing(service_id): @transactional -def dao_update_annual_billing_for_current_and_future_years(service_id, free_sms_fragment_limit, financial_year_start): +def dao_update_annual_billing_for_future_years(service_id, free_sms_fragment_limit, financial_year_start): AnnualBilling.query.filter( AnnualBilling.service_id == service_id, - AnnualBilling.financial_year_start >= financial_year_start + AnnualBilling.financial_year_start > financial_year_start ).update( {'free_sms_fragment_limit': free_sms_fragment_limit} ) diff --git a/tests/app/dao/test_annual_billing_dao.py b/tests/app/dao/test_annual_billing_dao.py index 559e1c8f4..ac0c4df2f 100644 --- a/tests/app/dao/test_annual_billing_dao.py +++ b/tests/app/dao/test_annual_billing_dao.py @@ -1,9 +1,10 @@ + from app.dao.date_util import get_current_financial_year_start_year from app.dao.annual_billing_dao import ( dao_create_or_update_annual_billing_for_year, dao_get_free_sms_fragment_limit_for_year, - dao_update_annual_billing_for_current_and_future_years, + dao_update_annual_billing_for_future_years, ) from tests.app.db import create_annual_billing @@ -26,14 +27,14 @@ def test_create_annual_billing(sample_service): assert free_limit.free_sms_fragment_limit == 9999 -def test_dao_update_annual_billing_for_current_and_future_years(notify_db_session, sample_service): +def test_dao_update_annual_billing_for_future_years(notify_db_session, sample_service): current_year = get_current_financial_year_start_year() limits = [1, 2, 3, 4] create_annual_billing(sample_service.id, limits[0], current_year - 1) create_annual_billing(sample_service.id, limits[2], current_year + 1) create_annual_billing(sample_service.id, limits[3], current_year + 2) - dao_update_annual_billing_for_current_and_future_years(sample_service.id, 9999, current_year) + dao_update_annual_billing_for_future_years(sample_service.id, 9999, current_year) assert dao_get_free_sms_fragment_limit_for_year(sample_service.id, current_year - 1).free_sms_fragment_limit == 1 # current year is not created