2019-01-23 10:17:36 +00:00
|
|
|
|
from functools import partial
|
2018-02-20 11:22:17 +00:00
|
|
|
|
from unittest.mock import ANY, Mock
|
2016-02-02 14:24:08 +00:00
|
|
|
|
|
2016-06-06 11:42:40 +01:00
|
|
|
|
import pytest
|
2016-01-14 14:03:27 +00:00
|
|
|
|
from flask import url_for
|
2016-06-06 11:42:40 +01:00
|
|
|
|
from freezegun import freeze_time
|
2016-08-24 12:12:19 +01:00
|
|
|
|
from notifications_python_client.errors import HTTPError
|
2018-04-25 14:12:58 +01:00
|
|
|
|
|
2020-02-05 13:52:46 +00:00
|
|
|
|
from tests import sample_uuid, template_json, validate_route_permission
|
2019-01-07 14:49:33 +00:00
|
|
|
|
from tests.app.main.views.test_template_folders import (
|
|
|
|
|
|
CHILD_FOLDER_ID,
|
|
|
|
|
|
FOLDER_TWO_ID,
|
|
|
|
|
|
PARENT_FOLDER_ID,
|
|
|
|
|
|
_folder,
|
|
|
|
|
|
_template,
|
|
|
|
|
|
)
|
2017-07-04 13:38:08 +01:00
|
|
|
|
from tests.conftest import (
|
2018-02-20 11:22:17 +00:00
|
|
|
|
SERVICE_ONE_ID,
|
2018-07-19 12:30:04 +01:00
|
|
|
|
SERVICE_TWO_ID,
|
|
|
|
|
|
TEMPLATE_ONE_ID,
|
2018-11-28 13:48:13 +00:00
|
|
|
|
ElementNotFound,
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_caseworking_user,
|
|
|
|
|
|
create_active_user_view_permissions,
|
2019-12-20 14:34:45 +00:00
|
|
|
|
create_letter_contact_block,
|
2020-01-08 09:10:04 +00:00
|
|
|
|
create_template,
|
2017-07-04 13:38:08 +01:00
|
|
|
|
normalize_spaces,
|
|
|
|
|
|
)
|
2017-01-18 15:11:34 +00:00
|
|
|
|
|
2016-01-11 16:03:41 +00:00
|
|
|
|
|
2020-07-14 14:52:52 +01:00
|
|
|
|
@pytest.mark.parametrize('permissions, expected_message', (
|
|
|
|
|
|
(['email'], (
|
2020-07-14 14:54:55 +01:00
|
|
|
|
'You need a template before you can send emails, text messages or letters.'
|
2020-07-14 14:52:52 +01:00
|
|
|
|
)),
|
|
|
|
|
|
(['sms'], (
|
|
|
|
|
|
'You need a template before you can send emails, text messages or letters.'
|
|
|
|
|
|
)),
|
2020-07-14 14:54:55 +01:00
|
|
|
|
(['letter'], (
|
2020-07-14 14:52:52 +01:00
|
|
|
|
'You need a template before you can send emails, text messages or letters.'
|
|
|
|
|
|
)),
|
|
|
|
|
|
(['email', 'sms', 'letter'], (
|
|
|
|
|
|
'You need a template before you can send emails, text messages or letters.'
|
|
|
|
|
|
)),
|
|
|
|
|
|
(['broadcast'], (
|
|
|
|
|
|
'You need a template before you can prepare a broadcast.'
|
|
|
|
|
|
)),
|
|
|
|
|
|
))
|
2018-11-19 15:51:18 +00:00
|
|
|
|
def test_should_show_empty_page_when_no_templates(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_service_templates_when_no_templates_exist,
|
|
|
|
|
|
mock_get_template_folders,
|
2020-07-14 14:52:52 +01:00
|
|
|
|
permissions,
|
|
|
|
|
|
expected_message,
|
2018-11-19 15:51:18 +00:00
|
|
|
|
):
|
|
|
|
|
|
|
2020-07-14 14:52:52 +01:00
|
|
|
|
service_one['permissions'] = permissions
|
|
|
|
|
|
|
2018-11-19 15:51:18 +00:00
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select_one('h1').text) == (
|
|
|
|
|
|
'Templates'
|
|
|
|
|
|
)
|
|
|
|
|
|
assert normalize_spaces(page.select_one('main p').text) == (
|
2020-07-14 14:52:52 +01:00
|
|
|
|
expected_message
|
2018-11-19 15:51:18 +00:00
|
|
|
|
)
|
2019-02-11 16:06:46 +00:00
|
|
|
|
assert page.select_one('#add_new_folder_form')
|
|
|
|
|
|
assert page.select_one('#add_new_template_form')
|
2018-11-19 15:51:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-01-03 10:43:57 +00:00
|
|
|
|
def test_should_show_add_template_form_if_service_has_folder_permission(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_service_templates_when_no_templates_exist,
|
|
|
|
|
|
mock_get_template_folders,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select_one('h1').text) == (
|
|
|
|
|
|
'Templates'
|
|
|
|
|
|
)
|
|
|
|
|
|
assert normalize_spaces(page.select_one('main p').text) == (
|
2020-07-14 14:54:55 +01:00
|
|
|
|
'You need a template before you can send emails, text messages or letters.'
|
2019-01-03 10:43:57 +00:00
|
|
|
|
)
|
|
|
|
|
|
assert [
|
|
|
|
|
|
(item['name'], item['value']) for item in page.select('[type=radio]')
|
|
|
|
|
|
] == [
|
|
|
|
|
|
('add_template_by_template_type', 'email'),
|
|
|
|
|
|
('add_template_by_template_type', 'sms'),
|
|
|
|
|
|
]
|
|
|
|
|
|
assert not page.select('main a')
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-14 16:21:57 +01:00
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
|
'user, expected_page_title, extra_args, expected_nav_links, expected_templates',
|
|
|
|
|
|
[
|
|
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_view_permissions(),
|
2018-06-14 16:21:57 +01:00
|
|
|
|
'Templates',
|
|
|
|
|
|
{},
|
2019-02-22 17:11:12 +00:00
|
|
|
|
['Email', 'Text message', 'Letter'],
|
2018-06-14 16:21:57 +01:00
|
|
|
|
[
|
|
|
|
|
|
'sms_template_one',
|
|
|
|
|
|
'sms_template_two',
|
|
|
|
|
|
'email_template_one',
|
|
|
|
|
|
'email_template_two',
|
|
|
|
|
|
'letter_template_one',
|
|
|
|
|
|
'letter_template_two',
|
|
|
|
|
|
]
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_view_permissions(),
|
2018-06-14 16:21:57 +01:00
|
|
|
|
'Templates',
|
|
|
|
|
|
{'template_type': 'sms'},
|
|
|
|
|
|
['All', 'Email', 'Letter'],
|
|
|
|
|
|
['sms_template_one', 'sms_template_two'],
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_view_permissions(),
|
2018-06-14 16:21:57 +01:00
|
|
|
|
'Templates',
|
|
|
|
|
|
{'template_type': 'email'},
|
|
|
|
|
|
['All', 'Text message', 'Letter'],
|
|
|
|
|
|
['email_template_one', 'email_template_two'],
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_view_permissions(),
|
2018-06-14 16:21:57 +01:00
|
|
|
|
'Templates',
|
|
|
|
|
|
{'template_type': 'letter'},
|
2019-02-22 17:11:12 +00:00
|
|
|
|
['All', 'Email', 'Text message'],
|
2018-06-14 16:21:57 +01:00
|
|
|
|
['letter_template_one', 'letter_template_two'],
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_caseworking_user(),
|
2018-07-13 16:13:24 +01:00
|
|
|
|
'Templates',
|
2018-06-14 16:21:57 +01:00
|
|
|
|
{},
|
2019-02-22 17:11:12 +00:00
|
|
|
|
['Email', 'Text message', 'Letter'],
|
2018-06-14 16:21:57 +01:00
|
|
|
|
[
|
|
|
|
|
|
'sms_template_one',
|
|
|
|
|
|
'sms_template_two',
|
|
|
|
|
|
'email_template_one',
|
|
|
|
|
|
'email_template_two',
|
2018-08-07 11:45:19 +01:00
|
|
|
|
'letter_template_one',
|
|
|
|
|
|
'letter_template_two',
|
2018-06-14 16:21:57 +01:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_caseworking_user(),
|
2018-07-13 16:13:24 +01:00
|
|
|
|
'Templates',
|
2018-06-14 16:21:57 +01:00
|
|
|
|
{'template_type': 'email'},
|
2018-08-07 11:45:19 +01:00
|
|
|
|
['All', 'Text message', 'Letter'],
|
2018-06-14 16:21:57 +01:00
|
|
|
|
['email_template_one', 'email_template_two'],
|
|
|
|
|
|
),
|
|
|
|
|
|
]
|
|
|
|
|
|
)
|
2017-06-13 15:28:33 +01:00
|
|
|
|
def test_should_show_page_for_choosing_a_template(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_templates,
|
2018-11-01 17:11:58 +00:00
|
|
|
|
mock_get_template_folders,
|
2018-07-30 17:40:32 +01:00
|
|
|
|
mock_has_no_jobs,
|
2017-06-13 15:28:33 +01:00
|
|
|
|
extra_args,
|
|
|
|
|
|
expected_nav_links,
|
|
|
|
|
|
expected_templates,
|
2018-06-14 16:21:57 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
user,
|
|
|
|
|
|
expected_page_title,
|
2017-06-13 15:28:33 +01:00
|
|
|
|
):
|
2018-06-14 16:21:57 +01:00
|
|
|
|
service_one['permissions'].append('letter')
|
2019-12-19 16:59:07 +00:00
|
|
|
|
client_request.login(user)
|
2017-06-13 15:28:33 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_template',
|
2018-11-08 14:46:18 +00:00
|
|
|
|
service_id=service_one['id'],
|
2017-06-13 15:28:33 +01:00
|
|
|
|
**extra_args
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2018-06-14 16:21:57 +01:00
|
|
|
|
assert normalize_spaces(page.select_one('h1').text) == expected_page_title
|
2017-06-13 15:28:33 +01:00
|
|
|
|
|
|
|
|
|
|
links_in_page = page.select('.pill a')
|
|
|
|
|
|
|
|
|
|
|
|
assert len(links_in_page) == len(expected_nav_links)
|
|
|
|
|
|
|
|
|
|
|
|
for index, expected_link in enumerate(expected_nav_links):
|
|
|
|
|
|
assert links_in_page[index].text.strip() == expected_link
|
|
|
|
|
|
|
2020-04-23 10:57:24 +01:00
|
|
|
|
template_links = page.select('#template-list .govuk-label a, .message-name a')
|
2017-06-13 15:28:33 +01:00
|
|
|
|
|
|
|
|
|
|
assert len(template_links) == len(expected_templates)
|
|
|
|
|
|
|
|
|
|
|
|
for index, expected_template in enumerate(expected_templates):
|
|
|
|
|
|
assert template_links[index].text.strip() == expected_template
|
|
|
|
|
|
|
2018-10-26 11:47:42 +01:00
|
|
|
|
mock_get_service_templates.assert_called_once_with(SERVICE_ONE_ID)
|
2018-11-19 15:51:18 +00:00
|
|
|
|
mock_get_template_folders.assert_called_once_with(SERVICE_ONE_ID)
|
2017-06-13 15:28:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
2019-02-14 16:27:13 +00:00
|
|
|
|
def test_choose_template_can_pass_through_an_initial_state_to_templates_and_folders_selection_form(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_template_folders,
|
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
initial_state='add-new-template'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
templates_and_folders_form = page.find('form')
|
|
|
|
|
|
assert templates_and_folders_form['data-prev-state'] == 'add-new-template'
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-13 15:27:29 +01:00
|
|
|
|
def test_should_not_show_template_nav_if_only_one_type_of_template(
|
|
|
|
|
|
client_request,
|
2018-11-01 17:11:58 +00:00
|
|
|
|
mock_get_template_folders,
|
2017-06-13 15:27:29 +01:00
|
|
|
|
mock_get_service_templates_with_only_one_template,
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert not page.select('.pill')
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-16 12:18:07 +01:00
|
|
|
|
def test_should_not_show_live_search_if_list_of_templates_fits_onscreen(
|
|
|
|
|
|
client_request,
|
2018-11-01 17:11:58 +00:00
|
|
|
|
mock_get_template_folders,
|
2018-08-16 12:18:07 +01:00
|
|
|
|
mock_get_service_templates
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert not page.select('.live-search')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_show_live_search_if_list_of_templates_taller_than_screen(
|
|
|
|
|
|
client_request,
|
2018-11-01 17:11:58 +00:00
|
|
|
|
mock_get_template_folders,
|
2018-08-16 12:18:07 +01:00
|
|
|
|
mock_get_more_service_templates_than_can_fit_onscreen
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
2018-11-10 16:37:29 +00:00
|
|
|
|
search = page.select_one('.live-search')
|
2018-08-16 12:18:07 +01:00
|
|
|
|
|
2018-11-10 16:37:29 +00:00
|
|
|
|
assert search['data-module'] == 'live-search'
|
2018-11-08 11:56:29 +00:00
|
|
|
|
assert search['data-targets'] == '#template-list .template-list-item'
|
2018-11-10 16:37:29 +00:00
|
|
|
|
|
2020-04-23 10:57:24 +01:00
|
|
|
|
assert len(page.select(search['data-targets'])) == len(page.select('#template-list .govuk-label')) == 14
|
2018-08-16 12:18:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
2018-11-20 16:10:14 +00:00
|
|
|
|
def test_should_show_live_search_if_service_has_lots_of_folders(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_template_folders,
|
|
|
|
|
|
mock_get_service_templates, # returns 4 templates
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
mock_get_template_folders.return_value = [
|
|
|
|
|
|
_folder('one', PARENT_FOLDER_ID),
|
|
|
|
|
|
_folder('two', None, parent=PARENT_FOLDER_ID),
|
|
|
|
|
|
_folder('three', None, parent=PARENT_FOLDER_ID),
|
|
|
|
|
|
_folder('four', None, parent=PARENT_FOLDER_ID),
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2020-04-23 10:57:24 +01:00
|
|
|
|
count_of_templates_and_folders = len(page.select('#template-list .govuk-label'))
|
2020-06-09 16:44:05 +01:00
|
|
|
|
count_of_folders = len(page.select('.template-list-folder:first-of-type'))
|
2018-11-20 16:10:14 +00:00
|
|
|
|
count_of_templates = count_of_templates_and_folders - count_of_folders
|
|
|
|
|
|
|
|
|
|
|
|
assert len(page.select('.live-search')) == 1
|
2018-11-21 09:53:29 +00:00
|
|
|
|
assert count_of_folders == 4
|
2018-11-20 16:10:14 +00:00
|
|
|
|
assert count_of_templates == 4
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-28 13:48:13 +00:00
|
|
|
|
@pytest.mark.parametrize('extra_permissions, expected_values, expected_labels', (
|
2019-02-11 16:06:46 +00:00
|
|
|
|
pytest.param([], [
|
2018-11-28 13:48:13 +00:00
|
|
|
|
'email',
|
|
|
|
|
|
'sms',
|
|
|
|
|
|
'copy-existing',
|
|
|
|
|
|
], [
|
2019-02-20 15:12:44 +00:00
|
|
|
|
'Email',
|
|
|
|
|
|
'Text message',
|
|
|
|
|
|
'Copy an existing template',
|
2018-11-28 13:48:13 +00:00
|
|
|
|
]),
|
2019-02-11 16:06:46 +00:00
|
|
|
|
pytest.param(['letter'], [
|
2018-11-28 13:48:13 +00:00
|
|
|
|
'email',
|
|
|
|
|
|
'sms',
|
|
|
|
|
|
'letter',
|
|
|
|
|
|
'copy-existing',
|
|
|
|
|
|
], [
|
2019-02-20 15:12:44 +00:00
|
|
|
|
'Email',
|
|
|
|
|
|
'Text message',
|
|
|
|
|
|
'Letter',
|
|
|
|
|
|
'Copy an existing template',
|
2018-11-28 13:48:13 +00:00
|
|
|
|
]),
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_should_show_new_template_choices_if_service_has_folder_permission(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
mock_get_template_folders,
|
|
|
|
|
|
extra_permissions,
|
|
|
|
|
|
expected_values,
|
|
|
|
|
|
expected_labels,
|
|
|
|
|
|
):
|
|
|
|
|
|
service_one['permissions'] += extra_permissions
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if not page.select('#add_new_template_form'):
|
|
|
|
|
|
raise ElementNotFound()
|
|
|
|
|
|
|
2019-01-30 10:47:26 +00:00
|
|
|
|
assert normalize_spaces(page.select_one('#add_new_template_form fieldset legend').text) == (
|
2019-02-20 15:12:44 +00:00
|
|
|
|
'New template'
|
2018-11-28 13:48:13 +00:00
|
|
|
|
)
|
|
|
|
|
|
assert [
|
|
|
|
|
|
choice['value'] for choice in page.select('#add_new_template_form input[type=radio]')
|
|
|
|
|
|
] == expected_values
|
|
|
|
|
|
assert [
|
|
|
|
|
|
normalize_spaces(choice.text) for choice in page.select('#add_new_template_form label')
|
|
|
|
|
|
] == expected_labels
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-01 13:10:19 +01:00
|
|
|
|
def test_should_show_page_for_one_template(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
fake_uuid,
|
2016-07-01 13:10:19 +01:00
|
|
|
|
):
|
2017-02-03 12:07:21 +00:00
|
|
|
|
template_id = fake_uuid
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'.edit_service_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=template_id,
|
|
|
|
|
|
)
|
2015-12-20 00:00:01 +00:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
assert page.select_one('input[type=text]')['value'] == "Two week reminder"
|
|
|
|
|
|
assert "Template <em>content</em> with & entity" in str(
|
|
|
|
|
|
page.select_one('textarea')
|
|
|
|
|
|
)
|
2019-10-16 15:20:05 +01:00
|
|
|
|
assert page.select_one('textarea')['data-module'] == 'enhanced-textbox'
|
|
|
|
|
|
assert page.select_one('textarea')['data-highlight-placeholders'] == 'true'
|
2019-03-26 12:35:32 +00:00
|
|
|
|
assert "priority" not in str(page.select_one('main'))
|
2019-03-19 16:25:44 +00:00
|
|
|
|
mock_get_service_template.assert_called_with(SERVICE_ONE_ID, template_id, None)
|
2017-01-18 15:11:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
2018-06-12 16:17:20 +01:00
|
|
|
|
def test_caseworker_redirected_to_one_off(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_templates,
|
2018-08-07 11:43:33 +01:00
|
|
|
|
mock_get_service_template,
|
2018-06-12 16:17:20 +01:00
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
2019-12-19 16:59:07 +00:00
|
|
|
|
active_caseworking_user,
|
2018-06-12 16:17:20 +01:00
|
|
|
|
):
|
|
|
|
|
|
|
2019-12-19 16:59:07 +00:00
|
|
|
|
mocker.patch('app.user_api_client.get_user', return_value=active_caseworking_user)
|
2018-06-12 16:17:20 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.send_one_off',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-06 11:09:07 +01:00
|
|
|
|
def test_user_with_only_send_and_view_redirected_to_one_off(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_templates,
|
2018-08-07 11:43:33 +01:00
|
|
|
|
mock_get_service_template,
|
2018-08-06 11:09:07 +01:00
|
|
|
|
active_user_with_permissions,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
Make user API client return JSON, not a model
The data flow of other bits of our application looks like this:
```
API (returns JSON)
⬇
API client (returns a built in type, usually `dict`)
⬇
Model (returns an instance, eg of type `Service`)
⬇
View (returns HTML)
```
The user API client was architected weirdly, in that it returned a model
directly, like this:
```
API (returns JSON)
⬇
API client (returns a model, of type `User`, `InvitedUser`, etc)
⬇
View (returns HTML)
```
This mixing of different layers of the application is bad because it
makes it hard to write model code that doesn’t have circular
dependencies. As our application gets more complicated we will be
relying more on models to manage this complexity, so we should make it
easy, not hard to write them.
It also means that most of our mocking was of the User model, not just
the underlying JSON. So it would have been easy to introduce subtle bugs
to the user model, because it wasn’t being comprehensively tested. A lot
of the changed lines of code in this commit mean changing the tests to
mock only the JSON, which means that the model layer gets implicitly
tested.
For those reasons this commit changes the user API client to return
JSON, not an instance of `User` or other models.
2019-05-23 15:27:35 +01:00
|
|
|
|
active_user_with_permissions['permissions'][SERVICE_ONE_ID] = [
|
2018-08-06 11:09:07 +01:00
|
|
|
|
'send_messages',
|
|
|
|
|
|
'view_activity',
|
|
|
|
|
|
]
|
|
|
|
|
|
client_request.login(active_user_with_permissions)
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.send_one_off',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-07 11:43:33 +01:00
|
|
|
|
@pytest.mark.parametrize('permissions', (
|
|
|
|
|
|
{'send_messages', 'view_activity'},
|
|
|
|
|
|
{'send_messages'},
|
|
|
|
|
|
{'view_activity'},
|
|
|
|
|
|
{},
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_user_with_only_send_and_view_sees_letter_page(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_templates,
|
2018-11-16 14:09:14 +00:00
|
|
|
|
mock_get_template_folders,
|
2018-08-07 11:43:33 +01:00
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
single_letter_contact_block,
|
|
|
|
|
|
mock_has_jobs,
|
|
|
|
|
|
active_user_with_permissions,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
permissions,
|
|
|
|
|
|
):
|
|
|
|
|
|
mocker.patch('app.main.views.templates.get_page_count_for_letter', return_value=1)
|
Make user API client return JSON, not a model
The data flow of other bits of our application looks like this:
```
API (returns JSON)
⬇
API client (returns a built in type, usually `dict`)
⬇
Model (returns an instance, eg of type `Service`)
⬇
View (returns HTML)
```
The user API client was architected weirdly, in that it returned a model
directly, like this:
```
API (returns JSON)
⬇
API client (returns a model, of type `User`, `InvitedUser`, etc)
⬇
View (returns HTML)
```
This mixing of different layers of the application is bad because it
makes it hard to write model code that doesn’t have circular
dependencies. As our application gets more complicated we will be
relying more on models to manage this complexity, so we should make it
easy, not hard to write them.
It also means that most of our mocking was of the User model, not just
the underlying JSON. So it would have been easy to introduce subtle bugs
to the user model, because it wasn’t being comprehensively tested. A lot
of the changed lines of code in this commit mean changing the tests to
mock only the JSON, which means that the model layer gets implicitly
tested.
For those reasons this commit changes the user API client to return
JSON, not an instance of `User` or other models.
2019-05-23 15:27:35 +01:00
|
|
|
|
active_user_with_permissions['permissions'][SERVICE_ONE_ID] = permissions
|
2018-08-07 11:43:33 +01:00
|
|
|
|
client_request.login(active_user_with_permissions)
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
2019-04-30 16:32:20 +01:00
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert normalize_spaces(page.select_one('h1').text) == (
|
2019-06-24 16:02:49 +01:00
|
|
|
|
'Templates Two week reminder'
|
2019-04-30 16:32:20 +01:00
|
|
|
|
)
|
|
|
|
|
|
assert normalize_spaces(page.select_one('title').text) == (
|
|
|
|
|
|
'Two week reminder – Templates – service one – GOV.UK Notify'
|
2018-08-07 11:43:33 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-23 10:17:36 +00:00
|
|
|
|
@pytest.mark.parametrize('letter_branding, expected_link, expected_link_text', (
|
|
|
|
|
|
(
|
|
|
|
|
|
None,
|
2020-01-21 16:02:41 +00:00
|
|
|
|
partial(
|
|
|
|
|
|
url_for, 'main.branding_request',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID, branding_type="letter", from_template=TEMPLATE_ONE_ID
|
|
|
|
|
|
),
|
2019-01-23 10:17:36 +00:00
|
|
|
|
'Add logo',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
TEMPLATE_ONE_ID,
|
|
|
|
|
|
partial(url_for, 'main.edit_template_postage', template_id=TEMPLATE_ONE_ID),
|
|
|
|
|
|
'Change',
|
|
|
|
|
|
),
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_letter_with_default_branding_has_add_logo_button(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_template_folders,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
single_letter_contact_block,
|
|
|
|
|
|
letter_branding,
|
|
|
|
|
|
expected_link,
|
|
|
|
|
|
expected_link_text,
|
|
|
|
|
|
):
|
|
|
|
|
|
mocker.patch('app.main.views.templates.get_page_count_for_letter', return_value=1)
|
|
|
|
|
|
service_one['permissions'] += ['letter']
|
|
|
|
|
|
service_one['letter_branding'] = letter_branding
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=TEMPLATE_ONE_ID,
|
2019-04-30 16:32:20 +01:00
|
|
|
|
_test_page_title=False,
|
2019-01-23 10:17:36 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
first_edit_link = page.select_one('.template-container a')
|
|
|
|
|
|
assert first_edit_link['href'] == expected_link(service_id=SERVICE_ONE_ID)
|
|
|
|
|
|
assert first_edit_link.text == expected_link_text
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-02-04 16:55:00 +00:00
|
|
|
|
@pytest.mark.parametrize("template_postage,expected_result", [
|
|
|
|
|
|
("first", "Postage: first class"),
|
|
|
|
|
|
("second", "Postage: second class"),
|
2018-12-21 14:29:35 +00:00
|
|
|
|
])
|
2019-02-04 16:55:00 +00:00
|
|
|
|
def test_view_letter_template_displays_postage(
|
2018-12-21 12:51:05 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
mock_get_template_folders,
|
|
|
|
|
|
single_letter_contact_block,
|
|
|
|
|
|
mock_has_jobs,
|
|
|
|
|
|
active_user_with_permissions,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
2018-12-21 14:29:35 +00:00
|
|
|
|
template_postage,
|
|
|
|
|
|
expected_result
|
2018-12-21 12:51:05 +00:00
|
|
|
|
):
|
|
|
|
|
|
mocker.patch('app.main.views.templates.get_page_count_for_letter', return_value=1)
|
|
|
|
|
|
client_request.login(active_user_with_permissions)
|
2020-01-08 09:10:04 +00:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.service_api_client.get_service_template',
|
|
|
|
|
|
return_value={'data': create_template(template_type='letter', postage=template_postage)}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2018-12-21 12:51:05 +00:00
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
2019-04-30 16:32:20 +01:00
|
|
|
|
_test_page_title=False,
|
2018-12-21 12:51:05 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2019-02-05 16:19:17 +00:00
|
|
|
|
assert normalize_spaces(page.select_one('.letter-postage').text) == expected_result
|
2018-12-21 12:51:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_view_non_letter_template_does_not_display_postage(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2018-12-21 12:51:05 +00:00
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_get_template_folders,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2018-12-21 12:51:05 +00:00
|
|
|
|
'.view_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
2019-04-30 16:32:20 +01:00
|
|
|
|
_test_page_title=False,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
)
|
2018-12-21 12:51:05 +00:00
|
|
|
|
assert "Postage" not in page.text
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-27 16:52:09 +01:00
|
|
|
|
def test_view_letter_template_does_not_display_send_button_if_template_over_10_pages_long(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
mock_get_template_folders,
|
|
|
|
|
|
single_letter_contact_block,
|
|
|
|
|
|
mock_has_jobs,
|
|
|
|
|
|
active_user_with_permissions,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
mocker.patch('app.main.views.templates.get_page_count_for_letter', return_value=11)
|
|
|
|
|
|
client_request.login(active_user_with_permissions)
|
2020-01-08 09:10:04 +00:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.service_api_client.get_service_template',
|
|
|
|
|
|
return_value={'data': create_template(template_type='letter', postage='second')}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2019-09-27 16:52:09 +01:00
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert "Send" not in page.text
|
2019-10-25 16:53:31 +01:00
|
|
|
|
assert page.find('h1', {"data-error-type": "letter-too-long"})
|
2019-09-27 16:52:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
2019-01-29 15:43:59 +00:00
|
|
|
|
def test_edit_letter_template_postage_page_displays_correctly(
|
2018-12-21 14:50:07 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
mocker,
|
2020-01-06 15:29:21 +00:00
|
|
|
|
mock_get_service_letter_template,
|
2018-12-21 14:50:07 +00:00
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
2019-01-29 15:43:59 +00:00
|
|
|
|
'main.edit_template_postage',
|
2018-12-21 14:50:07 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2019-02-06 16:37:16 +00:00
|
|
|
|
assert page.select_one('h1').text.strip() == 'Change postage'
|
2019-01-29 15:43:59 +00:00
|
|
|
|
assert page.select('input[checked]')[0].attrs["value"] == 'second'
|
2018-12-21 14:50:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-01-29 15:43:59 +00:00
|
|
|
|
def test_edit_letter_template_postage_page_404s_if_template_is_not_a_letter(
|
|
|
|
|
|
client_request,
|
2018-12-21 15:51:24 +00:00
|
|
|
|
service_one,
|
2019-01-29 15:43:59 +00:00
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
active_user_with_permissions,
|
2018-12-21 15:51:24 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2019-01-29 15:43:59 +00:00
|
|
|
|
client_request.login(active_user_with_permissions)
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.edit_template_postage',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=404
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert page.select_one('h1').text.strip() != 'Edit postage'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_edit_letter_templates_postage_updates_postage(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2019-01-29 15:43:59 +00:00
|
|
|
|
service_one,
|
|
|
|
|
|
mocker,
|
2020-01-06 15:29:21 +00:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_letter_template,
|
2019-01-29 15:43:59 +00:00
|
|
|
|
):
|
|
|
|
|
|
mock_update_template_postage = mocker.patch(
|
|
|
|
|
|
'app.main.views.templates.service_api_client.update_service_template_postage'
|
|
|
|
|
|
)
|
2018-12-21 15:51:24 +00:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.post(
|
|
|
|
|
|
'main.edit_template_postage',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={'postage': 'first'},
|
2018-12-21 15:51:24 +00:00
|
|
|
|
)
|
2019-01-29 15:43:59 +00:00
|
|
|
|
mock_update_template_postage.assert_called_with(
|
2018-12-21 15:51:24 +00:00
|
|
|
|
SERVICE_ONE_ID,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
fake_uuid,
|
2019-01-29 15:43:59 +00:00
|
|
|
|
"first"
|
2018-12-21 15:51:24 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-12 15:46:54 +00:00
|
|
|
|
@pytest.mark.parametrize('permissions, links_to_be_shown, permissions_warning_to_be_shown', [
|
2017-03-10 16:46:28 +00:00
|
|
|
|
(
|
|
|
|
|
|
['view_activity'],
|
2018-03-12 15:46:54 +00:00
|
|
|
|
[],
|
|
|
|
|
|
'If you need to send this text message or edit this template, contact your manager.'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
['manage_api_keys'],
|
|
|
|
|
|
[],
|
|
|
|
|
|
None,
|
2017-03-10 16:46:28 +00:00
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
['manage_templates'],
|
2018-03-12 15:46:54 +00:00
|
|
|
|
['.edit_service_template'],
|
|
|
|
|
|
None,
|
2017-03-10 16:46:28 +00:00
|
|
|
|
),
|
|
|
|
|
|
(
|
2018-02-28 17:22:20 +00:00
|
|
|
|
['send_messages', 'manage_templates'],
|
2018-07-18 09:56:21 +01:00
|
|
|
|
['.set_sender', '.edit_service_template'],
|
2018-03-12 15:46:54 +00:00
|
|
|
|
None,
|
2017-03-10 16:46:28 +00:00
|
|
|
|
),
|
|
|
|
|
|
])
|
|
|
|
|
|
def test_should_be_able_to_view_a_template_with_links(
|
2019-04-30 16:32:20 +01:00
|
|
|
|
client_request,
|
2017-03-10 16:46:28 +00:00
|
|
|
|
mock_get_service_template,
|
2018-11-16 14:09:14 +00:00
|
|
|
|
mock_get_template_folders,
|
2017-03-10 16:46:28 +00:00
|
|
|
|
active_user_with_permissions,
|
2017-10-05 15:47:12 +01:00
|
|
|
|
single_letter_contact_block,
|
2017-03-10 16:46:28 +00:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
permissions,
|
|
|
|
|
|
links_to_be_shown,
|
2018-03-12 15:46:54 +00:00
|
|
|
|
permissions_warning_to_be_shown,
|
2017-03-10 16:46:28 +00:00
|
|
|
|
):
|
Make user API client return JSON, not a model
The data flow of other bits of our application looks like this:
```
API (returns JSON)
⬇
API client (returns a built in type, usually `dict`)
⬇
Model (returns an instance, eg of type `Service`)
⬇
View (returns HTML)
```
The user API client was architected weirdly, in that it returned a model
directly, like this:
```
API (returns JSON)
⬇
API client (returns a model, of type `User`, `InvitedUser`, etc)
⬇
View (returns HTML)
```
This mixing of different layers of the application is bad because it
makes it hard to write model code that doesn’t have circular
dependencies. As our application gets more complicated we will be
relying more on models to manage this complexity, so we should make it
easy, not hard to write them.
It also means that most of our mocking was of the User model, not just
the underlying JSON. So it would have been easy to introduce subtle bugs
to the user model, because it wasn’t being comprehensively tested. A lot
of the changed lines of code in this commit mean changing the tests to
mock only the JSON, which means that the model layer gets implicitly
tested.
For those reasons this commit changes the user API client to return
JSON, not an instance of `User` or other models.
2019-05-23 15:27:35 +01:00
|
|
|
|
active_user_with_permissions['permissions'][SERVICE_ONE_ID] = permissions + ['view_activity']
|
2019-04-30 16:32:20 +01:00
|
|
|
|
client_request.login(active_user_with_permissions)
|
2017-03-10 16:46:28 +00:00
|
|
|
|
|
2019-04-30 16:32:20 +01:00
|
|
|
|
page = client_request.get(
|
2017-03-10 16:46:28 +00:00
|
|
|
|
'.view_template',
|
2019-04-30 16:32:20 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select_one('h1').text) == (
|
2019-06-24 16:02:49 +01:00
|
|
|
|
'Templates Two week reminder'
|
2019-04-30 16:32:20 +01:00
|
|
|
|
)
|
|
|
|
|
|
assert normalize_spaces(page.select_one('title').text) == (
|
|
|
|
|
|
'Two week reminder – Templates – service one – GOV.UK Notify'
|
|
|
|
|
|
)
|
2017-03-10 16:46:28 +00:00
|
|
|
|
|
|
|
|
|
|
links_in_page = page.select('.pill-separate-item')
|
|
|
|
|
|
|
|
|
|
|
|
assert len(links_in_page) == len(links_to_be_shown)
|
|
|
|
|
|
|
|
|
|
|
|
for index, link_to_be_shown in enumerate(links_to_be_shown):
|
|
|
|
|
|
assert links_in_page[index]['href'] == url_for(
|
|
|
|
|
|
link_to_be_shown,
|
2019-04-30 16:32:20 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-03-10 16:46:28 +00:00
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2018-03-12 15:46:54 +00:00
|
|
|
|
assert normalize_spaces(page.select_one('main p').text) == (
|
|
|
|
|
|
permissions_warning_to_be_shown or 'To: phone number'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2017-03-10 16:46:28 +00:00
|
|
|
|
|
2020-07-01 17:43:30 +01:00
|
|
|
|
def test_view_broadcast_template(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_broadcast_template,
|
|
|
|
|
|
mock_get_template_folders,
|
|
|
|
|
|
active_user_with_permissions,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert [
|
|
|
|
|
|
(link.text.strip(), link['href'])
|
|
|
|
|
|
for link in page.select('.pill-separate-item')
|
|
|
|
|
|
] == [
|
2020-07-06 10:53:14 +01:00
|
|
|
|
('Prepare broadcast', url_for(
|
|
|
|
|
|
'.broadcast',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2020-07-09 10:33:50 +01:00
|
|
|
|
template_id=fake_uuid,
|
2020-07-06 10:53:14 +01:00
|
|
|
|
)),
|
2020-07-01 17:43:30 +01:00
|
|
|
|
('Edit', url_for(
|
|
|
|
|
|
'.edit_service_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)),
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
assert (
|
|
|
|
|
|
normalize_spaces(page.select_one('.template-container').text)
|
|
|
|
|
|
) == (
|
|
|
|
|
|
normalize_spaces(page.select_one('.broadcast-message-wrapper').text)
|
|
|
|
|
|
) == (
|
|
|
|
|
|
'This is a test'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-03-10 17:15:34 +00:00
|
|
|
|
def test_should_show_template_id_on_template_page(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-03-10 17:15:34 +00:00
|
|
|
|
mock_get_service_template,
|
2018-11-16 14:09:14 +00:00
|
|
|
|
mock_get_template_folders,
|
2017-03-10 17:15:34 +00:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2017-03-10 17:15:34 +00:00
|
|
|
|
'.view_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
2019-04-30 16:32:20 +01:00
|
|
|
|
_test_page_title=False,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
)
|
2020-02-06 14:47:47 +00:00
|
|
|
|
assert page.select('.api-key__key')[0].text == fake_uuid
|
2017-03-10 17:15:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
2020-07-08 15:49:32 +01:00
|
|
|
|
def test_should_hide_template_id_for_broadcast_templates(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_broadcast_template,
|
|
|
|
|
|
mock_get_template_folders,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert not page.select('.api-key__key')
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-20 12:03:16 +00:00
|
|
|
|
def test_should_show_sms_template_with_downgraded_unicode_characters(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-02-15 13:49:15 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
service_one,
|
2017-10-05 15:47:12 +01:00
|
|
|
|
single_letter_contact_block,
|
2018-11-16 14:09:14 +00:00
|
|
|
|
mock_get_template_folders,
|
2017-02-15 13:49:15 +00:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2017-02-20 12:03:16 +00:00
|
|
|
|
msg = 'here:\tare some “fancy quotes” and zero\u200Bwidth\u200Bspaces'
|
|
|
|
|
|
rendered_msg = 'here: are some "fancy quotes" and zerowidthspaces'
|
2017-02-15 13:49:15 +00:00
|
|
|
|
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.service_api_client.get_service_template',
|
|
|
|
|
|
return_value={'data': template_json(service_one['id'], fake_uuid, type_='sms', content=msg)}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2017-02-15 13:49:15 +00:00
|
|
|
|
'.view_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
2019-04-30 16:32:20 +01:00
|
|
|
|
_test_page_title=False,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
)
|
2017-02-15 13:49:15 +00:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
assert rendered_msg in page.text
|
2017-02-15 13:49:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-12-20 14:34:45 +00:00
|
|
|
|
@pytest.mark.parametrize('contact_block_data, expected_partial_url', (
|
|
|
|
|
|
([], partial(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
url_for, 'main.service_add_letter_contact', from_template=sample_uuid(),
|
2019-07-08 09:31:30 +01:00
|
|
|
|
)),
|
2019-12-20 14:34:45 +00:00
|
|
|
|
([create_letter_contact_block()], partial(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
url_for, 'main.set_template_sender', template_id=sample_uuid(),
|
2019-07-08 09:31:30 +01:00
|
|
|
|
)),
|
|
|
|
|
|
))
|
2018-01-03 10:44:36 +00:00
|
|
|
|
def test_should_let_letter_contact_block_be_changed_for_the_template(
|
2017-12-12 12:16:17 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_letter_template,
|
2018-11-16 14:09:14 +00:00
|
|
|
|
mock_get_template_folders,
|
2017-12-12 12:16:17 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
2019-12-20 14:34:45 +00:00
|
|
|
|
contact_block_data,
|
2019-07-08 09:31:30 +01:00
|
|
|
|
expected_partial_url
|
2017-12-12 12:16:17 +00:00
|
|
|
|
):
|
|
|
|
|
|
mocker.patch('app.main.views.templates.get_page_count_for_letter', return_value=1)
|
2019-12-20 14:34:45 +00:00
|
|
|
|
mocker.patch('app.service_api_client.get_letter_contacts', return_value=contact_block_data)
|
2017-12-12 12:16:17 +00:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2019-04-30 16:32:20 +01:00
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
2017-12-12 12:16:17 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2019-07-08 09:31:30 +01:00
|
|
|
|
assert page.select_one(
|
|
|
|
|
|
'a.edit-template-link-letter-contact'
|
|
|
|
|
|
)['href'] == expected_partial_url(service_id=SERVICE_ONE_ID)
|
2017-12-12 12:16:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-01-18 15:11:34 +00:00
|
|
|
|
def test_should_show_page_template_with_priority_select_if_platform_admin(
|
2019-08-27 16:01:28 +01:00
|
|
|
|
platform_admin_client,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
platform_admin_user,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_template,
|
2019-03-19 16:25:44 +00:00
|
|
|
|
service_one,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
fake_uuid,
|
2017-01-18 15:11:34 +00:00
|
|
|
|
):
|
2017-02-03 12:07:21 +00:00
|
|
|
|
mocker.patch('app.user_api_client.get_users_for_service', return_value=[platform_admin_user])
|
|
|
|
|
|
template_id = fake_uuid
|
2019-08-27 16:01:28 +01:00
|
|
|
|
response = platform_admin_client.get(url_for(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'.edit_service_template',
|
2019-03-19 16:25:44 +00:00
|
|
|
|
service_id=service_one['id'],
|
2018-08-06 11:10:37 +01:00
|
|
|
|
template_id=template_id,
|
|
|
|
|
|
))
|
2017-01-18 15:11:34 +00:00
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
|
assert "Two week reminder" in response.get_data(as_text=True)
|
2017-01-19 12:22:24 +00:00
|
|
|
|
assert "Template <em>content</em> with & entity" in response.get_data(as_text=True)
|
2017-01-18 16:03:30 +00:00
|
|
|
|
assert "Use priority queue?" in response.get_data(as_text=True)
|
2019-03-19 16:25:44 +00:00
|
|
|
|
mock_get_service_template.assert_called_with(service_one['id'], template_id, None)
|
2015-12-20 00:00:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-04-10 18:12:00 +01:00
|
|
|
|
@pytest.mark.parametrize('filetype', ['pdf', 'png'])
|
2016-12-20 14:38:34 +00:00
|
|
|
|
@pytest.mark.parametrize('view, extra_view_args', [
|
2019-11-29 11:40:49 +00:00
|
|
|
|
('no_cookie.view_letter_template_preview', {}),
|
|
|
|
|
|
('no_cookie.view_template_version_preview', {'version': 1}),
|
2016-12-20 14:38:34 +00:00
|
|
|
|
])
|
2016-11-27 18:10:18 +00:00
|
|
|
|
def test_should_show_preview_letter_templates(
|
|
|
|
|
|
view,
|
2016-12-20 14:38:34 +00:00
|
|
|
|
extra_view_args,
|
2017-04-10 18:12:00 +01:00
|
|
|
|
filetype,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
logged_in_client,
|
2016-12-08 11:50:59 +00:00
|
|
|
|
mock_get_service_email_template,
|
2017-02-15 13:49:15 +00:00
|
|
|
|
service_one,
|
2017-04-10 18:12:00 +01:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker
|
2016-11-27 18:10:18 +00:00
|
|
|
|
):
|
2017-04-10 18:12:00 +01:00
|
|
|
|
mocked_preview = mocker.patch(
|
|
|
|
|
|
'app.main.views.templates.TemplatePreview.from_database_object',
|
|
|
|
|
|
return_value='foo'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2017-02-15 13:49:15 +00:00
|
|
|
|
service_id, template_id = service_one['id'], fake_uuid
|
2017-04-10 18:12:00 +01:00
|
|
|
|
|
2017-02-03 12:07:21 +00:00
|
|
|
|
response = logged_in_client.get(url_for(
|
2017-04-10 18:12:00 +01:00
|
|
|
|
view,
|
2016-12-20 14:38:34 +00:00
|
|
|
|
service_id=service_id,
|
|
|
|
|
|
template_id=template_id,
|
2017-04-10 18:12:00 +01:00
|
|
|
|
filetype=filetype,
|
2016-12-20 14:38:34 +00:00
|
|
|
|
**extra_view_args
|
|
|
|
|
|
))
|
2016-11-27 18:10:18 +00:00
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
2017-04-10 18:12:00 +01:00
|
|
|
|
assert response.get_data(as_text=True) == 'foo'
|
2019-03-19 16:25:44 +00:00
|
|
|
|
mock_get_service_email_template.assert_called_with(service_id, template_id, extra_view_args.get('version'))
|
2017-04-10 18:12:00 +01:00
|
|
|
|
assert mocked_preview.call_args[0][0]['id'] == template_id
|
|
|
|
|
|
assert mocked_preview.call_args[0][0]['service'] == service_id
|
|
|
|
|
|
assert mocked_preview.call_args[0][1] == filetype
|
2016-11-27 18:10:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-04-12 12:12:11 +01:00
|
|
|
|
def test_dont_show_preview_letter_templates_for_bad_filetype(
|
|
|
|
|
|
logged_in_client,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid
|
|
|
|
|
|
):
|
|
|
|
|
|
resp = logged_in_client.get(
|
|
|
|
|
|
url_for(
|
2019-11-29 11:40:49 +00:00
|
|
|
|
'no_cookie.view_letter_template_preview',
|
2017-04-12 12:12:11 +01:00
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
filetype='blah'
|
|
|
|
|
|
)
|
2016-12-20 14:38:34 +00:00
|
|
|
|
)
|
2017-04-12 12:12:11 +01:00
|
|
|
|
assert resp.status_code == 404
|
|
|
|
|
|
assert mock_get_service_template.called is False
|
2016-11-27 18:10:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-02-15 14:47:39 +00:00
|
|
|
|
@pytest.mark.parametrize('original_filename, new_filename', [
|
|
|
|
|
|
('geo', 'geo'),
|
|
|
|
|
|
('no-branding', None)
|
|
|
|
|
|
])
|
|
|
|
|
|
def test_letter_branding_preview_image(
|
|
|
|
|
|
mocker,
|
2019-08-27 16:01:28 +01:00
|
|
|
|
platform_admin_client,
|
2019-02-15 14:47:39 +00:00
|
|
|
|
original_filename,
|
|
|
|
|
|
new_filename,
|
|
|
|
|
|
):
|
|
|
|
|
|
mocked_preview = mocker.patch(
|
|
|
|
|
|
'app.main.views.templates.TemplatePreview.from_example_template',
|
|
|
|
|
|
return_value='foo'
|
|
|
|
|
|
)
|
2019-08-27 16:01:28 +01:00
|
|
|
|
resp = platform_admin_client.get(
|
2019-11-29 11:40:49 +00:00
|
|
|
|
url_for('no_cookie.letter_branding_preview_image', filename=original_filename)
|
2019-02-15 14:47:39 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2020-04-21 10:59:35 +01:00
|
|
|
|
mocked_preview.assert_called_with(
|
|
|
|
|
|
{
|
|
|
|
|
|
'subject': 'An example letter',
|
|
|
|
|
|
'content': ANY,
|
|
|
|
|
|
'template_type': 'letter',
|
|
|
|
|
|
},
|
|
|
|
|
|
new_filename,
|
|
|
|
|
|
)
|
2019-02-15 14:47:39 +00:00
|
|
|
|
assert resp.get_data(as_text=True) == 'foo'
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-19 12:30:04 +01:00
|
|
|
|
def test_choosing_to_copy_redirects(
|
|
|
|
|
|
client_request,
|
2018-11-28 13:48:13 +00:00
|
|
|
|
service_one,
|
2018-07-19 12:30:04 +01:00
|
|
|
|
mock_get_service_templates,
|
2018-11-28 13:48:13 +00:00
|
|
|
|
mock_get_template_folders,
|
2018-07-19 12:30:04 +01:00
|
|
|
|
):
|
|
|
|
|
|
client_request.post(
|
2019-02-11 16:09:08 +00:00
|
|
|
|
'main.choose_template',
|
2018-07-19 12:30:04 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2019-02-11 16:09:08 +00:00
|
|
|
|
_data={
|
|
|
|
|
|
'operation': 'add-new-template',
|
|
|
|
|
|
'add_template_by_template_type': 'copy-existing'
|
|
|
|
|
|
},
|
2018-11-28 13:48:13 +00:00
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.choose_template_to_copy',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
),
|
2018-07-19 12:30:04 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_choose_a_template_to_copy(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_templates,
|
2019-01-07 14:49:33 +00:00
|
|
|
|
mock_get_template_folders,
|
2019-06-12 12:09:26 +01:00
|
|
|
|
mock_get_just_services_for_user,
|
2018-07-19 12:30:04 +01:00
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_template_to_copy',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2019-01-07 14:49:33 +00:00
|
|
|
|
assert page.select('.folder-heading') == []
|
|
|
|
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
|
|
(
|
|
|
|
|
|
'Service 1 '
|
|
|
|
|
|
'6 templates'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-06-24 16:02:49 +01:00
|
|
|
|
'Service 1 sms_template_one '
|
2019-01-07 14:49:33 +00:00
|
|
|
|
'Text message template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-06-24 16:02:49 +01:00
|
|
|
|
'Service 1 sms_template_two '
|
2019-01-07 14:49:33 +00:00
|
|
|
|
'Text message template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-06-24 16:02:49 +01:00
|
|
|
|
'Service 1 email_template_one '
|
2019-01-07 14:49:33 +00:00
|
|
|
|
'Email template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-06-24 16:02:49 +01:00
|
|
|
|
'Service 1 email_template_two '
|
2019-01-07 14:49:33 +00:00
|
|
|
|
'Email template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-06-24 16:02:49 +01:00
|
|
|
|
'Service 1 letter_template_one '
|
2019-01-07 14:49:33 +00:00
|
|
|
|
'Letter template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-06-24 16:02:49 +01:00
|
|
|
|
'Service 1 letter_template_two '
|
2019-01-07 14:49:33 +00:00
|
|
|
|
'Letter template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'Service 2 '
|
|
|
|
|
|
'6 templates'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-06-24 16:02:49 +01:00
|
|
|
|
'Service 2 sms_template_one '
|
2019-01-07 14:49:33 +00:00
|
|
|
|
'Text message template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-06-24 16:02:49 +01:00
|
|
|
|
'Service 2 sms_template_two '
|
2019-01-07 14:49:33 +00:00
|
|
|
|
'Text message template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-06-24 16:02:49 +01:00
|
|
|
|
'Service 2 email_template_one '
|
2019-01-07 14:49:33 +00:00
|
|
|
|
'Email template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-06-24 16:02:49 +01:00
|
|
|
|
'Service 2 email_template_two '
|
2019-01-07 14:49:33 +00:00
|
|
|
|
'Email template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-06-24 16:02:49 +01:00
|
|
|
|
'Service 2 letter_template_one '
|
2019-01-07 14:49:33 +00:00
|
|
|
|
'Letter template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-06-24 16:02:49 +01:00
|
|
|
|
'Service 2 letter_template_two '
|
2019-01-07 14:49:33 +00:00
|
|
|
|
'Letter template'
|
|
|
|
|
|
),
|
|
|
|
|
|
]
|
|
|
|
|
|
actual = page.select('.template-list-item')
|
|
|
|
|
|
|
|
|
|
|
|
assert len(actual) == len(expected)
|
|
|
|
|
|
|
|
|
|
|
|
for actual, expected in zip(actual, expected):
|
|
|
|
|
|
assert normalize_spaces(actual.text) == expected
|
|
|
|
|
|
|
|
|
|
|
|
links = page.select('main nav a')
|
|
|
|
|
|
assert links[0]['href'] == url_for(
|
|
|
|
|
|
'main.choose_template_to_copy',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_TWO_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert links[1]['href'] == url_for(
|
|
|
|
|
|
'main.choose_template_to_copy',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_TWO_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert links[2]['href'] == url_for(
|
|
|
|
|
|
'main.copy_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=TEMPLATE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_TWO_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_choose_a_template_to_copy_when_user_has_one_service(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
mock_get_template_folders,
|
|
|
|
|
|
mock_get_empty_organisations_and_one_service_for_user,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_template_to_copy',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert page.select('.folder-heading') == []
|
|
|
|
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
|
|
(
|
|
|
|
|
|
'sms_template_one '
|
|
|
|
|
|
'Text message template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'sms_template_two '
|
|
|
|
|
|
'Text message template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'email_template_one '
|
|
|
|
|
|
'Email template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'email_template_two '
|
|
|
|
|
|
'Email template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'letter_template_one '
|
|
|
|
|
|
'Letter template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'letter_template_two '
|
|
|
|
|
|
'Letter template'
|
|
|
|
|
|
),
|
|
|
|
|
|
]
|
|
|
|
|
|
actual = page.select('.template-list-item')
|
|
|
|
|
|
|
|
|
|
|
|
assert len(actual) == len(expected)
|
|
|
|
|
|
|
|
|
|
|
|
for actual, expected in zip(actual, expected):
|
|
|
|
|
|
assert normalize_spaces(actual.text) == expected
|
|
|
|
|
|
|
|
|
|
|
|
assert page.select('main nav a')[0]['href'] == url_for(
|
2018-07-19 12:30:04 +01:00
|
|
|
|
'main.copy_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=TEMPLATE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_TWO_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-07 14:49:33 +00:00
|
|
|
|
def test_choose_a_template_to_copy_from_folder_within_service(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_template_folders,
|
|
|
|
|
|
mock_get_non_empty_organisations_and_services_for_user,
|
|
|
|
|
|
):
|
|
|
|
|
|
mock_get_template_folders.return_value = [
|
|
|
|
|
|
_folder('Parent folder', PARENT_FOLDER_ID),
|
|
|
|
|
|
_folder('Child folder empty', CHILD_FOLDER_ID, parent=PARENT_FOLDER_ID),
|
|
|
|
|
|
_folder('Child folder non-empty', FOLDER_TWO_ID, parent=PARENT_FOLDER_ID),
|
|
|
|
|
|
]
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.service_api_client.get_service_templates',
|
|
|
|
|
|
return_value={'data': [
|
|
|
|
|
|
_template(
|
|
|
|
|
|
'sms',
|
|
|
|
|
|
'Should not appear in list (at service root)',
|
|
|
|
|
|
),
|
|
|
|
|
|
_template(
|
|
|
|
|
|
'sms',
|
|
|
|
|
|
'Should appear in list (at same level)',
|
|
|
|
|
|
parent=PARENT_FOLDER_ID,
|
|
|
|
|
|
),
|
|
|
|
|
|
_template(
|
|
|
|
|
|
'sms',
|
|
|
|
|
|
'Should appear in list (nested)',
|
|
|
|
|
|
parent=FOLDER_TWO_ID,
|
|
|
|
|
|
template_id=TEMPLATE_ONE_ID,
|
|
|
|
|
|
),
|
|
|
|
|
|
]}
|
|
|
|
|
|
)
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_template_to_copy',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_ONE_ID,
|
|
|
|
|
|
from_folder=PARENT_FOLDER_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select_one('.folder-heading').text) == (
|
2019-06-24 16:02:49 +01:00
|
|
|
|
'service one Parent folder'
|
2019-01-07 14:49:33 +00:00
|
|
|
|
)
|
|
|
|
|
|
breadcrumb_links = page.select('.folder-heading a')
|
|
|
|
|
|
assert len(breadcrumb_links) == 1
|
|
|
|
|
|
assert breadcrumb_links[0]['href'] == url_for(
|
|
|
|
|
|
'main.choose_template_to_copy',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
|
|
(
|
|
|
|
|
|
'Child folder empty '
|
|
|
|
|
|
'Empty'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'Child folder non-empty '
|
|
|
|
|
|
'1 template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-06-24 16:02:49 +01:00
|
|
|
|
'Child folder non-empty Should appear in list (nested) '
|
2019-01-07 14:49:33 +00:00
|
|
|
|
'Text message template'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'Should appear in list (at same level) '
|
|
|
|
|
|
'Text message template'
|
|
|
|
|
|
),
|
|
|
|
|
|
]
|
|
|
|
|
|
actual = page.select('.template-list-item')
|
|
|
|
|
|
|
|
|
|
|
|
assert len(actual) == len(expected)
|
|
|
|
|
|
|
|
|
|
|
|
for actual, expected in zip(actual, expected):
|
|
|
|
|
|
assert normalize_spaces(actual.text) == expected
|
|
|
|
|
|
|
|
|
|
|
|
links = page.select('main nav a')
|
|
|
|
|
|
assert links[0]['href'] == url_for(
|
|
|
|
|
|
'main.choose_template_to_copy',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_ONE_ID,
|
|
|
|
|
|
from_folder=CHILD_FOLDER_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert links[1]['href'] == url_for(
|
|
|
|
|
|
'main.choose_template_to_copy',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_ONE_ID,
|
|
|
|
|
|
from_folder=FOLDER_TWO_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert links[2]['href'] == url_for(
|
|
|
|
|
|
'main.choose_template_to_copy',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
from_folder=FOLDER_TWO_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert links[3]['href'] == url_for(
|
|
|
|
|
|
'main.copy_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=TEMPLATE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-13 15:06:39 +00:00
|
|
|
|
@pytest.mark.parametrize('existing_template_names, expected_name', (
|
|
|
|
|
|
(
|
|
|
|
|
|
['Two week reminder'],
|
|
|
|
|
|
'Two week reminder (copy)'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
['Two week reminder (copy)'],
|
|
|
|
|
|
'Two week reminder (copy 2)'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
['Two week reminder', 'Two week reminder (copy)'],
|
|
|
|
|
|
'Two week reminder (copy 2)'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
['Two week reminder (copy 8)', 'Two week reminder (copy 9)'],
|
|
|
|
|
|
'Two week reminder (copy 10)'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
['Two week reminder (copy)', 'Two week reminder (copy 9)'],
|
|
|
|
|
|
'Two week reminder (copy 10)'
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
['Two week reminder (copy)', 'Two week reminder (copy 10)'],
|
|
|
|
|
|
'Two week reminder (copy 2)'
|
|
|
|
|
|
),
|
|
|
|
|
|
))
|
2018-07-19 12:30:04 +01:00
|
|
|
|
def test_load_edit_template_with_copy_of_template(
|
|
|
|
|
|
client_request,
|
2019-01-07 14:49:33 +00:00
|
|
|
|
active_user_with_permission_to_two_services,
|
2018-11-13 15:06:39 +00:00
|
|
|
|
mock_get_service_templates,
|
2018-07-19 12:30:04 +01:00
|
|
|
|
mock_get_service_email_template,
|
|
|
|
|
|
mock_get_non_empty_organisations_and_services_for_user,
|
2018-11-13 15:06:39 +00:00
|
|
|
|
existing_template_names,
|
|
|
|
|
|
expected_name,
|
2018-07-19 12:30:04 +01:00
|
|
|
|
):
|
2018-11-13 15:06:39 +00:00
|
|
|
|
mock_get_service_templates.side_effect = lambda service_id: {'data': [
|
|
|
|
|
|
{'name': existing_template_name, 'template_type': 'sms'}
|
|
|
|
|
|
for existing_template_name in existing_template_names
|
|
|
|
|
|
]}
|
2019-01-07 14:49:33 +00:00
|
|
|
|
client_request.login(active_user_with_permission_to_two_services)
|
2018-07-19 12:30:04 +01:00
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.copy_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=TEMPLATE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_TWO_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert page.select_one('form')['method'] == 'post'
|
|
|
|
|
|
|
|
|
|
|
|
assert page.select_one('input')['value'] == (
|
2018-11-13 15:06:39 +00:00
|
|
|
|
expected_name
|
2018-07-19 12:30:04 +01:00
|
|
|
|
)
|
|
|
|
|
|
assert page.select_one('textarea').text == (
|
2020-04-22 17:49:03 +01:00
|
|
|
|
'\r\nYour ((thing)) is due soon'
|
2018-07-19 12:30:04 +01:00
|
|
|
|
)
|
|
|
|
|
|
mock_get_service_email_template.assert_called_once_with(
|
|
|
|
|
|
SERVICE_TWO_ID,
|
|
|
|
|
|
TEMPLATE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-03 13:59:44 +01:00
|
|
|
|
def test_copy_template_loads_template_from_within_subfolder(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
active_user_with_permission_to_two_services,
|
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
mock_get_non_empty_organisations_and_services_for_user,
|
|
|
|
|
|
mocker
|
|
|
|
|
|
):
|
|
|
|
|
|
template = template_json(
|
|
|
|
|
|
SERVICE_TWO_ID,
|
|
|
|
|
|
TEMPLATE_ONE_ID,
|
|
|
|
|
|
name='foo',
|
|
|
|
|
|
folder=PARENT_FOLDER_ID
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
mock_get_service_template = mocker.patch(
|
|
|
|
|
|
'app.service_api_client.get_service_template',
|
|
|
|
|
|
return_value={'data': template}
|
|
|
|
|
|
)
|
|
|
|
|
|
mock_get_template_folder = mocker.patch(
|
|
|
|
|
|
'app.template_folder_api_client.get_template_folder',
|
|
|
|
|
|
return_value=_folder('Parent folder', PARENT_FOLDER_ID),
|
|
|
|
|
|
)
|
|
|
|
|
|
client_request.login(active_user_with_permission_to_two_services)
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.copy_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=TEMPLATE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_TWO_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert page.select_one('input')['value'] == 'foo (copy)'
|
|
|
|
|
|
mock_get_service_template.assert_called_once_with(SERVICE_TWO_ID, TEMPLATE_ONE_ID)
|
|
|
|
|
|
mock_get_template_folder.assert_called_once_with(SERVICE_TWO_ID, PARENT_FOLDER_ID)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-19 12:30:04 +01:00
|
|
|
|
def test_cant_copy_template_from_non_member_service(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_email_template,
|
|
|
|
|
|
mock_get_organisations_and_services_for_user,
|
|
|
|
|
|
):
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.copy_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=TEMPLATE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_TWO_ID,
|
|
|
|
|
|
_expected_status=403,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert mock_get_service_email_template.call_args_list == []
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-01 16:43:08 +01:00
|
|
|
|
@pytest.mark.parametrize('service_permissions, data, expected_error', (
|
2018-11-28 13:48:13 +00:00
|
|
|
|
(
|
2020-07-01 16:43:08 +01:00
|
|
|
|
['letter'],
|
2018-11-28 13:48:13 +00:00
|
|
|
|
{
|
2018-12-04 14:47:05 +00:00
|
|
|
|
'operation': 'add-new-template',
|
2018-11-28 13:48:13 +00:00
|
|
|
|
'add_template_by_template_type': 'email',
|
|
|
|
|
|
},
|
|
|
|
|
|
"Sending emails has been disabled for your service."
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2020-07-01 16:43:08 +01:00
|
|
|
|
['email'],
|
2018-11-28 13:48:13 +00:00
|
|
|
|
{
|
2018-12-04 14:47:05 +00:00
|
|
|
|
'operation': 'add-new-template',
|
2018-11-28 13:48:13 +00:00
|
|
|
|
'add_template_by_template_type': 'sms',
|
|
|
|
|
|
},
|
|
|
|
|
|
"Sending text messages has been disabled for your service."
|
|
|
|
|
|
),
|
2020-07-01 16:43:08 +01:00
|
|
|
|
(
|
|
|
|
|
|
['sms'],
|
|
|
|
|
|
{
|
|
|
|
|
|
'operation': 'add-new-template',
|
|
|
|
|
|
'add_template_by_template_type': 'letter',
|
|
|
|
|
|
},
|
|
|
|
|
|
"Sending letters has been disabled for your service."
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
['letter'],
|
|
|
|
|
|
{
|
|
|
|
|
|
'operation': 'add-new-template',
|
|
|
|
|
|
'add_template_by_template_type': 'broadcast',
|
|
|
|
|
|
},
|
|
|
|
|
|
"Sending broadcasts has been disabled for your service."
|
|
|
|
|
|
),
|
2018-11-28 13:48:13 +00:00
|
|
|
|
))
|
2017-06-30 10:55:59 +01:00
|
|
|
|
def test_should_not_allow_creation_of_template_through_form_without_correct_permission(
|
2018-11-28 13:48:13 +00:00
|
|
|
|
client_request,
|
2017-06-30 10:55:59 +01:00
|
|
|
|
service_one,
|
2018-07-19 12:30:04 +01:00
|
|
|
|
mock_get_service_templates,
|
2018-11-28 13:48:13 +00:00
|
|
|
|
mock_get_template_folders,
|
2020-07-01 16:43:08 +01:00
|
|
|
|
service_permissions,
|
2018-11-28 13:48:13 +00:00
|
|
|
|
data,
|
|
|
|
|
|
expected_error,
|
2019-11-04 11:07:55 +00:00
|
|
|
|
fake_uuid,
|
2017-06-30 10:55:59 +01:00
|
|
|
|
):
|
2020-07-01 16:43:08 +01:00
|
|
|
|
service_one['permissions'] = service_permissions
|
2018-11-28 13:48:13 +00:00
|
|
|
|
page = client_request.post(
|
2020-07-01 16:43:08 +01:00
|
|
|
|
'main.choose_template',
|
2018-11-28 13:48:13 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
_data=data,
|
|
|
|
|
|
_follow_redirects=True,
|
2020-07-01 16:43:08 +01:00
|
|
|
|
_expected_status=403,
|
2018-11-28 13:48:13 +00:00
|
|
|
|
)
|
|
|
|
|
|
assert normalize_spaces(page.select('main p')[0].text) == expected_error
|
2019-04-29 11:44:05 +01:00
|
|
|
|
assert page.select(".govuk-back-link")[0].text == "Back"
|
|
|
|
|
|
assert page.select(".govuk-back-link")[0]['href'] == url_for(
|
2019-02-11 16:09:08 +00:00
|
|
|
|
'.choose_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-06-30 10:55:59 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-01 16:43:08 +01:00
|
|
|
|
@pytest.mark.parametrize('method', ('get', 'post'))
|
|
|
|
|
|
@pytest.mark.parametrize('type_of_template, expected_error', [
|
|
|
|
|
|
('email', 'Sending emails has been disabled for your service.'),
|
|
|
|
|
|
('sms', 'Sending text messages has been disabled for your service.'),
|
|
|
|
|
|
('letter', 'Sending letters has been disabled for your service.'),
|
|
|
|
|
|
('broadcast', 'Sending broadcasts has been disabled for your service.'),
|
|
|
|
|
|
])
|
2017-06-30 10:55:59 +01:00
|
|
|
|
def test_should_not_allow_creation_of_a_template_without_correct_permission(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-06-30 10:55:59 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
mocker,
|
2020-07-01 16:43:08 +01:00
|
|
|
|
method,
|
2017-06-30 10:55:59 +01:00
|
|
|
|
type_of_template,
|
2020-07-01 16:43:08 +01:00
|
|
|
|
expected_error,
|
2017-06-30 10:55:59 +01:00
|
|
|
|
):
|
|
|
|
|
|
service_one['permissions'] = []
|
|
|
|
|
|
|
2020-07-01 16:43:08 +01:00
|
|
|
|
page = getattr(client_request, method)(
|
2017-06-30 10:55:59 +01:00
|
|
|
|
'.add_service_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_type=type_of_template,
|
|
|
|
|
|
_follow_redirects=True,
|
2020-07-01 16:43:08 +01:00
|
|
|
|
_expected_status=403,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
)
|
2020-07-01 16:43:08 +01:00
|
|
|
|
assert page.select('main p')[0].text.strip() == expected_error
|
2019-04-29 11:44:05 +01:00
|
|
|
|
assert page.select(".govuk-back-link")[0].text == "Back"
|
|
|
|
|
|
assert page.select(".govuk-back-link")[0]['href'] == url_for(
|
2017-06-30 10:55:59 +01:00
|
|
|
|
'.choose_template',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-08 09:10:04 +00:00
|
|
|
|
@pytest.mark.parametrize('template_type, expected_status_code', [
|
|
|
|
|
|
('email', 200),
|
|
|
|
|
|
('sms', 200),
|
|
|
|
|
|
('letter', 302),
|
2017-10-16 16:35:35 +01:00
|
|
|
|
])
|
2017-11-02 12:07:46 +00:00
|
|
|
|
def test_should_redirect_to_one_off_if_template_type_is_letter(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-10-16 16:35:35 +01:00
|
|
|
|
multiple_reply_to_email_addresses,
|
2017-11-02 12:07:46 +00:00
|
|
|
|
multiple_sms_senders,
|
2017-10-16 16:35:35 +01:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
2020-01-08 09:10:04 +00:00
|
|
|
|
template_type,
|
2017-10-16 16:35:35 +01:00
|
|
|
|
expected_status_code
|
|
|
|
|
|
):
|
2020-01-08 09:10:04 +00:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.service_api_client.get_service_template',
|
|
|
|
|
|
return_value={'data': create_template(template_type=template_type)}
|
|
|
|
|
|
)
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.get(
|
|
|
|
|
|
'.set_sender',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=expected_status_code,
|
2017-10-16 16:35:35 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_should_redirect_when_saving_a_template(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_get_service_template,
|
2019-11-12 16:57:01 +00:00
|
|
|
|
mock_get_api_keys,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_update_service_template,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2017-02-03 12:07:21 +00:00
|
|
|
|
name = "new name"
|
|
|
|
|
|
content = "template <em>content</em> with & entity"
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.post(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'.edit_service_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={
|
|
|
|
|
|
'id': fake_uuid,
|
|
|
|
|
|
'name': name,
|
|
|
|
|
|
'template_content': content,
|
|
|
|
|
|
'template_type': 'sms',
|
|
|
|
|
|
'service': SERVICE_ONE_ID,
|
|
|
|
|
|
'process_type': 'normal',
|
|
|
|
|
|
},
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
mock_update_service_template.assert_called_with(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
fake_uuid, name, 'sms', content, SERVICE_ONE_ID, None, 'normal',
|
|
|
|
|
|
)
|
2017-01-18 15:11:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_edit_content_when_process_type_is_priority_not_platform_admin(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_get_service_template_with_priority,
|
|
|
|
|
|
mock_update_service_template,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.post(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'.edit_service_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={
|
|
|
|
|
|
'id': fake_uuid,
|
|
|
|
|
|
'name': "new name",
|
|
|
|
|
|
'template_content': "new template <em>content</em> with & entity",
|
|
|
|
|
|
'template_type': 'sms',
|
|
|
|
|
|
'service': SERVICE_ONE_ID,
|
|
|
|
|
|
'process_type': 'priority',
|
|
|
|
|
|
},
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
mock_update_service_template.assert_called_with(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
fake_uuid,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
"new name",
|
|
|
|
|
|
'sms',
|
|
|
|
|
|
"new template <em>content</em> with & entity",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
SERVICE_ONE_ID,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
None,
|
2019-01-29 16:39:47 +00:00
|
|
|
|
'priority'
|
2017-02-03 12:07:21 +00:00
|
|
|
|
)
|
2017-01-18 15:11:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-06-30 10:55:59 +01:00
|
|
|
|
def test_should_not_allow_template_edits_without_correct_permission(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-06-30 10:55:59 +01:00
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
service_one['permissions'] = ['email']
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2017-06-30 10:55:59 +01:00
|
|
|
|
'.edit_service_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_follow_redirects=True,
|
2020-07-01 16:43:08 +01:00
|
|
|
|
_expected_status=403,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
)
|
2017-06-30 10:55:59 +01:00
|
|
|
|
|
2017-07-10 12:25:01 +01:00
|
|
|
|
assert page.select('main p')[0].text.strip() == "Sending text messages has been disabled for your service."
|
2019-04-29 11:44:05 +01:00
|
|
|
|
assert page.select(".govuk-back-link")[0].text == "Back"
|
|
|
|
|
|
assert page.select(".govuk-back-link")[0]['href'] == url_for(
|
2017-06-30 10:55:59 +01:00
|
|
|
|
'.view_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
2017-06-30 10:55:59 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-01-18 15:11:34 +00:00
|
|
|
|
def test_should_403_when_edit_template_with_process_type_of_priority_for_non_platform_admin(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
client,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
active_user_with_permissions,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_update_service_template,
|
|
|
|
|
|
fake_uuid,
|
2019-12-20 14:34:45 +00:00
|
|
|
|
service_one,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
):
|
2019-12-20 14:34:45 +00:00
|
|
|
|
service_one['users'] = [active_user_with_permissions]
|
|
|
|
|
|
client.login(active_user_with_permissions, mocker, service_one)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
mocker.patch('app.user_api_client.get_users_for_service', return_value=[active_user_with_permissions])
|
|
|
|
|
|
template_id = fake_uuid
|
|
|
|
|
|
data = {
|
|
|
|
|
|
'id': template_id,
|
|
|
|
|
|
'name': "new name",
|
|
|
|
|
|
'template_content': "template <em>content</em> with & entity",
|
|
|
|
|
|
'template_type': 'sms',
|
2019-12-20 14:34:45 +00:00
|
|
|
|
'service': service_one['id'],
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'process_type': 'priority'
|
|
|
|
|
|
}
|
|
|
|
|
|
response = client.post(url_for(
|
|
|
|
|
|
'.edit_service_template',
|
2019-12-20 14:34:45 +00:00
|
|
|
|
service_id=service_one['id'],
|
2017-02-03 12:07:21 +00:00
|
|
|
|
template_id=template_id), data=data)
|
|
|
|
|
|
assert response.status_code == 403
|
|
|
|
|
|
mock_update_service_template.called == 0
|
2017-01-18 15:11:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_403_when_create_template_with_process_type_of_priority_for_non_platform_admin(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
client,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
active_user_with_permissions,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_update_service_template,
|
|
|
|
|
|
fake_uuid,
|
2019-12-20 14:34:45 +00:00
|
|
|
|
service_one,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
):
|
2019-12-20 14:34:45 +00:00
|
|
|
|
service_one['users'] = [active_user_with_permissions]
|
|
|
|
|
|
client.login(active_user_with_permissions, mocker, service_one)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
mocker.patch('app.user_api_client.get_users_for_service', return_value=[active_user_with_permissions])
|
|
|
|
|
|
template_id = fake_uuid
|
|
|
|
|
|
data = {
|
|
|
|
|
|
'id': template_id,
|
|
|
|
|
|
'name': "new name",
|
|
|
|
|
|
'template_content': "template <em>content</em> with & entity",
|
|
|
|
|
|
'template_type': 'sms',
|
2019-12-20 14:34:45 +00:00
|
|
|
|
'service': service_one['id'],
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'process_type': 'priority'
|
|
|
|
|
|
}
|
|
|
|
|
|
response = client.post(url_for(
|
|
|
|
|
|
'.add_service_template',
|
2019-12-20 14:34:45 +00:00
|
|
|
|
service_id=service_one['id'],
|
2017-02-03 12:07:21 +00:00
|
|
|
|
template_type='sms'), data=data)
|
|
|
|
|
|
assert response.status_code == 403
|
|
|
|
|
|
mock_update_service_template.called == 0
|
2016-04-14 14:08:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
2019-11-20 12:01:26 +00:00
|
|
|
|
@pytest.mark.parametrize('old_content, new_content, expected_paragraphs', [
|
2017-04-06 10:22:09 +01:00
|
|
|
|
(
|
2019-11-20 12:01:26 +00:00
|
|
|
|
"my favourite colour is blue",
|
|
|
|
|
|
"my favourite colour is ((colour))",
|
2017-04-06 10:22:09 +01:00
|
|
|
|
[
|
2019-11-20 12:01:26 +00:00
|
|
|
|
'You added ((colour))',
|
|
|
|
|
|
'Before you send any messages, make sure your API calls include colour.',
|
2017-04-06 10:22:09 +01:00
|
|
|
|
]
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-11-20 12:01:26 +00:00
|
|
|
|
"hello ((name))",
|
2019-11-20 13:52:00 +00:00
|
|
|
|
"hello ((first name)) ((middle name)) ((last name))",
|
2017-04-06 10:22:09 +01:00
|
|
|
|
[
|
2019-11-20 12:01:26 +00:00
|
|
|
|
'You removed ((name))',
|
2019-11-20 13:52:00 +00:00
|
|
|
|
'You added ((first name)) ((middle name)) and ((last name))',
|
|
|
|
|
|
'Before you send any messages, make sure your API calls include first name, middle name and last name.',
|
2017-04-06 10:22:09 +01:00
|
|
|
|
]
|
|
|
|
|
|
),
|
|
|
|
|
|
])
|
2016-05-27 16:21:29 +01:00
|
|
|
|
def test_should_show_interstitial_when_making_breaking_change(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_update_service_template,
|
|
|
|
|
|
mock_get_user_by_email,
|
2019-11-12 16:57:01 +00:00
|
|
|
|
mock_get_api_keys,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
fake_uuid,
|
2017-04-06 10:22:09 +01:00
|
|
|
|
mocker,
|
2019-11-20 12:01:26 +00:00
|
|
|
|
new_content,
|
|
|
|
|
|
old_content,
|
2017-04-06 10:22:09 +01:00
|
|
|
|
expected_paragraphs,
|
2016-05-27 16:21:29 +01:00
|
|
|
|
):
|
2020-01-08 09:10:04 +00:00
|
|
|
|
email_template = create_template(
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
template_type='email',
|
2017-04-06 10:22:09 +01:00
|
|
|
|
subject="Your ((thing)) is due soon",
|
2020-01-08 09:10:04 +00:00
|
|
|
|
content=old_content
|
2017-04-06 10:22:09 +01:00
|
|
|
|
)
|
2020-01-08 09:10:04 +00:00
|
|
|
|
mocker.patch('app.service_api_client.get_service_template', return_value={'data': email_template})
|
|
|
|
|
|
|
2018-12-19 17:06:09 +00:00
|
|
|
|
data = {
|
2019-03-26 12:35:32 +00:00
|
|
|
|
'id': fake_uuid,
|
2018-12-19 17:06:09 +00:00
|
|
|
|
'name': "new name",
|
2019-11-20 12:01:26 +00:00
|
|
|
|
'template_content': new_content,
|
|
|
|
|
|
'template_type': 'email',
|
|
|
|
|
|
'subject': 'reminder \'" <span> & ((thing))',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
'service': SERVICE_ONE_ID,
|
2018-12-19 17:06:09 +00:00
|
|
|
|
'process_type': 'normal'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'.edit_service_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data=data,
|
|
|
|
|
|
_expected_status=200,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert page.h1.string.strip() == "Confirm changes"
|
2019-04-29 11:44:05 +01:00
|
|
|
|
assert page.find('a', {'class': 'govuk-back-link'})['href'] == url_for(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
".edit_service_template",
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
2019-11-20 12:01:26 +00:00
|
|
|
|
assert [
|
|
|
|
|
|
normalize_spaces(paragraph.text) for paragraph in page.select('main p')
|
|
|
|
|
|
] == expected_paragraphs
|
2017-03-06 13:08:27 +00:00
|
|
|
|
|
2017-02-03 12:07:21 +00:00
|
|
|
|
for key, value in {
|
|
|
|
|
|
'name': 'new name',
|
2019-11-20 12:01:26 +00:00
|
|
|
|
'subject': 'reminder \'" <span> & ((thing))',
|
|
|
|
|
|
'template_content': new_content,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'confirm': 'true'
|
|
|
|
|
|
}.items():
|
|
|
|
|
|
assert page.find('input', {'name': key})['value'] == value
|
2016-05-27 16:21:29 +01:00
|
|
|
|
|
2017-04-14 08:52:02 +01:00
|
|
|
|
# BeautifulSoup returns the value attribute as unencoded, let’s make
|
|
|
|
|
|
# sure that it is properly encoded in the HTML
|
|
|
|
|
|
assert str(page.find('input', {'name': 'subject'})) == (
|
2019-11-20 12:01:26 +00:00
|
|
|
|
"""<input name="subject" type="hidden" value="reminder '" <span> & ((thing))"/>"""
|
2017-04-14 08:52:02 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2016-05-27 16:21:29 +01:00
|
|
|
|
|
2017-05-17 13:05:18 +01:00
|
|
|
|
def test_removing_placeholders_is_not_a_breaking_change(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-05-17 13:05:18 +01:00
|
|
|
|
mock_get_service_email_template,
|
|
|
|
|
|
mock_update_service_template,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
existing_template = mock_get_service_email_template(0, 0)['data']
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.post(
|
|
|
|
|
|
'.edit_service_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={
|
2017-05-17 13:05:18 +01:00
|
|
|
|
'name': existing_template['name'],
|
|
|
|
|
|
'template_content': "no placeholders",
|
|
|
|
|
|
'subject': existing_template['subject'],
|
2019-03-26 12:35:32 +00:00
|
|
|
|
},
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
),
|
2017-05-17 13:05:18 +01:00
|
|
|
|
)
|
2019-03-26 12:35:32 +00:00
|
|
|
|
assert mock_update_service_template.called is True
|
2017-05-17 13:05:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_should_not_create_too_big_template(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_create_service_template_content_too_big,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.post(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'.add_service_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_type='sms',
|
|
|
|
|
|
_data={
|
|
|
|
|
|
'name': "new name",
|
|
|
|
|
|
'template_content': "template content",
|
|
|
|
|
|
'template_type': 'sms',
|
|
|
|
|
|
'service': SERVICE_ONE_ID,
|
|
|
|
|
|
'process_type': 'normal'
|
|
|
|
|
|
},
|
|
|
|
|
|
_expected_status=200,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert "Content has a character count greater than the limit of 459" in page.text
|
2016-04-29 09:38:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_should_not_update_too_big_template(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_update_service_template_400_content_too_big,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.post(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'.edit_service_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={
|
|
|
|
|
|
'id': fake_uuid,
|
|
|
|
|
|
'name': "new name",
|
|
|
|
|
|
'template_content': "template content",
|
|
|
|
|
|
'service': SERVICE_ONE_ID,
|
|
|
|
|
|
'template_type': 'sms',
|
|
|
|
|
|
'process_type': 'normal',
|
|
|
|
|
|
},
|
|
|
|
|
|
_expected_status=200,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert "Content has a character count greater than the limit of 459" in page.text
|
2016-04-29 09:38:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_should_redirect_when_saving_a_template_email(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_get_service_email_template,
|
|
|
|
|
|
mock_update_service_template,
|
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2017-02-03 12:07:21 +00:00
|
|
|
|
name = "new name"
|
|
|
|
|
|
content = "template <em>content</em> with & entity ((thing)) ((date))"
|
2017-04-14 08:52:02 +01:00
|
|
|
|
subject = "subject & entity"
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.post(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'.edit_service_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={
|
|
|
|
|
|
'id': fake_uuid,
|
|
|
|
|
|
'name': name,
|
|
|
|
|
|
'template_content': content,
|
|
|
|
|
|
'template_type': 'email',
|
|
|
|
|
|
'service': SERVICE_ONE_ID,
|
|
|
|
|
|
'subject': subject,
|
|
|
|
|
|
'process_type': 'normal'
|
|
|
|
|
|
},
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
mock_update_service_template.assert_called_with(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
fake_uuid, name, 'email', content, SERVICE_ONE_ID, subject, 'normal',
|
|
|
|
|
|
)
|
2016-01-14 09:44:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_should_show_delete_template_page_with_time_block(
|
2017-07-24 14:50:56 +01:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_get_service_template,
|
2018-11-16 14:09:14 +00:00
|
|
|
|
mock_get_template_folders,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mocker,
|
2017-07-24 14:50:56 +01:00
|
|
|
|
fake_uuid
|
2017-02-03 10:42:01 +00:00
|
|
|
|
):
|
2020-02-05 13:52:46 +00:00
|
|
|
|
mocker.patch('app.template_statistics_client.get_last_used_date_for_template',
|
|
|
|
|
|
return_value='2012-01-01 12:00:00')
|
2017-02-03 12:07:21 +00:00
|
|
|
|
|
|
|
|
|
|
with freeze_time('2012-01-01 12:10:00'):
|
2017-07-24 14:50:56 +01:00
|
|
|
|
page = client_request.get(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'.delete_service_template',
|
2017-07-24 14:50:56 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
2018-11-15 17:14:03 +00:00
|
|
|
|
assert "Are you sure you want to delete ‘Two week reminder’?" in page.select('.banner-dangerous')[0].text
|
2017-07-24 14:50:56 +01:00
|
|
|
|
assert normalize_spaces(page.select('.banner-dangerous p')[0].text) == (
|
2018-11-16 11:03:16 +00:00
|
|
|
|
'This template was last used 10 minutes ago.'
|
2017-07-26 12:04:07 +01:00
|
|
|
|
)
|
|
|
|
|
|
assert normalize_spaces(page.select('.sms-message-wrapper')[0].text) == (
|
|
|
|
|
|
'service one: Template <em>content</em> with & entity'
|
|
|
|
|
|
)
|
2019-03-19 16:25:44 +00:00
|
|
|
|
mock_get_service_template.assert_called_with(SERVICE_ONE_ID, fake_uuid, None)
|
2017-07-26 12:04:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_show_delete_template_page_with_time_block_for_empty_notification(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template,
|
2018-11-16 14:09:14 +00:00
|
|
|
|
mock_get_template_folders,
|
2017-07-26 12:04:07 +01:00
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid
|
|
|
|
|
|
):
|
2020-02-05 13:52:46 +00:00
|
|
|
|
mocker.patch('app.template_statistics_client.get_last_used_date_for_template',
|
|
|
|
|
|
return_value=None)
|
2017-07-26 12:04:07 +01:00
|
|
|
|
|
|
|
|
|
|
with freeze_time('2012-01-01 11:00:00'):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'.delete_service_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
2018-11-15 17:14:03 +00:00
|
|
|
|
assert "Are you sure you want to delete ‘Two week reminder’?" in page.select('.banner-dangerous')[0].text
|
2017-07-26 12:04:07 +01:00
|
|
|
|
assert normalize_spaces(page.select('.banner-dangerous p')[0].text) == (
|
2020-02-04 16:00:51 +00:00
|
|
|
|
'This template has never been used.'
|
2017-07-24 14:50:56 +01:00
|
|
|
|
)
|
|
|
|
|
|
assert normalize_spaces(page.select('.sms-message-wrapper')[0].text) == (
|
|
|
|
|
|
'service one: Template <em>content</em> with & entity'
|
|
|
|
|
|
)
|
2019-03-19 16:25:44 +00:00
|
|
|
|
mock_get_service_template.assert_called_with(SERVICE_ONE_ID, fake_uuid, None)
|
2016-08-24 12:09:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_should_show_delete_template_page_with_never_used_block(
|
2017-07-24 14:50:56 +01:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_get_service_template,
|
2018-11-16 14:09:14 +00:00
|
|
|
|
mock_get_template_folders,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
):
|
2017-02-03 12:07:21 +00:00
|
|
|
|
mocker.patch(
|
2020-02-05 13:52:46 +00:00
|
|
|
|
'app.template_statistics_client.get_last_used_date_for_template',
|
2017-02-03 12:07:21 +00:00
|
|
|
|
side_effect=HTTPError(response=Mock(status_code=404), message="Default message")
|
|
|
|
|
|
)
|
2017-07-24 14:50:56 +01:00
|
|
|
|
page = client_request.get(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'.delete_service_template',
|
2017-07-24 14:50:56 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
2018-11-15 17:14:03 +00:00
|
|
|
|
assert "Are you sure you want to delete ‘Two week reminder’?" in page.select('.banner-dangerous')[0].text
|
2017-07-24 14:55:39 +01:00
|
|
|
|
assert not page.select('.banner-dangerous p')
|
2017-07-24 14:50:56 +01:00
|
|
|
|
assert normalize_spaces(page.select('.sms-message-wrapper')[0].text) == (
|
|
|
|
|
|
'service one: Template <em>content</em> with & entity'
|
|
|
|
|
|
)
|
2019-03-19 16:25:44 +00:00
|
|
|
|
mock_get_service_template.assert_called_with(SERVICE_ONE_ID, fake_uuid, None)
|
2016-01-14 09:44:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-02-13 17:46:35 +00:00
|
|
|
|
@pytest.mark.parametrize('parent', (
|
|
|
|
|
|
PARENT_FOLDER_ID, None
|
|
|
|
|
|
))
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_should_redirect_when_deleting_a_template(
|
2019-02-13 17:46:35 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_delete_service_template,
|
2019-03-20 17:26:51 +00:00
|
|
|
|
mock_get_template_folders,
|
2019-02-13 17:46:35 +00:00
|
|
|
|
parent,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
):
|
2019-03-20 17:26:51 +00:00
|
|
|
|
|
|
|
|
|
|
mock_get_template_folders.return_value = [
|
2019-04-02 15:23:46 +01:00
|
|
|
|
{'id': PARENT_FOLDER_ID, 'name': 'Folder', 'parent': None, 'users_with_permission': [ANY]}
|
2019-03-20 17:26:51 +00:00
|
|
|
|
]
|
2019-02-13 17:46:35 +00:00
|
|
|
|
mock_get_service_template = mocker.patch(
|
|
|
|
|
|
'app.service_api_client.get_service_template',
|
|
|
|
|
|
return_value={'data': _template(
|
|
|
|
|
|
'sms', 'Hello', parent=parent,
|
|
|
|
|
|
)},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
client_request.post(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'.delete_service_template',
|
2019-02-13 17:46:35 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=TEMPLATE_ONE_ID,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'.choose_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_folder_id=parent,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
|
|
|
|
|
|
mock_get_service_template.assert_called_with(
|
2019-03-19 16:25:44 +00:00
|
|
|
|
SERVICE_ONE_ID, TEMPLATE_ONE_ID, None
|
2019-02-13 17:46:35 +00:00
|
|
|
|
)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
mock_delete_service_template.assert_called_with(
|
2019-02-13 17:46:35 +00:00
|
|
|
|
SERVICE_ONE_ID, TEMPLATE_ONE_ID
|
|
|
|
|
|
)
|
2016-03-09 12:10:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-07-01 13:10:19 +01:00
|
|
|
|
@freeze_time('2016-01-01T15:00')
|
|
|
|
|
|
def test_should_show_page_for_a_deleted_template(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2018-11-16 14:09:14 +00:00
|
|
|
|
mock_get_template_folders,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_get_deleted_template,
|
2017-10-05 15:47:12 +01:00
|
|
|
|
single_letter_contact_block,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_get_user,
|
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
fake_uuid,
|
2016-07-01 13:10:19 +01:00
|
|
|
|
):
|
2017-02-03 12:07:21 +00:00
|
|
|
|
template_id = fake_uuid
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'.view_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=template_id,
|
2019-04-30 16:32:20 +01:00
|
|
|
|
_test_page_title=False,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
)
|
2016-07-01 13:10:19 +01:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
content = str(page)
|
|
|
|
|
|
assert url_for("main.edit_service_template", service_id=SERVICE_ONE_ID, template_id=fake_uuid) not in content
|
|
|
|
|
|
assert url_for("main.send_test", service_id=SERVICE_ONE_ID, template_id=fake_uuid) not in content
|
2017-03-13 10:55:15 +00:00
|
|
|
|
assert page.select('p.hint')[0].text.strip() == 'This template was deleted today at 3:00pm.'
|
2017-10-18 11:36:26 +01:00
|
|
|
|
assert 'Delete this template' not in page.select_one('main').text
|
2016-07-01 13:10:19 +01:00
|
|
|
|
|
2019-03-19 16:25:44 +00:00
|
|
|
|
mock_get_deleted_template.assert_called_with(SERVICE_ONE_ID, template_id, None)
|
2016-07-01 13:10:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
2016-06-14 11:01:33 +01:00
|
|
|
|
@pytest.mark.parametrize('route', [
|
|
|
|
|
|
'main.add_service_template',
|
|
|
|
|
|
'main.edit_service_template',
|
|
|
|
|
|
'main.delete_service_template'
|
|
|
|
|
|
])
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_route_permissions(
|
|
|
|
|
|
route,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
app_,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
client,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_service_template,
|
2018-11-16 14:09:14 +00:00
|
|
|
|
mock_get_template_folders,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2020-02-05 13:52:46 +00:00
|
|
|
|
mocker.patch('app.template_statistics_client.get_last_used_date_for_template',
|
|
|
|
|
|
return_value='2012-01-01 12:00:00')
|
2017-02-03 12:07:21 +00:00
|
|
|
|
validate_route_permission(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
app_,
|
|
|
|
|
|
"GET",
|
|
|
|
|
|
200,
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
route,
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_type='sms',
|
|
|
|
|
|
template_id=fake_uuid),
|
|
|
|
|
|
['manage_templates'],
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one)
|
2016-03-09 12:10:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_route_permissions_for_choose_template(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
app_,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
client,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
api_user_active,
|
2018-11-01 17:11:58 +00:00
|
|
|
|
mock_get_template_folders,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
service_one,
|
2018-11-19 15:26:43 +00:00
|
|
|
|
mock_get_service_templates
|
2017-02-03 10:42:01 +00:00
|
|
|
|
):
|
2016-03-30 08:41:07 +01:00
|
|
|
|
mocker.patch('app.job_api_client.get_job')
|
2017-02-03 12:07:21 +00:00
|
|
|
|
validate_route_permission(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
app_,
|
|
|
|
|
|
"GET",
|
|
|
|
|
|
200,
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=service_one['id'],
|
Merge email, text message + letter templates pages
Right now we have separate pages for email and text message templates.
In the future we will also have a separate page for letter templates.
This commit changes Notify to only have one page for all templates.
What is the problem?
---
The left-hand navigation is getting quite crowded, at 8 items for a
service that can send letters. Research suggests that the number of
objects an average human can hold in working memory is 7 ± 2 [1]. So
we’re at the limit of how many items the navigation should have.
In the future we will need to search/sort/filter templates by attributes
other than type, for example:
- show me the ‘confirmation’ templates
- show me the most recently used templates
- show me all templates containing the placeholder `((ref_no))`
These are hypothetical for now, but these needs (or others) may become
real in the future. At this point pre-filtering the list of templates
by type would restrict what searches a user could do. So by making this
change now we’re in a better position to iterate the design in the
future.
What’s the change?
---
This commit replaces the ‘Email templates’, ‘Text message templates’ and
‘Letter templates’ pages with one page called ‘Templates’.
This new templates page shows all the templates for the service, sorted
by most recently created first (as before).
To add a new template there is a new page with a form asking you what
kind of template you want to create. This is necessary because in the
past we knew what kind of template you wanted to create based on the
kind you were looking at.
What’s the impact of this change on new users?
---
This change alters the onboarding process slightly. We still want to
take people through the empty templates page from the call-to-action on
the dashboard because it helps them understand that to send a message
using Notify you need a template. But because we don’t have separate
pages for emails/text messages we will have to send users through the
extra step of choosing what kind of template to create. This is a bit
clunkier on first use but:
- it still gets the point across
- it takes them through the actual flow they will be using to create new
templates in the future (ie they’re learning how to use Notify, not
just being taken through a special onboarding route)
I’m not too worried about this change in terms of the experience for new
users. Furthermore, by making it now we get to validate whether it’s
causing any problems in the lab research booked for next week.
What’s the impact of this change on current services?
---
Looking at the top 15 services by number of templates[2], most are using
either text messages or emails. So this change would not have a
significant impact on these services because the page will not get any
longer. In other words we wouldn’t be making it worse for them.
Those services who do use both are not using as many templates. The
worst-case scenario is SSCS, who have 16 templates, evenly split between
email and text messages. So they would go from having 8 templates per
page to 16, which is still less than half the number that HMPO or
Digital Marketplace are managing.
References
---
1. https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two
2. Template usage by service
Service name | Template count | Template types
---------------------------------------|----------------|---------------
Her Majesty's Passport Office | 40 | sms
Digital Marketplace | 40 | email
GovWifi-Staging | 19 | sms
GovWifi | 18 | sms
Digital Apprenticeship Service | 16 | email
SSCS | 16 | both
Crown Commercial Service MI Collection | 15 | email
Help with Prison Visits | 12 | both
Digital Future | 12 | email
Export Licensing Service | 11 | email
Civil Money Claims | 9 | both
DVLA Drivers Medical Service | 9 | sms
GOV.UK Notify | 8 | both
Manage your benefit overpayments | 8 | both
Tax Renewals | 8 | both
2017-02-28 12:16:35 +00:00
|
|
|
|
),
|
2018-11-19 15:26:43 +00:00
|
|
|
|
[],
|
2017-02-03 12:07:21 +00:00
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one)
|
2016-03-29 13:23:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
2016-06-14 11:01:33 +01:00
|
|
|
|
@pytest.mark.parametrize('route', [
|
|
|
|
|
|
'main.add_service_template',
|
|
|
|
|
|
'main.edit_service_template',
|
|
|
|
|
|
'main.delete_service_template'
|
|
|
|
|
|
])
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_route_invalid_permissions(
|
|
|
|
|
|
route,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
app_,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
client,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2017-02-03 12:07:21 +00:00
|
|
|
|
validate_route_permission(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
app_,
|
|
|
|
|
|
"GET",
|
|
|
|
|
|
403,
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
route,
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_type='sms',
|
|
|
|
|
|
template_id=fake_uuid),
|
|
|
|
|
|
['view_activity'],
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one)
|
2016-06-06 11:42:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-02-15 15:06:47 +00:00
|
|
|
|
def test_can_create_email_template_with_emoji(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-02-15 15:06:47 +00:00
|
|
|
|
mock_create_service_template
|
|
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.post(
|
2017-02-15 15:06:47 +00:00
|
|
|
|
'.add_service_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_type='email',
|
|
|
|
|
|
_data={
|
|
|
|
|
|
'name': "new name",
|
|
|
|
|
|
'subject': "Food incoming!",
|
|
|
|
|
|
'template_content': "here's a burrito 🌯",
|
|
|
|
|
|
'template_type': 'email',
|
|
|
|
|
|
'service': SERVICE_ONE_ID,
|
|
|
|
|
|
'process_type': 'normal'
|
|
|
|
|
|
},
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert mock_create_service_template.called is True
|
2017-02-15 15:06:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
2020-07-03 15:46:00 +01:00
|
|
|
|
@pytest.mark.parametrize('template_type, expected_error', (
|
|
|
|
|
|
('sms', (
|
|
|
|
|
|
'You cannot use 🍜 in text messages.'
|
|
|
|
|
|
)),
|
|
|
|
|
|
('broadcast', (
|
|
|
|
|
|
'You cannot use 🍜 in broadcasts.'
|
|
|
|
|
|
)),
|
2020-07-01 16:43:08 +01:00
|
|
|
|
))
|
|
|
|
|
|
def test_should_not_create_sms_or_broadcast_template_with_emoji(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-02-15 13:49:15 +00:00
|
|
|
|
service_one,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
mock_create_service_template,
|
2020-07-01 16:43:08 +01:00
|
|
|
|
template_type,
|
2020-07-03 15:46:00 +01:00
|
|
|
|
expected_error,
|
2017-02-15 13:49:15 +00:00
|
|
|
|
):
|
2020-07-01 16:43:08 +01:00
|
|
|
|
service_one['permissions'] += [template_type]
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.post(
|
2017-02-15 13:49:15 +00:00
|
|
|
|
'.add_service_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2020-07-01 16:43:08 +01:00
|
|
|
|
template_type=template_type,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
_data={
|
|
|
|
|
|
'name': "new name",
|
|
|
|
|
|
'template_content': "here are some noodles 🍜",
|
|
|
|
|
|
'template_type': 'sms',
|
|
|
|
|
|
'service': SERVICE_ONE_ID,
|
|
|
|
|
|
'process_type': 'normal',
|
|
|
|
|
|
},
|
|
|
|
|
|
_expected_status=200,
|
|
|
|
|
|
)
|
2020-07-03 15:46:00 +01:00
|
|
|
|
assert expected_error in page.text
|
2019-03-26 12:35:32 +00:00
|
|
|
|
assert mock_create_service_template.called is False
|
2017-02-15 13:49:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
2020-07-03 15:46:00 +01:00
|
|
|
|
@pytest.mark.parametrize('template_type, expected_error', (
|
|
|
|
|
|
('sms', (
|
|
|
|
|
|
'You cannot use 🍔 in text messages.'
|
|
|
|
|
|
)),
|
|
|
|
|
|
('broadcast', (
|
|
|
|
|
|
'You cannot use 🍔 in broadcasts.'
|
|
|
|
|
|
)),
|
2020-07-01 16:43:08 +01:00
|
|
|
|
))
|
2017-02-15 13:49:15 +00:00
|
|
|
|
def test_should_not_update_sms_template_with_emoji(
|
2020-07-03 15:46:00 +01:00
|
|
|
|
mocker,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2020-07-01 16:43:08 +01:00
|
|
|
|
service_one,
|
2017-02-15 13:49:15 +00:00
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_update_service_template,
|
|
|
|
|
|
fake_uuid,
|
2020-07-01 16:43:08 +01:00
|
|
|
|
template_type,
|
2020-07-03 15:46:00 +01:00
|
|
|
|
expected_error,
|
2017-02-15 13:49:15 +00:00
|
|
|
|
):
|
2020-07-01 16:43:08 +01:00
|
|
|
|
service_one['permissions'] += [template_type]
|
2020-07-03 15:46:00 +01:00
|
|
|
|
return mocker.patch(
|
|
|
|
|
|
'app.service_api_client.get_service_template',
|
|
|
|
|
|
return_value=template_json(
|
|
|
|
|
|
SERVICE_ONE_ID,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
type_=template_type,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.post(
|
2017-02-15 13:49:15 +00:00
|
|
|
|
'.edit_service_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={
|
|
|
|
|
|
'id': fake_uuid,
|
|
|
|
|
|
'name': "new name",
|
|
|
|
|
|
'template_content': "here's a burger 🍔",
|
|
|
|
|
|
'service': SERVICE_ONE_ID,
|
2020-07-01 16:43:08 +01:00
|
|
|
|
'template_type': template_type,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
'process_type': 'normal'
|
|
|
|
|
|
},
|
|
|
|
|
|
_expected_status=200,
|
|
|
|
|
|
)
|
2020-07-03 15:46:00 +01:00
|
|
|
|
assert expected_error in page.text
|
2019-03-26 12:35:32 +00:00
|
|
|
|
assert mock_update_service_template.called is False
|
2017-02-15 13:49:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
2020-07-01 16:43:08 +01:00
|
|
|
|
@pytest.mark.parametrize('template_type', (
|
|
|
|
|
|
'sms', 'broadcast'
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_should_create_sms_or_broadcast_template_without_downgrading_unicode_characters(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2020-07-01 16:43:08 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
mock_create_service_template,
|
|
|
|
|
|
template_type,
|
2017-02-15 13:49:15 +00:00
|
|
|
|
):
|
2020-07-01 16:43:08 +01:00
|
|
|
|
service_one['permissions'] += [template_type]
|
|
|
|
|
|
|
2017-02-15 13:49:15 +00:00
|
|
|
|
msg = 'here:\tare some “fancy quotes” and non\u200Bbreaking\u200Bspaces'
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.post(
|
2017-02-15 13:49:15 +00:00
|
|
|
|
'.add_service_template',
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_type='sms',
|
|
|
|
|
|
_data={
|
|
|
|
|
|
'name': "new name",
|
|
|
|
|
|
'template_content': msg,
|
2020-07-01 16:43:08 +01:00
|
|
|
|
'template_type': template_type,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
'service': SERVICE_ONE_ID,
|
|
|
|
|
|
'process_type': 'normal'
|
|
|
|
|
|
},
|
|
|
|
|
|
expected_status=302,
|
|
|
|
|
|
)
|
2017-02-15 13:49:15 +00:00
|
|
|
|
|
|
|
|
|
|
mock_create_service_template.assert_called_with(
|
|
|
|
|
|
ANY, # name
|
|
|
|
|
|
ANY, # type
|
|
|
|
|
|
msg, # content
|
|
|
|
|
|
ANY, # service_id
|
|
|
|
|
|
ANY, # subject
|
2018-11-08 15:53:33 +00:00
|
|
|
|
ANY, # process_type
|
|
|
|
|
|
ANY, # parent_folder_id
|
2017-02-15 13:49:15 +00:00
|
|
|
|
)
|
2017-06-26 14:41:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-06-29 10:02:53 +01:00
|
|
|
|
def test_should_show_template_as_first_page_of_tour(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.start_tour',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(
|
|
|
|
|
|
page.select('.banner-tour .heading-medium')[0].text
|
|
|
|
|
|
) == (
|
|
|
|
|
|
'Try sending yourself this example'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(
|
|
|
|
|
|
page.select('.sms-message-wrapper')[0].text
|
|
|
|
|
|
) == (
|
|
|
|
|
|
'service one: Template <em>content</em> with & entity'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2020-01-30 14:01:13 +00:00
|
|
|
|
assert page.select('a.govuk-button')[0]['href'] == url_for(
|
2017-06-29 10:02:53 +01:00
|
|
|
|
'.send_test', service_id=SERVICE_ONE_ID, template_id=fake_uuid, help=2
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-08 09:10:04 +00:00
|
|
|
|
@pytest.mark.parametrize('template_type', ['email', 'letter'])
|
2017-06-29 10:02:53 +01:00
|
|
|
|
def test_cant_see_email_template_in_tour(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
2020-01-08 09:10:04 +00:00
|
|
|
|
template_type,
|
2017-06-29 10:02:53 +01:00
|
|
|
|
):
|
2020-01-08 09:10:04 +00:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.service_api_client.get_service_template',
|
|
|
|
|
|
return_value={'data': create_template(template_type=template_type)}
|
|
|
|
|
|
)
|
2017-06-29 10:02:53 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.start_tour',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=404,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-26 14:41:00 +01:00
|
|
|
|
def test_should_show_message_before_redacting_template(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.redact_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
2017-07-24 14:50:56 +01:00
|
|
|
|
_test_page_title=False,
|
2017-06-26 14:41:00 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert (
|
|
|
|
|
|
'Are you sure you want to hide personalisation after sending?'
|
|
|
|
|
|
) in page.select('.banner-dangerous')[0].text
|
|
|
|
|
|
|
|
|
|
|
|
form = page.select('.banner-dangerous form')[0]
|
|
|
|
|
|
|
|
|
|
|
|
assert 'action' not in form
|
|
|
|
|
|
assert form['method'] == 'post'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_show_redact_template(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template,
|
2018-11-16 14:09:14 +00:00
|
|
|
|
mock_get_template_folders,
|
2017-06-26 14:41:00 +01:00
|
|
|
|
mock_redact_template,
|
2017-10-05 15:47:12 +01:00
|
|
|
|
single_letter_contact_block,
|
2017-06-26 14:41:00 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.redact_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select('.banner-default-with-tick')[0].text) == (
|
|
|
|
|
|
'Personalised content will be hidden for messages sent with this template'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
mock_redact_template.assert_called_once_with(SERVICE_ONE_ID, fake_uuid)
|
2017-06-28 15:26:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_show_hint_once_template_redacted(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
service_one,
|
2018-11-16 14:09:14 +00:00
|
|
|
|
mock_get_template_folders,
|
2017-06-28 15:26:09 +01:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2020-01-08 09:10:04 +00:00
|
|
|
|
template = create_template(template_type='email', content='hi ((name))', redact_personalisation=True)
|
|
|
|
|
|
mocker.patch('app.service_api_client.get_service_template', return_value={'data': template})
|
2017-06-28 15:26:09 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
2019-04-30 16:32:20 +01:00
|
|
|
|
_test_page_title=False,
|
2017-06-28 15:26:09 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert page.select('.hint')[0].text == 'Personalisation is hidden after sending'
|
2017-08-22 11:36:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
2018-06-07 11:03:03 +01:00
|
|
|
|
def test_should_not_show_redaction_stuff_for_letters(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_letter_template,
|
2018-11-16 14:09:14 +00:00
|
|
|
|
mock_get_template_folders,
|
2018-06-07 11:03:03 +01:00
|
|
|
|
single_letter_contact_block,
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
mocker.patch('app.main.views.templates.get_page_count_for_letter', return_value=1)
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
2019-04-30 16:32:20 +01:00
|
|
|
|
_test_page_title=False,
|
2018-06-07 11:03:03 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert page.select('.hint') == []
|
|
|
|
|
|
assert 'personalisation' not in ' '.join(
|
|
|
|
|
|
link.text.lower() for link in page.select('a')
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-08 15:49:32 +01:00
|
|
|
|
def test_should_not_show_redaction_stuff_for_broadcasts(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_broadcast_template,
|
|
|
|
|
|
mock_get_template_folders,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert page.select('.hint') == []
|
|
|
|
|
|
assert 'personalisation' not in ' '.join(
|
|
|
|
|
|
link.text.lower() for link in page.select('a')
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-03 10:44:36 +00:00
|
|
|
|
def test_set_template_sender(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_update_service_template_sender,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
single_letter_contact_block
|
|
|
|
|
|
):
|
|
|
|
|
|
data = {
|
|
|
|
|
|
'sender': '1234',
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
client_request.post(
|
|
|
|
|
|
'main.set_template_sender',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data=data,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
mock_update_service_template_sender.assert_called_once_with(
|
|
|
|
|
|
SERVICE_ONE_ID,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
'1234',
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-12-20 14:34:45 +00:00
|
|
|
|
@pytest.mark.parametrize('contact_block_data', [
|
|
|
|
|
|
[], # no letter contact blocks
|
|
|
|
|
|
[create_letter_contact_block()],
|
2018-01-03 10:44:36 +00:00
|
|
|
|
])
|
|
|
|
|
|
def test_add_sender_link_only_appears_on_services_with_no_senders(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
2019-12-20 14:34:45 +00:00
|
|
|
|
contact_block_data,
|
2018-01-03 10:44:36 +00:00
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
):
|
2019-12-20 14:34:45 +00:00
|
|
|
|
mocker.patch('app.service_api_client.get_letter_contacts', return_value=contact_block_data)
|
2018-01-03 10:44:36 +00:00
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.set_template_sender',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2020-02-20 16:55:56 +00:00
|
|
|
|
assert page.select_one('.govuk-grid-column-three-quarters form > a')['href'] == url_for(
|
2019-07-08 09:54:01 +01:00
|
|
|
|
'main.service_add_letter_contact',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
from_template=fake_uuid,
|
|
|
|
|
|
)
|
2020-01-22 16:13:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_template_sender_escapes_letter_contact_block_names(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_letter_template,
|
|
|
|
|
|
):
|
|
|
|
|
|
letter_contact_block = create_letter_contact_block(contact_block='foo\n\n<script>\n\nbar')
|
|
|
|
|
|
mocker.patch('app.service_api_client.get_letter_contacts', return_value=[letter_contact_block])
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.set_template_sender',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# use decode_contents, which returns the raw html, rather than text, which sanitises it and makes
|
|
|
|
|
|
# testing confusing
|
2020-02-20 16:55:56 +00:00
|
|
|
|
radio_text = page.select_one('.govuk-grid-column-three-quarters label[for="sender-1"]').decode_contents()
|
2020-01-22 16:13:25 +00:00
|
|
|
|
assert "<script>" in radio_text
|
|
|
|
|
|
assert "<script>" not in radio_text
|