2021-01-06 11:54:27 +00:00
|
|
|
|
import json
|
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
|
2021-01-06 11:54:27 +00:00
|
|
|
|
from bs4 import BeautifulSoup
|
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'], (
|
|
|
|
|
|
'You need a template before you can send emails, text messages or letters.'
|
|
|
|
|
|
)),
|
2020-07-14 14:54:55 +01:00
|
|
|
|
(['sms'], (
|
|
|
|
|
|
'You need a template before you can send emails, text messages or letters.'
|
|
|
|
|
|
)),
|
|
|
|
|
|
(['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'], (
|
2020-11-20 17:03:26 +00:00
|
|
|
|
'You haven’t added any templates yet.'
|
2020-07-14 14:52:52 +01:00
|
|
|
|
)),
|
|
|
|
|
|
))
|
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,
|
2021-04-13 13:59:51 +01:00
|
|
|
|
mock_get_no_api_keys,
|
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,
|
2021-04-13 13:59:51 +01:00
|
|
|
|
mock_get_no_api_keys,
|
2019-01-03 10:43:57 +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: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,
|
2021-04-13 13:59:51 +01:00
|
|
|
|
mock_get_no_api_keys,
|
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
|
|
|
|
|
2020-09-04 14:32:07 +01:00
|
|
|
|
links_in_page = page.select('.pill a:not(.pill-item--selected)')
|
2017-06-13 15:28:33 +01:00
|
|
|
|
|
|
|
|
|
|
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-10-27 17:03:01 +00:00
|
|
|
|
template_links = page.select('#template-list .govuk-label a, .template-list-item 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
|
|
|
|
|
|
|
|
|
|
|
2020-10-13 17:37:38 +01:00
|
|
|
|
def test_should_show_page_of_broadcast_templates(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_template_folders,
|
2021-04-13 13:59:51 +01:00
|
|
|
|
mock_get_no_api_keys,
|
2020-10-13 17:37:38 +01:00
|
|
|
|
):
|
|
|
|
|
|
service_one['permissions'] += ['broadcast']
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.service_api_client.get_service_templates',
|
|
|
|
|
|
return_value={'data': [
|
|
|
|
|
|
template_json(
|
|
|
|
|
|
SERVICE_ONE_ID,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
type_='broadcast',
|
|
|
|
|
|
name='A',
|
|
|
|
|
|
content='a' * 40,
|
|
|
|
|
|
),
|
|
|
|
|
|
template_json(
|
|
|
|
|
|
SERVICE_ONE_ID,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
type_='broadcast',
|
|
|
|
|
|
name='B',
|
|
|
|
|
|
content='b' * 42,
|
|
|
|
|
|
),
|
|
|
|
|
|
template_json(
|
|
|
|
|
|
SERVICE_ONE_ID,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
type_='broadcast',
|
|
|
|
|
|
name='C',
|
|
|
|
|
|
content='c' * 43,
|
|
|
|
|
|
),
|
|
|
|
|
|
template_json(
|
|
|
|
|
|
SERVICE_ONE_ID,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
type_='broadcast',
|
|
|
|
|
|
name='D',
|
|
|
|
|
|
# This should be truncated at 40 chars, then have the
|
|
|
|
|
|
# trailing space stripped
|
|
|
|
|
|
content=('d' * 39) + ' ' + ('d' * 40),
|
|
|
|
|
|
),
|
|
|
|
|
|
]}
|
|
|
|
|
|
)
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert [
|
|
|
|
|
|
(
|
|
|
|
|
|
normalize_spaces(template.select_one('.govuk-link').text),
|
|
|
|
|
|
normalize_spaces(template.select_one('.govuk-hint').text),
|
|
|
|
|
|
)
|
|
|
|
|
|
for template in page.select('.template-list-item')
|
|
|
|
|
|
] == [
|
|
|
|
|
|
(
|
|
|
|
|
|
'A', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'B', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'C', 'cccccccccccccccccccccccccccccccccccccccc…',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'D', 'ddddddddddddddddddddddddddddddddddddddd…',
|
|
|
|
|
|
),
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
2021-04-13 13:59:51 +01:00
|
|
|
|
mock_get_no_api_keys,
|
2019-02-14 16:27:13 +00:00
|
|
|
|
):
|
|
|
|
|
|
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,
|
2021-04-13 13:59:51 +01:00
|
|
|
|
mock_get_no_api_keys,
|
2017-06-13 15:27:29 +01:00
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
2021-04-13 13:59:51 +01:00
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
mock_get_no_api_keys,
|
2018-08-16 12:18:07 +01:00
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
2021-04-13 13:59:51 +01:00
|
|
|
|
mock_get_more_service_templates_than_can_fit_onscreen,
|
|
|
|
|
|
mock_get_no_api_keys,
|
2018-08-16 12:18:07 +01:00
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
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'
|
2021-04-13 13:59:51 +01:00
|
|
|
|
assert normalize_spaces(search.select_one('label').text) == (
|
|
|
|
|
|
'Search by name'
|
|
|
|
|
|
)
|
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
|
|
|
|
|
|
|
|
|
|
|
2021-04-13 13:59:51 +01:00
|
|
|
|
def test_should_label_search_by_id_for_services_with_api_keys(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_template_folders,
|
|
|
|
|
|
mock_get_more_service_templates_than_can_fit_onscreen,
|
|
|
|
|
|
mock_get_api_keys,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert normalize_spaces(page.select_one('.live-search label').text) == (
|
|
|
|
|
|
'Search by name or ID'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2021-04-13 13:59:51 +01:00
|
|
|
|
mock_get_no_api_keys,
|
2018-11-20 16:10:14 +00:00
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-10 15:12:07 +01:00
|
|
|
|
@pytest.mark.parametrize('service_permissions, expected_values, expected_labels', (
|
|
|
|
|
|
pytest.param(['email', 'sms'], [
|
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
|
|
|
|
]),
|
2020-08-10 15:12:07 +01:00
|
|
|
|
pytest.param(['broadcast'], [
|
|
|
|
|
|
'broadcast',
|
|
|
|
|
|
], [
|
|
|
|
|
|
'Broadcast',
|
|
|
|
|
|
]),
|
|
|
|
|
|
pytest.param(['email', 'sms', '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,
|
2021-04-13 13:59:51 +01:00
|
|
|
|
mock_get_no_api_keys,
|
2020-08-10 15:12:07 +01:00
|
|
|
|
service_permissions,
|
2018-11-28 13:48:13 +00:00
|
|
|
|
expected_values,
|
|
|
|
|
|
expected_labels,
|
|
|
|
|
|
):
|
2020-08-10 15:12:07 +01:00
|
|
|
|
service_one['permissions'] = service_permissions
|
2018-11-28 13:48:13 +00:00
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-10 15:12:07 +01:00
|
|
|
|
@pytest.mark.parametrize("permissions,are_data_attrs_added", [
|
|
|
|
|
|
(['sms'], True),
|
|
|
|
|
|
(['email'], True),
|
|
|
|
|
|
(['letter'], True),
|
|
|
|
|
|
(['broadcast'], True),
|
|
|
|
|
|
(['sms', 'email'], False),
|
|
|
|
|
|
])
|
|
|
|
|
|
def test_should_add_data_attributes_for_services_that_only_allow_one_type_of_notifications(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
mock_get_template_folders,
|
2021-04-13 13:59:51 +01:00
|
|
|
|
mock_get_no_api_keys,
|
2020-08-10 15:12:07 +01:00
|
|
|
|
permissions,
|
|
|
|
|
|
are_data_attrs_added
|
|
|
|
|
|
):
|
|
|
|
|
|
service_one['permissions'] = permissions
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if not page.select('#add_new_template_form'):
|
|
|
|
|
|
raise ElementNotFound()
|
|
|
|
|
|
|
|
|
|
|
|
if are_data_attrs_added:
|
|
|
|
|
|
assert page.find(id='add_new_template_form').attrs['data-channel'] == permissions[0]
|
|
|
|
|
|
assert page.find(id='add_new_template_form').attrs['data-service'] == SERVICE_ONE_ID
|
|
|
|
|
|
else:
|
|
|
|
|
|
assert page.find(id='add_new_template_form').attrs.get('data-channel') is None
|
|
|
|
|
|
assert page.find(id='add_new_template_form').attrs.get('data-service') is None
|
|
|
|
|
|
|
|
|
|
|
|
|
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'))
|
2021-01-06 17:32:46 +00:00
|
|
|
|
|
|
|
|
|
|
assert (
|
|
|
|
|
|
page.select_one('[data-module=update-status]')['data-target']
|
|
|
|
|
|
) == (
|
|
|
|
|
|
page.select_one('textarea')['id']
|
|
|
|
|
|
) == (
|
|
|
|
|
|
'template_content'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert (
|
|
|
|
|
|
page.select_one('[data-module=update-status]')['data-updates-url']
|
|
|
|
|
|
) == url_for(
|
|
|
|
|
|
'.count_content_length',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_type='sms',
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-01-07 14:30:48 +00:00
|
|
|
|
assert (
|
|
|
|
|
|
page.select_one('[data-module=update-status]')['aria-live']
|
|
|
|
|
|
) == (
|
|
|
|
|
|
'polite'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2021-01-06 17:32:46 +00:00
|
|
|
|
def test_broadcast_template_doesnt_highlight_placeholders_but_does_count_characters(
|
2020-10-05 17:22:06 +01:00
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_broadcast_template,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
service_one['permissions'] += ['broadcast']
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'.edit_service_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
2020-12-24 14:10:37 +00:00
|
|
|
|
assert page.select_one('textarea')['data-module'] == 'enhanced-textbox'
|
2020-10-05 17:22:06 +01:00
|
|
|
|
assert page.select_one('textarea')['data-highlight-placeholders'] == 'false'
|
|
|
|
|
|
|
2021-01-06 17:32:46 +00:00
|
|
|
|
assert (
|
|
|
|
|
|
page.select_one('[data-module=update-status]')['data-target']
|
|
|
|
|
|
) == (
|
|
|
|
|
|
page.select_one('textarea')['id']
|
|
|
|
|
|
) == (
|
|
|
|
|
|
'template_content'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert (
|
|
|
|
|
|
page.select_one('[data-module=update-status]')['data-updates-url']
|
|
|
|
|
|
) == url_for(
|
|
|
|
|
|
'.count_content_length',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_type='broadcast',
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-01-07 14:30:48 +00:00
|
|
|
|
assert (
|
|
|
|
|
|
page.select_one('[data-module=update-status]')['aria-live']
|
|
|
|
|
|
) == (
|
|
|
|
|
|
'polite'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2020-10-05 17:22:06 +01:00
|
|
|
|
|
2021-01-22 18:34:30 +00:00
|
|
|
|
def test_caseworker_redirected_to_set_sender_for_one_off(
|
2018-06-12 16:17:20 +01:00
|
|
|
|
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(
|
2021-01-22 18:34:30 +00:00
|
|
|
|
'main.set_sender',
|
2018-06-12 16:17:20 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-21 16:06:23 +01:00
|
|
|
|
@freeze_time('2020-01-01 15:00')
|
|
|
|
|
|
def test_caseworker_sees_template_page_if_template_is_deleted(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_deleted_template,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
active_caseworking_user,
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
mocker.patch('app.user_api_client.get_user', return_value=active_caseworking_user)
|
|
|
|
|
|
|
|
|
|
|
|
template_id = fake_uuid
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'.view_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=template_id,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
content = str(page)
|
|
|
|
|
|
assert url_for("main.send_one_off", service_id=SERVICE_ONE_ID, template_id=fake_uuid) not in content
|
|
|
|
|
|
assert page.select('p.hint')[0].text.strip() == 'This template was deleted today at 3:00pm.'
|
|
|
|
|
|
|
|
|
|
|
|
mock_get_deleted_template.assert_called_with(SERVICE_ONE_ID, template_id, None)
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-22 18:34:30 +00:00
|
|
|
|
def test_user_with_only_send_and_view_redirected_to_set_sender_for_one_off(
|
2018-08-06 11:09:07 +01:00
|
|
|
|
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,
|
|
|
|
|
|
):
|
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(
|
2021-01-22 18:34:30 +00:00
|
|
|
|
'main.set_sender',
|
2018-08-06 11:09:07 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
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(
|
2022-01-19 15:39:05 +00:00
|
|
|
|
url_for, 'main.letter_branding_request',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID, from_template=TEMPLATE_ONE_ID
|
2020-01-21 16:02:41 +00:00
|
|
|
|
),
|
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),
|
2020-09-09 20:50:05 +01:00
|
|
|
|
'Change postage',
|
2019-01-23 10:17:36 +00:00
|
|
|
|
),
|
|
|
|
|
|
))
|
|
|
|
|
|
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,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
active_user_with_permissions,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
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,
|
2018-12-21 15:51:24 +00:00
|
|
|
|
service_one,
|
|
|
|
|
|
mocker,
|
2020-01-06 15:29:21 +00:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_letter_template,
|
2018-12-21 15:51:24 +00:00
|
|
|
|
):
|
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'],
|
2021-11-24 16:35:34 +00:00
|
|
|
|
[
|
|
|
|
|
|
('.edit_service_template', 'Edit'),
|
|
|
|
|
|
],
|
2018-03-12 15:46:54 +00:00
|
|
|
|
None,
|
2017-03-10 16:46:28 +00:00
|
|
|
|
),
|
|
|
|
|
|
(
|
2018-02-28 17:22:20 +00:00
|
|
|
|
['send_messages', 'manage_templates'],
|
2021-11-24 16:35:34 +00:00
|
|
|
|
[
|
|
|
|
|
|
('.set_sender', 'Get ready to send a message using this template'),
|
|
|
|
|
|
('.edit_service_template', 'Edit'),
|
|
|
|
|
|
],
|
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
|
|
|
|
):
|
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
|
|
|
|
|
2021-11-24 16:35:34 +00:00
|
|
|
|
assert [
|
|
|
|
|
|
(link['href'], normalize_spaces(link.text))
|
|
|
|
|
|
for link in page.select('.pill-separate-item')
|
|
|
|
|
|
] == [
|
|
|
|
|
|
(url_for(
|
|
|
|
|
|
endpoint,
|
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,
|
2021-11-24 16:35:34 +00:00
|
|
|
|
), text)
|
|
|
|
|
|
for endpoint, text in links_to_be_shown
|
|
|
|
|
|
]
|
2017-03-10 16:46:28 +00:00
|
|
|
|
|
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,
|
|
|
|
|
|
fake_uuid,
|
2021-07-22 17:18:07 +01:00
|
|
|
|
active_user_create_broadcasts_permission,
|
2020-07-01 17:43:30 +01:00
|
|
|
|
):
|
2021-07-22 17:18:07 +01:00
|
|
|
|
client_request.login(active_user_create_broadcasts_permission)
|
|
|
|
|
|
active_user_create_broadcasts_permission['permissions'][SERVICE_ONE_ID].append('manage_templates')
|
2020-07-01 17:43:30 +01:00
|
|
|
|
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')
|
|
|
|
|
|
] == [
|
2021-07-05 16:39:48 +01:00
|
|
|
|
('Get ready to send', url_for(
|
2020-07-06 10:53:14 +01:00
|
|
|
|
'.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-08-05 16:45:16 +01:00
|
|
|
|
('Edit this template', url_for(
|
2020-07-01 17:43:30 +01:00
|
|
|
|
'.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)
|
|
|
|
|
|
) == (
|
2020-10-06 10:09:25 +01:00
|
|
|
|
'Emergency alert '
|
2020-07-01 17:43:30 +01:00
|
|
|
|
'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
|
|
|
|
)
|
2021-08-27 17:32:06 +01:00
|
|
|
|
assert fake_uuid in page.select('.copy-to-clipboard__value')[0].text
|
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,
|
|
|
|
|
|
)
|
2021-08-27 17:32:06 +01:00
|
|
|
|
assert not page.select('.copy-to-clipboard__value')
|
2020-07-08 15:49:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2021-07-02 16:25:45 +01:00
|
|
|
|
@pytest.mark.parametrize('prefix_sms', [
|
|
|
|
|
|
True,
|
|
|
|
|
|
pytest.param(False, marks=pytest.mark.xfail())
|
|
|
|
|
|
])
|
|
|
|
|
|
def test_should_show_message_with_prefix_hint_if_enabled_for_service(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
prefix_sms
|
|
|
|
|
|
):
|
|
|
|
|
|
service_one['prefix_sms'] = prefix_sms
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'.edit_service_template',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-07-06 16:30:24 +01:00
|
|
|
|
assert 'Your message will start with your service name' in page.text
|
2021-07-02 16:25:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-01-18 15:11:34 +00:00
|
|
|
|
def test_should_show_page_template_with_priority_select_if_platform_admin(
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request,
|
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
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
|
|
|
|
|
page = client_request.get(
|
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,
|
2021-12-30 16:13:49 +00:00
|
|
|
|
)
|
2017-01-18 15:11:34 +00:00
|
|
|
|
|
2021-12-30 16:13:49 +00:00
|
|
|
|
assert page.select_one('input[name=name]')['value'] == "Two week reminder"
|
|
|
|
|
|
assert "Template <em>content</em> with & entity" in str(page.select_one('textarea'))
|
|
|
|
|
|
assert "Use priority queue?" in page.text
|
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,
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
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
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
response = client_request.get_response(
|
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
|
2021-12-31 12:08:14 +00:00
|
|
|
|
)
|
2016-11-27 18:10:18 +00:00
|
|
|
|
|
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(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2017-04-12 12:12:11 +01:00
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid
|
|
|
|
|
|
):
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request.get_response(
|
|
|
|
|
|
'no_cookie.view_letter_template_preview',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
filetype='blah',
|
|
|
|
|
|
_expected_status=404,
|
2016-12-20 14:38:34 +00:00
|
|
|
|
)
|
2017-04-12 12:12:11 +01:00
|
|
|
|
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,
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
platform_admin_user,
|
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'
|
|
|
|
|
|
)
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
2021-12-31 12:16:12 +00:00
|
|
|
|
resp = client_request.get_response(
|
2021-12-30 16:13:49 +00:00
|
|
|
|
'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,
|
|
|
|
|
|
),
|
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,
|
2021-04-13 13:59:51 +01:00
|
|
|
|
mock_get_no_api_keys,
|
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') == []
|
2018-07-19 12:30:04 +01:00
|
|
|
|
|
2019-01-07 14:49:33 +00:00
|
|
|
|
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)
|
|
|
|
|
|
|
2022-04-06 11:35:14 +01:00
|
|
|
|
for actual, expected in zip(actual, expected): # noqa: B020
|
2019-01-07 14:49:33 +00:00
|
|
|
|
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(
|
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_when_user_has_one_service(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
mock_get_template_folders,
|
2021-04-13 13:59:51 +01:00
|
|
|
|
mock_get_no_api_keys,
|
2019-01-07 14:49:33 +00:00
|
|
|
|
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)
|
|
|
|
|
|
|
2022-04-06 11:35:14 +01:00
|
|
|
|
for actual, expected in zip(actual, expected): # noqa: B020
|
2019-01-07 14:49:33 +00:00
|
|
|
|
assert normalize_spaces(actual.text) == expected
|
|
|
|
|
|
|
|
|
|
|
|
assert page.select('main nav a')[0]['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_from_folder_within_service(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_template_folders,
|
|
|
|
|
|
mock_get_non_empty_organisations_and_services_for_user,
|
2021-04-13 13:59:51 +01:00
|
|
|
|
mock_get_no_api_keys,
|
2019-01-07 14:49:33 +00:00
|
|
|
|
):
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
2022-04-06 11:35:14 +01:00
|
|
|
|
for actual, expected in zip(actual, expected): # noqa: B020
|
2019-01-07 14:49:33 +00:00
|
|
|
|
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,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
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,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
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(
|
2022-01-04 10:56:25 +00:00
|
|
|
|
client_request,
|
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]
|
2022-01-04 10:56:25 +00:00
|
|
|
|
client_request.login(active_user_with_permissions)
|
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'
|
|
|
|
|
|
}
|
2022-01-04 10:56:25 +00:00
|
|
|
|
client_request.post(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'.edit_service_template',
|
2019-12-20 14:34:45 +00:00
|
|
|
|
service_id=service_one['id'],
|
2022-01-04 10:56:25 +00:00
|
|
|
|
template_id=template_id,
|
|
|
|
|
|
_data=data,
|
|
|
|
|
|
_expected_status=403,
|
|
|
|
|
|
)
|
2021-03-08 15:36:23 +00:00
|
|
|
|
assert mock_update_service_template.called is False
|
2017-01-18 15:11:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_403_when_create_template_with_process_type_of_priority_for_non_platform_admin(
|
2022-01-04 10:56:25 +00:00
|
|
|
|
client_request,
|
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]
|
2022-01-04 10:56:25 +00:00
|
|
|
|
client_request.login(active_user_with_permissions, 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'
|
|
|
|
|
|
}
|
2022-01-04 10:56:25 +00:00
|
|
|
|
client_request.post(
|
2017-02-03 12:07:21 +00:00
|
|
|
|
'.add_service_template',
|
2019-12-20 14:34:45 +00:00
|
|
|
|
service_id=service_one['id'],
|
2022-01-04 10:56:25 +00:00
|
|
|
|
template_type='sms',
|
|
|
|
|
|
_data=data,
|
|
|
|
|
|
_expected_status=403,
|
|
|
|
|
|
)
|
2021-03-08 15:36:23 +00:00
|
|
|
|
assert mock_update_service_template.called is False
|
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
|
|
|
|
)
|
2016-05-27 16:21:29 +01:00
|
|
|
|
|
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,
|
|
|
|
|
|
),
|
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
|
|
|
|
|
|
|
|
|
|
|
2020-12-24 13:56:24 +00:00
|
|
|
|
@pytest.mark.parametrize('content, expected_error', (
|
|
|
|
|
|
(("ŴŶ" * 308), (
|
|
|
|
|
|
'Content must be 615 characters or fewer because it contains Ŵ and Ŷ'
|
|
|
|
|
|
)),
|
|
|
|
|
|
(("ab" * 698), (
|
|
|
|
|
|
'Content must be 1,395 characters or fewer'
|
|
|
|
|
|
)),
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_should_not_create_too_big_template_for_broadcasts(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
content,
|
|
|
|
|
|
expected_error,
|
|
|
|
|
|
):
|
|
|
|
|
|
service_one['permissions'] = ['broadcast']
|
|
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'.add_service_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_type='broadcast',
|
|
|
|
|
|
_data={
|
|
|
|
|
|
'name': 'New name',
|
|
|
|
|
|
'template_content': content,
|
|
|
|
|
|
'template_type': 'broadcast',
|
|
|
|
|
|
'service': SERVICE_ONE_ID,
|
|
|
|
|
|
'process_type': 'normal'
|
|
|
|
|
|
},
|
|
|
|
|
|
_expected_status=200,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert normalize_spaces(page.select_one('.error-message').text) == expected_error
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
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')
|
2016-08-24 12:09:38 +01: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,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2015-12-20 00:00:01 +00:00
|
|
|
|
|
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
|
2020-10-07 14:51:18 +01:00
|
|
|
|
assert url_for("main.send_one_off", 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,
|
2021-05-12 14:57:21 +01:00
|
|
|
|
notify_admin,
|
2022-01-04 18:33:23 +00:00
|
|
|
|
client_request,
|
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,
|
2021-05-12 14:57:21 +01:00
|
|
|
|
notify_admin,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
"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,
|
2021-05-12 14:57:21 +01:00
|
|
|
|
notify_admin,
|
2022-01-04 18:33:23 +00:00
|
|
|
|
client_request,
|
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,
|
2021-04-13 13:59:51 +01:00
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
mock_get_no_api_keys,
|
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,
|
2021-05-12 14:57:21 +01:00
|
|
|
|
notify_admin,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
"GET",
|
|
|
|
|
|
200,
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=service_one['id'],
|
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,
|
2021-05-12 14:57:21 +01:00
|
|
|
|
notify_admin,
|
2022-01-04 18:33:23 +00:00
|
|
|
|
client_request,
|
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,
|
2021-05-12 14:57:21 +01:00
|
|
|
|
notify_admin,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
"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
|
|
|
|
|
|
|
|
|
|
|
2020-08-17 13:01:33 +01:00
|
|
|
|
@pytest.mark.parametrize('template_type, expected', (
|
|
|
|
|
|
('email', 'New email template'),
|
|
|
|
|
|
('sms', 'New text message template'),
|
|
|
|
|
|
('broadcast', 'New template'),
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_add_template_page_title(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
template_type,
|
|
|
|
|
|
expected,
|
|
|
|
|
|
):
|
|
|
|
|
|
service_one['permissions'] += [template_type]
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'.add_service_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_type=template_type,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert normalize_spaces(page.select_one('h1').text) == expected
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-01-13 14:58:39 +00:00
|
|
|
|
assert page.select_one('form .page-footer + 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
|
2020-10-05 17:17:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('template_content', (
|
|
|
|
|
|
'This is a ((test))',
|
|
|
|
|
|
'This ((unsure??might)) be a test',
|
|
|
|
|
|
pytest.param('This is a test', marks=pytest.mark.xfail),
|
|
|
|
|
|
))
|
|
|
|
|
|
@pytest.mark.parametrize('template_type', (
|
|
|
|
|
|
'broadcast',
|
|
|
|
|
|
pytest.param('sms', marks=pytest.mark.xfail),
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_should_not_create_broadcast_template_with_placeholders(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_create_service_template,
|
|
|
|
|
|
mock_update_service_template,
|
|
|
|
|
|
template_content,
|
|
|
|
|
|
template_type,
|
|
|
|
|
|
):
|
|
|
|
|
|
service_one['permissions'] += [template_type]
|
|
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'.add_service_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_type=template_type,
|
|
|
|
|
|
_data={
|
|
|
|
|
|
'name': 'new name',
|
|
|
|
|
|
'template_content': template_content,
|
|
|
|
|
|
'service': SERVICE_ONE_ID,
|
|
|
|
|
|
},
|
|
|
|
|
|
_expected_status=200,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert normalize_spaces(
|
|
|
|
|
|
page.select_one('.error-message').text
|
|
|
|
|
|
) == (
|
|
|
|
|
|
'You can’t use ((double brackets)) to personalise this message'
|
|
|
|
|
|
)
|
|
|
|
|
|
assert mock_create_service_template.called is False
|
2021-01-06 11:54:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
|
'template_type, prefix_sms, content, expected_message, expected_class', (
|
|
|
|
|
|
(
|
|
|
|
|
|
'sms', False, '',
|
2021-01-08 15:23:54 +00:00
|
|
|
|
'Will be charged as 1 text message',
|
2021-01-06 11:54:27 +00:00
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'sms', False, 'a' * 160,
|
|
|
|
|
|
'Will be charged as 1 text message',
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'sms', False, 'a' * 161,
|
|
|
|
|
|
'Will be charged as 2 text messages',
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
# service name takes 13 characters, 147 + 13 = 160
|
|
|
|
|
|
'sms', True, 'a' * 147,
|
|
|
|
|
|
'Will be charged as 1 text message',
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
# service name takes 13 characters, 148 + 13 = 161
|
|
|
|
|
|
'sms', True, 'a' * 148,
|
|
|
|
|
|
'Will be charged as 2 text messages',
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'sms', False, 'a' * 918,
|
|
|
|
|
|
'Will be charged as 6 text messages',
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
# Service name increases fragment count but doesn’t count
|
|
|
|
|
|
# against total character limit
|
|
|
|
|
|
'sms', True, 'a' * 918,
|
|
|
|
|
|
'Will be charged as 7 text messages',
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
# Can’t make a 7 fragment text template from content alone
|
|
|
|
|
|
'sms', False, 'a' * 919,
|
|
|
|
|
|
'You have 1 character too many',
|
|
|
|
|
|
'govuk-error-message',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
# Service name increases content count but character count
|
|
|
|
|
|
# is based on content alone
|
|
|
|
|
|
'sms', True, 'a' * 919,
|
|
|
|
|
|
'You have 1 character too many',
|
|
|
|
|
|
'govuk-error-message',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
# Service name increases content count but character count
|
|
|
|
|
|
# is based on content alone
|
|
|
|
|
|
'sms', True, 'a' * 920,
|
|
|
|
|
|
'You have 2 characters too many',
|
|
|
|
|
|
'govuk-error-message',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'sms', False, 'Ẅ' * 70,
|
|
|
|
|
|
'Will be charged as 1 text message',
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'sms', False, 'Ẅ' * 71,
|
|
|
|
|
|
'Will be charged as 2 text messages',
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'sms', False, 'Ẅ' * 918,
|
|
|
|
|
|
'Will be charged as 14 text messages',
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'sms', False, 'Ẅ' * 919,
|
|
|
|
|
|
'You have 1 character too many',
|
|
|
|
|
|
'govuk-error-message',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'sms', False, 'Hello ((name))',
|
|
|
|
|
|
'Will be charged as 1 text message (not including personalisation)',
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
# Length of placeholder body doesn’t count towards fragment count
|
|
|
|
|
|
'sms', False, f'Hello (( {"a" * 999} ))',
|
|
|
|
|
|
'Will be charged as 1 text message (not including personalisation)',
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'broadcast', False, '',
|
2021-01-08 15:23:54 +00:00
|
|
|
|
'You have 1,395 characters remaining',
|
2021-01-06 11:54:27 +00:00
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'broadcast', False, 'a',
|
|
|
|
|
|
'You have 1,394 characters remaining',
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'broadcast', False, 'a' * 1395,
|
|
|
|
|
|
'You have 0 characters remaining',
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'broadcast', False, 'a' * 1396,
|
|
|
|
|
|
'You have 1 character too many',
|
|
|
|
|
|
'govuk-error-message',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'broadcast', False, 'a' * 1397,
|
|
|
|
|
|
'You have 2 characters too many',
|
|
|
|
|
|
'govuk-error-message',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'broadcast', False, 'Ẅ' * 615,
|
|
|
|
|
|
'You have 0 characters remaining',
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
'broadcast', False, 'Ẅ' * 616,
|
|
|
|
|
|
'You have 1 character too many',
|
|
|
|
|
|
'govuk-error-message',
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
def test_content_count_json_endpoint(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2021-01-06 11:54:27 +00:00
|
|
|
|
service_one,
|
|
|
|
|
|
template_type,
|
|
|
|
|
|
prefix_sms,
|
|
|
|
|
|
content,
|
|
|
|
|
|
expected_message,
|
|
|
|
|
|
expected_class,
|
|
|
|
|
|
):
|
|
|
|
|
|
service_one['prefix_sms'] = prefix_sms
|
2021-12-31 12:08:14 +00:00
|
|
|
|
response = client_request.post_response(
|
|
|
|
|
|
'main.count_content_length',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_type=template_type,
|
|
|
|
|
|
_data={
|
2021-01-06 11:54:27 +00:00
|
|
|
|
'template_content': content,
|
|
|
|
|
|
},
|
2021-12-31 12:08:14 +00:00
|
|
|
|
_expected_status=200,
|
2021-01-06 11:54:27 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
html = json.loads(response.get_data(as_text=True))['html']
|
|
|
|
|
|
snippet = BeautifulSoup(html, 'html.parser').select_one('span')
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(snippet.text) == expected_message
|
|
|
|
|
|
|
|
|
|
|
|
if snippet.has_attr('class'):
|
|
|
|
|
|
assert snippet['class'] == [expected_class]
|
|
|
|
|
|
else:
|
|
|
|
|
|
assert expected_class is None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('template_type', (
|
|
|
|
|
|
'email', 'letter', 'banana',
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_content_count_json_endpoint_for_unsupported_template_types(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
template_type,
|
|
|
|
|
|
):
|
|
|
|
|
|
client_request.post(
|
|
|
|
|
|
'main.count_content_length',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_type=template_type,
|
|
|
|
|
|
content='foo',
|
|
|
|
|
|
_expected_status=404,
|
|
|
|
|
|
)
|