From 9f91694c7128602230de180dcc5be24f96b85367 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 4 Jul 2016 16:25:20 +0100 Subject: [PATCH] =?UTF-8?q?Add=20a=20=E2=80=98private=E2=80=99=20preview?= =?UTF-8?q?=20email=20template=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will make working on the email template easier. Includes examples of features like lists, headings, blockquotes, etc. --- app/main/views/index.py | 41 +++++++++++++++++++++- requirements.txt | 2 +- tests/app/main/views/test_email_preview.py | 23 ++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 tests/app/main/views/test_email_preview.py diff --git a/app/main/views/index.py b/app/main/views/index.py index d3b9fae03..569d716c8 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -1,12 +1,15 @@ import markdown import os -from flask import (render_template, url_for, redirect, Markup) +from flask import (render_template, url_for, redirect, Markup, request) from app.main import main +from app import convert_to_boolean from flask_login import login_required from flask.ext.login import current_user from mdx_gfm import GithubFlavoredMarkdownExtension +from notifications_utils.renderers import HTMLEmail + @main.route('/') def index(): @@ -46,6 +49,42 @@ def delivery_and_failure(): return render_template('views/delivery-and-failure.html') +@main.route('/_email') +def email_template(): + return HTMLEmail( + govuk_banner=convert_to_boolean(request.args.get('govuk_banner', True)) + )( + 'Lorem Ipsum is simply dummy text of the printing and typesetting ' + 'industry.\n\nLorem Ipsum has been the industry’s standard dummy ' + 'text ever since the 1500s, when an unknown printer took a galley ' + 'of type and scrambled it to make a type specimen book. ' + '\n\n' + '# History' + '\n\n' + 'It has ' + 'survived not only' + '\n' + '*five centuries' + '\n' + '* but also the leap into electronic typesetting' + '\n\n' + 'It was ' + 'popularised in the 1960s with the release of Letraset sheets ' + 'containing Lorem Ipsum passages, and more recently with desktop ' + 'publishing software like Aldus PageMaker including versions of ' + 'Lorem Ipsum.' + '\n\n' + '^ It is a long established fact that a reader will be distracted ' + 'by the readable content of a page when looking at its layout.' + '\n\n' + 'The point of using Lorem Ipsum is that it has a more-or-less ' + 'normal distribution of letters, as opposed to using ‘Content ' + 'here, content here’, making it look like readable English.' + '\n\n\n' + 'This is an example of an email sent using GOV.UK Notify.' + ) + + @main.route('/documentation') def documentation(): curr_dir = os.path.dirname(os.path.realpath(__file__)) diff --git a/requirements.txt b/requirements.txt index a633bd6b0..72d032994 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,4 +18,4 @@ pytz==2016.4 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@6.2.0#egg=notifications-utils==6.2.0 +git+https://github.com/alphagov/notifications-utils.git@8.3.0#egg=notifications-utils==8.3.0 diff --git a/tests/app/main/views/test_email_preview.py b/tests/app/main/views/test_email_preview.py new file mode 100644 index 000000000..b19d5e985 --- /dev/null +++ b/tests/app/main/views/test_email_preview.py @@ -0,0 +1,23 @@ +import pytest +from flask import url_for + + +@pytest.mark.parametrize( + "query_args, params", [ + ({}, {'govuk_banner': True}), + ({'govuk_banner': 'false'}, {'govuk_banner': False}) + ] +) +def test_renders(app_, mocker, query_args, params): + with app_.test_request_context(), app_.test_client() as client: + + mock_html_email = mocker.patch( + 'app.main.views.index.HTMLEmail', + return_value=lambda x: 'rendered' + ) + + response = client.get(url_for('main.email_template', **query_args)) + + assert response.status_code == 200 + assert response.get_data(as_text=True) == 'rendered' + mock_html_email.assert_called_once_with(**params)