def test_email_preview_shows_reply_to_address(extra_args):
    template = EmailPreviewTemplate(
        {'content': 'content', 'subject': 'subject'},
        **extra_args
    )
    assert '<th>Reply&nbsp;to</th>' in str(template)
    assert '*****@*****.**' in str(template)
Beispiel #2
0
def get_preview_of_content(notification):

    if notification['template'].get('redact_personalisation'):
        notification['personalisation'] = {}

    if notification['template']['is_precompiled_letter']:
        return notification['client_reference']

    if notification['template']['template_type'] == 'sms':
        return str(
            SMSBodyPreviewTemplate(
                notification['template'],
                notification['personalisation'],
            ))

    if notification['template']['template_type'] == 'email':
        return Markup(
            EmailPreviewTemplate(
                notification['template'],
                notification['personalisation'],
                redact_missing_personalisation=True,
            ).subject)

    if notification['template']['template_type'] == 'letter':
        return Markup(
            LetterPreviewTemplate(
                notification['template'],
                notification['personalisation'],
            ).subject)
def test_email_preview_escapes_html_in_from_name():
    template = EmailPreviewTemplate(
        {'content': 'content', 'subject': 'subject'},
        from_name='<script>alert("")</script>',
        from_address='*****@*****.**',
    )
    assert '<script>' not in str(template)
    assert '&lt;script&gt;alert("")&lt;/script&gt;' in str(template)
def test_email_preview_shows_from_name(extra_args):
    template = EmailPreviewTemplate(
        {'content': 'content', 'subject': 'subject'},
        **extra_args
    )
    assert '<th>From</th>' in str(template)
    assert 'Example service' in str(template)
    assert '*****@*****.**' not in str(template)
Beispiel #5
0
def get_template(
    template,
    service,
    show_recipient=False,
    letter_preview_url=None,
    page_count=1,
    redact_missing_personalisation=False,
    email_reply_to=None,
    sms_sender=None,
):
    # Local Jinja support - add USE_LOCAL_JINJA_TEMPLATES=True to .env
    # Add a folder to the project root called 'jinja_templates' with copies from notification-utls repo of:
    # 'email_preview_template.jinja2'
    # 'sms_preview_template.jinja2'
    debug_template_path = path.dirname(
        path.abspath(__file__)) if os.environ.get(
            "USE_LOCAL_JINJA_TEMPLATES") == "True" else None

    if "email" == template["template_type"]:
        return EmailPreviewTemplate(
            template,
            from_name=service.name,
            from_address="{}@notifications.service.gov.uk".format(
                service.email_from),
            show_recipient=show_recipient,
            redact_missing_personalisation=redact_missing_personalisation,
            reply_to=email_reply_to,
            jinja_path=debug_template_path,
            **get_email_logo_options(service),
        )
    if "sms" == template["template_type"]:
        return SMSPreviewTemplate(
            template,
            prefix=service.name,
            show_prefix=service.prefix_sms,
            sender=sms_sender,
            show_sender=bool(sms_sender),
            show_recipient=show_recipient,
            redact_missing_personalisation=redact_missing_personalisation,
            jinja_path=debug_template_path,
        )
    if "letter" == template["template_type"]:
        if letter_preview_url:
            return LetterImageTemplate(
                template,
                image_url=letter_preview_url,
                page_count=int(page_count),
                contact_block=template["reply_to_text"],
                postage=template["postage"],
            )
        else:
            return LetterPreviewTemplate(
                template,
                contact_block=template["reply_to_text"],
                admin_base_url=current_app.config["ADMIN_BASE_URL"],
                redact_missing_personalisation=redact_missing_personalisation,
            )
def test_email_preview_shows_recipient_address(
    template_values,
    expected_content,
):
    template = EmailPreviewTemplate(
        {'content': 'content', 'subject': 'subject'},
        template_values,
    )
    assert expected_content in str(template)
