diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index ac0ca5cf8..bba4aa4bc 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -4850,117 +4850,6 @@ def test_letter_branding_request_page_when_no_branding_is_set( assert not page.select('.conditional-radios-panel') -@pytest.mark.parametrize('branding_type', ['email', 'letter']) -@pytest.mark.parametrize('organisation_type, expected_options', ( - ('local', [ - ('organisation', 'Test Organisation'), - ('something_else', 'Something else'), - ]), - ('nhs_central', [ - ('nhs', 'NHS'), - ('something_else', 'Something else'), - ]), - ('nhs_local', [ - ('nhs', 'NHS'), - ('something_else', 'Something else'), - ]), - ('nhs_gp', [ - ('nhs', 'NHS'), - ('something_else', 'Something else'), - ]), - ('emergency_service', [ - ('organisation', 'Test Organisation'), - ('something_else', 'Something else'), - ]), - ('other', [ - ('organisation', 'Test Organisation'), - ('something_else', 'Something else'), - ]), -)) -def test_branding_request_page_when_no_branding_is_set_but_organisation_exists( - mocker, - service_one, - client_request, - mock_get_email_branding, - mock_get_letter_branding_by_id, - mock_get_service_organisation, - organisation_type, - expected_options, - branding_type -): - service_one['{}_branding'.format(branding_type)] = None - mocker.patch( - 'app.organisations_client.get_organisation', - return_value=organisation_json(organisation_type=organisation_type), - ) - - page = client_request.get( - f'.{branding_type}_branding_request', service_id=SERVICE_ONE_ID - ) - - assert mock_get_email_branding.called is False - assert mock_get_letter_branding_by_id.called is False - - assert [ - ( - radio['value'], - page.select_one('label[for={}]'.format(radio['id'])).text.strip() - ) - for radio in page.select('input[type=radio]') - ] == expected_options - - button_text = normalize_spaces(page.select_one('.page-footer button').text) - - if branding_type == 'email': - assert button_text == 'Continue' - else: - assert button_text == 'Request new branding' - - -@pytest.mark.parametrize('organisation_type, expected_options, branding_type', ( - ('central', [ - ('govuk_and_org', 'GOV.UK and Test Organisation'), - ('organisation', 'Test Organisation'), - ('something_else', 'Something else'), - ], 'email'), - ('central', [ - ('organisation', 'Test Organisation'), - ('something_else', 'Something else'), - ], 'letter'), -)) -def test_branding_request_page_when_no_branding_is_set_but_organisation_exists_central_org( - mocker, - service_one, - client_request, - mock_get_email_branding, - mock_get_letter_branding_by_id, - mock_get_service_organisation, - organisation_type, - expected_options, - branding_type -): - service_one['{}_branding'.format(branding_type)] = None - mocker.patch( - 'app.organisations_client.get_organisation', - return_value=organisation_json(organisation_type=organisation_type), - ) - - page = client_request.get( - f'.{branding_type}_branding_request', service_id=SERVICE_ONE_ID - ) - - assert mock_get_email_branding.called is False - assert mock_get_letter_branding_by_id.called is False - - assert [ - ( - radio['value'], - page.select_one('label[for={}]'.format(radio['id'])).text.strip() - ) - for radio in page.select('input[type=radio]') - ] == expected_options - - def test_email_branding_request_page_when_email_branding_is_set( mocker, service_one, diff --git a/tests/app/utils/test_branding.py b/tests/app/utils/test_branding.py index 2dfab64f3..7a8a6f168 100644 --- a/tests/app/utils/test_branding.py +++ b/tests/app/utils/test_branding.py @@ -2,6 +2,7 @@ import pytest from app.models.service import Service from app.utils.branding import get_available_choices +from tests import organisation_json @pytest.mark.parametrize('branding_type', ['email', 'letter']) @@ -26,3 +27,59 @@ def test_get_available_choices_no_org( options = get_available_choices(service, branding_type=branding_type) assert list(options) == expected_options + + +@pytest.mark.parametrize('branding_type', ['email', 'letter']) +@pytest.mark.parametrize('org_type, existing_branding, expected_options', [ + ('local', None, [('organisation', 'Test Organisation')]), + ('nhs_central', None, [('nhs', 'NHS')]), + ('nhs_local', None, [('nhs', 'NHS')]), + ('nhs_gp', None, [('nhs', 'NHS')]), + ('emergency_service', None, [('organisation', 'Test Organisation')]), + ('other', None, [('organisation', 'Test Organisation')]), +]) +def test_get_available_choices_with_org( + mocker, + service_one, + branding_type, + org_type, + existing_branding, + expected_options, + mock_get_service_organisation, +): + service = Service(service_one) + + mocker.patch( + 'app.organisations_client.get_organisation', + return_value=organisation_json(organisation_type=org_type) + ) + + options = get_available_choices(service, branding_type=branding_type) + assert list(options) == expected_options + + +@pytest.mark.parametrize('branding_type, expected_options', [ + ('email', [ + ('govuk_and_org', 'GOV.UK and Test Organisation'), + ('organisation', 'Test Organisation'), + ]), + ('letter', [ + ('organisation', 'Test Organisation'), + ]) +]) +def test_get_available_choices_with_central_org( + mocker, + service_one, + branding_type, + expected_options, + mock_get_service_organisation, +): + service = Service(service_one) + + mocker.patch( + 'app.organisations_client.get_organisation', + return_value=organisation_json(organisation_type='central'), + ) + + options = get_available_choices(service, branding_type=branding_type) + assert list(options) == expected_options