diff --git a/tests/app/main/views/test_email_preview.py b/tests/app/main/views/test_email_preview.py index e1f819f52..55421cb7f 100644 --- a/tests/app/main/views/test_email_preview.py +++ b/tests/app/main/views/test_email_preview.py @@ -32,9 +32,9 @@ def test_displays_govuk_branding_by_default(client): assert page.find("a", attrs={"href": "https://www.gov.uk"}) -def test_displays_govuk_branding(client): +def test_displays_govuk_branding(client, mock_get_email_branding_with_govuk_brand_type): - response = client.get(url_for('main.email_template', branding_type="govuk", branding_style="1")) + response = client.get(url_for('main.email_template', branding_style="1")) page = BeautifulSoup(response.data.decode("utf-8"), "html.parser") @@ -43,14 +43,14 @@ def test_displays_govuk_branding(client): assert page.find("a", attrs={"href": "https://www.gov.uk"}) -def test_displays_both_branding(client, mock_get_email_branding): +def test_displays_both_branding(client, mock_get_email_branding_with_both_brand_type): - response = client.get(url_for('main.email_template', branding_type="both", branding_style="1")) + response = client.get(url_for('main.email_template', branding_style="1")) page = BeautifulSoup(response.data.decode("utf-8"), "html.parser") assert response.status_code == 200 - mock_get_email_branding.assert_called_once_with('1') + mock_get_email_branding_with_both_brand_type.assert_called_once_with('1') assert page.find("a", attrs={"href": "https://www.gov.uk"}) assert page.find("img", attrs={"src": re.compile("example.png$")}) @@ -60,7 +60,8 @@ def test_displays_both_branding(client, mock_get_email_branding): def test_displays_org_branding(client, mock_get_email_branding): - response = client.get(url_for('main.email_template', branding_type="org", branding_style="1")) + # mock_get_email_branding has 'brand_type' of 'org' + response = client.get(url_for('main.email_template', branding_style="1")) page = BeautifulSoup(response.data.decode("utf-8"), "html.parser") @@ -74,15 +75,15 @@ def test_displays_org_branding(client, mock_get_email_branding): .get_text().strip() == 'Organisation text' # brand text is set -def test_displays_org_branding_with_banner(client, mock_get_email_branding): +def test_displays_org_branding_with_banner( + client, mock_get_email_branding_with_org_banner_brand_type): - response = client.get(url_for('main.email_template', branding_type="org_banner", - branding_style="1")) + response = client.get(url_for('main.email_template', branding_style="1")) page = BeautifulSoup(response.data.decode("utf-8"), "html.parser") assert response.status_code == 200 - mock_get_email_branding.assert_called_once_with('1') + mock_get_email_branding_with_org_banner_brand_type.assert_called_once_with('1') assert not page.find("a", attrs={"href": "https://www.gov.uk"}) assert page.find("img", attrs={"src": re.compile("example.png")}) @@ -94,8 +95,8 @@ def test_displays_org_branding_with_banner(client, mock_get_email_branding): def test_displays_org_branding_with_banner_without_brand_text( client, mock_get_email_branding_without_brand_text): - response = client.get(url_for('main.email_template', branding_type="org_banner", - branding_style="1")) + # mock_get_email_branding_without_brand_text has 'brand_type' of 'org_banner' + response = client.get(url_for('main.email_template', branding_style="1")) page = BeautifulSoup(response.data.decode("utf-8"), "html.parser") diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index b87f834bd..d3b85ca05 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -1718,31 +1718,6 @@ def test_set_letter_branding_saves( mock_update_service.assert_called_once_with(service_one['id'], dvla_organisation='500') -def test_should_show_branding_types( - logged_in_platform_admin_client, - service_one, - mock_get_all_email_branding, -): - response = logged_in_platform_admin_client.get(url_for( - 'main.service_set_email_branding', service_id=service_one['id'] - )) - assert response.status_code == 200 - page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') - - assert page.find('input', attrs={"id": "branding_type-0"})['value'] == 'govuk' - assert page.find('input', attrs={"id": "branding_type-1"})['value'] == 'both' - assert page.find('input', attrs={"id": "branding_type-2"})['value'] == 'org' - assert page.find('input', attrs={"id": "branding_type-3"})['value'] == 'org_banner' - - assert 'checked' in page.find('input', attrs={"id": "branding_type-0"}).attrs - assert 'checked' not in page.find('input', attrs={"id": "branding_type-1"}).attrs - assert 'checked' not in page.find('input', attrs={"id": "branding_type-2"}).attrs - assert 'checked' not in page.find('input', attrs={"id": "branding_type-3"}).attrs - - app.email_branding_client.get_all_email_branding.assert_called_once_with() - app.service_api_client.get_service.assert_called_once_with(service_one['id']) - - def test_should_show_branding_styles( logged_in_platform_admin_client, service_one, @@ -1827,8 +1802,8 @@ def test_should_send_branding_and_organisations_to_preview( ) assert response.status_code == 302 assert response.location == url_for('main.service_preview_email_branding', - service_id=service_one['id'], branding_type='org', - branding_style='1', _external=True) + service_id=service_one['id'], branding_style='1', + _external=True) mock_get_all_email_branding.assert_called_once_with() @@ -1847,10 +1822,8 @@ def test_should_preview_email_branding( iframeURLComponents = urlparse(iframe['src']) iframeQString = parse_qs(iframeURLComponents.query) - assert page.find('input', attrs={"id": "branding_type"})['value'] == 'org' assert page.find('input', attrs={"id": "branding_style"})['value'] == '1' assert iframeURLComponents.path == '/_email' - assert iframeQString['branding_type'] == ['org'] assert iframeQString['branding_style'] == ['1'] app.service_api_client.get_service.assert_called_once_with(service_one['id']) @@ -1866,7 +1839,6 @@ def test_should_set_branding_and_organisations( 'main.service_preview_email_branding', service_id=service_one['id'] ), data={ - 'branding_type': 'org', 'branding_style': '1' } ) @@ -1876,7 +1848,6 @@ def test_should_set_branding_and_organisations( mock_update_service.assert_called_once_with( service_one['id'], - branding='org', email_branding='1' ) diff --git a/tests/conftest.py b/tests/conftest.py index 5ed2681da..e00d303e2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2519,20 +2519,57 @@ def mock_no_email_branding(mocker): ) +def create_email_branding(id, non_standard_values={}): + branding = { + 'logo': 'example.png', + 'name': 'Organisation name', + 'text': 'Organisation text', + 'id': id, + 'colour': '#f00', + 'domain': 'sample.com', + 'brand_type': 'org', + } + + if bool(non_standard_values): + branding.update(non_standard_values) + + return {'email_branding': branding} + + @pytest.fixture(scope='function') def mock_get_email_branding(mocker, fake_uuid): def _get_email_branding(id): - return { - 'email_branding': { - 'logo': 'example.png', - 'name': 'Organisation name', - 'text': 'Organisation text', - 'id': fake_uuid, - 'colour': '#f00', - 'domain': 'sample.com', - 'brand_type': 'org', - } - } + return create_email_branding(fake_uuid) + + return mocker.patch( + 'app.email_branding_client.get_email_branding', side_effect=_get_email_branding + ) + + +@pytest.fixture(scope='function') +def mock_get_email_branding_with_govuk_brand_type(mocker, fake_uuid): + def _get_email_branding(id): + return create_email_branding(fake_uuid, {'brand_type': 'govuk'}) + + return mocker.patch( + 'app.email_branding_client.get_email_branding', side_effect=_get_email_branding + ) + + +@pytest.fixture(scope='function') +def mock_get_email_branding_with_both_brand_type(mocker, fake_uuid): + def _get_email_branding(id): + return create_email_branding(fake_uuid, {'brand_type': 'both'}) + + return mocker.patch( + 'app.email_branding_client.get_email_branding', side_effect=_get_email_branding + ) + + +@pytest.fixture(scope='function') +def mock_get_email_branding_with_org_banner_brand_type(mocker, fake_uuid): + def _get_email_branding(id): + return create_email_branding(fake_uuid, {'brand_type': 'org_banner'}) return mocker.patch( 'app.email_branding_client.get_email_branding', side_effect=_get_email_branding @@ -2542,16 +2579,7 @@ def mock_get_email_branding(mocker, fake_uuid): @pytest.fixture(scope='function') def mock_get_email_branding_without_brand_text(mocker, fake_uuid): def _get_email_branding_without_brand_text(id): - return { - 'email_branding': { - 'logo': 'example.png', - 'name': 'Organisation name', - 'text': '', - 'id': fake_uuid, - 'colour': '#f00', - 'brand_type': 'org_banner' - } - } + return create_email_branding(fake_uuid, {'text': '', 'brand_type': 'org_banner'}) return mocker.patch( 'app.email_branding_client.get_email_branding',