DRY-up tests by parametrizing on existing branding

This is possible now we're testing letters and emails separately.
I've added a few missing cases for NHS and non-central branding.
In the next commits we'll look at the remaining special cases.
This commit is contained in:
Ben Thorner
2022-03-23 14:34:41 +00:00
parent 330c23ad30
commit 3beb56be57

View File

@@ -3,7 +3,11 @@ 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 app.utils.branding import (
NHS_EMAIL_BRANDING_ID,
get_email_choices,
get_letter_choices,
)
from tests import organisation_json
@@ -26,20 +30,37 @@ def test_get_choices_service_not_assigned_to_org(
assert list(options) == expected_options
@pytest.mark.parametrize('org_type, expected_options', [
('central', [
@pytest.mark.parametrize('org_type, branding_id, expected_options', [
('central', None, [
('govuk_and_org', 'GOV.UK and Test Organisation'),
('organisation', 'Test Organisation'),
]),
('local', [('organisation', 'Test Organisation')]),
('nhs_central', [('nhs', 'NHS')]),
('central', 'some-branding-id', [
('govuk', 'GOV.UK'), # central orgs can switch back to GOV.UK
('govuk_and_org', 'GOV.UK and Test Organisation'),
('organisation', 'Test Organisation'),
]),
('local', None, [
('organisation', 'Test Organisation')
]),
('local', 'some-branding-id', [
('organisation', 'Test Organisation')
]),
('nhs_central', None, [
('nhs', 'NHS')
]),
('nhs_central', NHS_EMAIL_BRANDING_ID, [
# don't show NHS if it's the current branding
]),
])
def test_get_email_choices_service_assigned_to_org(
mocker,
service_one,
org_type,
branding_id,
expected_options,
mock_get_service_organisation,
mock_get_email_branding
):
service = Service(service_one)
@@ -47,45 +68,35 @@ def test_get_email_choices_service_assigned_to_org(
'app.organisations_client.get_organisation',
return_value=organisation_json(organisation_type=org_type)
)
mocker.patch(
'app.models.service.Service.email_branding_id',
new_callable=PropertyMock,
return_value=branding_id
)
options = get_email_choices(service)
assert list(options) == expected_options
def test_get_email_choices_central_org_includes_govuk(
mocker,
service_one,
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='some-random-branding',
)
assert list(get_email_choices(service)) == [
('govuk', 'GOV.UK'), # central orgs can switch back to GOV.UK
('govuk_and_org', 'GOV.UK and Test Organisation'),
('organisation', 'Test Organisation'),
]
@pytest.mark.parametrize('org_type, expected_options', [
('central', [('organisation', 'Test Organisation')]),
('local', [('organisation', 'Test Organisation')]),
('nhs_central', [('nhs', 'NHS')]),
@pytest.mark.parametrize('org_type, branding_id, expected_options', [
('central', None, [
('organisation', 'Test Organisation')
]),
('local', None, [
('organisation', 'Test Organisation')
]),
('local', 'some-random-branding', [
('organisation', 'Test Organisation')
]),
('nhs_central', None, [
('nhs', 'NHS')
]),
])
def test_get_letter_choices_service_assigned_to_org(
mocker,
service_one,
org_type,
branding_id,
expected_options,
mock_get_service_organisation,
):
@@ -95,30 +106,11 @@ def test_get_letter_choices_service_assigned_to_org(
'app.organisations_client.get_organisation',
return_value=organisation_json(organisation_type=org_type)
)
options = get_letter_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',
return_value=branding_id,
)
options = get_letter_choices(service)
assert list(options) == [
('organisation', 'Test Organisation'),
]
assert list(options) == expected_options