2020-09-29 14:48:56 +01:00
|
|
|
|
import pytest
|
|
|
|
|
|
from flask import url_for
|
|
|
|
|
|
|
|
|
|
|
|
from app import current_user
|
|
|
|
|
|
from tests import validate_route_permission
|
|
|
|
|
|
from tests.conftest import SERVICE_ONE_ID, create_template, normalize_spaces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_200_for_tour_start(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.begin_tour",
|
2020-09-29 14:48:56 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".banner-tour .heading-medium")[0].text) == (
|
|
|
|
|
|
"Try sending yourself this example"
|
2020-09-29 14:48:56 +01:00
|
|
|
|
)
|
2023-08-28 12:12:21 -04:00
|
|
|
|
selected_hint = page.select(".banner-tour .grid-row")[0]
|
|
|
|
|
|
selected_hint_text = normalize_spaces(selected_hint.select(".usa-body")[0].text)
|
2020-09-29 14:48:56 +01:00
|
|
|
|
assert "greyed-out-step" not in selected_hint["class"]
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert selected_hint_text == "Every message is sent from a template"
|
2020-09-29 14:48:56 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".sms-message-recipient")[0].text) == (
|
|
|
|
|
|
"To: 202-867-5303"
|
2020-09-29 14:48:56 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".sms-message-wrapper")[0].text) == (
|
|
|
|
|
|
"service one: ((one)) ((two)) ((three))"
|
2020-09-29 14:48:56 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select("a.usa-button")[0]["href"] == url_for(
|
|
|
|
|
|
".tour_step", service_id=SERVICE_ONE_ID, template_id=fake_uuid, step_index=1
|
2020-09-29 14:48:56 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-30 11:08:05 +01:00
|
|
|
|
def test_should_clear_session_on_tour_start(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
session["placeholders"] = {"one": "hello", "phone number": "202-867-5303"}
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.begin_tour",
|
2020-09-30 11:08:05 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert session["placeholders"] == {}
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize("template_type", ["email"])
|
2020-09-29 14:48:56 +01:00
|
|
|
|
def test_should_404_if_non_sms_template_for_tour_start(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
template_type,
|
|
|
|
|
|
):
|
|
|
|
|
|
mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.service_api_client.get_service_template",
|
|
|
|
|
|
return_value={"data": create_template(template_type=template_type)},
|
2020-09-29 14:48:56 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.begin_tour",
|
2020-09-29 14:48:56 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=404,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_404_if_no_mobile_number_for_tour_start(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
active_user_with_permissions_no_mobile,
|
2020-09-29 14:48:56 +01:00
|
|
|
|
):
|
|
|
|
|
|
client_request.login(active_user_with_permissions_no_mobile)
|
|
|
|
|
|
assert current_user.mobile_number is None
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.begin_tour",
|
2020-09-29 14:48:56 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_expected_status=404,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_403_if_user_does_not_have_send_permissions_for_tour_start(
|
|
|
|
|
|
mocker,
|
2021-05-12 14:57:21 +01:00
|
|
|
|
notify_admin,
|
2022-01-04 18:33:23 +00:00
|
|
|
|
client_request,
|
2020-09-29 14:48:56 +01:00
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
validate_route_permission(
|
|
|
|
|
|
mocker,
|
2021-05-12 14:57:21 +01:00
|
|
|
|
notify_admin,
|
2020-09-29 14:48:56 +01:00
|
|
|
|
"GET",
|
|
|
|
|
|
403,
|
|
|
|
|
|
url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.begin_tour",
|
2020-09-29 14:48:56 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
["view_activity"],
|
2020-09-29 14:48:56 +01:00
|
|
|
|
api_user_active,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one,
|
|
|
|
|
|
)
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_200_for_get_tour_step(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
session["placeholders"] = {}
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step", service_id=SERVICE_ONE_ID, template_id=fake_uuid, step_index=1
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert "Example text message" in normalize_spaces(page.select_one("title").text)
|
|
|
|
|
|
assert normalize_spaces(page.select(".banner-tour .heading-medium")[0].text) == (
|
|
|
|
|
|
"Try sending yourself this example"
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
2023-08-28 12:12:21 -04:00
|
|
|
|
selected_hint = page.select(".banner-tour .grid-row")[1]
|
|
|
|
|
|
selected_hint_text = normalize_spaces(selected_hint.select(".usa-body")[0].text)
|
2020-09-30 11:08:05 +01:00
|
|
|
|
assert "greyed-out-step" not in selected_hint["class"]
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert selected_hint_text == "The template pulls in the data you provide"
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".sms-message-recipient")[0].text) == (
|
|
|
|
|
|
"To: 202-867-5303"
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".sms-message-wrapper")[0].text) == (
|
|
|
|
|
|
"service one: ((one)) ((two)) ((three))"
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-04 11:28:31 +00:00
|
|
|
|
def test_should_show_empty_text_box(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
session["placeholders"] = {"phone number": "202-867-5303"}
|
2021-11-04 11:28:31 +00:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step", service_id=SERVICE_ONE_ID, template_id=fake_uuid, step_index=1
|
2021-11-04 11:28:31 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
textbox = page.select_one(
|
|
|
|
|
|
"[data-module=autofocus][data-force-focus=True] .usa-input"
|
|
|
|
|
|
)
|
|
|
|
|
|
assert "value" not in textbox
|
|
|
|
|
|
assert textbox["name"] == "placeholder_value"
|
|
|
|
|
|
assert textbox["class"] == [
|
|
|
|
|
|
"usa-input",
|
2021-11-04 11:28:31 +00:00
|
|
|
|
]
|
|
|
|
|
|
# data-module=autofocus is set on a containing element so it
|
|
|
|
|
|
# shouldn’t also be set on the textbox itself
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert "data-module" not in textbox
|
|
|
|
|
|
assert (
|
|
|
|
|
|
normalize_spaces(page.select_one("label[for=placeholder_value]").text) == "one"
|
|
|
|
|
|
)
|
2021-11-04 11:28:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
2020-09-30 11:08:05 +01:00
|
|
|
|
def test_should_prefill_answers_for_get_tour_step(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
session["placeholders"] = session["placeholders"] = {
|
|
|
|
|
|
"one": "hello",
|
|
|
|
|
|
"phone number": "202-867-5303",
|
|
|
|
|
|
}
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step", service_id=SERVICE_ONE_ID, template_id=fake_uuid, step_index=1
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select(".usa-input")[0]["value"] == "hello"
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize("template_type", ["email"])
|
|
|
|
|
|
@pytest.mark.parametrize("method", ["get", "post"])
|
2020-09-30 11:08:05 +01:00
|
|
|
|
def test_should_404_if_non_sms_template_for_tour_step(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
client_request, fake_uuid, mocker, template_type, method
|
2020-09-30 11:08:05 +01:00
|
|
|
|
):
|
|
|
|
|
|
mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.service_api_client.get_service_template",
|
|
|
|
|
|
return_value={"data": create_template(template_type=template_type)},
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
getattr(client_request, method)(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step",
|
2020-09-30 11:08:05 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=1,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_expected_status=404,
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-02 13:52:37 +01:00
|
|
|
|
def test_should_404_for_get_tour_step_0(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
session["placeholders"] = {}
|
2020-10-02 13:52:37 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step",
|
2020-10-02 13:52:37 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=0,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_expected_status=404,
|
2020-10-02 13:52:37 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize("method", ["GET", "POST"])
|
2020-09-30 11:08:05 +01:00
|
|
|
|
def test_should_403_if_user_does_not_have_send_permissions_for_tour_step(
|
|
|
|
|
|
mocker,
|
2021-05-12 14:57:21 +01:00
|
|
|
|
notify_admin,
|
2022-01-04 18:33:23 +00:00
|
|
|
|
client_request,
|
2020-09-30 11:08:05 +01:00
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
method,
|
2020-09-30 11:08:05 +01:00
|
|
|
|
):
|
|
|
|
|
|
validate_route_permission(
|
|
|
|
|
|
mocker,
|
2021-05-12 14:57:21 +01:00
|
|
|
|
notify_admin,
|
2020-09-30 11:08:05 +01:00
|
|
|
|
method,
|
|
|
|
|
|
403,
|
|
|
|
|
|
url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step",
|
2020-09-30 11:08:05 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
step_index=1,
|
2020-09-30 11:08:05 +01:00
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
["view_activity"],
|
2020-09-30 11:08:05 +01:00
|
|
|
|
api_user_active,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one,
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-02 12:45:01 +01:00
|
|
|
|
def test_tour_step_redirects_to_tour_start_if_placeholders_doesnt_exist_in_session(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert "placeholders" not in session
|
2020-10-02 12:45:01 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step",
|
2020-10-02 12:45:01 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=1,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.begin_tour",
|
2020-10-02 12:45:01 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-30 11:08:05 +01:00
|
|
|
|
def test_back_link_from_first_get_tour_step_points_to_tour_start(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
session["placeholders"] = {}
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step", service_id=SERVICE_ONE_ID, template_id=fake_uuid, step_index=1
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select(".usa-back-link")[0]["href"] == url_for(
|
|
|
|
|
|
"main.begin_tour", service_id=SERVICE_ONE_ID, template_id=fake_uuid
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_back_link_from_get_tour_step_points_to_previous_step(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
session["placeholders"] = {}
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step", service_id=SERVICE_ONE_ID, template_id=fake_uuid, step_index=2
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select(".usa-back-link")[0]["href"] == url_for(
|
|
|
|
|
|
"main.tour_step", service_id=SERVICE_ONE_ID, template_id=fake_uuid, step_index=1
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_post_tour_step_saves_data_and_redirects_to_next_step(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
session["placeholders"] = {}
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step",
|
2020-09-30 11:08:05 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=1,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_data={"placeholder_value": "hello"},
|
2020-09-30 11:08:05 +01:00
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step",
|
2020-09-30 11:08:05 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=2,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert session["placeholders"] == {
|
|
|
|
|
|
"one": "hello",
|
|
|
|
|
|
"phone number": "202-867-5303",
|
|
|
|
|
|
}
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_post_tour_step_adds_data_to_saved_data_and_redirects_to_next_step(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
session["placeholders"] = {"one": "hello", "phone number": "202-867-5303"}
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step",
|
2020-09-30 11:08:05 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=2,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_data={"placeholder_value": "is it me you are looking for"},
|
2020-09-30 11:08:05 +01:00
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step",
|
2020-09-30 11:08:05 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=3,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert session["placeholders"] == {
|
|
|
|
|
|
"one": "hello",
|
|
|
|
|
|
"two": "is it me you are looking for",
|
|
|
|
|
|
"phone number": "202-867-5303",
|
2020-09-30 11:08:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_post_tour_step_raises_validation_error_for_form_error(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
session["placeholders"] = {"one": "hi", "phone number": "202-867-5303"}
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step",
|
2020-09-30 11:08:05 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=2,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_data={"placeholder_value": ""},
|
2020-09-30 11:08:05 +01:00
|
|
|
|
_expected_status=200, # should this be 400
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".usa-error-message")[0].text) == (
|
|
|
|
|
|
"Error: Cannot be empty"
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".sms-message-recipient")[0].text) == (
|
|
|
|
|
|
"To: 202-867-5303"
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".sms-message-wrapper")[0].text) == (
|
|
|
|
|
|
"service one: hi ((two)) ((three))"
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert session["placeholders"] == {"one": "hi", "phone number": "202-867-5303"}
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_post_final_tour_step_saves_data_and_redirects_to_check_notification(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
session["placeholders"] = {
|
|
|
|
|
|
"one": "hello",
|
|
|
|
|
|
"two": "hi",
|
|
|
|
|
|
"phone number": "202-867-5303",
|
|
|
|
|
|
}
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step",
|
2020-09-30 11:08:05 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=3,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_data={"placeholder_value": "howdy"},
|
2020-09-30 11:08:05 +01:00
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.check_tour_notification",
|
2020-09-30 11:08:05 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
2020-09-30 13:39:37 +01:00
|
|
|
|
),
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert session["placeholders"] == {
|
|
|
|
|
|
"one": "hello",
|
|
|
|
|
|
"two": "hi",
|
|
|
|
|
|
"three": "howdy",
|
|
|
|
|
|
"phone number": "202-867-5303",
|
2021-03-08 15:36:23 +00:00
|
|
|
|
}
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_test_step_out_of_index_redirects_to_first_step(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
session["placeholders"] = {}
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step",
|
2020-09-30 11:08:05 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=4,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step",
|
2020-09-30 11:08:05 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=1,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_test_step_out_of_index_redirects_to_check_notification_if_all_placeholders_filled(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
session["placeholders"] = {
|
|
|
|
|
|
"one": "hello",
|
|
|
|
|
|
"two": "hi",
|
|
|
|
|
|
"three": "howdy",
|
|
|
|
|
|
"phone number": "202-867-5303",
|
|
|
|
|
|
}
|
2020-09-30 11:08:05 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.tour_step",
|
2020-09-30 11:08:05 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=4,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.check_tour_notification",
|
2020-09-30 11:08:05 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
2020-09-30 13:39:37 +01:00
|
|
|
|
),
|
2020-09-30 11:08:05 +01:00
|
|
|
|
)
|
2020-09-30 14:22:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_200_for_check_tour_notification(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
session["placeholders"] = {
|
|
|
|
|
|
"one": "hello",
|
|
|
|
|
|
"two": "hi",
|
|
|
|
|
|
"three": "howdy",
|
|
|
|
|
|
"phone number": "202-867-5303",
|
|
|
|
|
|
}
|
2020-09-30 14:22:42 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.check_tour_notification",
|
2020-09-30 14:22:42 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".banner-tour .heading-medium")[0].text) == (
|
|
|
|
|
|
"Try sending yourself this example"
|
2020-09-30 14:22:42 +01:00
|
|
|
|
)
|
2024-06-24 15:33:48 -07:00
|
|
|
|
selected_hint = page.select(".banner-tour .grid-row")[2]
|
2023-08-28 12:12:21 -04:00
|
|
|
|
selected_hint_text = normalize_spaces(selected_hint.select(".usa-body")[0].text)
|
2020-09-30 14:22:42 +01:00
|
|
|
|
assert "greyed-out-step" not in selected_hint["class"]
|
2024-06-24 15:33:48 -07:00
|
|
|
|
assert selected_hint_text == "Notify delivers the message"
|
2020-09-30 14:22:42 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".sms-message-recipient")[0].text) == (
|
|
|
|
|
|
"To: 202-867-5303"
|
2020-09-30 14:22:42 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".sms-message-wrapper")[0].text) == (
|
|
|
|
|
|
"service one: hello hi howdy"
|
2020-09-30 14:22:42 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2020-10-05 11:55:15 +01:00
|
|
|
|
# post to send_notification keeps help argument
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.form.attrs["action"] == url_for(
|
2024-06-24 15:33:48 -07:00
|
|
|
|
"main.send_notification",
|
2020-10-05 11:55:15 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
2024-06-24 15:33:48 -07:00
|
|
|
|
help=3,
|
2020-10-05 11:55:15 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2020-09-30 14:22:42 +01:00
|
|
|
|
|
|
|
|
|
|
def test_back_link_from_check_tour_notification_points_to_last_tour_step(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
session["placeholders"] = {
|
|
|
|
|
|
"one": "hello",
|
|
|
|
|
|
"two": "hi",
|
|
|
|
|
|
"three": "howdy",
|
|
|
|
|
|
"phone number": "202-867-5303",
|
|
|
|
|
|
}
|
2020-09-30 14:22:42 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.check_tour_notification",
|
2020-09-30 14:22:42 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select(".usa-back-link")[0]["href"] == url_for(
|
|
|
|
|
|
"main.tour_step", service_id=SERVICE_ONE_ID, template_id=fake_uuid, step_index=3
|
2020-09-30 14:22:42 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-02 12:45:01 +01:00
|
|
|
|
def test_check_tour_notification_redirects_to_tour_start_if_placeholders_doesnt_exist_in_session(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert "placeholders" not in session
|
2020-10-02 12:45:01 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.check_tour_notification",
|
2020-10-02 12:45:01 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=1,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.begin_tour",
|
2020-10-02 12:45:01 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-30 14:22:42 +01:00
|
|
|
|
def test_check_tour_notification_redirects_to_first_step_if_not_all_placeholders_in_session(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_template_with_multiple_placeholders,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
session["placeholders"] = {
|
|
|
|
|
|
"one": "hello",
|
|
|
|
|
|
"two": "hi",
|
|
|
|
|
|
"phone number": "202-867-5303",
|
|
|
|
|
|
}
|
2020-09-30 14:22:42 +01:00
|
|
|
|
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.check_tour_notification",
|
2020-09-30 14:22:42 +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.tour_step",
|
2020-09-30 14:22:42 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
step_index=1,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
2021-10-06 12:32:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_shows_link_to_end_tour(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_notification,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notification",
|
2021-10-06 12:32:00 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
|
|
|
|
|
help=3,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select(".banner-tour a")[0]["href"] == url_for(
|
|
|
|
|
|
"main.go_to_dashboard_after_tour",
|
2021-10-06 12:32:00 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
example_template_id="5407f4db-51c7-4150-8758-35412d42186a",
|
2021-10-06 12:32:00 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_go_to_dashboard_after_tour_link(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2021-10-06 12:32:00 +01:00
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_login,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
mock_delete_service_template,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
fake_uuid,
|
2021-10-06 12:32:00 +01:00
|
|
|
|
):
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.go_to_dashboard_after_tour",
|
2021-12-31 12:08:14 +00:00
|
|
|
|
service_id=fake_uuid,
|
|
|
|
|
|
example_template_id=fake_uuid,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
"main.service_dashboard",
|
|
|
|
|
|
service_id=fake_uuid,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
2021-10-06 12:32:00 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
mock_delete_service_template.assert_called_once_with(fake_uuid, fake_uuid)
|