add tests for gsm handling in save/edit template

This commit is contained in:
Leo Hemsted
2017-02-15 13:49:15 +00:00
parent 73a965a3c6
commit 6f8568b904
3 changed files with 109 additions and 15 deletions

View File

@@ -33,4 +33,4 @@ notifications-python-client>=3.1,<3.2
awscli>=1.11,<1.12
awscli-cwlogs>=1.4,<1.5
git+https://github.com/alphagov/notifications-utils.git@13.5.0#egg=notifications-utils==13.5.0
git+https://github.com/alphagov/notifications-utils.git@13.6.0#egg=notifications-utils==13.6.0

View File

@@ -1,6 +1,6 @@
from itertools import repeat
from datetime import datetime
from unittest.mock import Mock, patch
from unittest.mock import Mock, patch, ANY
import pytest
from bs4 import BeautifulSoup
@@ -32,6 +32,29 @@ def test_should_show_page_for_one_template(
mock_get_service_template.assert_called_with(service_one['id'], template_id)
def test_should_show_sms_template_without_downgrading_unicode_characters(
logged_in_client,
mocker,
service_one,
fake_uuid,
):
msg = 'here:\tare some “fancy quotes” and non\u200Bbreaking\u200Bspaces'
mocker.patch(
'app.service_api_client.get_service_template',
return_value={'data': template_json(service_one['id'], fake_uuid, type_='sms', content=msg)}
)
template_id = fake_uuid
response = logged_in_client.get(url_for(
'.view_template',
service_id=service_one['id'],
template_id=template_id))
assert response.status_code == 200
assert msg in response.get_data(as_text=True)
def test_should_show_page_template_with_priority_select_if_platform_admin(
logged_in_platform_admin_client,
platform_admin_user,
@@ -69,17 +92,12 @@ def test_should_show_preview_letter_templates(
view_suffix,
expected_content_type,
logged_in_client,
api_user_active,
mock_login,
mock_get_service,
mock_get_service_email_template,
mock_get_user,
mock_get_user_by_email,
mock_has_permissions,
fake_uuid,
mocker,
service_one,
fake_uuid
):
service_id, template_id = repeat(fake_uuid, 2)
service_id, template_id = service_one['id'], fake_uuid
response = logged_in_client.get(url_for(
'{}_{}'.format(view, view_suffix),
service_id=service_id,
@@ -609,3 +627,81 @@ def test_get_last_use_message_uses_most_recent_statistics():
])
def test_get_human_readable_delta(from_time, until_time, message):
assert get_human_readable_delta(from_time, until_time) == message
def test_should_not_create_sms_template_with_emoji(
logged_in_client,
service_one,
mock_get_service_template,
mock_create_service_template
):
data = {
'name': "new name",
'template_content': "here are some noodles 🍜",
'template_type': 'sms',
'service': service_one['id'],
'process_type': 'normal'
}
resp = logged_in_client.post(url_for(
'.add_service_template',
service_id=service_one['id'],
template_type='sms'
), data=data)
assert resp.status_code == 200
assert "You cant use ‘🍜’ in text messages." in resp.get_data(as_text=True)
def test_should_not_update_sms_template_with_emoji(
logged_in_client,
service_one,
mock_get_service_template,
mock_update_service_template,
fake_uuid,
):
data = {
'id': fake_uuid,
'name': "new name",
'template_content': "here's a burger 🍔",
'service': service_one['id'],
'template_type': 'sms',
'process_type': 'normal'
}
resp = logged_in_client.post(url_for(
'.edit_service_template',
service_id=service_one['id'],
template_id=fake_uuid), data=data)
assert resp.status_code == 200
assert "You cant use ‘🍔’ in text messages." in resp.get_data(as_text=True)
def test_should_create_sms_template_without_downgrading_unicode_characters(
logged_in_client,
service_one,
mock_create_service_template
):
msg = 'here:\tare some “fancy quotes” and non\u200Bbreaking\u200Bspaces'
data = {
'name': "new name",
'template_content': msg,
'template_type': 'sms',
'service': service_one['id'],
'process_type': 'normal'
}
resp = logged_in_client.post(url_for(
'.add_service_template',
service_id=service_one['id'],
template_type='sms'
), data=data)
mock_create_service_template.assert_called_with(
ANY, # name
ANY, # type
msg, # content
ANY, # service_id
ANY, # subject
ANY # process_type
)
assert resp.status_code == 302

View File

@@ -386,9 +386,8 @@ def mock_get_service_letter_template(mocker):
@pytest.fixture(scope='function')
def mock_create_service_template(mocker, fake_uuid):
def _create(name, type_, content, service, subject=None):
template = template_json(
fake_uuid, name, type_, content, service)
def _create(name, type_, content, service, subject=None, process_type=None):
template = template_json(fake_uuid, name, type_, content, service, process_type)
return {'data': template}
return mocker.patch(
@@ -399,8 +398,7 @@ def mock_create_service_template(mocker, fake_uuid):
@pytest.fixture(scope='function')
def mock_update_service_template(mocker):
def _update(id_, name, type_, content, service, subject=None, process_type=None):
template = template_json(
service, id_, name, type_, content, subject)
template = template_json(service, id_, name, type_, content, subject, process_type)
return {'data': template}
return mocker.patch(