mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 07:21:13 -05:00
make sure POST /free-sms-fragment-limit always creates
refactored billing/rest.py and annual_billing_dao.py to remove logic from the dao, and simplify the process around creating new rows. Make sure that the POST always creates (it previously wouldn't create rows for years that don't already exist). Clean up some tests that were doing too much set-up/data verification via rest calls rather than directly inserting test data in to the DB.
This commit is contained in:
@@ -117,6 +117,7 @@ def get_free_sms_fragment_limit(service_id):
|
||||
financial_year_start = get_current_financial_year_start_year()
|
||||
|
||||
if int(financial_year_start) < get_current_financial_year_start_year():
|
||||
# return the earliest historical entry
|
||||
annual_billing = sms_list[0] # The oldest entry
|
||||
else:
|
||||
annual_billing = sms_list[-1] # The newest entry
|
||||
@@ -141,10 +142,21 @@ def create_or_update_free_sms_fragment_limit(service_id):
|
||||
return jsonify(form), 201
|
||||
|
||||
|
||||
def update_free_sms_fragment_limit_data(service_id, free_sms_fragment_limit, financial_year_start=None):
|
||||
def update_free_sms_fragment_limit_data(service_id, free_sms_fragment_limit, financial_year_start):
|
||||
current_year = get_current_financial_year_start_year()
|
||||
if financial_year_start is None or financial_year_start >= current_year:
|
||||
dao_update_annual_billing_for_current_and_future_years(service_id, free_sms_fragment_limit)
|
||||
else:
|
||||
dao_create_or_update_annual_billing_for_year(service_id,
|
||||
free_sms_fragment_limit, financial_year_start)
|
||||
if not financial_year_start:
|
||||
financial_year_start = current_year
|
||||
|
||||
dao_create_or_update_annual_billing_for_year(
|
||||
service_id,
|
||||
free_sms_fragment_limit,
|
||||
financial_year_start
|
||||
)
|
||||
# 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(
|
||||
service_id,
|
||||
free_sms_fragment_limit,
|
||||
financial_year_start
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user