2021-01-06 11:54:27 +00:00
|
|
|
|
import json
|
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
|
2018-04-25 14:12:58 +01:00
|
|
|
|
|
2025-07-17 01:00:00 -07:00
|
|
|
|
from app.enums import ServicePermission
|
2025-06-10 11:40:14 -07:00
|
|
|
|
from notifications_python_client.errors import HTTPError
|
2022-12-05 15:33:44 -05:00
|
|
|
|
from tests import 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,
|
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
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-08 17:58:06 -04:00
|
|
|
|
("permissions", "expected_message"),
|
|
|
|
|
|
[
|
2023-08-25 09:12:23 -07:00
|
|
|
|
(
|
|
|
|
|
|
["email"],
|
|
|
|
|
|
(
|
|
|
|
|
|
"Every message starts with a template. You can change it later. "
|
|
|
|
|
|
"You need a template before you can send messages."
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
["sms"],
|
|
|
|
|
|
(
|
|
|
|
|
|
"Every message starts with a template. You can change it later. "
|
|
|
|
|
|
"You need a template before you can send messages."
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
["email", "sms"],
|
|
|
|
|
|
(
|
|
|
|
|
|
"Every message starts with a template. You can change it later. "
|
|
|
|
|
|
"You need a template before you can send messages."
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
2023-09-08 17:58:06 -04:00
|
|
|
|
],
|
2023-08-25 09:12:23 -07: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
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one["permissions"] = permissions
|
2020-07-14 14:52:52 +01:00
|
|
|
|
|
2018-11-19 15:51:18 +00:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.choose_template",
|
|
|
|
|
|
service_id=service_one["id"],
|
2018-11-19 15:51:18 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2024-12-13 12:37:11 -05:00
|
|
|
|
assert normalize_spaces(page.select_one("h1").text) == (
|
|
|
|
|
|
"Select or create a template"
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select_one("main p").text) == (expected_message)
|
|
|
|
|
|
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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.choose_template",
|
|
|
|
|
|
service_id=service_one["id"],
|
2019-01-03 10:43:57 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2024-12-13 12:37:11 -05:00
|
|
|
|
assert normalize_spaces(page.select_one("h1").text) == (
|
|
|
|
|
|
"Select or create a template"
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select_one("main p").text) == (
|
|
|
|
|
|
"Every message starts with a template. You can change it later. "
|
|
|
|
|
|
"You need a template before you can send messages."
|
2019-01-03 10:43:57 +00:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert [(item["name"], item["value"]) for item in page.select("[type=radio]")] == [
|
2022-12-02 14:04:54 -05:00
|
|
|
|
# ('add_template_by_template_type', 'email'),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
("add_template_by_template_type", "sms"),
|
2019-01-03 10:43:57 +00:00
|
|
|
|
]
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert not page.select("main a")
|
2019-01-03 10:43:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
2018-06-14 16:21:57 +01:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-08 17:58:06 -04:00
|
|
|
|
(
|
|
|
|
|
|
"user",
|
|
|
|
|
|
"expected_page_title",
|
|
|
|
|
|
"extra_args",
|
|
|
|
|
|
"expected_nav_links",
|
|
|
|
|
|
"expected_templates",
|
|
|
|
|
|
),
|
2018-06-14 16:21:57 +01:00
|
|
|
|
[
|
|
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_view_permissions(),
|
2024-12-02 12:09:43 -05:00
|
|
|
|
"Select or create a template",
|
2018-06-14 16:21:57 +01:00
|
|
|
|
{},
|
2023-08-25 09:12:23 -07:00
|
|
|
|
["Email", "Text message"],
|
2018-06-14 16:21:57 +01:00
|
|
|
|
[
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms_template_one",
|
|
|
|
|
|
"sms_template_two",
|
|
|
|
|
|
"email_template_one",
|
|
|
|
|
|
"email_template_two",
|
|
|
|
|
|
],
|
2018-06-14 16:21:57 +01:00
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_view_permissions(),
|
2024-12-02 12:09:43 -05:00
|
|
|
|
"Select or create a template",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
{"template_type": "sms"},
|
|
|
|
|
|
["All", "Email"],
|
|
|
|
|
|
["sms_template_one", "sms_template_two"],
|
2018-06-14 16:21:57 +01:00
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_view_permissions(),
|
2024-12-02 12:09:43 -05:00
|
|
|
|
"Select or create a template",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
{"template_type": "email"},
|
|
|
|
|
|
["All", "Text message"],
|
|
|
|
|
|
["email_template_one", "email_template_two"],
|
2018-06-14 16:21:57 +01:00
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_caseworking_user(),
|
2024-12-02 12:09:43 -05:00
|
|
|
|
"Select or create a template",
|
2018-06-14 16:21:57 +01:00
|
|
|
|
{},
|
2023-08-25 09:12:23 -07:00
|
|
|
|
["Email", "Text message"],
|
2018-06-14 16:21:57 +01:00
|
|
|
|
[
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms_template_one",
|
|
|
|
|
|
"sms_template_two",
|
|
|
|
|
|
"email_template_one",
|
|
|
|
|
|
"email_template_two",
|
2018-06-14 16:21:57 +01:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_caseworking_user(),
|
2024-12-02 12:09:43 -05:00
|
|
|
|
"Select or create a template",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
{"template_type": "email"},
|
|
|
|
|
|
["All", "Text message"],
|
|
|
|
|
|
["email_template_one", "email_template_two"],
|
2018-06-14 16:21:57 +01:00
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
],
|
2018-06-14 16:21:57 +01:00
|
|
|
|
)
|
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
|
|
|
|
):
|
2019-12-19 16:59:07 +00:00
|
|
|
|
client_request.login(user)
|
2017-06-13 15:28:33 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.choose_template", service_id=service_one["id"], **extra_args
|
2017-06-13 15:28:33 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-10-06 09:38:54 -04:00
|
|
|
|
assert expected_page_title in str(page)
|
2017-06-13 15:28:33 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07: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
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
template_links = page.select("#template-list 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
|
|
|
|
|
|
|
|
|
|
|
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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.choose_template",
|
2019-02-14 16:27:13 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
initial_state="add-new-template",
|
2019-02-14 16:27:13 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
templates_and_folders_form = page.find("form")
|
|
|
|
|
|
assert templates_and_folders_form["data-prev-state"] == "add-new-template"
|
2019-02-14 16:27:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.choose_template",
|
2017-06-13 15:27:29 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert not page.select(".pill")
|
2017-06-13 15:27:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.choose_template",
|
2018-08-16 12:18:07 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert not page.select(".live-search")
|
2018-08-16 12:18:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.choose_template",
|
2018-08-16 12:18:07 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
search = page.select_one(".live-search")
|
2018-08-16 12:18:07 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert search["data-module"] == "live-search"
|
|
|
|
|
|
assert search["data-targets"] == "#template-list .template-list-item"
|
|
|
|
|
|
assert normalize_spaces(search.select_one("label").text) == ("Search by name")
|
|
|
|
|
|
|
|
|
|
|
|
assert (
|
|
|
|
|
|
len(page.select(search["data-targets"]))
|
|
|
|
|
|
== len(page.select("#template-list .usa-checkbox"))
|
|
|
|
|
|
== 20
|
2021-04-13 13:59:51 +01:00
|
|
|
|
)
|
2018-11-10 16:37:29 +00:00
|
|
|
|
|
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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.choose_template",
|
2021-04-13 13:59:51 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select_one(".live-search label").text) == (
|
|
|
|
|
|
"Search by name or ID"
|
2021-04-13 13:59:51 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-20 16:10:14 +00:00
|
|
|
|
def test_should_show_live_search_if_service_has_lots_of_folders(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_template_folders,
|
|
|
|
|
|
mock_get_service_templates, # returns 4 templates
|
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 = [
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_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),
|
2018-11-20 16:10:14 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.choose_template",
|
2018-11-20 16:10:14 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
count_of_templates_and_folders = len(page.select("#template-list .usa-checkbox"))
|
|
|
|
|
|
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
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-26 11:38:03 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-08 17:58:06 -04:00
|
|
|
|
("service_permissions", "expected_values", "expected_labels"),
|
|
|
|
|
|
[
|
2023-08-25 09:12:23 -07:00
|
|
|
|
pytest.param(
|
|
|
|
|
|
["email", "sms"],
|
|
|
|
|
|
[
|
|
|
|
|
|
# 'email',
|
|
|
|
|
|
"sms",
|
|
|
|
|
|
"copy-existing",
|
|
|
|
|
|
],
|
|
|
|
|
|
[
|
|
|
|
|
|
# 'Email',
|
2023-10-03 11:14:21 -04:00
|
|
|
|
"Start with a blank template",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"Copy an existing template",
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
2023-10-26 11:38:03 -07:00
|
|
|
|
# TODO This is a duplicate of above. Why?
|
|
|
|
|
|
# pytest.param(
|
|
|
|
|
|
# ["email", "sms"],
|
|
|
|
|
|
# [
|
|
|
|
|
|
# # 'email',
|
|
|
|
|
|
# "sms",
|
|
|
|
|
|
# "copy-existing",
|
|
|
|
|
|
# ],
|
|
|
|
|
|
# [
|
|
|
|
|
|
# # 'Email',
|
|
|
|
|
|
# "Start with a blank template",
|
|
|
|
|
|
# "Copy an existing template",
|
|
|
|
|
|
# ],
|
|
|
|
|
|
# ),
|
2023-09-08 17:58:06 -04:00
|
|
|
|
],
|
2023-08-25 09:12:23 -07:00
|
|
|
|
)
|
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,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one["permissions"] = service_permissions
|
2018-11-28 13:48:13 +00:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.choose_template",
|
2018-11-28 13:48:13 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
if not page.select("#add_new_template_form"):
|
2018-11-28 13:48:13 +00:00
|
|
|
|
raise ElementNotFound()
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(
|
|
|
|
|
|
page.select_one("#add_new_template_form fieldset legend").text
|
|
|
|
|
|
) == ("New template")
|
2018-11-28 13:48:13 +00:00
|
|
|
|
assert [
|
2023-08-25 09:12:23 -07:00
|
|
|
|
choice["value"]
|
|
|
|
|
|
for choice in page.select("#add_new_template_form input[type=radio]")
|
2018-11-28 13:48:13 +00:00
|
|
|
|
] == expected_values
|
|
|
|
|
|
assert [
|
2023-08-25 09:12:23 -07:00
|
|
|
|
normalize_spaces(choice.text)
|
|
|
|
|
|
for choice in page.select("#add_new_template_form label")
|
2018-11-28 13:48:13 +00:00
|
|
|
|
] == expected_labels
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-08 17:58:06 -04:00
|
|
|
|
("permissions", "are_data_attrs_added"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
|
|
|
|
|
(["sms"], True),
|
|
|
|
|
|
(["email"], True),
|
|
|
|
|
|
(["sms", "email"], False),
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2020-08-10 15:12:07 +01:00
|
|
|
|
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,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
are_data_attrs_added,
|
2020-08-10 15:12:07 +01:00
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one["permissions"] = permissions
|
2020-08-10 15:12:07 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.choose_template",
|
2020-08-10 15:12:07 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
if not page.select("#add_new_template_form"):
|
2020-08-10 15:12:07 +01:00
|
|
|
|
raise ElementNotFound()
|
|
|
|
|
|
|
|
|
|
|
|
if are_data_attrs_added:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
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
|
|
|
|
|
|
)
|
2020-08-10 15:12:07 +01:00
|
|
|
|
else:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
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
|
2020-08-10 15:12:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
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(
|
2023-08-25 09:12:23 -07: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
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select_one("input[type=text]")["value"] == "Two week reminder"
|
2019-03-26 12:35:32 +00:00
|
|
|
|
assert "Template <em>content</em> with & entity" in str(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
page.select_one("textarea")
|
2019-03-26 12:35:32 +00:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select_one("textarea")["data-module"] == "enhanced-textbox"
|
|
|
|
|
|
assert page.select_one("textarea")["data-highlight-placeholders"] == "true"
|
|
|
|
|
|
assert "priority" not in str(page.select_one("main"))
|
2021-01-06 17:32:46 +00:00
|
|
|
|
|
|
|
|
|
|
assert (
|
2023-08-25 09:12:23 -07:00
|
|
|
|
(page.select_one("[data-module=update-status]")["data-target"])
|
|
|
|
|
|
== (page.select_one("textarea")["id"])
|
|
|
|
|
|
== ("template_content")
|
2021-01-06 17:32:46 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert (
|
2023-08-25 09:12:23 -07:00
|
|
|
|
page.select_one("[data-module=update-status]")["data-updates-url"]
|
2021-01-06 17:32:46 +00:00
|
|
|
|
) == url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".count_content_length",
|
2021-01-06 17:32:46 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
template_type="sms",
|
2021-01-06 17:32:46 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert (page.select_one("[data-module=update-status]")["aria-live"]) == ("polite")
|
2021-01-07 14:30:48 +00:00
|
|
|
|
|
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-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
|
|
|
|
):
|
2023-01-19 17:29:21 -05:00
|
|
|
|
client_request.login(active_caseworking_user)
|
2018-06-12 16:17:20 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_template",
|
2018-06-12 16:17:20 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.set_sender",
|
2018-06-12 16:17:20 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-16 12:24:27 -08:00
|
|
|
|
@freeze_time("2020-01-01 20:00")
|
2021-07-21 16:06:23 +01:00
|
|
|
|
def test_caseworker_sees_template_page_if_template_is_deleted(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_deleted_template,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
active_caseworking_user,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch("app.user_api_client.get_user", return_value=active_caseworking_user)
|
2021-07-21 16:06:23 +01:00
|
|
|
|
|
|
|
|
|
|
template_id = fake_uuid
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".view_template",
|
2021-07-21 16:06:23 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=template_id,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
content = str(page)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert (
|
|
|
|
|
|
url_for("main.send_one_off", service_id=SERVICE_ONE_ID, template_id=fake_uuid)
|
|
|
|
|
|
not in content
|
|
|
|
|
|
)
|
2025-10-06 09:38:54 -04:00
|
|
|
|
assert "This template was deleted" in content or "deleted" in content.lower()
|
2021-07-21 16:06:23 +01:00
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
active_user_with_permissions["permissions"][SERVICE_ONE_ID] = [
|
|
|
|
|
|
"send_messages",
|
2025-07-21 14:24:11 -07:00
|
|
|
|
ServicePermission.VIEW_ACTIVITY,
|
2018-08-06 11:09:07 +01:00
|
|
|
|
]
|
|
|
|
|
|
client_request.login(active_user_with_permissions)
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_template",
|
2018-08-06 11:09:07 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.set_sender",
|
2018-08-06 11:09:07 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-08 17:58:06 -04:00
|
|
|
|
("permissions", "links_to_be_shown", "permissions_warning_to_be_shown"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
|
|
|
|
|
(
|
2025-07-21 14:24:11 -07:00
|
|
|
|
[ServicePermission.VIEW_ACTIVITY],
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[],
|
|
|
|
|
|
"If you need to send this text message or edit this template, contact your manager.",
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
["manage_api_keys"],
|
|
|
|
|
|
[],
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2025-07-17 01:00:00 -07:00
|
|
|
|
[ServicePermission.MANAGE_TEMPLATES],
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
2024-12-11 11:24:26 -05:00
|
|
|
|
(".edit_service_template", "Edit this template"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
],
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2025-07-17 01:00:00 -07:00
|
|
|
|
[ServicePermission.SEND_MESSAGES, ServicePermission.MANAGE_TEMPLATES],
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
2023-10-06 13:13:18 -04:00
|
|
|
|
(".set_sender", "Use this template"),
|
2024-12-11 11:24:26 -05:00
|
|
|
|
(".edit_service_template", "Edit this template"),
|
2023-08-25 09:12:23 -07: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,
|
|
|
|
|
|
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
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
active_user_with_permissions["permissions"][SERVICE_ONE_ID] = permissions + [
|
2025-07-21 14:24:11 -07:00
|
|
|
|
ServicePermission.VIEW_ACTIVITY
|
2023-08-25 09:12:23 -07:00
|
|
|
|
]
|
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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".view_template",
|
2019-04-30 16:32:20 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2024-12-03 17:15:52 -08:00
|
|
|
|
assert normalize_spaces(page.select_one("h1").text) == ("Confirm your template")
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select_one("title").text) == (
|
2024-12-03 17:15:52 -08:00
|
|
|
|
"Confirm your template – service one – Notify.gov"
|
2019-04-30 16:32:20 +01:00
|
|
|
|
)
|
2017-03-10 16:46:28 +00:00
|
|
|
|
|
2021-11-24 16:35:34 +00:00
|
|
|
|
assert [
|
2023-08-25 09:12:23 -07:00
|
|
|
|
(link["href"], normalize_spaces(link.text))
|
|
|
|
|
|
for link in page.select(".usa-pill-separate-item")
|
2021-11-24 16:35:34 +00:00
|
|
|
|
] == [
|
2023-08-25 09:12:23 -07:00
|
|
|
|
(
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
endpoint,
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
),
|
|
|
|
|
|
text,
|
|
|
|
|
|
)
|
2021-11-24 16:35:34 +00:00
|
|
|
|
for endpoint, text in links_to_be_shown
|
|
|
|
|
|
]
|
2017-03-10 16:46:28 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select_one("main p").text) == (
|
|
|
|
|
|
"To: phone number" or permissions_warning_to_be_shown
|
2018-03-12 15:46:54 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2017-03-10 16:46:28 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.skip(
|
|
|
|
|
|
reason="Hiding the copy-to-clipboard widget until API access is opened up"
|
|
|
|
|
|
)
|
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(
|
2023-08-25 09:12:23 -07: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
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert fake_uuid in page.select(".copy-to-clipboard__value")[0].text
|
2017-03-10 17:15:34 +00: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,
|
2018-11-16 14:09:14 +00:00
|
|
|
|
mock_get_template_folders,
|
2017-02-15 13:49:15 +00:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2025-03-31 08:45:33 -07:00
|
|
|
|
msg = "here:\tare some “fancy quotes” and zero\u200bwidth\u200bspaces"
|
2023-12-15 07:20:34 -08:00
|
|
|
|
rendered_msg = "here: are some “fancy quotes” and zerowidthspaces"
|
2017-02-15 13:49:15 +00:00
|
|
|
|
|
|
|
|
|
|
mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.service_api_client.get_service_template",
|
|
|
|
|
|
return_value={
|
|
|
|
|
|
"data": template_json(
|
|
|
|
|
|
service_one["id"], fake_uuid, type_="sms", content=msg
|
|
|
|
|
|
)
|
|
|
|
|
|
},
|
2017-02-15 13:49:15 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07: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
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
|
"prefix_sms", [True, pytest.param(False, marks=pytest.mark.xfail())]
|
|
|
|
|
|
)
|
2021-07-02 16:25:45 +01:00
|
|
|
|
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,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
prefix_sms,
|
2021-07-02 16:25:45 +01:00
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one["prefix_sms"] = prefix_sms
|
2021-07-02 16:25:45 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".edit_service_template",
|
|
|
|
|
|
service_id=service_one["id"],
|
2021-07-02 16:25:45 +01:00
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert "Your service name will be added to the start of your message" 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
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.user_api_client.get_users_for_service", return_value=[platform_admin_user]
|
|
|
|
|
|
)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
template_id = fake_uuid
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".edit_service_template",
|
|
|
|
|
|
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
|
|
|
|
|
2023-08-25 09:12:23 -07: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")
|
|
|
|
|
|
)
|
2023-06-20 08:37:56 -07:00
|
|
|
|
assert "Use priority queue?" not in page.text
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_get_service_template.assert_called_with(service_one["id"], template_id, None)
|
2015-12-20 00:00:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
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(
|
2023-08-25 09:12:23 -07: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={
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"operation": "add-new-template",
|
|
|
|
|
|
"add_template_by_template_type": "copy-existing",
|
2019-02-11 16:09:08 +00:00
|
|
|
|
},
|
2018-11-28 13:48:13 +00:00
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.choose_template_to_copy",
|
2018-11-28 13:48:13 +00:00
|
|
|
|
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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.choose_template_to_copy",
|
2018-07-19 12:30:04 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select(".folder-heading") == []
|
2018-07-19 12:30:04 +01:00
|
|
|
|
|
2019-01-07 14:49:33 +00:00
|
|
|
|
expected = [
|
2023-12-04 12:42:15 -05:00
|
|
|
|
(""),
|
|
|
|
|
|
("Service 1 sms_template_one"),
|
|
|
|
|
|
("Service 1 sms_template_two"),
|
|
|
|
|
|
("Service 1 email_template_one"),
|
|
|
|
|
|
("Service 1 email_template_two"),
|
|
|
|
|
|
(""),
|
|
|
|
|
|
("Service 2 sms_template_one"),
|
|
|
|
|
|
("Service 2 sms_template_two"),
|
|
|
|
|
|
("Service 2 email_template_one"),
|
|
|
|
|
|
("Service 2 email_template_two"),
|
2019-01-07 14:49:33 +00:00
|
|
|
|
]
|
2023-08-25 09:12:23 -07:00
|
|
|
|
actual = page.select(".template-list-item")
|
2019-01-07 14:49:33 +00:00
|
|
|
|
|
|
|
|
|
|
assert len(actual) == len(expected)
|
|
|
|
|
|
|
2023-10-26 11:38:03 -07:00
|
|
|
|
zipobject = zip(actual, expected)
|
|
|
|
|
|
for actual, expected in zipobject:
|
2019-01-07 14:49:33 +00:00
|
|
|
|
assert normalize_spaces(actual.text) == expected
|
2023-08-25 09:12:23 -07:00
|
|
|
|
links = page.select("main nav a")
|
|
|
|
|
|
assert links[0]["href"] == url_for(
|
|
|
|
|
|
"main.choose_template_to_copy",
|
2019-01-07 14:49:33 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_TWO_ID,
|
|
|
|
|
|
)
|
2018-07-19 12:30:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
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,
|
2023-07-12 12:09:44 -04:00
|
|
|
|
mock_get_empty_organizations_and_one_service_for_user,
|
2019-01-07 14:49:33 +00:00
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.choose_template_to_copy",
|
2019-01-07 14:49:33 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select(".folder-heading") == []
|
2019-01-07 14:49:33 +00:00
|
|
|
|
|
|
|
|
|
|
expected = [
|
2023-12-04 12:42:15 -05:00
|
|
|
|
("sms_template_one"),
|
|
|
|
|
|
("sms_template_two"),
|
|
|
|
|
|
("email_template_one"),
|
|
|
|
|
|
("email_template_two"),
|
2019-01-07 14:49:33 +00:00
|
|
|
|
]
|
2023-08-25 09:12:23 -07:00
|
|
|
|
actual = page.select(".template-list-item")
|
2019-01-07 14:49:33 +00:00
|
|
|
|
|
|
|
|
|
|
assert len(actual) == len(expected)
|
|
|
|
|
|
|
2023-10-26 11:38:03 -07:00
|
|
|
|
zipobject = zip(actual, expected)
|
|
|
|
|
|
for actual, expected in zipobject:
|
2019-01-07 14:49:33 +00:00
|
|
|
|
assert normalize_spaces(actual.text) == expected
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select("main nav a")[0]["href"] == url_for(
|
|
|
|
|
|
"main.copy_template",
|
2019-01-07 14:49:33 +00:00
|
|
|
|
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,
|
2023-07-12 12:09:44 -04:00
|
|
|
|
mock_get_non_empty_organizations_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 = [
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_folder("Parent folder", PARENT_FOLDER_ID),
|
2023-12-04 12:42:15 -05:00
|
|
|
|
_folder("", CHILD_FOLDER_ID, parent=PARENT_FOLDER_ID),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_folder("Child folder non-empty", FOLDER_TWO_ID, parent=PARENT_FOLDER_ID),
|
2019-01-07 14:49:33 +00:00
|
|
|
|
]
|
|
|
|
|
|
mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"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,
|
2025-09-23 07:15:18 -07:00
|
|
|
|
template_id=TEMPLATE_ONE_ID,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
|
|
|
|
|
_template(
|
|
|
|
|
|
"sms",
|
|
|
|
|
|
"Should appear in list (nested)",
|
|
|
|
|
|
parent=FOLDER_TWO_ID,
|
|
|
|
|
|
template_id=TEMPLATE_ONE_ID,
|
|
|
|
|
|
),
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
2019-01-07 14:49:33 +00:00
|
|
|
|
)
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.choose_template_to_copy",
|
2019-01-07 14:49:33 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_ONE_ID,
|
|
|
|
|
|
from_folder=PARENT_FOLDER_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select_one(".folder-heading").text) == (
|
|
|
|
|
|
"service one Parent folder"
|
2019-01-07 14:49:33 +00:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
breadcrumb_links = page.select(".folder-heading a")
|
2019-01-07 14:49:33 +00:00
|
|
|
|
assert len(breadcrumb_links) == 1
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert breadcrumb_links[0]["href"] == url_for(
|
|
|
|
|
|
"main.choose_template_to_copy",
|
2019-01-07 14:49:33 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
expected = [
|
2023-12-04 12:42:15 -05:00
|
|
|
|
(""),
|
|
|
|
|
|
(""),
|
|
|
|
|
|
("Child folder non-empty Should appear in list (nested)"),
|
|
|
|
|
|
("Should appear in list (at same level)"),
|
2019-01-07 14:49:33 +00:00
|
|
|
|
]
|
2023-08-25 09:12:23 -07:00
|
|
|
|
actual = page.select(".template-list-item")
|
2019-01-07 14:49:33 +00:00
|
|
|
|
|
|
|
|
|
|
assert len(actual) == len(expected)
|
|
|
|
|
|
|
2023-10-26 11:38:03 -07:00
|
|
|
|
zipobject = zip(actual, expected)
|
|
|
|
|
|
for actual, expected in zipobject:
|
2019-01-07 14:49:33 +00:00
|
|
|
|
assert normalize_spaces(actual.text) == expected
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
links = page.select("main nav a")
|
|
|
|
|
|
assert links[0]["href"] == url_for(
|
|
|
|
|
|
"main.choose_template_to_copy",
|
2019-01-07 14:49:33 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
from_folder=FOLDER_TWO_ID,
|
|
|
|
|
|
)
|
2025-09-23 07:15:18 -07:00
|
|
|
|
|
|
|
|
|
|
assert links[1]["href"] == url_for(
|
|
|
|
|
|
"main.copy_template",
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=TEMPLATE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert links[2]["href"] == url_for(
|
|
|
|
|
|
"main.copy_template",
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=TEMPLATE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
2019-01-07 14:49:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-08 17:58:06 -04:00
|
|
|
|
("existing_template_names", "expected_name"),
|
|
|
|
|
|
[
|
2023-08-25 09:12:23 -07:00
|
|
|
|
(["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)",
|
|
|
|
|
|
),
|
2023-09-08 17:58:06 -04:00
|
|
|
|
],
|
2023-08-25 09:12:23 -07:00
|
|
|
|
)
|
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,
|
2023-07-12 12:09:44 -04:00
|
|
|
|
mock_get_non_empty_organizations_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
|
|
|
|
):
|
2023-08-25 09:12:23 -07: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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.copy_template",
|
2018-07-19 12:30:04 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=TEMPLATE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_TWO_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select_one("form")["method"] == "post"
|
2018-07-19 12:30:04 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select_one("input")["value"] == (expected_name)
|
2025-04-21 11:42:24 -04:00
|
|
|
|
assert page.select_one("textarea").text.strip() == ("Your ((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,
|
2023-07-12 12:09:44 -04:00
|
|
|
|
mock_get_non_empty_organizations_and_services_for_user,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker,
|
2019-04-03 13:59:44 +01:00
|
|
|
|
):
|
|
|
|
|
|
template = template_json(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
SERVICE_TWO_ID, TEMPLATE_ONE_ID, name="foo", folder=PARENT_FOLDER_ID
|
2019-04-03 13:59:44 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
mock_get_service_template = mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.service_api_client.get_service_template", return_value={"data": template}
|
2019-04-03 13:59:44 +01:00
|
|
|
|
)
|
|
|
|
|
|
mock_get_template_folder = mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.template_folder_api_client.get_template_folder",
|
|
|
|
|
|
return_value=_folder("Parent folder", PARENT_FOLDER_ID),
|
2019-04-03 13:59:44 +01:00
|
|
|
|
)
|
|
|
|
|
|
client_request.login(active_user_with_permission_to_two_services)
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.copy_template",
|
2019-04-03 13:59:44 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=TEMPLATE_ONE_ID,
|
|
|
|
|
|
from_service=SERVICE_TWO_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select_one("input")["value"] == "foo (copy)"
|
2019-04-03 13:59:44 +01:00
|
|
|
|
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,
|
2023-07-12 12:09:44 -04:00
|
|
|
|
mock_get_organizations_and_services_for_user,
|
2018-07-19 12:30:04 +01:00
|
|
|
|
):
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.copy_template",
|
2018-07-19 12:30:04 +01:00
|
|
|
|
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 == []
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-08 17:58:06 -04:00
|
|
|
|
("service_permissions", "data", "expected_error"),
|
|
|
|
|
|
[
|
2023-08-25 09:12:23 -07:00
|
|
|
|
(
|
|
|
|
|
|
["email"],
|
|
|
|
|
|
{
|
|
|
|
|
|
"operation": "add-new-template",
|
|
|
|
|
|
"add_template_by_template_type": "sms",
|
|
|
|
|
|
},
|
|
|
|
|
|
"Sending text messages has been disabled for your service.",
|
|
|
|
|
|
),
|
2023-09-08 17:58:06 -04:00
|
|
|
|
],
|
2023-08-25 09:12:23 -07: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
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one["permissions"] = service_permissions
|
2018-11-28 13:48:13 +00:00
|
|
|
|
page = client_request.post(
|
2023-08-25 09:12:23 -07: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
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select("main p")[0].text) == expected_error
|
2025-10-06 09:38:54 -04:00
|
|
|
|
assert "Back" in page.select("nav.usa-breadcrumb a")[0].text
|
|
|
|
|
|
assert page.select("nav.usa-breadcrumb a")[0]["href"] == url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".choose_template",
|
2019-02-11 16:09:08 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-06-30 10:55:59 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-08 17:58:06 -04:00
|
|
|
|
@pytest.mark.parametrize("method", ["get", "post"])
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-08 17:58:06 -04:00
|
|
|
|
("type_of_template", "expected_error"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
|
|
|
|
|
("email", "Sending emails has been disabled for your service."),
|
|
|
|
|
|
("sms", "Sending text messages 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
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one["permissions"] = []
|
2017-06-30 10:55:59 +01:00
|
|
|
|
|
2020-07-01 16:43:08 +01:00
|
|
|
|
page = getattr(client_request, method)(
|
2023-08-25 09:12:23 -07: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
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select("main p")[0].text.strip() == expected_error
|
2025-10-06 09:38:54 -04:00
|
|
|
|
assert "Back" in page.select("nav.usa-breadcrumb a")[0].text
|
|
|
|
|
|
assert page.select("nav.usa-breadcrumb a")[0]["href"] == url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".choose_template",
|
|
|
|
|
|
service_id=service_one["id"],
|
2017-06-30 10:55:59 +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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".edit_service_template",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"id": fake_uuid,
|
|
|
|
|
|
"name": name,
|
|
|
|
|
|
"template_content": content,
|
|
|
|
|
|
"template_type": "sms",
|
|
|
|
|
|
"service": SERVICE_ONE_ID,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
},
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".view_template",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
mock_update_service_template.assert_called_with(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
fake_uuid, name, "sms", content, SERVICE_ONE_ID, None
|
2019-03-26 12:35:32 +00:00
|
|
|
|
)
|
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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".edit_service_template",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"id": fake_uuid,
|
|
|
|
|
|
"name": "new name",
|
|
|
|
|
|
"template_content": "new template <em>content</em> with & entity",
|
|
|
|
|
|
"template_type": "sms",
|
|
|
|
|
|
"service": SERVICE_ONE_ID,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
},
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".view_template",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
2019-03-26 12:35:32 +00:00
|
|
|
|
)
|
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",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms",
|
2017-02-03 12:07:21 +00:00
|
|
|
|
"new template <em>content</em> with & entity",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
SERVICE_ONE_ID,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
None,
|
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,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one["permissions"] = ["email"]
|
2017-06-30 10:55:59 +01:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07: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
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert (
|
|
|
|
|
|
page.select("main p")[0].text.strip()
|
|
|
|
|
|
== "Sending text messages has been disabled for your service."
|
|
|
|
|
|
)
|
2025-10-06 09:38:54 -04:00
|
|
|
|
assert "Back" in page.select("nav.usa-breadcrumb a")[0].text
|
|
|
|
|
|
assert page.select("nav.usa-breadcrumb a")[0]["href"] == url_for(
|
2023-08-25 09:12:23 -07: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
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one["users"] = [active_user_with_permissions]
|
2022-01-04 10:56:25 +00:00
|
|
|
|
client_request.login(active_user_with_permissions)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.user_api_client.get_users_for_service",
|
|
|
|
|
|
return_value=[active_user_with_permissions],
|
|
|
|
|
|
)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
template_id = fake_uuid
|
|
|
|
|
|
data = {
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"id": template_id,
|
|
|
|
|
|
"name": "new name",
|
|
|
|
|
|
"template_content": "template <em>content</em> with & entity",
|
|
|
|
|
|
"template_type": "sms",
|
|
|
|
|
|
"service": service_one["id"],
|
|
|
|
|
|
"process_type": "priority",
|
2017-02-03 12:07:21 +00:00
|
|
|
|
}
|
2022-01-04 10:56:25 +00:00
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".edit_service_template",
|
|
|
|
|
|
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
|
|
|
|
):
|
2023-08-25 09:12:23 -07: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)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.user_api_client.get_users_for_service",
|
|
|
|
|
|
return_value=[active_user_with_permissions],
|
|
|
|
|
|
)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
template_id = fake_uuid
|
|
|
|
|
|
data = {
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"id": template_id,
|
|
|
|
|
|
"name": "new name",
|
|
|
|
|
|
"template_content": "template <em>content</em> with & entity",
|
|
|
|
|
|
"template_type": "sms",
|
|
|
|
|
|
"service": service_one["id"],
|
|
|
|
|
|
"process_type": "priority",
|
2017-02-03 12:07:21 +00:00
|
|
|
|
}
|
2022-01-04 10:56:25 +00:00
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".add_service_template",
|
|
|
|
|
|
service_id=service_one["id"],
|
|
|
|
|
|
template_type="sms",
|
2022-01-04 10:56:25 +00:00
|
|
|
|
_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
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-08 17:58:06 -04:00
|
|
|
|
("old_content", "new_content", "expected_paragraphs"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
|
|
|
|
|
(
|
|
|
|
|
|
"my favorite color is blue",
|
|
|
|
|
|
"my favorite color is ((color))",
|
|
|
|
|
|
[
|
|
|
|
|
|
"You added ((color))",
|
|
|
|
|
|
"Before you send any messages, make sure your API calls include color.",
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
"hello ((name))",
|
|
|
|
|
|
"hello ((first name)) ((middle name)) ((last name))",
|
|
|
|
|
|
[
|
|
|
|
|
|
"You removed ((name))",
|
|
|
|
|
|
"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.",
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
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,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
template_type="email",
|
2017-04-06 10:22:09 +01:00
|
|
|
|
subject="Your ((thing)) is due soon",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
content=old_content,
|
|
|
|
|
|
)
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.service_api_client.get_service_template",
|
|
|
|
|
|
return_value={"data": email_template},
|
2017-04-06 10:22:09 +01:00
|
|
|
|
)
|
2020-01-08 09:10:04 +00:00
|
|
|
|
|
2018-12-19 17:06:09 +00:00
|
|
|
|
data = {
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"id": fake_uuid,
|
|
|
|
|
|
"name": "new name",
|
|
|
|
|
|
"template_content": new_content,
|
|
|
|
|
|
"template_type": "email",
|
|
|
|
|
|
"subject": "reminder '\" <span> & ((thing))",
|
|
|
|
|
|
"service": SERVICE_ONE_ID,
|
|
|
|
|
|
"process_type": "normal",
|
2018-12-19 17:06:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".edit_service_template",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
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"
|
2025-10-06 09:38:54 -04:00
|
|
|
|
assert page.select_one("nav.usa-breadcrumb a")["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 [
|
2023-08-25 09:12:23 -07:00
|
|
|
|
normalize_spaces(paragraph.text) for paragraph in page.select("main p")
|
2019-11-20 12:01:26 +00:00
|
|
|
|
] == expected_paragraphs
|
2017-03-06 13:08:27 +00:00
|
|
|
|
|
2017-02-03 12:07:21 +00:00
|
|
|
|
for key, value in {
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"name": "new name",
|
|
|
|
|
|
"subject": "reminder '\" <span> & ((thing))",
|
|
|
|
|
|
"template_content": new_content,
|
|
|
|
|
|
"confirm": "true",
|
2017-02-03 12:07:21 +00:00
|
|
|
|
}.items():
|
2023-08-25 09:12:23 -07:00
|
|
|
|
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
|
2023-08-25 09:12:23 -07:00
|
|
|
|
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,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
existing_template = mock_get_service_email_template(0, 0)["data"]
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".edit_service_template",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={
|
2023-08-25 09:12:23 -07: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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_template",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".add_service_template",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
template_type="sms",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
_data={
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"name": "new name",
|
|
|
|
|
|
"template_content": "template content",
|
|
|
|
|
|
"template_type": "sms",
|
|
|
|
|
|
"service": SERVICE_ONE_ID,
|
|
|
|
|
|
"process_type": "normal",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
},
|
|
|
|
|
|
_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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".edit_service_template",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"id": fake_uuid,
|
|
|
|
|
|
"name": "new name",
|
|
|
|
|
|
"template_content": "template content",
|
|
|
|
|
|
"service": SERVICE_ONE_ID,
|
|
|
|
|
|
"template_type": "sms",
|
|
|
|
|
|
"process_type": "normal",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
},
|
|
|
|
|
|
_expected_status=200,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert "Content has a character count greater than the limit of 459" in page.text
|
2016-04-29 09:38:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-02-03 10:42:01 +00:00
|
|
|
|
def test_should_redirect_when_saving_a_template_email(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
mock_get_service_email_template,
|
|
|
|
|
|
mock_update_service_template,
|
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2017-02-03 12:07:21 +00:00
|
|
|
|
name = "new name"
|
|
|
|
|
|
content = "template <em>content</em> with & entity ((thing)) ((date))"
|
2017-04-14 08:52:02 +01:00
|
|
|
|
subject = "subject & entity"
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".edit_service_template",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_data={
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"id": fake_uuid,
|
|
|
|
|
|
"name": name,
|
|
|
|
|
|
"template_content": content,
|
|
|
|
|
|
"template_type": "email",
|
|
|
|
|
|
"service": SERVICE_ONE_ID,
|
|
|
|
|
|
"subject": subject,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
},
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".view_template",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
mock_update_service_template.assert_called_with(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
fake_uuid, name, "email", content, SERVICE_ONE_ID, subject
|
2019-03-26 12:35:32 +00:00
|
|
|
|
)
|
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,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
fake_uuid,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
):
|
2023-08-25 09:12:23 -07: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
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
with freeze_time("2012-01-01 12:10:00"):
|
2017-07-24 14:50:56 +01:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07: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,
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert (
|
|
|
|
|
|
"Are you sure you want to delete ‘Two week reminder’?"
|
2025-10-30 17:30:20 -07:00
|
|
|
|
in page.select(".usa-alert--error")[0].text
|
2023-08-25 09:12:23 -07:00
|
|
|
|
)
|
2025-10-30 17:30:20 -07:00
|
|
|
|
assert normalize_spaces(
|
|
|
|
|
|
page.select(".usa-alert--error .usa-alert__text")[1].text
|
|
|
|
|
|
) == ("This template was last used 10 minutes ago.")
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".sms-message-wrapper")[0].text) == (
|
|
|
|
|
|
"service one: Template <em>content</em> with & entity"
|
2017-07-26 12:04:07 +01:00
|
|
|
|
)
|
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,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
fake_uuid,
|
2017-07-26 12:04:07 +01:00
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.template_statistics_client.get_last_used_date_for_template",
|
|
|
|
|
|
return_value=None,
|
|
|
|
|
|
)
|
2017-07-26 12:04:07 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
with freeze_time("2012-01-01 11:00:00"):
|
2017-07-26 12:04:07 +01:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".delete_service_template",
|
2017-07-26 12:04:07 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert (
|
|
|
|
|
|
"Are you sure you want to delete ‘Two week reminder’?"
|
2025-10-30 17:30:20 -07:00
|
|
|
|
in page.select(".usa-alert--error")[0].text
|
2023-08-25 09:12:23 -07:00
|
|
|
|
)
|
2025-10-30 17:30:20 -07:00
|
|
|
|
assert normalize_spaces(
|
|
|
|
|
|
page.select(".usa-alert--error .usa-alert__text")[1].text
|
|
|
|
|
|
) == ("This template has never been used.")
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".sms-message-wrapper")[0].text) == (
|
|
|
|
|
|
"service one: Template <em>content</em> with & entity"
|
2017-07-24 14:50:56 +01:00
|
|
|
|
)
|
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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.template_statistics_client.get_last_used_date_for_template",
|
|
|
|
|
|
side_effect=HTTPError(
|
|
|
|
|
|
response=Mock(status_code=404), message="Default message"
|
|
|
|
|
|
),
|
2017-02-03 12:07:21 +00:00
|
|
|
|
)
|
2017-07-24 14:50:56 +01:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07: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,
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert (
|
|
|
|
|
|
"Are you sure you want to delete ‘Two week reminder’?"
|
2025-10-30 17:30:20 -07:00
|
|
|
|
in page.select(".usa-alert--error")[0].text
|
2023-08-25 09:12:23 -07:00
|
|
|
|
)
|
2025-10-30 17:30:20 -07:00
|
|
|
|
# When message is None, there's only one .usa-alert__text (the main message), not two
|
|
|
|
|
|
assert len(page.select(".usa-alert--error .usa-alert__text")) == 1
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".sms-message-wrapper")[0].text) == (
|
|
|
|
|
|
"service one: Template <em>content</em> with & entity"
|
2017-07-24 14:50:56 +01:00
|
|
|
|
)
|
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
|
|
|
|
|
|
|
|
|
|
|
2023-09-08 17:58:06 -04: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 = [
|
2023-08-25 09:12:23 -07: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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.service_api_client.get_service_template",
|
|
|
|
|
|
return_value={
|
|
|
|
|
|
"data": _template(
|
|
|
|
|
|
"sms",
|
|
|
|
|
|
"Hello",
|
|
|
|
|
|
parent=parent,
|
|
|
|
|
|
)
|
|
|
|
|
|
},
|
2019-02-13 17:46:35 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07: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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".choose_template",
|
2019-02-13 17:46:35 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_folder_id=parent,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
2019-02-13 17:46:35 +00:00
|
|
|
|
)
|
2015-12-20 00:00:01 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_get_service_template.assert_called_with(SERVICE_ONE_ID, TEMPLATE_ONE_ID, None)
|
|
|
|
|
|
mock_delete_service_template.assert_called_with(SERVICE_ONE_ID, TEMPLATE_ONE_ID)
|
2016-03-09 12:10:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-11-16 12:24:27 -08:00
|
|
|
|
@freeze_time("2016-01-01T20:00")
|
2016-07-01 13:10:19 +01: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,
|
|
|
|
|
|
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(
|
2023-08-25 09:12:23 -07: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)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert (
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
"main.edit_service_template",
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
not in content
|
|
|
|
|
|
)
|
|
|
|
|
|
assert (
|
|
|
|
|
|
url_for("main.send_one_off", service_id=SERVICE_ONE_ID, template_id=fake_uuid)
|
|
|
|
|
|
not in content
|
|
|
|
|
|
)
|
2025-10-06 09:38:54 -04:00
|
|
|
|
assert "This template was deleted" in content or "deleted" in content.lower()
|
2023-08-25 09:12:23 -07: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
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07: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,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07: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,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_id=service_one["id"],
|
|
|
|
|
|
template_type="sms",
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
),
|
2025-07-17 01:00:00 -07:00
|
|
|
|
[ServicePermission.MANAGE_TEMPLATES],
|
2017-02-03 12:07:21 +00:00
|
|
|
|
api_user_active,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
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
|
|
|
|
):
|
2023-08-25 09:12:23 -07: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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"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,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one,
|
|
|
|
|
|
)
|
2016-03-29 13:23:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07: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,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_id=service_one["id"],
|
|
|
|
|
|
template_type="sms",
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
),
|
2025-07-21 14:24:11 -07:00
|
|
|
|
[ServicePermission.VIEW_ACTIVITY],
|
2017-02-03 12:07:21 +00:00
|
|
|
|
api_user_active,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one,
|
|
|
|
|
|
)
|
2016-06-06 11:42:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-08 17:58:06 -04:00
|
|
|
|
("template_type", "expected"),
|
|
|
|
|
|
[
|
2023-08-25 09:12:23 -07:00
|
|
|
|
("email", "New email template"),
|
|
|
|
|
|
("sms", "New text message template"),
|
2023-09-08 17:58:06 -04:00
|
|
|
|
],
|
2023-08-25 09:12:23 -07:00
|
|
|
|
)
|
2020-08-17 13:01:33 +01:00
|
|
|
|
def test_add_template_page_title(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
template_type,
|
|
|
|
|
|
expected,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one["permissions"] += [template_type]
|
2020-08-17 13:01:33 +01:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".add_service_template",
|
2020-08-17 13:01:33 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_type=template_type,
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select_one("h1").text) == expected
|
2020-08-17 13:01:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
2025-06-09 12:28:08 -07:00
|
|
|
|
# def test_can_create_email_template_with_emoji(
|
|
|
|
|
|
# client_request, mock_create_service_template
|
|
|
|
|
|
# ):
|
|
|
|
|
|
# client_request.post(
|
|
|
|
|
|
# ".add_service_template",
|
|
|
|
|
|
# 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
|
|
|
|
|
2025-06-04 11:22:28 -07:00
|
|
|
|
|
2025-06-09 12:28:08 -07:00
|
|
|
|
# @pytest.mark.parametrize(
|
|
|
|
|
|
# ("template_type", "expected_error"),
|
|
|
|
|
|
# [
|
|
|
|
|
|
# (
|
|
|
|
|
|
# "sms",
|
|
|
|
|
|
# (
|
|
|
|
|
|
# "Please remove the unaccepted character 🍜 in your message, then save again"
|
|
|
|
|
|
# ),
|
|
|
|
|
|
# ),
|
|
|
|
|
|
# ],
|
|
|
|
|
|
# )
|
|
|
|
|
|
# def test_should_not_create_sms_template_with_emoji(
|
|
|
|
|
|
# client_request,
|
|
|
|
|
|
# service_one,
|
|
|
|
|
|
# mock_create_service_template,
|
|
|
|
|
|
# template_type,
|
|
|
|
|
|
# expected_error,
|
|
|
|
|
|
# ):
|
|
|
|
|
|
# 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": "here are some noodles 🍜",
|
|
|
|
|
|
# "template_type": "sms",
|
|
|
|
|
|
# "service": SERVICE_ONE_ID,
|
|
|
|
|
|
# "process_type": "normal",
|
|
|
|
|
|
# },
|
|
|
|
|
|
# _expected_status=200,
|
|
|
|
|
|
# )
|
|
|
|
|
|
# # print(page.main.prettify())
|
|
|
|
|
|
# assert expected_error in normalize_spaces(
|
|
|
|
|
|
# page.select_one("#template_content-error").text
|
|
|
|
|
|
# )
|
|
|
|
|
|
# assert mock_create_service_template.called is False
|
2017-02-15 13:49:15 +00:00
|
|
|
|
|
2025-06-04 11:49:55 -07:00
|
|
|
|
|
2025-06-09 12:28:08 -07:00
|
|
|
|
# @pytest.mark.parametrize(
|
|
|
|
|
|
# ("template_type", "expected_error"),
|
|
|
|
|
|
# [
|
|
|
|
|
|
# (
|
|
|
|
|
|
# "sms",
|
|
|
|
|
|
# (
|
|
|
|
|
|
# "Please remove the unaccepted character 🍔 in your message, then save again"
|
|
|
|
|
|
# ),
|
|
|
|
|
|
# ),
|
|
|
|
|
|
# ],
|
|
|
|
|
|
# )
|
|
|
|
|
|
# def test_should_not_update_sms_template_with_emoji(
|
|
|
|
|
|
# mocker,
|
|
|
|
|
|
# client_request,
|
|
|
|
|
|
# service_one,
|
|
|
|
|
|
# mock_get_service_template,
|
|
|
|
|
|
# mock_update_service_template,
|
|
|
|
|
|
# fake_uuid,
|
|
|
|
|
|
# template_type,
|
|
|
|
|
|
# expected_error,
|
|
|
|
|
|
# ):
|
|
|
|
|
|
# service_one["permissions"] += [template_type]
|
|
|
|
|
|
# return mocker.patch(
|
|
|
|
|
|
# "app.service_api_client.get_service_template",
|
|
|
|
|
|
# return_value=template_json(
|
|
|
|
|
|
# SERVICE_ONE_ID,
|
|
|
|
|
|
# fake_uuid,
|
|
|
|
|
|
# type_=template_type,
|
|
|
|
|
|
# ),
|
|
|
|
|
|
# )
|
|
|
|
|
|
# page = client_request.post(
|
|
|
|
|
|
# ".edit_service_template",
|
|
|
|
|
|
# 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,
|
|
|
|
|
|
# "template_type": template_type,
|
|
|
|
|
|
# "process_type": "normal",
|
|
|
|
|
|
# },
|
|
|
|
|
|
# _expected_status=200,
|
|
|
|
|
|
# )
|
|
|
|
|
|
# assert expected_error in page.text
|
|
|
|
|
|
# assert mock_update_service_template.called is False
|
2017-02-15 13:49:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-09-08 17:58:06 -04:00
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
|
"template_type",
|
|
|
|
|
|
[
|
|
|
|
|
|
"sms",
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2022-10-04 03:04:13 +00:00
|
|
|
|
def test_should_create_sms_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
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one["permissions"] += [template_type]
|
2020-07-01 16:43:08 +01:00
|
|
|
|
|
2025-03-31 08:45:33 -07:00
|
|
|
|
msg = "here:\tare some “fancy quotes” and non\u200bbreaking\u200bspaces"
|
2017-02-15 13:49:15 +00:00
|
|
|
|
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".add_service_template",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
template_type="sms",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
_data={
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"name": "new name",
|
|
|
|
|
|
"template_content": msg,
|
|
|
|
|
|
"template_type": template_type,
|
|
|
|
|
|
"service": SERVICE_ONE_ID,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
},
|
|
|
|
|
|
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
|
2023-08-25 09:12:23 -07:00
|
|
|
|
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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.redact_template",
|
2017-06-26 14:41:00 +01:00
|
|
|
|
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 (
|
2024-03-26 11:23:39 -04:00
|
|
|
|
"Are you sure you want to hide all personalized and conditional"
|
|
|
|
|
|
" content after sending for increased privacy protection?"
|
2025-10-30 17:30:20 -07:00
|
|
|
|
) in page.select(".usa-alert--error")[0].text
|
2017-06-26 14:41:00 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
form = page.select(".banner-dangerous form")[0]
|
2017-06-26 14:41:00 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert "action" not in form
|
|
|
|
|
|
assert form["method"] == "post"
|
2017-06-26 14:41:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.redact_template",
|
2017-06-26 14:41:00 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-10-30 17:30:20 -07:00
|
|
|
|
assert normalize_spaces(page.select(".usa-alert--success")[0].text) == (
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"Personalized content will be hidden for messages sent with this template"
|
2017-06-26 14:41:00 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07: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(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_template",
|
2017-06-28 15:26:09 +01:00
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
|
|
2025-10-06 09:38:54 -04:00
|
|
|
|
page_content = str(page)
|
|
|
|
|
|
assert (
|
|
|
|
|
|
"Personalization is hidden after sending" in page_content
|
|
|
|
|
|
or "redact" in page_content.lower()
|
|
|
|
|
|
)
|
2017-08-22 11:36:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
2018-01-03 10:44:36 +00:00
|
|
|
|
def test_set_template_sender(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_update_service_template_sender,
|
2022-12-05 15:33:44 -05:00
|
|
|
|
mock_get_service_template,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
single_sms_sender,
|
2018-01-03 10:44:36 +00:00
|
|
|
|
):
|
|
|
|
|
|
data = {
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sender": "1234",
|
2018-01-03 10:44:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.set_template_sender",
|
2018-01-03 10:44:36 +00:00
|
|
|
|
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,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"1234",
|
2018-01-03 10:44:36 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-06 11:54:27 +00:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-08 17:58:06 -04:00
|
|
|
|
("template_type", "prefix_sms", "content", "expected_message", "expected_class"),
|
|
|
|
|
|
[
|
2021-01-06 11:54:27 +00:00
|
|
|
|
(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms",
|
|
|
|
|
|
False,
|
|
|
|
|
|
"a" * 160,
|
2024-01-24 15:35:09 -05:00
|
|
|
|
"Will be charged as 1 text message",
|
2021-01-06 11:54:27 +00:00
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms",
|
|
|
|
|
|
False,
|
|
|
|
|
|
"a" * 161,
|
|
|
|
|
|
"Will be charged as 2 text messages",
|
2021-01-06 11:54:27 +00:00
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms",
|
|
|
|
|
|
True,
|
|
|
|
|
|
"a" * 147,
|
2024-01-24 15:35:09 -05:00
|
|
|
|
"Will be charged as 1 text message",
|
2021-01-06 11:54:27 +00:00
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
# service name takes 13 characters, 148 + 13 = 161
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms",
|
|
|
|
|
|
True,
|
|
|
|
|
|
"a" * 148,
|
|
|
|
|
|
"Will be charged as 2 text messages",
|
2021-01-06 11:54:27 +00:00
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms",
|
|
|
|
|
|
False,
|
|
|
|
|
|
"a" * 918,
|
2024-01-24 15:35:09 -05:00
|
|
|
|
"Will be charged as 6 text messages",
|
2021-01-06 11:54:27 +00:00
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
# Service name increases fragment count but doesn’t count
|
|
|
|
|
|
# against total character limit
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms",
|
|
|
|
|
|
True,
|
|
|
|
|
|
"a" * 918,
|
|
|
|
|
|
"Will be charged as 7 text messages",
|
2021-01-06 11:54:27 +00:00
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
# Can’t make a 7 fragment text template from content alone
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms",
|
|
|
|
|
|
False,
|
|
|
|
|
|
"a" * 919,
|
|
|
|
|
|
"You have 1 character too many",
|
|
|
|
|
|
"usa-error-message",
|
2021-01-06 11:54:27 +00:00
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
# Service name increases content count but character count
|
|
|
|
|
|
# is based on content alone
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms",
|
|
|
|
|
|
True,
|
|
|
|
|
|
"a" * 919,
|
|
|
|
|
|
"You have 1 character too many",
|
|
|
|
|
|
"usa-error-message",
|
2021-01-06 11:54:27 +00:00
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
# Service name increases content count but character count
|
|
|
|
|
|
# is based on content alone
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms",
|
|
|
|
|
|
True,
|
|
|
|
|
|
"a" * 920,
|
|
|
|
|
|
"You have 2 characters too many",
|
|
|
|
|
|
"usa-error-message",
|
2021-01-06 11:54:27 +00:00
|
|
|
|
),
|
|
|
|
|
|
(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms",
|
|
|
|
|
|
False,
|
|
|
|
|
|
"Ẅ" * 70,
|
2025-03-19 10:26:49 -04:00
|
|
|
|
"Will be charged as 1 text message.", # noqa E501
|
2021-01-06 11:54:27 +00:00
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms",
|
|
|
|
|
|
False,
|
|
|
|
|
|
"Ẅ" * 71,
|
|
|
|
|
|
"Will be charged as 2 text messages",
|
2021-01-06 11:54:27 +00:00
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms",
|
|
|
|
|
|
False,
|
|
|
|
|
|
"Ẅ" * 918,
|
2024-01-24 15:35:09 -05:00
|
|
|
|
"Will be charged as 14 text messages",
|
2021-01-06 11:54:27 +00:00
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms",
|
|
|
|
|
|
False,
|
|
|
|
|
|
"Ẅ" * 919,
|
|
|
|
|
|
"You have 1 character too many",
|
|
|
|
|
|
"usa-error-message",
|
2021-01-06 11:54:27 +00:00
|
|
|
|
),
|
|
|
|
|
|
(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms",
|
|
|
|
|
|
False,
|
|
|
|
|
|
"Hello ((name))",
|
2025-03-19 11:30:01 -04:00
|
|
|
|
"Will be charged as 1 text message (not including personalization).",
|
2021-01-06 11:54:27 +00:00
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
# Length of placeholder body doesn’t count towards fragment count
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"sms",
|
|
|
|
|
|
False,
|
|
|
|
|
|
f'Hello (( {"a" * 999} ))',
|
2025-03-19 11:30:01 -04:00
|
|
|
|
"Will be charged as 1 text message (not including personalization).",
|
2021-01-06 11:54:27 +00:00
|
|
|
|
None,
|
|
|
|
|
|
),
|
2023-09-08 17:58:06 -04:00
|
|
|
|
],
|
2021-01-06 11:54:27 +00:00
|
|
|
|
)
|
|
|
|
|
|
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,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one["prefix_sms"] = prefix_sms
|
2021-12-31 12:08:14 +00:00
|
|
|
|
response = client_request.post_response(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.count_content_length",
|
2021-12-31 12:08:14 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_type=template_type,
|
|
|
|
|
|
_data={
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"template_content": content,
|
2021-01-06 11:54:27 +00:00
|
|
|
|
},
|
2021-12-31 12:08:14 +00:00
|
|
|
|
_expected_status=200,
|
2021-01-06 11:54:27 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
html = json.loads(response.get_data(as_text=True))["html"]
|
|
|
|
|
|
snippet = BeautifulSoup(html, "html.parser").select_one("span")
|
2021-01-06 11:54:27 +00:00
|
|
|
|
|
2023-11-28 07:42:33 -08:00
|
|
|
|
assert expected_message in normalize_spaces(snippet.text)
|
2021-01-06 11:54:27 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
if snippet.has_attr("class"):
|
|
|
|
|
|
assert snippet["class"] == [expected_class]
|
2021-01-06 11:54:27 +00:00
|
|
|
|
else:
|
|
|
|
|
|
assert expected_class is None
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
|
"template_type",
|
2023-09-08 17:58:06 -04:00
|
|
|
|
[
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"email",
|
|
|
|
|
|
"banana",
|
2023-09-08 17:58:06 -04:00
|
|
|
|
],
|
2023-08-25 09:12:23 -07:00
|
|
|
|
)
|
2021-01-06 11:54:27 +00:00
|
|
|
|
def test_content_count_json_endpoint_for_unsupported_template_types(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
template_type,
|
|
|
|
|
|
):
|
|
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.count_content_length",
|
2021-01-06 11:54:27 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_type=template_type,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
content="foo",
|
2021-01-06 11:54:27 +00:00
|
|
|
|
_expected_status=404,
|
|
|
|
|
|
)
|