mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
Merge pull request #796 from alphagov/dont-strip-html-on-save
Don’t strip HTML when saving templates
This commit is contained in:
@@ -188,6 +188,14 @@ def sample_template_with_placeholders(notify_db, notify_db_session):
|
||||
return sample_template(notify_db, notify_db_session, content="Hello (( Name))\nYour thing is due soon")
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def sample_sms_template_with_html(notify_db, notify_db_session):
|
||||
# deliberate space and title case in placeholder
|
||||
return sample_template(notify_db, notify_db_session, content=(
|
||||
"Hello (( Name))\nHere is <em>some HTML</em> & entities"
|
||||
))
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def sample_email_template(
|
||||
notify_db,
|
||||
@@ -224,6 +232,15 @@ def sample_email_template_with_placeholders(notify_db, notify_db_session):
|
||||
subject_line="((name))")
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def sample_email_template_with_html(notify_db, notify_db_session):
|
||||
return sample_email_template(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
content="Hello ((name))\nThis is an email from GOV.UK with <em>some HTML</em>",
|
||||
subject_line="((name)) <em>some HTML</em>")
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def sample_api_key(notify_db,
|
||||
notify_db_session,
|
||||
|
||||
@@ -50,10 +50,10 @@ def test_should_return_highest_priority_active_provider(notify_db, notify_db_ses
|
||||
def test_should_send_personalised_template_to_correct_sms_provider_and_persist(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template_with_placeholders,
|
||||
sample_sms_template_with_html,
|
||||
mocker
|
||||
):
|
||||
db_notification = sample_notification(notify_db, notify_db_session, template=sample_template_with_placeholders,
|
||||
db_notification = sample_notification(notify_db, notify_db_session, template=sample_sms_template_with_html,
|
||||
to_field="+447234123123", personalisation={"name": "Jo"},
|
||||
status='created')
|
||||
|
||||
@@ -66,7 +66,7 @@ def test_should_send_personalised_template_to_correct_sms_provider_and_persist(
|
||||
|
||||
mmg_client.send_sms.assert_called_once_with(
|
||||
to=format_phone_number(validate_phone_number("+447234123123")),
|
||||
content="Sample service: Hello Jo\nYour thing is due soon",
|
||||
content="Sample service: Hello Jo\nHere is <em>some HTML</em> & entities",
|
||||
reference=str(db_notification.id),
|
||||
sender=None
|
||||
)
|
||||
@@ -82,12 +82,12 @@ def test_should_send_personalised_template_to_correct_sms_provider_and_persist(
|
||||
def test_should_send_personalised_template_to_correct_email_provider_and_persist(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_email_template_with_placeholders,
|
||||
sample_email_template_with_html,
|
||||
mocker
|
||||
):
|
||||
db_notification = sample_notification(
|
||||
notify_db=notify_db, notify_db_session=notify_db_session,
|
||||
template=sample_email_template_with_placeholders,
|
||||
template=sample_email_template_with_html,
|
||||
to_field="jo.smith@example.com",
|
||||
personalisation={'name': 'Jo'}
|
||||
)
|
||||
@@ -102,12 +102,13 @@ def test_should_send_personalised_template_to_correct_email_provider_and_persist
|
||||
app.aws_ses_client.send_email.assert_called_once_with(
|
||||
'"Sample service" <sample.service@test.notify.com>',
|
||||
'jo.smith@example.com',
|
||||
'Jo',
|
||||
body='Hello Jo\nThis is an email from GOV.\u200bUK',
|
||||
'Jo <em>some HTML</em>',
|
||||
body='Hello Jo\nThis is an email from GOV.\u200bUK with <em>some HTML</em>',
|
||||
html_body=ANY,
|
||||
reply_to_address=None
|
||||
)
|
||||
assert '<!DOCTYPE html' in app.aws_ses_client.send_email.call_args[1]['html_body']
|
||||
assert '<em>some HTML</em>' in app.aws_ses_client.send_email.call_args[1]['html_body']
|
||||
|
||||
notification = Notification.query.filter_by(id=db_notification.id).one()
|
||||
assert notification.status == 'sending'
|
||||
|
||||
@@ -37,7 +37,7 @@ def test_should_create_a_new_template_for_a_service(
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
assert json_resp['data']['name'] == 'my template'
|
||||
assert json_resp['data']['template_type'] == template_type
|
||||
assert json_resp['data']['content'] == 'template content'
|
||||
assert json_resp['data']['content'] == 'template <b>content</b>'
|
||||
assert json_resp['data']['service'] == str(sample_service.id)
|
||||
assert json_resp['data']['id']
|
||||
assert json_resp['data']['version'] == 1
|
||||
@@ -153,7 +153,9 @@ def test_update_should_update_a_template(client, sample_user, sample_template):
|
||||
|
||||
assert update_response.status_code == 200
|
||||
update_json_resp = json.loads(update_response.get_data(as_text=True))
|
||||
assert update_json_resp['data']['content'] == 'my template has new content alert("foo")'
|
||||
assert update_json_resp['data']['content'] == (
|
||||
'my template has new content <script type="text/javascript">alert("foo")</script>'
|
||||
)
|
||||
assert update_json_resp['data']['name'] == sample_template.name
|
||||
assert update_json_resp['data']['template_type'] == sample_template.template_type
|
||||
assert update_json_resp['data']['version'] == 2
|
||||
|
||||
Reference in New Issue
Block a user