diff --git a/app/billing/rest.py b/app/billing/rest.py index f4c337903..45b3b5baa 100644 --- a/app/billing/rest.py +++ b/app/billing/rest.py @@ -18,6 +18,7 @@ from app.billing.billing_schemas import create_or_update_free_sms_fragment_limit from app.errors import InvalidRequest from app.schema_validation import validate from app.models import AnnualBilling +from app.service.utils import get_current_financial_year_start_year billing_blueprint = Blueprint( 'billing', @@ -96,10 +97,14 @@ def _transform_billing_for_month(billing_for_month): @billing_blueprint.route('/free-sms-fragment-limit', methods=["GET"]) +@billing_blueprint.route('/free-sms-fragment-limit/current-year', methods=["GET"]) def get_free_sms_fragment_limit(service_id): financial_year_start = request.args.get('financial_year_start') + if request.path.split('/')[-1] == 'current-year': + financial_year_start = get_current_financial_year_start_year() + if financial_year_start is None: results = dao_get_all_free_sms_fragment_limit(service_id) diff --git a/tests/app/billing/test_billing.py b/tests/app/billing/test_billing.py index e6655f293..fb946e657 100644 --- a/tests/app/billing/test_billing.py +++ b/tests/app/billing/test_billing.py @@ -369,3 +369,12 @@ def test_get_free_sms_fragment_limit_unknown_service_id_return_404(client): 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 + + +def test_get_free_sms_fragment_limit_current_year(client, sample_service): + response = client.get( + 'service/{}/billing/free-sms-fragment-limit/current-year'.format(sample_service.id, True), + 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'] == 250000