mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 13:39:41 -04:00
Merge pull request #2955 from alphagov/auto-nhs-org-type
Set org type to NHS if user has NHS email address
This commit is contained in:
@@ -3,7 +3,7 @@ from flask import session, url_for
|
||||
|
||||
from app.utils import is_gov_user
|
||||
from tests import organisation_json
|
||||
from tests.conftest import mock_get_organisation_by_domain
|
||||
from tests.conftest import mock_get_organisation_by_domain, normalize_spaces
|
||||
|
||||
|
||||
def test_non_gov_user_cannot_see_add_service_button(
|
||||
@@ -62,6 +62,11 @@ def test_get_should_not_render_radios_if_org_type_known(
|
||||
assert not page.select('.multiple-choice')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('email_address', (
|
||||
# User’s email address doesn’t matter when the organisation is known
|
||||
'test@example.gov.uk',
|
||||
'test@example.nhs.uk',
|
||||
))
|
||||
@pytest.mark.parametrize('inherited, posted, persisted, sms_limit', (
|
||||
(None, 'central', 'central', 250000),
|
||||
('central', None, 'central', 250000),
|
||||
@@ -79,10 +84,13 @@ def test_should_add_service_and_redirect_to_tour_when_no_services(
|
||||
mock_create_or_update_free_sms_fragment_limit,
|
||||
mock_get_all_email_branding,
|
||||
inherited,
|
||||
email_address,
|
||||
posted,
|
||||
persisted,
|
||||
sms_limit,
|
||||
):
|
||||
api_user_active.email_address = email_address
|
||||
client_request.login(api_user_active)
|
||||
mock_get_organisation_by_domain(mocker, organisation_type=inherited)
|
||||
client_request.post(
|
||||
'main.add_service',
|
||||
@@ -120,6 +128,69 @@ 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, sms_limit)
|
||||
|
||||
|
||||
def test_add_service_has_to_choose_org_type(
|
||||
mocker,
|
||||
client_request,
|
||||
mock_create_service,
|
||||
mock_create_service_template,
|
||||
mock_get_services_with_no_services,
|
||||
api_user_active,
|
||||
mock_create_or_update_free_sms_fragment_limit,
|
||||
mock_get_all_email_branding,
|
||||
):
|
||||
mocker.patch(
|
||||
'app.organisations_client.get_organisation_by_domain',
|
||||
return_value=None,
|
||||
)
|
||||
page = client_request.post(
|
||||
'main.add_service',
|
||||
_data={
|
||||
'name': 'testing the post',
|
||||
},
|
||||
_expected_status=200,
|
||||
)
|
||||
assert normalize_spaces(page.select_one('.error-message').text) == (
|
||||
'Not a valid choice'
|
||||
)
|
||||
assert mock_create_service.called is False
|
||||
assert mock_create_service_template.called is False
|
||||
assert mock_create_or_update_free_sms_fragment_limit.called is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize('email_address', (
|
||||
'test@nhs.net',
|
||||
'test@nhs.uk',
|
||||
'test@example.NhS.uK',
|
||||
'test@EXAMPLE.NHS.NET',
|
||||
pytest.param(
|
||||
'test@not-nhs.uk',
|
||||
marks=pytest.mark.xfail(raises=AssertionError)
|
||||
)
|
||||
))
|
||||
def test_add_service_guesses_org_type_for_unknown_nhs_orgs(
|
||||
mocker,
|
||||
client_request,
|
||||
mock_create_service,
|
||||
mock_create_service_template,
|
||||
mock_get_services_with_no_services,
|
||||
api_user_active,
|
||||
mock_create_or_update_free_sms_fragment_limit,
|
||||
mock_get_all_email_branding,
|
||||
email_address,
|
||||
):
|
||||
api_user_active.email_address = email_address
|
||||
client_request.login(api_user_active)
|
||||
mocker.patch(
|
||||
'app.organisations_client.get_organisation_by_domain',
|
||||
return_value=None,
|
||||
)
|
||||
client_request.post(
|
||||
'main.add_service',
|
||||
_data={'name': 'example'},
|
||||
)
|
||||
assert mock_create_service.call_args[1]['organisation_type'] == 'nhs'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('organisation_type, free_allowance', [
|
||||
('central', 250 * 1000),
|
||||
('local', 25 * 1000),
|
||||
|
||||
Reference in New Issue
Block a user