From 1c679ae621bbd320f1c2a446578b9b07ea02526a Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 14 Dec 2016 10:12:53 +0000 Subject: [PATCH] Make breaking change not use rendered template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The breaking change page was taking the rendered template and saving that if the user confirmed the change. This meant that templates could be saved with `` in their subject line for example. This commit fixes it so that it uses whatever data the user submitted, not the rendered version of this. --- app/main/views/templates.py | 6 +++++- tests/app/main/views/test_send.py | 2 +- tests/app/main/views/test_templates.py | 15 ++++++++------- tests/conftest.py | 21 ++++++++++++++++++++- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index fcbd14ef8..626ebf93e 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -161,7 +161,11 @@ def edit_service_template(service_id, template_id): return render_template( 'views/templates/breaking-change.html', template_change=template_change, - new_template=new_template, + new_template={ + 'name': form.name.data, + 'subject': subject, + 'content': form.template_content.data, + }, column_headings=list(ascii_uppercase[:len(new_template.placeholders) + 1]), example_rows=[ first_column_headings[new_template.template_type] + list(new_template.placeholders), diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index f3a339cae..dcc19c64e 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -175,7 +175,7 @@ def test_send_test_email_message( api_user_active, mock_login, mock_get_service, - mock_get_service_email_template, + mock_get_service_email_template_without_placeholders, mock_s3_upload, mock_has_permissions, mock_get_users_by_service, diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index 21676c939..70b5d6b37 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -70,7 +70,7 @@ def test_should_show_preview_letter_templates( assert response.status_code == 200 assert response.content_type == expected_content_type mock_get_service_email_template.assert_called_with(service_id, template_id) - assert mock_letter_preview.call_args[0][0]['content'] == "Your vehicle tax is about to expire" + assert mock_letter_preview.call_args[0][0]['content'] == "Your vehicle tax expires on ((date))" def test_should_redirect_when_saving_a_template(app_, @@ -113,7 +113,7 @@ def test_should_show_interstitial_when_making_breaking_change( app_, api_user_active, mock_login, - mock_get_service_template, + mock_get_service_email_template, mock_update_service_template, mock_get_user, mock_get_service, @@ -131,8 +131,9 @@ def test_should_show_interstitial_when_making_breaking_change( data={ 'id': template_id, 'name': "new name", - 'template_content': "hello ((name))", - 'template_type': 'sms', + 'template_content': "hello", + 'template_type': 'email', + 'subject': 'reminder', 'service': service_id } ) @@ -143,8 +144,8 @@ def test_should_show_interstitial_when_making_breaking_change( for key, value in { 'name': 'new name', - 'subject': '', - 'template_content': 'hello ((name))', + 'subject': 'reminder', + 'template_content': 'hello', 'confirm': 'true' }.items(): assert page.find('input', {'name': key})['value'] == value @@ -229,7 +230,7 @@ def test_should_redirect_when_saving_a_template_email(app_, service_id = fake_uuid template_id = fake_uuid name = "new name" - content = "template content" + content = "template content ((thing)) ((date))" subject = "subject" data = { 'id': template_id, diff --git a/tests/conftest.py b/tests/conftest.py index 93a9c8813..39ddb2a78 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -322,7 +322,26 @@ def mock_get_service_email_template(mocker): template_id, "Two week reminder", "email", - "Your vehicle tax is about to expire", "Subject") + "Your vehicle tax expires on ((date))", + "Your ((thing)) is due soon" + ) + return {'data': template} + + return mocker.patch( + 'app.service_api_client.get_service_template', side_effect=_create) + + +@pytest.fixture(scope='function') +def mock_get_service_email_template_without_placeholders(mocker): + def _create(service_id, template_id): + template = template_json( + service_id, + template_id, + "Two week reminder", + "email", + "Your vehicle tax expires soon", + "Your thing is due soon" + ) return {'data': template} return mocker.patch(