mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-18 08:02:31 -05:00
look at service's organisation for branding to pass through to email renderer
This commit is contained in:
@@ -23,7 +23,7 @@ from app.dao.templates_dao import dao_get_template_by_id
|
||||
from notifications_utils.template import Template, get_sms_fragment_count
|
||||
from notifications_utils.renderers import HTMLEmail, PlainTextEmail, SMSMessage
|
||||
|
||||
from app.models import SMS_TYPE, EMAIL_TYPE, KEY_TYPE_TEST
|
||||
from app.models import SMS_TYPE, EMAIL_TYPE, KEY_TYPE_TEST, BRANDING_ORG
|
||||
from app.statsd_decorators import statsd
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ def send_email_to_provider(self, service_id, notification_id):
|
||||
html_email = Template(
|
||||
template_dict,
|
||||
values=notification.personalisation,
|
||||
renderer=HTMLEmail()
|
||||
renderer=get_html_email_renderer(service)
|
||||
)
|
||||
|
||||
plain_text_email = Template(
|
||||
@@ -185,3 +185,17 @@ def send_email_to_provider(self, service_id, notification_id):
|
||||
)
|
||||
delta_milliseconds = (datetime.utcnow() - notification.created_at).total_seconds() * 1000
|
||||
statsd_client.timing("email.total-time", delta_milliseconds)
|
||||
|
||||
|
||||
def get_html_email_renderer(service):
|
||||
govuk_banner = service.branding != BRANDING_ORG
|
||||
if service.organisation:
|
||||
branding = {
|
||||
'brand_colour': service.organisation.colour,
|
||||
'brand_logo': service.organisation.logo,
|
||||
'brand_name': service.organisation.name,
|
||||
}
|
||||
else:
|
||||
branding = {}
|
||||
|
||||
return HTMLEmail(govuk_banner=govuk_banner, **branding)
|
||||
|
||||
@@ -16,7 +16,16 @@ from app.clients.sms import SmsClientException
|
||||
from app.dao import notifications_dao, provider_details_dao
|
||||
from app.dao import provider_statistics_dao
|
||||
from app.dao.provider_statistics_dao import get_provider_statistics
|
||||
from app.models import Notification, NotificationStatistics, Job, KEY_TYPE_NORMAL, KEY_TYPE_TEST
|
||||
from app.models import (
|
||||
Notification,
|
||||
NotificationStatistics,
|
||||
Job,
|
||||
Organisation,
|
||||
KEY_TYPE_NORMAL,
|
||||
KEY_TYPE_TEST,
|
||||
BRANDING_ORG,
|
||||
BRANDING_BOTH
|
||||
)
|
||||
from tests.app.conftest import sample_notification
|
||||
|
||||
|
||||
@@ -503,6 +512,45 @@ def test_should_not_set_billable_units_if_research_mode(notify_db, sample_servic
|
||||
assert persisted_notification.billable_units == 0
|
||||
|
||||
|
||||
def test_get_html_email_renderer_should_return_for_normal_service(sample_service):
|
||||
renderer = provider_tasks.get_html_email_renderer(sample_service)
|
||||
assert renderer.govuk_banner == True
|
||||
assert renderer.brand_colour == None
|
||||
assert renderer.brand_logo == None
|
||||
assert renderer.brand_name == None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('branding_type, govuk_banner', [
|
||||
(BRANDING_ORG, False),
|
||||
(BRANDING_BOTH, True)
|
||||
])
|
||||
def test_get_html_email_renderer_with_branding_details(branding_type, govuk_banner, notify_db, sample_service):
|
||||
sample_service.branding = branding_type
|
||||
org = Organisation(colour='#000000', logo='justice-league.png', name='Justice League')
|
||||
sample_service.organisation = org
|
||||
notify_db.session.add_all([sample_service, org])
|
||||
notify_db.session.commit()
|
||||
|
||||
renderer = provider_tasks.get_html_email_renderer(sample_service)
|
||||
|
||||
assert renderer.govuk_banner == govuk_banner
|
||||
assert renderer.brand_colour == '#000000'
|
||||
assert renderer.brand_name == 'Justice League'
|
||||
|
||||
|
||||
@pytest.mark.xfail(strict=True)
|
||||
def test_get_html_email_renderer_prepends_logo_path(branding_type, govuk_banner, notify_db, sample_service):
|
||||
sample_service.branding = BRANDING_ORG
|
||||
org = Organisation(colour='#000000', logo='justice-league.png', name='Justice League')
|
||||
sample_service.organisation = org
|
||||
notify_db.session.add_all([sample_service, org])
|
||||
notify_db.session.commit()
|
||||
|
||||
renderer = provider_tasks.get_html_email_renderer(sample_service)
|
||||
|
||||
assert renderer.brand_logo == 'https://localhost:6062/test/assets/images/justice-league.png'
|
||||
|
||||
|
||||
def _get_provider_statistics(service, **kwargs):
|
||||
query = ProviderStatistics.query.filter_by(service=service)
|
||||
if 'providers' in kwargs:
|
||||
|
||||
Reference in New Issue
Block a user