Make breaking change not use rendered template

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 `<span class="placeholder">…</span>` 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.
This commit is contained in:
Chris Hill-Scott
2016-12-14 10:12:53 +00:00
parent dc63de0f4e
commit 1c679ae621
4 changed files with 34 additions and 10 deletions

View File

@@ -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),

View File

@@ -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,

View File

@@ -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,

View File

@@ -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(