Added a method to decide which colour to send to the notifications-utils HTMLEmailTemplate to create the content.

This commit is contained in:
Rebecca Law
2018-08-22 12:59:06 +01:00
parent 0b0e551626
commit fd16d7060a
3 changed files with 52 additions and 9 deletions

View File

@@ -30,7 +30,8 @@ from app.models import (
NOTIFICATION_CREATED, NOTIFICATION_CREATED,
NOTIFICATION_TECHNICAL_FAILURE, NOTIFICATION_TECHNICAL_FAILURE,
NOTIFICATION_SENT, NOTIFICATION_SENT,
NOTIFICATION_SENDING NOTIFICATION_SENDING,
BRANDING_BOTH
) )
@@ -198,8 +199,10 @@ def get_html_email_options(service):
service.email_branding.logo service.email_branding.logo
) if service.email_branding.logo else None ) if service.email_branding.logo else None
colour = _set_colour(service)
branding = { branding = {
'brand_colour': service.email_branding.colour, 'brand_colour': colour,
'brand_logo': logo_url, 'brand_logo': logo_url,
'brand_name': service.email_branding.text, '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) 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): def technical_failure(notification):
notification.status = NOTIFICATION_TECHNICAL_FAILURE notification.status = NOTIFICATION_TECHNICAL_FAILURE
dao_update_notification(notification) dao_update_notification(notification)

View File

@@ -77,7 +77,8 @@ def create_service(
email_from=None, email_from=None,
prefix_sms=True, prefix_sms=True,
message_limit=1000, message_limit=1000,
organisation_type='central' organisation_type='central',
branding=None
): ):
service = Service( service = Service(
name=service_name, name=service_name,
@@ -86,7 +87,8 @@ def create_service(
email_from=email_from if email_from else service_name.lower().replace(' ', '.'), 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())), created_by=user or create_user(email='{}@digital.cabinet-office.gov.uk'.format(uuid.uuid4())),
prefix_sms=prefix_sms, 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) 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 import (provider_details_dao, notifications_dao)
from app.dao.provider_details_dao import dao_switch_sms_provider_to_provider_with_identifier 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 import send_to_providers
from app.delivery.send_to_providers import _set_colour
from app.exceptions import NotificationTechnicalFailureException from app.exceptions import NotificationTechnicalFailureException
from app.models import ( from app.models import (
Notification, 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( def test_should_call_send_sms_response_task_if_research_mode(
notify_db, sample_service, sample_notification, mocker, research_mode, key_type 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.mmg_client.send_sms')
mocker.patch('app.delivery.send_to_providers.send_sms_response') 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): def test_get_html_email_renderer_prepends_logo_path(notify_api):
Service = namedtuple('Service', ['branding', 'email_branding']) 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', email_branding = EmailBranding(colour='#000000', logo='justice-league.png',
name='Justice League', 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) service = Service(branding=BRANDING_ORG, email_branding=email_branding)
renderer = send_to_providers.get_html_email_options(service) 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): def test_get_html_email_renderer_handles_email_branding_without_logo(notify_api):
Service = namedtuple('Service', ['branding', 'email_branding']) 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') email_branding = EmailBranding(colour='#000000', logo=None, name='Justice League', text='League of Justice',
service = Service(branding=BRANDING_ORG, email_branding=email_branding) 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) 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, html_body=ANY,
reply_to_address=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