def test_basic_templates_return_markup(): template_dict = {'content': 'content', 'subject': 'subject'} for output in [ str(Template(template_dict)), str(WithSubjectTemplate(template_dict)), WithSubjectTemplate(template_dict).subject, ]: assert isinstance(output, Markup)
def add_preview_of_content_to_notifications(notifications): for notification in notifications: if notification["template"].get("redact_personalisation"): notification["personalisation"] = {} if notification["template"]["template_type"] == "sms": yield dict( preview_of_content=str( Template( notification["template"], notification["personalisation"], redact_missing_personalisation=True, )), **notification, ) else: if notification["template"]["is_precompiled_letter"]: notification["template"]["subject"] = "Provided as PDF" yield dict( preview_of_content=(WithSubjectTemplate( notification["template"], notification["personalisation"], redact_missing_personalisation=True, ).subject), **notification, )
def add_preview_of_content_to_notifications(notifications): for notification in notifications: if notification['template'].get('redact_personalisation'): notification['personalisation'] = {} if notification['template']['template_type'] == 'sms': yield dict(preview_of_content=str( Template( notification['template'], notification['personalisation'], redact_missing_personalisation=True, )), **notification) else: if notification['template']['is_precompiled_letter']: notification['template']['subject'] = notification[ 'client_reference'] yield dict(preview_of_content=(WithSubjectTemplate( notification['template'], notification['personalisation'], redact_missing_personalisation=True, ).subject), **notification)
def test_subject_line_gets_replaced(): template = WithSubjectTemplate({"content": '', 'subject': '((name))'}) assert template.subject == Markup("<span class='placeholder'>((name))</span>") template.values = {'name': 'Jo'} assert template.subject == 'Jo'
def test_sets_subject(): assert WithSubjectTemplate({"content": '', 'subject': 'Your tax is due'}).subject == 'Your tax is due'
def test_extracting_placeholders(template_content, template_subject, expected): assert WithSubjectTemplate({ "content": template_content, 'subject': template_subject }).placeholders == expected