diff --git a/app/delivery/send_to_providers.py b/app/delivery/send_to_providers.py index c285c00e2..22439cf59 100644 --- a/app/delivery/send_to_providers.py +++ b/app/delivery/send_to_providers.py @@ -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) diff --git a/tests/app/db.py b/tests/app/db.py index c97e908c0..c2ecf8488 100644 --- a/tests/app/db.py +++ b/tests/app/db.py @@ -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) diff --git a/tests/app/delivery/test_send_to_providers.py b/tests/app/delivery/test_send_to_providers.py index 15e0abfcf..3b95ba47e 100644 --- a/tests/app/delivery/test_send_to_providers.py +++ b/tests/app/delivery/test_send_to_providers.py @@ -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