Files
notifications-admin/tests/app/utils/test_branding.py
Ben Thorner 8f55972aae Split "get_available_choices" by branding type
We already had different functionality for email branding and will
soon be adding more for email branding pools.

Note that the "get_available_choices" class method was only used for
email branding - we can do it in the constructor for letters.
2022-03-30 17:46:39 +01:00

118 lines
3.2 KiB
Python

from unittest.mock import PropertyMock
import pytest
from app.models.service import Service
from app.utils.branding import get_email_choices, get_letter_choices
from tests import organisation_json
@pytest.mark.parametrize('function', [get_email_choices, get_letter_choices])
@pytest.mark.parametrize('org_type, expected_options', [
('central', []),
('local', []),
('nhs_central', [('nhs', 'NHS')]),
('nhs_local', [('nhs', 'NHS')]),
('nhs_gp', [('nhs', 'NHS')]),
('emergency_service', []),
('other', []),
])
def test_get_choices_service_not_assigned_to_org(
service_one,
function,
org_type,
expected_options,
):
service_one['organisation_type'] = org_type
service = Service(service_one)
options = function(service)
assert list(options) == expected_options
@pytest.mark.parametrize('function', [get_email_choices, get_letter_choices])
@pytest.mark.parametrize('org_type, expected_options', [
('local', [('organisation', 'Test Organisation')]),
('nhs_central', [('nhs', 'NHS')]),
('nhs_local', [('nhs', 'NHS')]),
('nhs_gp', [('nhs', 'NHS')]),
('emergency_service', [('organisation', 'Test Organisation')]),
('other', [('organisation', 'Test Organisation')]),
])
def test_get_choices_service_assigned_to_org(
mocker,
service_one,
function,
org_type,
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 = function(service)
assert list(options) == expected_options
@pytest.mark.parametrize('service_branding, expected_options', [
(None, [
('govuk_and_org', 'GOV.UK and Test Organisation'),
('organisation', 'Test Organisation'),
]),
('some-random-branding', [
('govuk', 'GOV.UK'), # central orgs can switch back to GOV.UK
('govuk_and_org', 'GOV.UK and Test Organisation'),
('organisation', 'Test Organisation'),
])
])
def test_get_email_choices_central_org(
mocker,
service_one,
service_branding,
expected_options,
mock_get_service_organisation,
mock_get_email_branding,
):
service = Service(service_one)
mocker.patch(
'app.organisations_client.get_organisation',
return_value=organisation_json(organisation_type='central'),
)
mocker.patch(
'app.models.service.Service.email_branding_id',
new_callable=PropertyMock,
return_value=service_branding,
)
options = get_email_choices(service)
assert list(options) == expected_options
def test_get_letter_choices_branding_set(
mocker,
service_one,
mock_get_service_organisation,
mock_get_letter_branding_by_id,
):
service = Service(service_one)
mocker.patch(
'app.organisations_client.get_organisation',
return_value=organisation_json()
)
mocker.patch(
'app.models.service.Service.letter_branding_id',
new_callable=PropertyMock,
return_value='some-random-branding',
)
options = get_letter_choices(service)
assert list(options) == [
('organisation', 'Test Organisation'),
]