diff --git a/app/config.py b/app/config.py index 645f0042f..2cd1bc3fb 100644 --- a/app/config.py +++ b/app/config.py @@ -36,6 +36,11 @@ class Config(object): ASSETS_DEBUG = False AWS_REGION = 'eu-west-1' DEFAULT_SERVICE_LIMIT = 50 + DEFAULT_FREE_SMS_FRAGMENT_LIMITS = { + 'central': 250000, + 'local': 25000, + 'nhs': 25000, + } EMAIL_EXPIRY_SECONDS = 3600 * 24 * 7 # one week HEADER_COLOUR = '#FFBF47' # $yellow HTTP_PROTOCOL = 'http' diff --git a/app/main/views/add_service.py b/app/main/views/add_service.py index 8019199e6..a6779fc38 100644 --- a/app/main/views/add_service.py +++ b/app/main/views/add_service.py @@ -45,6 +45,7 @@ def _create_service(service_name, organisation_type, email_from, form): service_name=service_name, organisation_type=organisation_type, message_limit=current_app.config['DEFAULT_SERVICE_LIMIT'], + free_sms_fragment_limit=current_app.config['DEFAULT_FREE_SMS_FRAGMENT_LIMITS'].get(organisation_type), restricted=True, user_id=session['user_id'], email_from=email_from, diff --git a/app/notify_client/service_api_client.py b/app/notify_client/service_api_client.py index aa92b0e1b..a35044e6c 100644 --- a/app/notify_client/service_api_client.py +++ b/app/notify_client/service_api_client.py @@ -20,6 +20,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): self, service_name, organisation_type, + free_sms_fragment_limit, message_limit, restricted, user_id, @@ -31,6 +32,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): data = { "name": service_name, "organisation_type": organisation_type, + "free_sms_fragment_limit": free_sms_fragment_limit, "active": True, "message_limit": message_limit, "user_id": user_id, diff --git a/tests/app/main/views/test_add_service.py b/tests/app/main/views/test_add_service.py index b40b7a85d..ee584a27a 100644 --- a/tests/app/main/views/test_add_service.py +++ b/tests/app/main/views/test_add_service.py @@ -1,3 +1,4 @@ +import pytest from flask import url_for, session from app.utils import is_gov_user @@ -43,6 +44,7 @@ def test_should_add_service_and_redirect_to_tour_when_no_services( service_name='testing the post', organisation_type='local', message_limit=app_.config['DEFAULT_SERVICE_LIMIT'], + free_sms_fragment_limit=25000, restricted=True, user_id=api_user_active.id, email_from='testing.the.post' @@ -67,6 +69,11 @@ def test_should_add_service_and_redirect_to_tour_when_no_services( ) +@pytest.mark.parametrize('organisation_type, free_allowance', [ + ('central', 250 * 1000), + ('local', 25 * 1000), + ('nhs', 25 * 1000), +]) def test_should_add_service_and_redirect_to_dashboard_when_existing_service( app_, logged_in_client, @@ -74,19 +81,22 @@ def test_should_add_service_and_redirect_to_dashboard_when_existing_service( mock_create_service_template, mock_get_services, api_user_active, + organisation_type, + free_allowance, ): response = logged_in_client.post( url_for('main.add_service'), data={ 'name': 'testing the post', - 'organisation_type': 'central', + 'organisation_type': organisation_type, } ) assert mock_get_services.called mock_create_service.assert_called_once_with( service_name='testing the post', - organisation_type='central', + organisation_type=organisation_type, message_limit=app_.config['DEFAULT_SERVICE_LIMIT'], + free_sms_fragment_limit=free_allowance, restricted=True, user_id=api_user_active.id, email_from='testing.the.post' diff --git a/tests/app/notify_client/test_service_api_client.py b/tests/app/notify_client/test_service_api_client.py index 710d2260d..a77090a5f 100644 --- a/tests/app/notify_client/test_service_api_client.py +++ b/tests/app/notify_client/test_service_api_client.py @@ -57,6 +57,7 @@ def test_client_creates_service_with_correct_data( client.create_service( service_name='My first service', organisation_type='central_government', + free_sms_fragment_limit=2, message_limit=1, restricted=True, user_id=fake_uuid, @@ -72,6 +73,7 @@ def test_client_creates_service_with_correct_data( name='My first service', # The rest pass through with the same names organisation_type='central_government', + free_sms_fragment_limit=2, message_limit=1, restricted=True, user_id=fake_uuid, diff --git a/tests/conftest.py b/tests/conftest.py index 2051247fd..27bcad9a1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -488,7 +488,15 @@ def mock_get_service_with_letters(mocker, api_user_active): @pytest.fixture(scope='function') def mock_create_service(mocker): - def _create(service_name, organisation_type, message_limit, restricted, user_id, email_from): + def _create( + service_name, + organisation_type, + message_limit, + free_sms_fragment_limit, + restricted, + user_id, + email_from, + ): service = service_json( 101, service_name, [user_id], message_limit=message_limit, restricted=restricted, email_from=email_from) return service['id'] @@ -499,7 +507,15 @@ def mock_create_service(mocker): @pytest.fixture(scope='function') def mock_create_duplicate_service(mocker): - def _create(service_name, organisation_type, message_limit, restricted, user_id, email_from): + def _create( + service_name, + organisation_type, + message_limit, + free_sms_fragment_limit, + restricted, + user_id, + email_from, + ): json_mock = Mock(return_value={'message': {'name': ["Duplicate service name '{}'".format(service_name)]}}) resp_mock = Mock(status_code=400, json=json_mock) http_error = HTTPError(response=resp_mock, message="Default message")