2018-03-01 15:38:42 +00:00
|
|
|
|
from functools import partial
|
2017-06-16 12:13:21 +01:00
|
|
|
|
|
2018-02-20 11:22:17 +00:00
|
|
|
|
import pytest
|
|
|
|
|
|
from flask import url_for
|
|
|
|
|
|
from freezegun import freeze_time
|
2018-04-25 14:12:58 +01:00
|
|
|
|
|
2018-03-01 15:38:42 +00:00
|
|
|
|
from tests.conftest import (
|
|
|
|
|
|
SERVICE_ONE_ID,
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_caseworking_user,
|
|
|
|
|
|
create_active_user_with_permissions,
|
2019-12-20 15:48:25 +00:00
|
|
|
|
create_notification,
|
2018-03-01 15:38:42 +00:00
|
|
|
|
normalize_spaces,
|
|
|
|
|
|
)
|
2017-06-16 14:57:48 +01:00
|
|
|
|
|
2017-06-16 12:13:21 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
|
"key_type, notification_status, expected_status",
|
|
|
|
|
|
[
|
|
|
|
|
|
(None, "created", "Sending"),
|
|
|
|
|
|
(
|
|
|
|
|
|
None,
|
|
|
|
|
|
"sending",
|
|
|
|
|
|
"Pending. Messages will remain in pending state until carrier status is received, typically 5 minutes.",
|
|
|
|
|
|
),
|
|
|
|
|
|
(None, "delivered", "Delivered"),
|
|
|
|
|
|
(None, "failed", "Failed"),
|
|
|
|
|
|
(None, "temporary-failure", "Phone not accepting messages right now"),
|
|
|
|
|
|
(None, "permanent-failure", "Not delivered"),
|
|
|
|
|
|
(None, "technical-failure", "Technical failure"),
|
|
|
|
|
|
("team", "delivered", "Delivered"),
|
|
|
|
|
|
("live", "delivered", "Delivered"),
|
|
|
|
|
|
(
|
|
|
|
|
|
"test",
|
|
|
|
|
|
"sending",
|
|
|
|
|
|
"Pending. Messages will remain in pending state until carrier status "
|
|
|
|
|
|
"is received, typically 5 minutes. (test)",
|
|
|
|
|
|
),
|
|
|
|
|
|
("test", "delivered", "Delivered (test)"),
|
|
|
|
|
|
("test", "permanent-failure", "Not delivered (test)"),
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
|
"user",
|
|
|
|
|
|
[
|
|
|
|
|
|
create_active_user_with_permissions(),
|
|
|
|
|
|
create_active_caseworking_user(),
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2017-06-16 14:57:48 +01:00
|
|
|
|
@freeze_time("2016-01-01 11:09:00.061258")
|
|
|
|
|
|
def test_notification_status_page_shows_details(
|
|
|
|
|
|
client_request,
|
2017-06-19 14:37:16 +01:00
|
|
|
|
mocker,
|
2018-07-30 17:40:32 +01:00
|
|
|
|
mock_has_no_jobs,
|
2017-06-16 14:57:48 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
2018-06-12 16:17:20 +01:00
|
|
|
|
user,
|
2018-09-06 10:41:59 +01:00
|
|
|
|
key_type,
|
2017-06-19 14:37:16 +01:00
|
|
|
|
notification_status,
|
2017-06-24 17:12:45 +01:00
|
|
|
|
expected_status,
|
2017-06-16 14:57:48 +01:00
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch("app.user_api_client.get_user", return_value=user)
|
2017-06-24 17:12:45 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
notification = create_notification(
|
|
|
|
|
|
notification_status=notification_status, key_type=key_type
|
|
|
|
|
|
)
|
|
|
|
|
|
_mock_get_notification = mocker.patch(
|
|
|
|
|
|
"app.notification_api_client.get_notification", return_value=notification
|
|
|
|
|
|
)
|
2017-06-19 14:37:16 +01:00
|
|
|
|
|
2017-06-16 14:57:48 +01:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notification",
|
|
|
|
|
|
service_id=service_one["id"],
|
|
|
|
|
|
notification_id=fake_uuid,
|
2017-06-16 14:57:48 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".sms-message-recipient")[0].text) == (
|
|
|
|
|
|
"To: 2021234567"
|
2017-06-24 17:12:45 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".sms-message-wrapper")[0].text) == (
|
|
|
|
|
|
"service one: hello Jo"
|
2017-06-24 17:12:45 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select(".ajax-block-container p")[0].text) == (
|
2017-06-24 17:12:45 +01:00
|
|
|
|
expected_status
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_mock_get_notification.assert_called_with(service_one["id"], fake_uuid)
|
2017-06-24 17:29:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
|
"notification_type, notification_status, expected_class",
|
|
|
|
|
|
[
|
|
|
|
|
|
("sms", "failed", "error"),
|
|
|
|
|
|
("email", "failed", "error"),
|
|
|
|
|
|
("sms", "sent", "sent-international"),
|
|
|
|
|
|
("email", "sent", None),
|
|
|
|
|
|
("sms", "created", "default"),
|
|
|
|
|
|
("email", "created", "default"),
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2020-09-18 16:26:08 +01:00
|
|
|
|
@freeze_time("2016-01-01 11:09:00.061258")
|
|
|
|
|
|
def test_notification_status_page_formats_email_and_sms_status_correctly(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_has_no_jobs,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
active_user_with_permissions,
|
|
|
|
|
|
notification_type,
|
|
|
|
|
|
notification_status,
|
|
|
|
|
|
expected_class,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.user_api_client.get_user", return_value=active_user_with_permissions
|
|
|
|
|
|
)
|
|
|
|
|
|
notification = create_notification(
|
|
|
|
|
|
notification_status=notification_status, template_type=notification_type
|
|
|
|
|
|
)
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.notification_api_client.get_notification", return_value=notification
|
|
|
|
|
|
)
|
2020-09-18 16:26:08 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notification",
|
|
|
|
|
|
service_id=service_one["id"],
|
|
|
|
|
|
notification_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert page.select_one(
|
|
|
|
|
|
f".ajax-block-container p.notification-status.{expected_class}"
|
2020-09-18 16:26:08 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
|
"template_redaction_setting, expected_content",
|
|
|
|
|
|
[
|
|
|
|
|
|
(False, "service one: hello Jo"),
|
|
|
|
|
|
(True, "service one: hello hidden"),
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2017-06-24 17:29:28 +01:00
|
|
|
|
@freeze_time("2016-01-01 11:09:00.061258")
|
|
|
|
|
|
def test_notification_status_page_respects_redaction(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
template_redaction_setting,
|
|
|
|
|
|
expected_content,
|
|
|
|
|
|
):
|
2019-12-20 15:48:25 +00:00
|
|
|
|
_mock_get_notification = mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.notification_api_client.get_notification",
|
|
|
|
|
|
return_value=create_notification(
|
|
|
|
|
|
redact_personalisation=template_redaction_setting
|
|
|
|
|
|
),
|
2017-06-24 17:29:28 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notification",
|
|
|
|
|
|
service_id=service_one["id"],
|
|
|
|
|
|
notification_id=fake_uuid,
|
2017-06-24 17:29:28 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert (
|
|
|
|
|
|
normalize_spaces(page.select(".sms-message-wrapper")[0].text)
|
|
|
|
|
|
== expected_content
|
|
|
|
|
|
)
|
2017-06-24 17:29:28 +01:00
|
|
|
|
|
|
|
|
|
|
_mock_get_notification.assert_called_with(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one["id"],
|
2017-06-24 17:29:28 +01:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
)
|
2017-07-04 09:32:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
|
"extra_args, expected_back_link",
|
|
|
|
|
|
[
|
|
|
|
|
|
(
|
|
|
|
|
|
{},
|
|
|
|
|
|
partial(
|
|
|
|
|
|
url_for,
|
|
|
|
|
|
"main.view_notifications",
|
|
|
|
|
|
message_type="sms",
|
|
|
|
|
|
status="sending,delivered,failed",
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{"from_job": "job_id"},
|
|
|
|
|
|
partial(url_for, "main.view_job", job_id="job_id"),
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{"help": "0"},
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{"help": "1"},
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{"help": "2"},
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2019-05-09 17:33:22 +01:00
|
|
|
|
def test_notification_status_shows_expected_back_link(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_notification,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
extra_args,
|
|
|
|
|
|
expected_back_link,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notification",
|
2019-05-09 17:33:22 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
**extra_args,
|
2019-05-09 17:33:22 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
back_link = page.select_one(".usa-back-link")
|
2019-05-09 17:33:22 +01:00
|
|
|
|
|
|
|
|
|
|
if expected_back_link:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert back_link["href"] == expected_back_link(service_id=SERVICE_ONE_ID)
|
2019-05-09 17:33:22 +01:00
|
|
|
|
else:
|
|
|
|
|
|
assert back_link is None
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
|
"time_of_viewing_page, expected_message",
|
|
|
|
|
|
(
|
|
|
|
|
|
(
|
|
|
|
|
|
"2012-01-01 06:01",
|
|
|
|
|
|
("‘sample template’ was sent by Test User today at 06:01 UTC"),
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
"2012-01-02 06:01",
|
|
|
|
|
|
("‘sample template’ was sent by Test User yesterday at 06:01 UTC"),
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
"2012-01-03 06:01",
|
|
|
|
|
|
("‘sample template’ was sent by Test User on 1 January at 06:01 UTC"),
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
"2013-01-03 06:01",
|
|
|
|
|
|
("‘sample template’ was sent by Test User on 1 January 2012 at 06:01 UTC"),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
2017-07-04 09:32:09 +01:00
|
|
|
|
def test_notification_page_doesnt_link_to_template_in_tour(
|
2020-02-19 17:11:31 +00:00
|
|
|
|
mocker,
|
2017-07-04 09:32:09 +01:00
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_notification,
|
2020-02-19 17:11:31 +00:00
|
|
|
|
time_of_viewing_page,
|
|
|
|
|
|
expected_message,
|
2017-07-04 09:32:09 +01:00
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
with freeze_time("2012-01-01 06:01"):
|
2020-02-19 17:11:31 +00:00
|
|
|
|
notification = create_notification()
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.notification_api_client.get_notification", return_value=notification
|
|
|
|
|
|
)
|
2020-02-19 17:11:31 +00:00
|
|
|
|
|
|
|
|
|
|
with freeze_time(time_of_viewing_page):
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notification",
|
2020-02-19 17:11:31 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
|
|
|
|
|
help=3,
|
|
|
|
|
|
)
|
2017-07-04 09:32:09 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select("main p:nth-of-type(1)")[0].text) == (
|
2020-02-19 17:11:31 +00:00
|
|
|
|
expected_message
|
2017-07-04 09:32:09 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert len(page.select("main p:nth-of-type(1) a")) == 0
|
2017-07-13 13:05:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize("notification_type", ["email", "sms"])
|
|
|
|
|
|
@freeze_time("2016-01-01 15:00")
|
2018-12-05 10:58:27 +00:00
|
|
|
|
def test_notification_page_does_not_show_cancel_link_for_sms_or_email_notifications(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
notification_type,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
notification = create_notification(
|
|
|
|
|
|
template_type=notification_type, notification_status="created"
|
|
|
|
|
|
)
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.notification_api_client.get_notification", return_value=notification
|
|
|
|
|
|
)
|
2018-12-05 10:58:27 +00:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notification",
|
2018-12-05 10:58:27 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert "Cancel sending this letter" not in normalize_spaces(page.text)
|
2018-12-05 10:58:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
|
"service_permissions, template_type, link_expected",
|
|
|
|
|
|
[
|
|
|
|
|
|
([], "", False),
|
|
|
|
|
|
(["inbound_sms"], "email", False),
|
|
|
|
|
|
(["inbound_sms"], "sms", True),
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2017-10-16 10:30:59 +01:00
|
|
|
|
def test_notification_page_has_link_to_send_another_for_sms(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
service_permissions,
|
|
|
|
|
|
template_type,
|
|
|
|
|
|
link_expected,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one["permissions"] = service_permissions
|
2019-12-20 15:48:25 +00:00
|
|
|
|
notification = create_notification(template_type=template_type)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.notification_api_client.get_notification", return_value=notification
|
|
|
|
|
|
)
|
2017-10-16 10:30:59 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notification",
|
2017-10-16 10:30:59 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
last_paragraph = page.select("main p")[-1]
|
2017-11-10 08:42:49 +00:00
|
|
|
|
conversation_link = url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".conversation",
|
2017-11-10 08:42:49 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_anchor="n{}".format(fake_uuid),
|
2017-11-10 08:42:49 +00:00
|
|
|
|
)
|
2017-10-16 10:30:59 +01:00
|
|
|
|
|
|
|
|
|
|
if link_expected:
|
|
|
|
|
|
assert normalize_spaces(last_paragraph.text) == (
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"See all text messages sent to this phone number"
|
2017-10-16 10:30:59 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert last_paragraph.select_one("a")["href"] == conversation_link
|
2017-10-16 10:30:59 +01:00
|
|
|
|
else:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert conversation_link not in str(page.select_one("main"))
|
2017-11-10 08:42:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize("notification_type", ["sms", "email"])
|
2021-02-08 16:38:50 +00:00
|
|
|
|
def test_should_show_reply_to_from_notification(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
notification_type,
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
notification = create_notification(
|
|
|
|
|
|
reply_to_text="reply to info", template_type=notification_type
|
|
|
|
|
|
)
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.notification_api_client.get_notification", return_value=notification
|
|
|
|
|
|
)
|
2021-02-08 16:38:50 +00:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notification",
|
2021-02-08 16:38:50 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert "reply to info" in page.text
|