diff --git a/app/main/forms.py b/app/main/forms.py index e2efb9cfa..2dd9bec41 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -756,35 +756,6 @@ class ServiceUpdateEmailBranding(StripWhitespaceForm): file = FileField_wtf('Upload a PNG logo', validators=[FileAllowed(['png'], 'PNG Images only!')]) -class ServiceCreateEmailBranding(StripWhitespaceForm): - - name = StringField('Name of brand') - text = StringField('Text') - domain = StringField('Domain') - colour = StringField( - 'Colour', - render_kw={'onchange': 'update_colour(this)'}, - validators=[ - Regexp(regex="^$|^#(?:[0-9a-fA-F]{3}){1,2}$", message='Must be a valid color hex code') - ] - ) - banner_colour = StringField( - 'Banner colour', - render_kw={'onchange': 'update_colour(this)'}, - validators=[ - Regexp(regex="^$|^#(?:[0-9a-fA-F]{3}){1,2}$", message='Must be a valid color hex code') - ] - ) - single_id_colour = StringField( - 'Single identity colour', - render_kw={'onchange': 'update_colour(this)'}, - validators=[ - Regexp(regex="^$|^#(?:[0-9a-fA-F]{3}){1,2}$", message='Must be a valid color hex code') - ] - ) - file = FileField_wtf('Upload a PNG logo', validators=[FileAllowed(['png'], 'PNG Images only!')]) - - class CreateOrUpdateOrganisation(StripWhitespaceForm): name = StringField('Name', validators=[DataRequired()]) diff --git a/app/main/views/email_branding.py b/app/main/views/email_branding.py index 008b94052..fbe5595d4 100644 --- a/app/main/views/email_branding.py +++ b/app/main/views/email_branding.py @@ -4,7 +4,6 @@ from flask_login import login_required from app import email_branding_client from app.main import main from app.main.forms import ( - ServiceCreateEmailBranding, ServiceSelectEmailBranding, ServiceUpdateEmailBranding, ) @@ -109,7 +108,7 @@ def update_email_branding(branding_id, logo=None): @login_required @user_is_platform_admin def create_email_branding(logo=None): - form = ServiceCreateEmailBranding() + form = ServiceUpdateEmailBranding() if form.validate_on_submit(): if form.file.data: diff --git a/app/main/views/index.py b/app/main/views/index.py index 5e46f95c9..3b4232825 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -78,6 +78,13 @@ def design_content(): return render_template('views/design-patterns-content-guidance.html') +def _set_colour(branding_style, email_branding): + if branding_style in ['both', 'org']: + return email_branding['single_id_colour'] or email_branding['colour'] + elif branding_style == 'org_banner': + return email_branding['banner_colour'] or email_branding['colour'] + + @main.route('/_email') def email_template(): branding_type = request.args.get('branding_type', 'govuk') @@ -91,8 +98,9 @@ def email_template(): brand_banner = False else: email_branding = email_branding_client.get_email_branding(branding_style)['email_branding'] + colour = _set_colour(branding_type, email_branding) brand_name = email_branding['text'] - brand_colour = email_branding['colour'] + brand_colour = colour brand_logo = 'https://{}/{}'.format(get_cdn_domain(), email_branding['logo']) govuk_banner = branding_type in ['govuk', 'both'] brand_banner = branding_type == 'org_banner' diff --git a/tests/app/main/views/test_email_preview.py b/tests/app/main/views/test_email_preview.py index e1f819f52..fd14de170 100644 --- a/tests/app/main/views/test_email_preview.py +++ b/tests/app/main/views/test_email_preview.py @@ -4,6 +4,8 @@ import pytest from bs4 import BeautifulSoup from flask import url_for +from app.main.views.index import _set_colour + @pytest.mark.parametrize( "query_args, result", [ @@ -86,7 +88,7 @@ def test_displays_org_branding_with_banner(client, mock_get_email_branding): assert not page.find("a", attrs={"href": "https://www.gov.uk"}) assert page.find("img", attrs={"src": re.compile("example.png")}) - assert page.select("body > table > tr > td[bgcolor='#f00']") # banner colour is set + assert page.select("body > table > tr > td[bgcolor='#f11']") # banner colour is set assert page.select("body > table table > tr > td > span")[0]\ .get_text().strip() == 'Organisation text' # brand text is set @@ -104,5 +106,28 @@ def test_displays_org_branding_with_banner_without_brand_text( assert not page.find("a", attrs={"href": "https://www.gov.uk"}) assert page.find("img", attrs={"src": re.compile("example.png")}) - assert page.select("body > table > tr > td[bgcolor='#f00']") # banner colour is set + assert page.select("body > table > tr > td[bgcolor='#f11']") # banner colour is set assert not page.select("body > table table > tr > td > span") == 0 # brand text is not set + + +@pytest.mark.parametrize('colour, banner_colour, single_id_colour, branding_type, expected_colour', [ + ('black', 'yellow', 'red', 'org', 'red'), + ('black', 'yellow', None, 'org', 'black'), + ('black', 'yellow', 'red', 'org_banner', 'yellow'), + ('black', None, 'red', 'org_banner', 'black'), + ('black', 'yellow', 'red', 'govuk', None), + ('black', 'yellow', 'red', 'both', 'red'), + ('black', 'yellow', None, 'both', 'black'), +]) +def test_set_colour(colour, banner_colour, single_id_colour, branding_type, expected_colour): + email_branding = { + 'logo': None, + 'colour': colour, + 'text': 'new text', + 'name': 'new name', + 'domain': 'sample.com', + 'banner_colour': banner_colour, + 'single_id_colour': single_id_colour, + } + colour = _set_colour(branding_type, email_branding) + assert colour == expected_colour diff --git a/tests/conftest.py b/tests/conftest.py index c80849a7b..492c5675d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2514,7 +2514,9 @@ def mock_get_email_branding_without_brand_text(mocker, fake_uuid): 'name': 'Organisation name', 'text': '', 'id': fake_uuid, - 'colour': '#f00' + 'colour': '#f00', + 'banner_colour': '#f11', + 'single_id_colour': '#f22' } }