Beispiel #7
0
def get_sample_template(template_type):
    if template_type == 'email':
        return EmailPreviewTemplate({'content': 'any', 'subject': '', 'template_type': 'email'})
    if template_type == 'sms':
        return SMSPreviewTemplate({'content': 'any', 'template_type': 'sms'})
    if template_type == 'letter':
        return LetterImageTemplate(
            {'content': 'any', 'subject': '', 'template_type': 'letter'}, postage='second', image_url='x', page_count=1
        )
Beispiel #8
0
def get_template(
    template,
    service,
    show_recipient=False,
    letter_preview_url=None,
    page_count=1,
    redact_missing_personalisation=False,
    email_reply_to=None,
    sms_sender=None,
):
    if 'email' == template['template_type']:
        return EmailPreviewTemplate(
            template,
            from_name=service.name,
            from_address='{}@notifications.service.gov.uk'.format(service.email_from),
            show_recipient=show_recipient,
            redact_missing_personalisation=redact_missing_personalisation,
            reply_to=email_reply_to,
        )
    if 'sms' == template['template_type']:
        return SMSPreviewTemplate(
            template,
            prefix=service.name,
            show_prefix=service.prefix_sms,
            sender=sms_sender,
            show_sender=bool(sms_sender),
            show_recipient=show_recipient,
            redact_missing_personalisation=redact_missing_personalisation,
        )
    if 'letter' == template['template_type']:
        if letter_preview_url:
            return LetterImageTemplate(
                template,
                image_url=letter_preview_url,
                page_count=int(page_count),
                contact_block=template['reply_to_text'],
                postage=template['postage'],
            )
        else:
            return LetterPreviewTemplate(
                template,
                contact_block=template['reply_to_text'],
                admin_base_url=current_app.config['ADMIN_BASE_URL'],
                redact_missing_personalisation=redact_missing_personalisation,
            )
    if 'broadcast' == template['template_type']:
        return BroadcastPreviewTemplate(
            template,
        )
def get_sample_template(template_type):
    if template_type == 'email':
        return EmailPreviewTemplate({
            'content': 'any',
            'subject': '',
            'template_type': 'email'
        })
    if template_type == 'sms':
        return SMSPreviewTemplate({'content': 'any', 'template_type': 'sms'})
    if template_type == 'letter':
        return LetterImageTemplate({
            'content': 'any',
            'subject': '',
            'template_type': 'letter'
        })
def _sample_template(template_type, content='foo'):
    return {
        'email':
        EmailPreviewTemplate({
            'content': content,
            'subject': 'bar',
            'template_type': 'email'
        }),
        'sms':
        SMSMessageTemplate({
            'content': content,
            'template_type': 'sms'
        }),
        'letter':
        LetterImageTemplate(
            {
                'content': content,
                'subject': 'bar',
                'template_type': 'letter'
            },
            image_url='https://example.com',
            page_count=1,
        ),
    }.get(template_type)
def test_makes_links_out_of_URLs(url, url_with_entities_replaced):
    link = '<a style="word-wrap: break-word;" href="{}">{}</a>'.format(
        url_with_entities_replaced, url_with_entities_replaced
    )
    assert link in str(HTMLEmailTemplate({'content': url, 'subject': ''}))
    assert link in str(EmailPreviewTemplate({'content': url, 'subject': ''}))
 ),
 (
     PlainTextEmailTemplate(
         {"content": "((content))", "subject": "((subject))"},
     ),
     ['content', 'subject'],
 ),
 (
     HTMLEmailTemplate(
         {"content": "((content))", "subject": "((subject))"},
     ),
     ['content', 'subject'],
 ),
 (
     EmailPreviewTemplate(
         {"content": "((content))", "subject": "((subject))"},
     ),
     ['content', 'subject'],
 ),
 (
     LetterPreviewTemplate(
         {"content": "((content))", "subject": "((subject))"},
         contact_block='((contact_block))',
     ),
     ['content', 'subject', 'contact_block'],
 ),
 (
     LetterImageTemplate(
         {"content": "((content))", "subject": "((subject))"},
         contact_block='((contact_block))',
         image_url='http://example.com',