Fix the EmailBranding

This commit is contained in:
Rebecca Law
2018-08-23 17:44:34 +01:00
parent 34d938ce18
commit f7f202b670
7 changed files with 51 additions and 99 deletions

View File

@@ -51,8 +51,6 @@ def test_edit_email_branding_shows_the_correct_branding_info(
assert page.select_one('#name').attrs.get('value') == 'Organisation name'
assert page.select_one('#text').attrs.get('value') == 'Organisation text'
assert page.select_one('#colour').attrs.get('value') == '#f00'
assert page.select_one('#banner_colour').attrs.get('value') == '#f11'
assert page.select_one('#single_id_colour').attrs.get('value') == '#f22'
assert page.select_one('#domain').attrs.get('value') == 'sample.com'
@@ -72,8 +70,6 @@ def test_create_email_branding_does_not_show_any_branding_info(
assert page.select_one('#name').attrs.get('value') == ''
assert page.select_one('#text').attrs.get('value') == ''
assert page.select_one('#colour').attrs.get('value') == ''
assert page.select_one('#banner_colour').attrs.get('value') == ''
assert page.select_one('#single_id_colour').attrs.get('value') == ''
assert page.select_one('#domain').attrs.get('value') == ''
@@ -89,8 +85,7 @@ def test_create_new_email_branding_without_logo(
'text': 'new text',
'name': 'new name',
'domain': 'sample.com',
'banner_colour': '#FFFF00',
'single_id_colour': '#00FF00',
'brand_type': 'govuk'
}
mock_persist = mocker.patch('app.main.views.email_branding.persist_logo')
@@ -108,9 +103,8 @@ def test_create_new_email_branding_without_logo(
name=data['name'],
text=data['text'],
colour=data['colour'],
banner_colour=data['banner_colour'],
single_id_colour=data['single_id_colour'],
domain=data['domain']
domain=data['domain'],
brand_type=data['brand_type']
)
assert mock_persist.call_args_list == []
@@ -130,8 +124,7 @@ def test_create_new_email_branding_when_branding_saved(
'text': 'new text',
'name': 'new name',
'domain': 'sample.com',
'banner_colour': '#FFFF00',
'single_id_colour': '#00FF00',
'brand_type': 'govuk'
}
temp_filename = LOGO_LOCATION_STRUCTURE.format(
@@ -152,8 +145,7 @@ def test_create_new_email_branding_when_branding_saved(
'text': data['text'],
'cdn_url': 'https://static-logos.cdn.com',
'domain': data['domain'],
'banner_colour': data['banner_colour'],
'single_id_colour': data['single_id_colour'],
'brand_type': data['brand_type']
}
)
@@ -163,9 +155,8 @@ def test_create_new_email_branding_when_branding_saved(
name=data['name'],
text=data['text'],
colour=data['colour'],
banner_colour=data['banner_colour'],
single_id_colour=data['single_id_colour'],
domain=data['domain']
domain=data['domain'],
brand_type=data['brand_type']
)
@@ -207,7 +198,9 @@ def test_deletes_previous_temp_logo_after_uploading_logo(
logged_in_platform_admin_client.post(
url_for('main.create_email_branding', logo=temp_old_filename, branding_id=fake_uuid),
data={'file': (BytesIO(''.encode('utf-8')), 'test.png')},
data={'file': (BytesIO(''.encode('utf-8')), 'test.png'),
'brand_type': 'govuk'
},
content_type='multipart/form-data'
)
@@ -231,9 +224,8 @@ def test_update_existing_branding(
'colour': '#0000ff',
'text': 'new text',
'name': 'new name',
'banner_colour': '#FFFF00',
'single_id_colour': '#00FF00',
'domain': 'sample.com',
'brand_type': 'govuk'
}
temp_filename = LOGO_LOCATION_STRUCTURE.format(
@@ -250,8 +242,7 @@ def test_update_existing_branding(
content_type='multipart/form-data',
data={'colour': data['colour'], 'name': data['name'], 'text': data['text'],
'cdn_url': 'https://static-logos.cdn.com',
'banner_colour': data['banner_colour'], 'single_id_colour': data['single_id_colour'],
'domain': data['domain']
'domain': data['domain'], 'brand_type': data['brand_type']
}
)
@@ -262,9 +253,8 @@ def test_update_existing_branding(
name=data['name'],
text=data['text'],
colour=data['colour'],
banner_colour=data['banner_colour'],
single_id_colour=data['single_id_colour'],
domain=data['domain'],
brand_type=data['brand_type']
)
@@ -287,7 +277,8 @@ def test_temp_logo_is_shown_after_uploading_logo(
response = logged_in_platform_admin_client.post(
url_for('main.create_email_branding'),
data={'file': (BytesIO(''.encode('utf-8')), 'test.png')},
data={'file': (BytesIO(''.encode('utf-8')), 'test.png'),
'brand_type': 'govuk'},
content_type='multipart/form-data',
follow_redirects=True
)
@@ -317,9 +308,9 @@ def test_logo_persisted_when_organisation_saved(
resp = logged_in_platform_admin_client.post(
url_for('.create_email_branding', logo=temp_filename),
data={'brand_type': 'govuk'},
content_type='multipart/form-data'
)
assert resp.status_code == 302
assert not mocked_upload_logo.called
@@ -348,8 +339,7 @@ def test_colour_regex_validation(
'text': 'new text',
'name': 'new name',
'domain': 'sample.com',
'banner_colour': '#FFFF00',
'single_id_colour': '#00FF00',
'brand_type': 'govuk'
}
mocker.patch('app.main.views.email_branding.delete_temp_files_created_by')
@@ -359,5 +349,4 @@ def test_colour_regex_validation(
content_type='multipart/form-data',
data=data
)
assert response.status_code == expected_status_code

View File

@@ -4,8 +4,6 @@ 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", [
@@ -88,7 +86,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='#f11']") # banner colour is set
assert page.select("body > table > tr > td[bgcolor='#f00']") # banner colour is set
assert page.select("body > table table > tr > td > span")[0]\
.get_text().strip() == 'Organisation text' # brand text is set
@@ -106,28 +104,5 @@ 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='#f11']") # banner colour is set
assert page.select("body > table > tr > td[bgcolor='#f00']") # 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