Merge pull request #2048 from alphagov/email-colours-and-domain

Add banner_colour, single_id_color and domain to email_branding.
This commit is contained in:
Chris Hill-Scott
2018-08-22 16:04:14 +01:00
committed by GitHub
5 changed files with 69 additions and 12 deletions

View File

@@ -30,7 +30,8 @@ from app.models import (
NOTIFICATION_CREATED,
NOTIFICATION_TECHNICAL_FAILURE,
NOTIFICATION_SENT,
NOTIFICATION_SENDING
NOTIFICATION_SENDING,
BRANDING_BOTH
)
@@ -198,8 +199,10 @@ def get_html_email_options(service):
service.email_branding.logo
) if service.email_branding.logo else None
colour = _set_colour(service)
branding = {
'brand_colour': service.email_branding.colour,
'brand_colour': colour,
'brand_logo': logo_url,
'brand_name': service.email_branding.text,
}
@@ -209,6 +212,15 @@ def get_html_email_options(service):
return dict(govuk_banner=govuk_banner, brand_banner=brand_banner, **branding)
def _set_colour(service):
if service.branding in [BRANDING_BOTH, BRANDING_ORG]:
return service.email_branding.single_id_colour or service.email_branding.colour
elif service.branding == BRANDING_ORG_BANNER:
return service.email_branding.banner_colour or service.email_branding.colour
elif service.branding == BRANDING_GOVUK:
return None
def technical_failure(notification):
notification.status = NOTIFICATION_TECHNICAL_FAILURE
dao_update_notification(notification)

View File

@@ -4,9 +4,12 @@ post_create_email_branding_schema = {
"type": "object",
"properties": {
"colour": {"type": ["string", "null"]},
"banner_colour": {"type": ["string", "null"]},
"single_id_colour": {"type": ["string", "null"]},
"name": {"type": ["string", "null"]},
"text": {"type": ["string", "null"]},
"logo": {"type": ["string", "null"]}
"logo": {"type": ["string", "null"]},
"domain": {"type": ["string", "null"]},
},
"required": []
}
@@ -17,9 +20,12 @@ post_update_email_branding_schema = {
"type": "object",
"properties": {
"colour": {"type": ["string", "null"]},
"banner_colour": {"type": ["string", "null"]},
"single_id_colour": {"type": ["string", "null"]},
"name": {"type": ["string", "null"]},
"text": {"type": ["string", "null"]},
"logo": {"type": ["string", "null"]}
"logo": {"type": ["string", "null"]},
"domain": {"type": ["string", "null"]},
},
"required": []
}

View File

