mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 09:59:50 -04:00
add tests for gsm handling in save/edit template
This commit is contained in:
@@ -33,4 +33,4 @@ notifications-python-client>=3.1,<3.2
|
|||||||
awscli>=1.11,<1.12
|
awscli>=1.11,<1.12
|
||||||
awscli-cwlogs>=1.4,<1.5
|
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
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from itertools import repeat
|
from itertools import repeat
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch, ANY
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from bs4 import BeautifulSoup
|
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)
|
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(
|
def test_should_show_page_template_with_priority_select_if_platform_admin(
|
||||||
logged_in_platform_admin_client,
|
logged_in_platform_admin_client,
|
||||||
platform_admin_user,
|
platform_admin_user,
|
||||||
@@ -69,17 +92,12 @@ def test_should_show_preview_letter_templates(
|
|||||||
view_suffix,
|
view_suffix,
|
||||||
expected_content_type,
|
expected_content_type,
|
||||||
logged_in_client,
|
logged_in_client,
|
||||||
api_user_active,
|
|
||||||
mock_login,
|
|
||||||
mock_get_service,
|
|
||||||
mock_get_service_email_template,
|
mock_get_service_email_template,
|
||||||
mock_get_user,
|
|
||||||
mock_get_user_by_email,
|
mock_get_user_by_email,
|
||||||
mock_has_permissions,
|
service_one,
|
||||||
fake_uuid,
|
fake_uuid
|
||||||
mocker,
|
|
||||||
):
|
):
|
||||||
service_id, template_id = repeat(fake_uuid, 2)
|
service_id, template_id = service_one['id'], fake_uuid
|
||||||
response = logged_in_client.get(url_for(
|
response = logged_in_client.get(url_for(
|
||||||
'{}_{}'.format(view, view_suffix),
|
'{}_{}'.format(view, view_suffix),
|
||||||
service_id=service_id,
|
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):
|
def test_get_human_readable_delta(from_time, until_time, message):
|
||||||
assert 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 can’t 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 can’t 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
|
||||||
|
|||||||
@@ -386,9 +386,8 @@ def mock_get_service_letter_template(mocker):
|
|||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def mock_create_service_template(mocker, fake_uuid):
|
def mock_create_service_template(mocker, fake_uuid):
|
||||||
def _create(name, type_, content, service, subject=None):
|
def _create(name, type_, content, service, subject=None, process_type=None):
|
||||||
template = template_json(
|
template = template_json(fake_uuid, name, type_, content, service, process_type)
|
||||||
fake_uuid, name, type_, content, service)
|
|
||||||
return {'data': template}
|
return {'data': template}
|
||||||
|
|
||||||
return mocker.patch(
|
return mocker.patch(
|
||||||
@@ -399,8 +398,7 @@ def mock_create_service_template(mocker, fake_uuid):
|
|||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def mock_update_service_template(mocker):
|
def mock_update_service_template(mocker):
|
||||||
def _update(id_, name, type_, content, service, subject=None, process_type=None):
|
def _update(id_, name, type_, content, service, subject=None, process_type=None):
|
||||||
template = template_json(
|
template = template_json(service, id_, name, type_, content, subject, process_type)
|
||||||
service, id_, name, type_, content, subject)
|
|
||||||
return {'data': template}
|
return {'data': template}
|
||||||
|
|
||||||
return mocker.patch(
|
return mocker.patch(
|
||||||
|
|||||||
Reference in New Issue
Block a user