Merge pull request #1392 from alphagov/vb-free-sms-bridging-code

Bridging API to update annual_billing table
This commit is contained in:
Venus Bailey
2017-11-15 10:33:14 +00:00
committed by GitHub
3 changed files with 23 additions and 4 deletions

View File

@@ -135,14 +135,16 @@ def create_or_update_free_sms_fragment_limit(service_id):
form = validate(req_args, create_or_update_free_sms_fragment_limit_schema)
financial_year_start = form.get('financial_year_start')
free_sms_fragment_limit = form.get('free_sms_fragment_limit')
update_free_sms_fragment_limit_data(service_id,
free_sms_fragment_limit=form.get('free_sms_fragment_limit'),
financial_year_start=form.get('financial_year_start'))
return jsonify(form), 201
def update_free_sms_fragment_limit_data(service_id, free_sms_fragment_limit, financial_year_start=None):
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)
return jsonify(form), 201

View File

@@ -98,6 +98,7 @@ from app.schemas import (
detailed_service_schema
)
from app.utils import pagination_links
from app.billing.rest import update_free_sms_fragment_limit_data
service_blueprint = Blueprint('service', __name__)
@@ -202,6 +203,10 @@ def update_service(service_id):
if 'letter_contact_block' in req_json:
create_or_update_letter_contact(fetched_service.id, req_json['letter_contact_block'])
# bridging code between frontend is deployed and data has not been migrated yet. Can only update current year
if 'free_sms_fragment_limit' in req_json:
update_free_sms_fragment_limit_data(fetched_service.id, req_json['free_sms_fragment_limit'])
if service_going_live:
send_notification_to_service_users(
service_id=service_id,

View File

@@ -18,6 +18,7 @@ from tests import create_authorization_header
from app.dao.date_util import get_current_financial_year_start_year
from app.dao.annual_billing_dao import dao_get_free_sms_fragment_limit_for_year
from tests.app.db import create_annual_billing
from app.billing.rest import update_free_sms_fragment_limit_data
APR_2016_MONTH_START = datetime(2016, 3, 31, 23, 00, 00)
@@ -380,3 +381,14 @@ def test_get_free_sms_fragment_limit_future_year_not_exist(client, sample_servic
assert res_get.status_code == 200
assert json_resp['financial_year_start'] == current_year + 2
assert json_resp['free_sms_fragment_limit'] == 10000
def test_update_free_sms_fragment_limit_data(client, sample_service):
current_year = get_current_financial_year_start_year()
annual_billing = dao_get_free_sms_fragment_limit_for_year(sample_service.id, current_year)
assert annual_billing.free_sms_fragment_limit == 250000
update_free_sms_fragment_limit_data(sample_service.id, 9999)
annual_billing = dao_get_free_sms_fragment_limit_for_year(sample_service.id, current_year)
assert annual_billing.free_sms_fragment_limit == 9999