@@ -77,7 +77,8 @@ def create_service(
email_from=None,
prefix_sms=True,
message_limit=1000,
organisation_type='central'
organisation_type='central',
branding=None
):
service = Service(
name=service_name,
@@ -86,7 +87,8 @@ def create_service(
email_from=email_from if email_from else service_name.lower().replace(' ', '.'),
created_by=user or create_user(email='{}@digital.cabinet-office.gov.uk'.format(uuid.uuid4())),
prefix_sms=prefix_sms,
organisation_type=organisation_type
organisation_type=organisation_type,
branding=branding
)
dao_create_service(service, service.created_by, service_id, service_permissions=service_permissions)

View File

@@ -13,6 +13,7 @@ from app import mmg_client, firetext_client
from app.dao import (provider_details_dao, notifications_dao)
from app.dao.provider_details_dao import dao_switch_sms_provider_to_provider_with_identifier
from app.delivery import send_to_providers
from app.delivery.send_to_providers import _set_colour
from app.exceptions import NotificationTechnicalFailureException
from app.models import (
Notification,
@@ -202,6 +203,7 @@ def test_send_sms_should_use_template_version_from_notification_not_latest(
def test_should_call_send_sms_response_task_if_research_mode(
notify_db, sample_service, sample_notification, mocker, research_mode, key_type
):
sample_service.branding = BRANDING_GOVUK
mocker.patch('app.mmg_client.send_sms')
mocker.patch('app.delivery.send_to_providers.send_sms_response')
@@ -454,11 +456,13 @@ def test_get_html_email_renderer_with_branding_details_and_render_govuk_banner_o
def test_get_html_email_renderer_prepends_logo_path(notify_api):
Service = namedtuple('Service', ['branding', 'email_branding'])
EmailBranding = namedtuple('EmailBranding', ['colour', 'name', 'logo', 'text'])
EmailBranding = namedtuple('EmailBranding', ['colour', 'name', 'logo', 'text', 'banner_colour', 'single_id_colour'])
email_branding = EmailBranding(colour='#000000', logo='justice-league.png',
name='Justice League',
text='League of Justice')
text='League of Justice',
banner_colour='#ABEBC6',
single_id_colour='#DB6849')
service = Service(branding=BRANDING_ORG, email_branding=email_branding)
renderer = send_to_providers.get_html_email_options(service)
@@ -468,10 +472,12 @@ def test_get_html_email_renderer_prepends_logo_path(notify_api):
def test_get_html_email_renderer_handles_email_branding_without_logo(notify_api):
Service = namedtuple('Service', ['branding', 'email_branding'])
EmailBranding = namedtuple('EmailBranding', ['colour', 'name', 'logo', 'text'])
EmailBranding = namedtuple('EmailBranding', ['colour', 'name', 'logo', 'text', 'banner_colour', 'single_id_colour'])
email_branding = EmailBranding(colour='#000000', logo=None, name='Justice League', text='League of Justice')
service = Service(branding=BRANDING_ORG, email_branding=email_branding)
email_branding = EmailBranding(colour='#000000', logo=None, name='Justice League', text='League of Justice',
banner_colour='#ABEBC6',
single_id_colour='#DB6849')
service = Service(branding=BRANDING_ORG_BANNER, email_branding=email_branding)
renderer = send_to_providers.get_html_email_options(service)
@@ -746,3 +752,26 @@ def test_send_email_to_provider_should_format_email_address(sample_email_notific
html_body=ANY,
reply_to_address=ANY,
)
@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(notify_db_session, colour, banner_colour, single_id_colour, branding_type, expected_colour):
Service = namedtuple('Service', ['branding', 'email_branding'])
email_branding = EmailBranding(colour=colour,
logo='justice-league.png',
name='Justice League',
text='League of Justice',
banner_colour=banner_colour,
single_id_colour=single_id_colour)
service = Service(branding=branding_type, email_branding=email_branding)
colour = _set_colour(service)
assert colour == expected_colour

View File

@@ -45,7 +45,10 @@ def test_post_create_email_branding(admin_request, notify_db_session):
data = {
'name': 'test email_branding',
'colour': '#0000ff',
'logo': '/images/test_x2.png'
'banner_colour': '#808080',
'single_id_colour': '#FF0000',
'logo': '/images/test_x2.png',
'domain': 'gov.uk'
}
response = admin_request.post(
'email_branding.create_email_branding',
@@ -54,8 +57,11 @@ def test_post_create_email_branding(admin_request, notify_db_session):
)
assert data['name'] == response['data']['name']
assert data['colour'] == response['data']['colour']
assert data['banner_colour'] == response['data']['banner_colour']
assert data['single_id_colour'] == response['data']['single_id_colour']
assert data['logo'] == response['data']['logo']
assert data['name'] == response['data']['text']
assert data['domain'] == response['data']['domain']
def test_post_create_email_branding_without_logo_is_ok(admin_request, notify_db_session):
@@ -142,6 +148,8 @@ def test_post_create_email_branding_with_text_as_none_and_name(admin_request, no
@pytest.mark.parametrize('data_update', [
({'name': 'test email_branding 1'}),
({'logo': 'images/text_x3.png', 'colour': '#ffffff'}),
({'logo': 'images/text_x3.png', 'banner_colour': '#ffffff', 'single_id_colour': '#808080'}),
({'logo': 'images/text_x3.png', 'banner_colour': '#ffffff', 'single_id_colour': '#808080', 'domain': 'gov.uk'}),
])
def test_post_update_email_branding_updates_field(admin_request, notify_db_session, data_update):
data = {