diff --git a/app/main/views/add_service.py b/app/main/views/add_service.py index 1fed9c5ad..8e6d942f1 100644 --- a/app/main/views/add_service.py +++ b/app/main/views/add_service.py @@ -10,10 +10,9 @@ from app.utils import AgreementInfo, email_safe, user_is_gov_user def _create_service(service_name, organisation_type, email_from, form): free_sms_fragment_limit = current_app.config['DEFAULT_FREE_SMS_FRAGMENT_LIMITS'].get(organisation_type) - email_branding = email_branding_client.get_email_branding_id_for_domain( - 'nhs.uk' if organisation_type == 'nhs' else - AgreementInfo.from_current_user().canonical_domain - ) + + domain = 'nhs.uk' if organisation_type == 'nhs' else AgreementInfo.from_current_user().canonical_domain + email_branding = email_branding_client.get_email_branding_id_for_domain(domain) try: service_id = service_api_client.create_service( service_name=service_name, @@ -22,6 +21,7 @@ def _create_service(service_name, organisation_type, email_from, form): restricted=True, user_id=session['user_id'], email_from=email_from, + service_domain=domain ) session['service_id'] = service_id diff --git a/app/notify_client/service_api_client.py b/app/notify_client/service_api_client.py index 7bce1b2d3..8dfd24b97 100644 --- a/app/notify_client/service_api_client.py +++ b/app/notify_client/service_api_client.py @@ -13,6 +13,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): restricted, user_id, email_from, + service_domain, ): """ Create a service and return the json. @@ -24,7 +25,8 @@ class ServiceAPIClient(NotifyAdminAPIClient): "message_limit": message_limit, "user_id": user_id, "restricted": restricted, - "email_from": email_from + "email_from": email_from, + "service_domain": service_domain } data = _attach_current_user(data) return self.post("/service", data)['data']['id'] diff --git a/tests/app/main/views/test_add_service.py b/tests/app/main/views/test_add_service.py index 56002884c..708aeb388 100644 --- a/tests/app/main/views/test_add_service.py +++ b/tests/app/main/views/test_add_service.py @@ -49,7 +49,8 @@ def test_should_add_service_and_redirect_to_tour_when_no_services( message_limit=app_.config['DEFAULT_SERVICE_LIMIT'], restricted=True, user_id=api_user_active.id, - email_from='testing.the.post' + email_from='testing.the.post', + service_domain=None ) mock_create_service_template.assert_called_once_with( 'Example text message template', @@ -71,10 +72,10 @@ def test_should_add_service_and_redirect_to_tour_when_no_services( mock_create_or_update_free_sms_fragment_limit.assert_called_once_with(101, 25000) -@pytest.mark.parametrize('organisation_type, free_allowance', [ - ('central', 250 * 1000), - ('local', 25 * 1000), - ('nhs', 25 * 1000), +@pytest.mark.parametrize('organisation_type, free_allowance, service_domain', [ + ('central', 250 * 1000, None), + ('local', 25 * 1000, None), + ('nhs', 25 * 1000, 'nhs.uk'), ]) def test_should_add_service_and_redirect_to_dashboard_when_existing_service( app_, @@ -86,6 +87,7 @@ def test_should_add_service_and_redirect_to_dashboard_when_existing_service( api_user_active, organisation_type, free_allowance, + service_domain, mock_create_or_update_free_sms_fragment_limit, mock_get_all_email_branding, ): @@ -103,7 +105,8 @@ def test_should_add_service_and_redirect_to_dashboard_when_existing_service( message_limit=app_.config['DEFAULT_SERVICE_LIMIT'], restricted=True, user_id=api_user_active.id, - email_from='testing.the.post' + email_from='testing.the.post', + service_domain=service_domain ) mock_create_or_update_free_sms_fragment_limit.assert_called_once_with(101, free_allowance) assert len(mock_create_service_template.call_args_list) == 0 diff --git a/tests/app/notify_client/test_service_api_client.py b/tests/app/notify_client/test_service_api_client.py index b5dd793a2..f809259db 100644 --- a/tests/app/notify_client/test_service_api_client.py +++ b/tests/app/notify_client/test_service_api_client.py @@ -74,6 +74,7 @@ def test_client_creates_service_with_correct_data( True, fake_uuid, 'test@example.com', + 'nhs.uk' ) mock_post.assert_called_once_with( '/service', @@ -89,6 +90,7 @@ def test_client_creates_service_with_correct_data( restricted=True, user_id=fake_uuid, email_from='test@example.com', + service_domain='nhs.uk' ), ) diff --git a/tests/app/notify_client/test_user_client.py b/tests/app/notify_client/test_user_client.py index 6eebb9cd2..c3b93cd2b 100644 --- a/tests/app/notify_client/test_user_client.py +++ b/tests/app/notify_client/test_user_client.py @@ -249,7 +249,7 @@ def test_returns_value_from_cache( (user_api_client, 'set_user_permissions', [user_id, SERVICE_ONE_ID, []], {}), (user_api_client, 'activate_user', [api_user_pending(sample_uuid())], {}), (service_api_client, 'remove_user_from_service', [SERVICE_ONE_ID, user_id], {}), - (service_api_client, 'create_service', ['', '', 0, False, user_id, sample_uuid()], {}), + (service_api_client, 'create_service', ['', '', 0, False, user_id, sample_uuid(), ''], {}), (invite_api_client, 'accept_invite', [SERVICE_ONE_ID, user_id], {}), ]) def test_deletes_user_cache( diff --git a/tests/conftest.py b/tests/conftest.py index 61decdcd7..f96cba090 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -625,6 +625,7 @@ def mock_create_service(mocker): restricted, user_id, email_from, + service_domain, ): service = service_json( 101, service_name, [user_id], message_limit=message_limit, restricted=restricted, email_from=email_from) @@ -643,6 +644,7 @@ def mock_create_duplicate_service(mocker): restricted, user_id, email_from, + service_domain, ): json_mock = Mock(return_value={'message': {'name': ["Duplicate service name '{}'".format(service_name)]}}) resp_mock = Mock(status_code=400, json=json_mock)