From fa0196bc887d98a067b4387b69d1c924e9309e47 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Fri, 2 Mar 2018 10:48:59 +0000 Subject: [PATCH 1/3] Update the free allowance when the organisation type is changed. The free allowance affect the number of free text messages a services get per yer. This allowance is being set properly when an organisation is created by not updated. This PR updates the free allowance when the organisation type is updated. The free allowance can also be changed if service has an exceptional free allowance. --- app/main/views/service_settings.py | 6 ++++++ tests/app/main/views/test_service_settings.py | 1 + 2 files changed, 7 insertions(+) diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 1af8ed6dd..7b42732c3 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -1,5 +1,6 @@ from flask import ( abort, + current_app, flash, redirect, render_template, @@ -695,10 +696,15 @@ def set_organisation_type(service_id): form = OrganisationTypeForm(organisation_type=current_service.get('organisation_type')) if form.validate_on_submit(): + free_sms_fragment_limit = current_app.config['DEFAULT_FREE_SMS_FRAGMENT_LIMITS'].get( + form.organisation_type.data) + service_api_client.update_service( service_id, organisation_type=form.organisation_type.data, ) + billing_api_client.create_or_update_free_sms_fragment_limit(service_id, free_sms_fragment_limit) + return redirect(url_for('.service_settings', service_id=service_id)) return render_template( diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index 8b5b11211..a360f06f7 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -1560,6 +1560,7 @@ def test_should_set_organisation_type( logged_in_platform_admin_client, mock_update_service, organisation_type, + mock_create_or_update_free_sms_fragment_limit ): response = logged_in_platform_admin_client.post( url_for( From f7e1ca29fe00b849459b7e3c090bdd524e59cb2d Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Fri, 2 Mar 2018 15:09:07 +0000 Subject: [PATCH 2/3] Added an assert for the mocker --- tests/app/main/views/test_service_settings.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index a360f06f7..d71849835 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -1550,16 +1550,17 @@ def test_should_show_page_to_set_organisation_type( assert normalize_spaces(labels[index].text) == expected -@pytest.mark.parametrize('organisation_type', [ - 'central', - 'local', - 'nhs', - pytest.mark.xfail('private sector'), +@pytest.mark.parametrize('organisation_type, free_allowance', [ + ('central', 250000), + ('local', 25000), + ('nhs', 25000), + (pytest.mark.xfail('private sector'), 1000) ]) def test_should_set_organisation_type( logged_in_platform_admin_client, mock_update_service, organisation_type, + free_allowance, mock_create_or_update_free_sms_fragment_limit ): response = logged_in_platform_admin_client.post( @@ -1579,6 +1580,7 @@ def test_should_set_organisation_type( SERVICE_ONE_ID, organisation_type=organisation_type, ) + mock_create_or_update_free_sms_fragment_limit.assert_called_once_with(SERVICE_ONE_ID, free_allowance) def test_should_show_page_to_set_sms_allowance( From dcb3b84468bdc45d8380d69b8a78942291fb6b84 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Fri, 2 Mar 2018 15:16:33 +0000 Subject: [PATCH 3/3] Fix syntax error --- tests/app/main/views/test_service_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index d71849835..65ddb912c 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -1554,7 +1554,7 @@ def test_should_show_page_to_set_organisation_type( ('central', 250000), ('local', 25000), ('nhs', 25000), - (pytest.mark.xfail('private sector'), 1000) + pytest.mark.xfail(('private sector', 1000)) ]) def test_should_set_organisation_type( logged_in_platform_admin_client,