Use PassThrough renderer

Implements and depends on:
- [ ] https://github.com/alphagov/notifications-utils/pull/49
This commit is contained in:
Chris Hill-Scott
2016-07-07 15:59:50 +01:00
parent d28775800c
commit a8a556d02a
6 changed files with 16 additions and 9 deletions

View File

@@ -9,6 +9,7 @@ from flask import (
) )
from notifications_utils.recipients import allowed_to_send_to, first_column_heading from notifications_utils.recipients import allowed_to_send_to, first_column_heading
from notifications_utils.template import Template from notifications_utils.template import Template
from notifications_utils.renderers import PassThrough
from app.clients.email.aws_ses import get_aws_responses from app.clients.email.aws_ses import get_aws_responses
from app import api_user, encryption, create_uuid, DATETIME_FORMAT, DATE_FORMAT, statsd_client from app import api_user, encryption, create_uuid, DATETIME_FORMAT, DATE_FORMAT, statsd_client
from app.models import KEY_TYPE_TEAM from app.models import KEY_TYPE_TEAM
@@ -243,7 +244,7 @@ def send_notification(notification_type):
template_object = Template( template_object = Template(
template.__dict__, template.__dict__,
notification.get('personalisation', {}), notification.get('personalisation', {}),
renderer=lambda content: content renderer=PassThrough()
) )
if template_object.missing_data: if template_object.missing_data:
message = 'Missing personalisation: {}'.format(", ".join(template_object.missing_data)) message = 'Missing personalisation: {}'.format(", ".join(template_object.missing_data))

View File

@@ -24,6 +24,8 @@ from notifications_utils.recipients import (
validate_and_format_phone_number validate_and_format_phone_number
) )
from notifications_utils.renderers import PassThrough
from app import ma from app import ma
from app import models from app import models
from app.dao.permissions_dao import permission_dao from app.dao.permissions_dao import permission_dao
@@ -272,7 +274,11 @@ class NotificationStatusSchema(BaseSchema):
@post_dump @post_dump
def handle_template_merge(self, in_data): def handle_template_merge(self, in_data):
from notifications_utils.template import Template from notifications_utils.template import Template
template = Template(in_data['template'], in_data['personalisation']) template = Template(
in_data['template'],
in_data['personalisation'],
renderer=PassThrough()
)
in_data['body'] = template.replaced in_data['body'] = template.replaced
if in_data['template']['template_type'] == 'email': if in_data['template']['template_type'] == 'email':
in_data['subject'] = template.replaced_subject in_data['subject'] = template.replaced_subject

View File

@@ -23,4 +23,4 @@ statsd==3.2.1
git+https://github.com/alphagov/notifications-python-client.git@1.0.0#egg=notifications-python-client==1.0.0 git+https://github.com/alphagov/notifications-python-client.git@1.0.0#egg=notifications-python-client==1.0.0
git+https://github.com/alphagov/notifications-utils.git@8.1.0#egg=notifications-utils==8.1.0 git+https://github.com/alphagov/notifications-utils.git@8.2.0#egg=notifications-utils==8.2.0

View File

@@ -141,7 +141,7 @@ def test_send_sms_should_use_template_version_from_notification_not_latest(
mmg_client.send_sms.assert_called_once_with( mmg_client.send_sms.assert_called_once_with(
to=format_phone_number(validate_phone_number("+447234123123")), to=format_phone_number(validate_phone_number("+447234123123")),
content="Sample service: This is a template", content="Sample service: This is a template:\nwith a newline",
reference=str(db_notification.id), reference=str(db_notification.id),
sender=None sender=None
) )
@@ -151,7 +151,7 @@ def test_send_sms_should_use_template_version_from_notification_not_latest(
assert persisted_notification.template_id == sample_template.id assert persisted_notification.template_id == sample_template.id
assert persisted_notification.template_version == version_on_notification assert persisted_notification.template_version == version_on_notification
assert persisted_notification.template_version != sample_template.version assert persisted_notification.template_version != sample_template.version
assert persisted_notification.content_char_count == len("Sample service: This is a template") assert persisted_notification.content_char_count == len("Sample service: This is a template:\nwith a newline")
assert persisted_notification.status == 'sending' assert persisted_notification.status == 'sending'
assert not persisted_notification.personalisation assert not persisted_notification.personalisation
@@ -332,7 +332,7 @@ def test_should_send_sms_sender_from_service_if_present(
mmg_client.send_sms.assert_called_once_with( mmg_client.send_sms.assert_called_once_with(
to=format_phone_number(validate_phone_number("+447234123123")), to=format_phone_number(validate_phone_number("+447234123123")),
content="Sample service: This is a template", content="Sample service: This is a template:\nwith a newline",
reference=str(db_notification.id), reference=str(db_notification.id),
sender=sample_service.sms_sender sender=sample_service.sms_sender
) )

View File

@@ -154,7 +154,7 @@ def sample_template(notify_db,
notify_db_session, notify_db_session,
template_name="Template Name", template_name="Template Name",
template_type="sms", template_type="sms",
content="This is a template", content="This is a template:\nwith a newline",
archived=False, archived=False,
subject_line='Subject', subject_line='Subject',
user=None, user=None,

View File

@@ -34,7 +34,7 @@ def test_get_sms_notification_by_id(notify_api, sample_notification):
} }
assert notification['to'] == '+447700900855' assert notification['to'] == '+447700900855'
assert notification['service'] == str(sample_notification.service_id) assert notification['service'] == str(sample_notification.service_id)
assert notification['body'] == "This is a template" # sample_template.content assert notification['body'] == "This is a template:\nwith a newline"
assert not notification.get('subject') assert not notification.get('subject')
@@ -172,7 +172,7 @@ def test_get_all_notifications(notify_api, sample_notification):
assert notifications['notifications'][0]['to'] == '+447700900855' assert notifications['notifications'][0]['to'] == '+447700900855'
assert notifications['notifications'][0]['service'] == str(sample_notification.service_id) assert notifications['notifications'][0]['service'] == str(sample_notification.service_id)
assert notifications['notifications'][0]['body'] == "This is a template" # sample_template.content assert notifications['notifications'][0]['body'] == "This is a template:\nwith a newline"
def test_normal_api_key_returns_notifications_created_from_jobs_and_from_api( def test_normal_api_key_returns_notifications_created_from_jobs_and_from_api(