add logic to change future free_sms_fragment_limit items when service setting changed

This commit is contained in:
venusbb
2017-10-31 11:56:51 +00:00
parent 8ea38ba7b6
commit 8e6c284d7b
3 changed files with 28 additions and 6 deletions

View File

@@ -41,6 +41,7 @@ from app.main.forms import (
)
from app import user_api_client, current_service, organisations_client, inbound_number_client, billing_api_client
from notifications_utils.formatters import formatted_list
from app.utils import get_current_financial_year
dummy_bearer_token = 'bearer_token_set'
@@ -715,9 +716,16 @@ def set_free_sms_allowance(service_id):
# TODO: Retire this after new end points are added.
free_sms_fragment_limit=form.free_sms_allowance.data,
)
form.set_free_sms_allowance = \
billing_api_client.create_or_update_free_sms_fragment_limit_for_year(service_id,
form.free_sms_allowance.data)
# get a list of all the free sms allowance entries for this service
sms_list = billing_api_client.get_free_sms_fragment_limit_for_all_years(service_id)
for item in range(0, len(sms_list)):
if sms_list[item]['financial_year_start'] >= get_current_financial_year():
form.set_free_sms_allowance = \
billing_api_client.create_or_update_free_sms_fragment_limit_for_year(service_id,
form.free_sms_allowance.data,
sms_list[item][
'financial_year_start'])
return redirect(url_for('.service_settings', service_id=service_id))
return render_template(

View File

@@ -29,6 +29,7 @@ from tests.conftest import (
get_inbound_number_sms_sender,
SERVICE_ONE_ID
)
from freezegun import freeze_time
@pytest.mark.parametrize('user, expected_rows', [
@@ -1583,6 +1584,7 @@ def test_should_show_page_to_set_sms_allowance(
assert normalize_spaces(page.select_one('label').text) == 'Numbers of text message fragments per year'
@freeze_time("2017-04-01 11:09:00.061258")
@pytest.mark.parametrize('given_allowance, expected_api_argument', [
('1', 1),
('250000', 250000),
@@ -1593,7 +1595,8 @@ def test_should_set_sms_allowance(
mock_update_service,
given_allowance,
expected_api_argument,
mock_create_or_update_free_sms_fragment_limit
mock_create_or_update_free_sms_fragment_limit,
mock_get_free_sms_fragment_limit_for_all_years
):
response = logged_in_platform_admin_client.post(
@@ -1612,10 +1615,12 @@ def test_should_set_sms_allowance(
SERVICE_ONE_ID,
free_sms_fragment_limit=expected_api_argument,
)
mock_create_or_update_free_sms_fragment_limit.assert_called_once_with(
mock_create_or_update_free_sms_fragment_limit.assert_called_with(
SERVICE_ONE_ID,
expected_api_argument
expected_api_argument,
2017
)
mock_get_free_sms_fragment_limit_for_all_years.assert_called_once_with(SERVICE_ONE_ID)
def test_switch_service_enable_letters(

View File

@@ -2341,3 +2341,12 @@ def mock_create_or_update_free_sms_fragment_limit(mocker):
sample_limit = 250000
return mocker.patch('app.billing_api_client.create_or_update_free_sms_fragment_limit_for_year',
return_value=sample_limit)
@pytest.fixture(scope='function')
def mock_get_free_sms_fragment_limit_for_all_years(mocker):
sample_limit = [{'financial_year_start': 2016, 'free_sms_fragment_limit': 250000},
{'financial_year_start': 2017, 'free_sms_fragment_limit': 500000}]
return mocker.patch('app.billing_api_client.get_free_sms_fragment_limit_for_all_years',
return_value=sample_limit)