2017-06-13 10:32:36 +01:00
|
|
|
|
import json
|
|
|
|
|
|
import uuid
|
2018-07-10 15:49:57 +01:00
|
|
|
|
from functools import partial
|
2022-05-27 15:42:53 +01:00
|
|
|
|
from urllib.parse import parse_qs, urlparse
|
2017-06-13 10:32:36 +01:00
|
|
|
|
|
|
|
|
|
|
import pytest
|
2018-02-20 11:22:17 +00:00
|
|
|
|
from flask import url_for
|
|
|
|
|
|
from freezegun import freeze_time
|
2018-04-25 14:12:58 +01:00
|
|
|
|
|
|
|
|
|
|
from app.main.views.jobs import get_status_filters, get_time_left
|
2018-10-26 15:58:44 +01:00
|
|
|
|
from app.models.service import Service
|
2017-10-02 12:34:10 +01:00
|
|
|
|
from tests.conftest import (
|
|
|
|
|
|
SERVICE_ONE_ID,
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_caseworking_user,
|
|
|
|
|
|
create_active_user_view_permissions,
|
|
|
|
|
|
create_active_user_with_permissions,
|
2020-01-07 15:24:33 +00:00
|
|
|
|
create_notifications,
|
2017-10-02 12:34:10 +01:00
|
|
|
|
normalize_spaces,
|
|
|
|
|
|
)
|
2018-02-20 11:22:17 +00:00
|
|
|
|
|
2017-06-13 10:32:36 +01:00
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-25 17:55:42 -04:00
|
|
|
|
(
|
|
|
|
|
|
"user",
|
|
|
|
|
|
"extra_args",
|
|
|
|
|
|
"expected_update_endpoint",
|
|
|
|
|
|
"expected_limit_days",
|
|
|
|
|
|
"page_title",
|
|
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
2018-11-15 17:04:11 +00:00
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_view_permissions(),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
{"message_type": "email"},
|
|
|
|
|
|
"/email.json",
|
2018-11-15 17:04:11 +00:00
|
|
|
|
7,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"Emails",
|
2018-11-15 17:04:11 +00:00
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_user_view_permissions(),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
{"message_type": "sms"},
|
|
|
|
|
|
"/sms.json",
|
2018-11-15 17:04:11 +00:00
|
|
|
|
7,
|
2024-03-28 15:58:02 -04:00
|
|
|
|
"Text message",
|
2018-11-15 17:04:11 +00:00
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-12-19 16:59:07 +00:00
|
|
|
|
create_active_caseworking_user(),
|
2018-11-15 17:04:11 +00:00
|
|
|
|
{},
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".json",
|
2018-11-15 17:04:11 +00:00
|
|
|
|
None,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"Sent messages",
|
2018-11-15 17:04:11 +00:00
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
],
|
2017-06-13 10:32:36 +01:00
|
|
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-25 17:55:42 -04:00
|
|
|
|
("status_argument", "expected_api_call"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
2017-06-13 10:32:36 +01:00
|
|
|
|
(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"",
|
2017-06-13 10:32:36 +01:00
|
|
|
|
[
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"created",
|
|
|
|
|
|
"pending",
|
|
|
|
|
|
"sending",
|
|
|
|
|
|
"delivered",
|
|
|
|
|
|
"sent",
|
|
|
|
|
|
"failed",
|
|
|
|
|
|
"temporary-failure",
|
|
|
|
|
|
"permanent-failure",
|
|
|
|
|
|
"technical-failure",
|
|
|
|
|
|
"validation-failed",
|
|
|
|
|
|
],
|
2017-06-13 10:32:36 +01:00
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
("sending", ["sending", "created", "pending"]),
|
|
|
|
|
|
("delivered", ["delivered", "sent"]),
|
2017-06-13 10:32:36 +01:00
|
|
|
|
(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"failed",
|
2019-01-10 15:54:31 +00:00
|
|
|
|
[
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"failed",
|
|
|
|
|
|
"temporary-failure",
|
|
|
|
|
|
"permanent-failure",
|
|
|
|
|
|
"technical-failure",
|
|
|
|
|
|
"validation-failed",
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
2017-06-13 10:32:36 +01:00
|
|
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-25 17:55:42 -04:00
|
|
|
|
("page_argument", "expected_page_argument"), [(1, 1), (22, 22), (None, 1)]
|
2017-06-13 10:32:36 +01:00
|
|
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-25 17:55:42 -04:00
|
|
|
|
("to_argument", "expected_to_argument"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
|
|
|
|
|
("", ""),
|
|
|
|
|
|
("+12029000123", "+12029000123"),
|
|
|
|
|
|
("test@example.com", "test@example.com"),
|
|
|
|
|
|
],
|
2017-06-13 10:32:36 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@freeze_time("2020-01-01 06:00")
|
2017-06-13 10:32:36 +01:00
|
|
|
|
def test_can_show_notifications(
|
2018-07-13 16:21:22 +01:00
|
|
|
|
client_request,
|
2017-06-13 10:32:36 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_notifications,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-12-03 17:19:38 +00:00
|
|
|
|
mock_get_service_data_retention,
|
2018-07-30 17:40:32 +01:00
|
|
|
|
mock_has_no_jobs,
|
2019-12-13 14:27:56 +00:00
|
|
|
|
mock_get_no_api_keys,
|
2018-07-13 16:21:22 +01:00
|
|
|
|
user,
|
|
|
|
|
|
extra_args,
|
|
|
|
|
|
expected_update_endpoint,
|
2018-11-15 17:04:11 +00:00
|
|
|
|
expected_limit_days,
|
2017-06-13 10:32:36 +01:00
|
|
|
|
page_title,
|
|
|
|
|
|
status_argument,
|
|
|
|
|
|
expected_api_call,
|
|
|
|
|
|
page_argument,
|
|
|
|
|
|
expected_page_argument,
|
|
|
|
|
|
to_argument,
|
|
|
|
|
|
expected_to_argument,
|
2018-06-13 14:16:10 +01:00
|
|
|
|
mocker,
|
2017-06-13 10:32:36 +01:00
|
|
|
|
):
|
2019-12-19 16:59:07 +00:00
|
|
|
|
client_request.login(user)
|
2017-06-13 11:05:57 +01:00
|
|
|
|
if expected_to_argument:
|
2018-07-13 16:21:22 +01:00
|
|
|
|
page = client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notifications",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2018-07-13 16:21:22 +01:00
|
|
|
|
status=status_argument,
|
|
|
|
|
|
page=page_argument,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_data={"to": to_argument},
|
2018-07-13 16:21:22 +01:00
|
|
|
|
_expected_status=200,
|
|
|
|
|
|
**extra_args
|
2017-06-13 11:05:57 +01:00
|
|
|
|
)
|
|
|
|
|
|
else:
|
2018-07-13 16:21:22 +01:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notifications",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-06-13 11:05:57 +01:00
|
|
|
|
status=status_argument,
|
|
|
|
|
|
page=page_argument,
|
2018-07-13 16:21:22 +01:00
|
|
|
|
**extra_args
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
first_row = page.select_one("tbody tr")
|
2020-04-22 16:03:37 +01:00
|
|
|
|
assert normalize_spaces(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
first_row.select_one("a.file-list-filename.usa-link").text
|
2020-04-22 16:03:37 +01:00
|
|
|
|
) == (
|
2020-04-23 10:12:02 +01:00
|
|
|
|
# Comes from
|
|
|
|
|
|
# https://github.com/alphagov/notifications-admin/blob/8faffad508f9a087b0006989c197741c693cc2e2/tests/__init__.py#L436
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"2021234567"
|
2017-06-24 17:12:45 +01:00
|
|
|
|
)
|
2020-04-22 16:03:37 +01:00
|
|
|
|
assert normalize_spaces(
|
|
|
|
|
|
# We’re doing str() here not .text to make sure there’s no extra
|
|
|
|
|
|
# HTML sneaking in
|
2023-08-25 09:12:23 -07:00
|
|
|
|
str(first_row.select_one(".file-list-hint"))
|
2020-04-22 16:03:37 +01:00
|
|
|
|
) == (
|
2020-04-23 10:12:02 +01:00
|
|
|
|
# Comes from
|
|
|
|
|
|
# https://github.com/alphagov/notifications-admin/blob/8faffad508f9a087b0006989c197741c693cc2e2/tests/__init__.py#L271
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"template content"
|
2020-04-22 16:03:37 +01:00
|
|
|
|
) or (
|
2020-04-23 10:12:02 +01:00
|
|
|
|
# Comes from
|
|
|
|
|
|
# https://github.com/alphagov/notifications-admin/blob/8faffad508f9a087b0006989c197741c693cc2e2/tests/__init__.py#L273
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"template subject"
|
2020-04-22 16:03:37 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
first_row.select_one(".table-field-right-aligned .align-with-message-body").text
|
2023-11-16 12:24:27 -08:00
|
|
|
|
) in [
|
2024-02-29 08:24:53 -08:00
|
|
|
|
"Delivered 01-01-2020 at 01:00 AM",
|
|
|
|
|
|
"Delivered 01-01-2020 at 01:00 AM",
|
2023-11-16 12:24:27 -08:00
|
|
|
|
]
|
2020-04-22 16:03:37 +01:00
|
|
|
|
|
2017-06-13 10:32:36 +01:00
|
|
|
|
assert page_title in page.h1.text.strip()
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
path_to_json = page.find("div", {"data-key": "notifications"})["data-resource"]
|
2017-06-13 10:32:36 +01:00
|
|
|
|
|
|
|
|
|
|
url = urlparse(path_to_json)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert url.path == "/services/{}/notifications{}".format(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
SERVICE_ONE_ID,
|
2018-07-13 16:21:22 +01:00
|
|
|
|
expected_update_endpoint,
|
|
|
|
|
|
)
|
2017-06-13 10:32:36 +01:00
|
|
|
|
query_dict = parse_qs(url.query)
|
|
|
|
|
|
if status_argument:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert query_dict["status"] == [status_argument]
|
2017-06-13 10:32:36 +01:00
|
|
|
|
if expected_page_argument:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert query_dict["page"] == [str(expected_page_argument)]
|
|
|
|
|
|
assert "to" not in query_dict
|
2017-06-13 10:32:36 +01:00
|
|
|
|
|
|
|
|
|
|
mock_get_notifications.assert_called_with(
|
2018-11-15 17:04:11 +00:00
|
|
|
|
limit_days=expected_limit_days,
|
2017-06-13 10:32:36 +01:00
|
|
|
|
page=expected_page_argument,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2017-06-13 10:32:36 +01:00
|
|
|
|
status=expected_api_call,
|
2018-07-13 16:21:22 +01:00
|
|
|
|
template_type=list(extra_args.values()),
|
2017-06-13 10:32:36 +01:00
|
|
|
|
to=expected_to_argument,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
json_response = client_request.get_response(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.get_notifications_as_json",
|
|
|
|
|
|
service_id=service_one["id"],
|
2018-07-13 16:21:22 +01:00
|
|
|
|
status=status_argument,
|
|
|
|
|
|
**extra_args
|
2021-12-31 12:08:14 +00:00
|
|
|
|
)
|
2017-06-13 10:32:36 +01:00
|
|
|
|
json_content = json.loads(json_response.get_data(as_text=True))
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert json_content.keys() == {
|
|
|
|
|
|
"counts",
|
|
|
|
|
|
"notifications",
|
|
|
|
|
|
"service_data_retention_days",
|
|
|
|
|
|
}
|
2017-06-13 10:32:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 17:04:11 +00:00
|
|
|
|
def test_can_show_notifications_if_data_retention_not_available(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_notifications,
|
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
|
mock_has_no_jobs,
|
2019-12-13 14:27:56 +00:00
|
|
|
|
mock_get_no_api_keys,
|
2018-11-15 17:04:11 +00:00
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notifications",
|
2018-11-15 17:04:11 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
status="sending,delivered,failed",
|
2018-11-15 17:04:11 +00:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.h1.text.strip() == "Messages"
|
2018-11-15 17:04:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-25 17:55:42 -04:00
|
|
|
|
("user", "query_parameters", "expected_download_link"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
|
|
|
|
|
(
|
|
|
|
|
|
create_active_user_with_permissions(),
|
|
|
|
|
|
{},
|
|
|
|
|
|
partial(
|
|
|
|
|
|
url_for,
|
|
|
|
|
|
".download_notifications_csv",
|
|
|
|
|
|
message_type=None,
|
2024-06-10 10:15:22 -06:00
|
|
|
|
number_of_days="seven_day",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
2018-07-10 15:49:57 +01:00
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
(
|
|
|
|
|
|
create_active_user_with_permissions(),
|
|
|
|
|
|
{"status": "failed"},
|
2024-06-10 10:15:22 -06:00
|
|
|
|
partial(
|
|
|
|
|
|
url_for,
|
|
|
|
|
|
".download_notifications_csv",
|
|
|
|
|
|
status="failed",
|
|
|
|
|
|
number_of_days="seven_day",
|
|
|
|
|
|
),
|
2018-07-10 15:49:57 +01:00
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
(
|
|
|
|
|
|
create_active_user_with_permissions(),
|
|
|
|
|
|
{"message_type": "sms"},
|
|
|
|
|
|
partial(
|
|
|
|
|
|
url_for,
|
|
|
|
|
|
".download_notifications_csv",
|
|
|
|
|
|
message_type="sms",
|
2024-06-10 10:15:22 -06:00
|
|
|
|
number_of_days="seven_day",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
2018-07-10 15:49:57 +01:00
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
(
|
|
|
|
|
|
create_active_user_view_permissions(),
|
|
|
|
|
|
{},
|
2024-06-10 10:15:22 -06:00
|
|
|
|
partial(url_for, ".download_notifications_csv", number_of_days="seven_day"),
|
2018-07-10 15:49:57 +01:00
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
(
|
|
|
|
|
|
create_active_caseworking_user(),
|
|
|
|
|
|
{},
|
|
|
|
|
|
lambda service_id: None,
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2018-07-10 15:49:57 +01:00
|
|
|
|
def test_link_to_download_notifications(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_notifications,
|
|
|
|
|
|
mock_get_service_statistics,
|
2018-12-03 17:19:38 +00:00
|
|
|
|
mock_get_service_data_retention,
|
2018-07-30 17:40:32 +01:00
|
|
|
|
mock_has_no_jobs,
|
2019-12-13 14:27:56 +00:00
|
|
|
|
mock_get_no_api_keys,
|
2018-07-10 15:49:57 +01:00
|
|
|
|
user,
|
|
|
|
|
|
query_parameters,
|
|
|
|
|
|
expected_download_link,
|
|
|
|
|
|
):
|
2019-12-19 16:59:07 +00:00
|
|
|
|
client_request.login(user)
|
2018-07-10 15:49:57 +01:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notifications", service_id=SERVICE_ONE_ID, **query_parameters
|
|
|
|
|
|
)
|
|
|
|
|
|
download_link = page.select_one("a[download=download]")
|
|
|
|
|
|
assert (download_link["href"] if download_link else None) == expected_download_link(
|
|
|
|
|
|
service_id=SERVICE_ONE_ID
|
2018-07-10 15:49:57 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-09 17:51:34 +01:00
|
|
|
|
def test_download_not_available_to_users_without_dashboard(
|
2018-07-10 15:49:57 +01:00
|
|
|
|
client_request,
|
|
|
|
|
|
active_caseworking_user,
|
|
|
|
|
|
):
|
|
|
|
|
|
client_request.login(active_caseworking_user)
|
|
|
|
|
|
client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.download_notifications_csv",
|
2018-07-10 15:49:57 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
_expected_status=403,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-24 17:12:45 +01:00
|
|
|
|
def test_shows_message_when_no_notifications(
|
|
|
|
|
|
client_request,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-12-03 17:19:38 +00:00
|
|
|
|
mock_get_service_data_retention,
|
2017-06-24 17:12:45 +01:00
|
|
|
|
mock_get_notifications_with_no_notifications,
|
2019-12-13 14:27:56 +00:00
|
|
|
|
mock_get_no_api_keys,
|
2017-06-24 17:12:45 +01:00
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notifications",
|
2017-06-24 17:12:45 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
message_type="sms",
|
2017-06-24 17:12:45 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select("tbody tr")[0].text) == (
|
|
|
|
|
|
"No messages found (messages are kept for 7 days)"
|
2017-06-24 17:12:45 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2017-06-13 10:32:36 +01:00
|
|
|
|
(
|
2023-09-25 17:55:42 -04:00
|
|
|
|
"initial_query_arguments",
|
|
|
|
|
|
"form_post_data",
|
|
|
|
|
|
"expected_search_box_label",
|
|
|
|
|
|
"expected_search_box_contents",
|
2017-06-13 10:32:36 +01:00
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
|
|
|
|
|
(
|
|
|
|
|
|
{},
|
|
|
|
|
|
{},
|
|
|
|
|
|
"Search by recipient",
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{
|
|
|
|
|
|
"message_type": "sms",
|
|
|
|
|
|
},
|
|
|
|
|
|
{},
|
|
|
|
|
|
"Search by phone number",
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{
|
|
|
|
|
|
"message_type": "sms",
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"to": "+33(0)5-12-34-56-78",
|
|
|
|
|
|
},
|
|
|
|
|
|
"Search by phone number",
|
|
|
|
|
|
"+33(0)5-12-34-56-78",
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{
|
|
|
|
|
|
"status": "failed",
|
|
|
|
|
|
"message_type": "email",
|
|
|
|
|
|
"page": "99",
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"to": "test@example.com",
|
|
|
|
|
|
},
|
|
|
|
|
|
"Search by email address",
|
|
|
|
|
|
"test@example.com",
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2017-06-13 10:32:36 +01:00
|
|
|
|
def test_search_recipient_form(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-06-13 10:32:36 +01:00
|
|
|
|
mock_get_notifications,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-12-03 17:19:38 +00:00
|
|
|
|
mock_get_service_data_retention,
|
2019-12-13 14:27:56 +00:00
|
|
|
|
mock_get_no_api_keys,
|
2017-06-13 10:32:36 +01:00
|
|
|
|
initial_query_arguments,
|
2017-06-13 11:05:57 +01:00
|
|
|
|
form_post_data,
|
2018-08-07 14:44:09 +01:00
|
|
|
|
expected_search_box_label,
|
2017-06-13 10:32:36 +01:00
|
|
|
|
expected_search_box_contents,
|
|
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notifications",
|
2019-03-26 12:35:32 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
_data=form_post_data,
|
|
|
|
|
|
_expected_status=200,
|
|
|
|
|
|
**initial_query_arguments
|
2017-06-13 11:05:57 +01:00
|
|
|
|
)
|
2017-06-13 10:32:36 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.find("form")["method"] == "post"
|
|
|
|
|
|
action_url = page.find("form")["action"]
|
2017-06-13 10:32:36 +01:00
|
|
|
|
url = urlparse(action_url)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert url.path == "/services/{}/notifications/{}".format(
|
|
|
|
|
|
SERVICE_ONE_ID, initial_query_arguments.get("message_type", "")
|
|
|
|
|
|
).rstrip("/")
|
2017-06-13 10:32:36 +01:00
|
|
|
|
query_dict = parse_qs(url.query)
|
|
|
|
|
|
assert query_dict == {}
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select_one("label[for=to]").text.strip() == expected_search_box_label
|
2018-08-07 14:44:09 +01:00
|
|
|
|
|
2017-06-14 16:25:20 +01:00
|
|
|
|
recipient_inputs = page.select("input[name=to]")
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert len(recipient_inputs) == 2
|
2017-06-14 16:25:20 +01:00
|
|
|
|
|
|
|
|
|
|
for field in recipient_inputs:
|
2020-08-07 10:16:24 +01:00
|
|
|
|
assert field.get("value") == expected_search_box_contents
|
2017-06-13 10:32:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-25 17:55:42 -04:00
|
|
|
|
("message_type", "expected_search_box_label"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
|
|
|
|
|
(None, "Search by recipient or reference"),
|
|
|
|
|
|
("sms", "Search by phone number or reference"),
|
|
|
|
|
|
("email", "Search by email address or reference"),
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2020-01-10 15:42:46 +00:00
|
|
|
|
def test_api_users_are_told_they_can_search_by_reference_when_service_has_api_keys(
|
2020-01-06 14:42:52 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_notifications,
|
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
|
mock_get_service_data_retention,
|
|
|
|
|
|
message_type,
|
|
|
|
|
|
expected_search_box_label,
|
2020-01-10 15:42:46 +00:00
|
|
|
|
mock_get_api_keys,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notifications",
|
2020-01-10 15:42:46 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
message_type=message_type,
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select_one("label[for=to]").text.strip() == expected_search_box_label
|
2020-01-10 15:42:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-25 17:55:42 -04:00
|
|
|
|
("message_type", "expected_search_box_label"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
|
|
|
|
|
(None, "Search by recipient"),
|
|
|
|
|
|
("sms", "Search by phone number"),
|
|
|
|
|
|
("email", "Search by email address"),
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2020-01-10 15:42:46 +00:00
|
|
|
|
def test_api_users_are_not_told_they_can_search_by_reference_when_service_has_no_api_keys(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_notifications,
|
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
|
mock_get_service_data_retention,
|
|
|
|
|
|
message_type,
|
|
|
|
|
|
expected_search_box_label,
|
|
|
|
|
|
mock_get_no_api_keys,
|
2019-12-13 14:27:56 +00:00
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notifications",
|
2019-12-13 14:27:56 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
message_type=message_type,
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select_one("label[for=to]").text.strip() == expected_search_box_label
|
2019-12-13 14:27:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-06-13 10:32:36 +01:00
|
|
|
|
def test_should_show_notifications_for_a_service_with_next_previous(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-06-13 10:32:36 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
active_user_with_permissions,
|
|
|
|
|
|
mock_get_notifications_with_previous_next,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-12-03 17:19:38 +00:00
|
|
|
|
mock_get_service_data_retention,
|
2019-12-13 14:27:56 +00:00
|
|
|
|
mock_get_no_api_keys,
|
2017-06-13 10:32:36 +01:00
|
|
|
|
mocker,
|
|
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notifications",
|
|
|
|
|
|
service_id=service_one["id"],
|
|
|
|
|
|
message_type="sms",
|
|
|
|
|
|
page=2,
|
2019-03-26 12:35:32 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
next_page_link = page.find("a", {"rel": "next"})
|
|
|
|
|
|
prev_page_link = page.find("a", {"rel": "previous"})
|
2017-06-13 10:32:36 +01:00
|
|
|
|
assert (
|
2023-08-25 09:12:23 -07:00
|
|
|
|
url_for(
|
|
|
|
|
|
"main.view_notifications",
|
|
|
|
|
|
service_id=service_one["id"],
|
|
|
|
|
|
message_type="sms",
|
|
|
|
|
|
page=3,
|
|
|
|
|
|
)
|
|
|
|
|
|
in next_page_link["href"]
|
2017-06-13 10:32:36 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert "Next page" in next_page_link.text.strip()
|
|
|
|
|
|
assert "page 3" in next_page_link.text.strip()
|
2017-06-13 10:32:36 +01:00
|
|
|
|
assert (
|
2023-08-25 09:12:23 -07:00
|
|
|
|
url_for(
|
|
|
|
|
|
"main.view_notifications",
|
|
|
|
|
|
service_id=service_one["id"],
|
|
|
|
|
|
message_type="sms",
|
|
|
|
|
|
page=1,
|
|
|
|
|
|
)
|
|
|
|
|
|
in prev_page_link["href"]
|
2017-06-13 10:32:36 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert "Previous page" in prev_page_link.text.strip()
|
|
|
|
|
|
assert "page 1" in prev_page_link.text.strip()
|
2017-06-13 10:32:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
2020-05-06 14:30:32 +01:00
|
|
|
|
def test_doesnt_show_pagination_with_search_term(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
active_user_with_permissions,
|
|
|
|
|
|
mock_get_notifications_with_previous_next,
|
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
|
mock_get_service_data_retention,
|
|
|
|
|
|
mock_get_no_api_keys,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notifications",
|
|
|
|
|
|
service_id=service_one["id"],
|
|
|
|
|
|
message_type="sms",
|
2020-05-06 14:30:32 +01:00
|
|
|
|
_data={
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"to": "test@example.com",
|
2020-05-06 14:30:32 +01:00
|
|
|
|
},
|
|
|
|
|
|
_expected_status=200,
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert len(page.select("tbody tr")) == 50
|
|
|
|
|
|
assert not page.find("a", {"rel": "next"})
|
|
|
|
|
|
assert not page.find("a", {"rel": "previous"})
|
|
|
|
|
|
assert normalize_spaces(page.select_one(".table-show-more-link").text) == (
|
|
|
|
|
|
"Only showing the first 50 messages"
|
2020-05-06 14:30:32 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-13 10:32:36 +01:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-25 17:55:42 -04:00
|
|
|
|
("job_created_at", "expected_message"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
2017-06-13 10:32:36 +01:00
|
|
|
|
("2016-01-10 11:09:00.000000+00:00", "Data available for 7 days"),
|
|
|
|
|
|
("2016-01-04 11:09:00.000000+00:00", "Data available for 1 day"),
|
2018-11-26 15:15:06 +00:00
|
|
|
|
("2016-01-03 11:09:00.000000+00:00", "Data available for 12 hours"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
("2016-01-02 23:59:59.000000+00:00", "Data no longer available"),
|
|
|
|
|
|
],
|
2017-06-13 10:32:36 +01:00
|
|
|
|
)
|
|
|
|
|
|
@freeze_time("2016-01-10 12:00:00.000000")
|
|
|
|
|
|
def test_time_left(job_created_at, expected_message):
|
|
|
|
|
|
assert get_time_left(job_created_at) == expected_message
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
STATISTICS = {"sms": {"requested": 6, "failed": 2, "delivered": 1}}
|
2017-06-13 10:32:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
2022-01-04 18:33:23 +00:00
|
|
|
|
def test_get_status_filters_calculates_stats(client_request):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
ret = get_status_filters(Service({"id": "foo"}), "sms", STATISTICS)
|
2017-06-13 10:32:36 +01:00
|
|
|
|
|
|
|
|
|
|
assert {label: count for label, _option, _link, count in ret} == {
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"total": 6,
|
|
|
|
|
|
"pending": 3,
|
|
|
|
|
|
"failed": 2,
|
|
|
|
|
|
"delivered": 1,
|
2017-06-13 10:32:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-01-04 18:33:23 +00:00
|
|
|
|
def test_get_status_filters_in_right_order(client_request):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
ret = get_status_filters(Service({"id": "foo"}), "sms", STATISTICS)
|
2017-06-13 10:32:36 +01:00
|
|
|
|
|
|
|
|
|
|
assert [label for label, _option, _link, _count in ret] == [
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"total",
|
|
|
|
|
|
"pending",
|
|
|
|
|
|
"delivered",
|
|
|
|
|
|
"failed",
|
2017-06-13 10:32:36 +01:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-01-04 18:33:23 +00:00
|
|
|
|
def test_get_status_filters_constructs_links(client_request):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
ret = get_status_filters(Service({"id": "foo"}), "sms", STATISTICS)
|
2017-06-13 10:32:36 +01:00
|
|
|
|
|
|
|
|
|
|
link = ret[0][2]
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert link == "/services/foo/notifications/sms?status={}".format(
|
|
|
|
|
|
"sending,delivered,failed"
|
|
|
|
|
|
)
|
2017-06-13 10:32:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_html_contains_notification_id(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-06-13 10:32:36 +01:00
|
|
|
|
service_one,
|
|
|
|
|
|
active_user_with_permissions,
|
|
|
|
|
|
mock_get_notifications,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-12-03 17:19:38 +00:00
|
|
|
|
mock_get_service_data_retention,
|
2019-12-13 14:27:56 +00:00
|
|
|
|
mock_get_no_api_keys,
|
2017-06-13 10:32:36 +01:00
|
|
|
|
mocker,
|
|
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notifications",
|
|
|
|
|
|
service_id=service_one["id"],
|
|
|
|
|
|
message_type="sms",
|
|
|
|
|
|
status="",
|
2017-06-13 10:32:36 +01:00
|
|
|
|
)
|
2019-03-26 12:35:32 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
notifications = page.tbody.find_all("tr")
|
2017-06-13 10:32:36 +01:00
|
|
|
|
for tr in notifications:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert uuid.UUID(tr.attrs["id"])
|
2017-06-24 17:29:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
2018-10-30 11:36:42 +00:00
|
|
|
|
def test_html_contains_links_for_failed_notifications(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_service_statistics,
|
2018-12-03 17:19:38 +00:00
|
|
|
|
mock_get_service_data_retention,
|
2019-12-13 14:27:56 +00:00
|
|
|
|
mock_get_no_api_keys,
|
2018-10-30 11:36:42 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
notifications = create_notifications(status="technical-failure")
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.notification_api_client.get_notifications_for_service",
|
|
|
|
|
|
return_value=notifications,
|
|
|
|
|
|
)
|
2020-01-07 15:24:33 +00:00
|
|
|
|
|
2018-10-30 11:36:42 +00:00
|
|
|
|
response = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notifications",
|
2018-10-30 11:36:42 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
message_type="sms",
|
|
|
|
|
|
status="sending%2Cdelivered%2Cfailed",
|
2018-10-30 11:36:42 +00:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
notifications = response.tbody.find_all("tr")
|
2018-10-30 11:36:42 +00:00
|
|
|
|
for tr in notifications:
|
2023-08-25 09:12:23 -07:00
|
|
|
|
link_text = tr.find("div", class_="table-field-status-error").find("a").text
|
|
|
|
|
|
assert normalize_spaces(link_text) == "Technical failure"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-25 17:55:42 -04:00
|
|
|
|
("notification_type", "expected_row_contents"),
|
|
|
|
|
|
[
|
2023-08-25 09:12:23 -07:00
|
|
|
|
("sms", ("2021234567 hello & welcome hidden")),
|
|
|
|
|
|
("email", ("example@gsa.gov hidden, hello & welcome")),
|
2023-09-25 17:55:42 -04:00
|
|
|
|
],
|
2023-08-25 09:12:23 -07:00
|
|
|
|
)
|
2017-06-24 17:29:28 +01:00
|
|
|
|
def test_redacts_templates_that_should_be_redacted(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-12-03 17:19:38 +00:00
|
|
|
|
mock_get_service_data_retention,
|
2019-12-13 14:27:56 +00:00
|
|
|
|
mock_get_no_api_keys,
|
2020-08-04 15:05:56 +01:00
|
|
|
|
notification_type,
|
|
|
|
|
|
expected_row_contents,
|
2017-06-24 17:29:28 +01:00
|
|
|
|
):
|
2020-01-07 15:24:33 +00:00
|
|
|
|
notifications = create_notifications(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
status="technical-failure",
|
|
|
|
|
|
content="hello & welcome ((name))",
|
|
|
|
|
|
subject="((name)), hello & welcome",
|
|
|
|
|
|
personalisation={"name": "Jo"},
|
2017-06-24 17:29:28 +01:00
|
|
|
|
redact_personalisation=True,
|
2020-08-04 15:05:56 +01:00
|
|
|
|
template_type=notification_type,
|
2017-06-24 17:29:28 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.notification_api_client.get_notifications_for_service",
|
|
|
|
|
|
return_value=notifications,
|
|
|
|
|
|
)
|
2020-01-07 15:24:33 +00:00
|
|
|
|
|
2017-06-24 17:29:28 +01:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notifications",
|
2017-06-24 17:29:28 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2020-08-04 15:05:56 +01:00
|
|
|
|
message_type=notification_type,
|
2017-06-24 17:29:28 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2024-07-23 15:27:03 -04:00
|
|
|
|
assert normalize_spaces(page.select("tbody tr td")[0].text) == (
|
2020-08-04 15:05:56 +01:00
|
|
|
|
expected_row_contents
|
2017-06-24 17:29:28 +01:00
|
|
|
|
)
|
2017-10-02 12:34:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-06-12 15:49:48 -04:00
|
|
|
|
@freeze_time("2017-09-27 12:30:00.000000")
|
2017-10-02 12:34:10 +01:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-25 17:55:42 -04:00
|
|
|
|
("message_type", "status", "expected_hint_status", "single_line"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
2024-02-29 08:24:53 -08:00
|
|
|
|
("email", "created", "Sending since 09-27-2017 at 08:30 AM", True),
|
|
|
|
|
|
("email", "sending", "Sending since 09-27-2017 at 08:30 AM", True),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
(
|
|
|
|
|
|
"email",
|
|
|
|
|
|
"temporary-failure",
|
2024-02-29 08:24:53 -08:00
|
|
|
|
"Inbox not accepting messages right now 09-27-2017 at 08:30 AM",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
False,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
"email",
|
|
|
|
|
|
"permanent-failure",
|
2024-02-29 08:24:53 -08:00
|
|
|
|
"Email address does not exist 09-27-2017 at 08:30 AM",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
False,
|
|
|
|
|
|
),
|
2024-02-29 08:24:53 -08:00
|
|
|
|
("email", "delivered", "Delivered 09-27-2017 at 08:30 AM", True),
|
|
|
|
|
|
("sms", "created", "Sending since 09-27-2017 at 08:30 AM", True),
|
|
|
|
|
|
("sms", "sending", "Sending since 09-27-2017 at 08:30 AM", True),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
(
|
|
|
|
|
|
"sms",
|
|
|
|
|
|
"temporary-failure",
|
2024-02-29 08:24:53 -08:00
|
|
|
|
"Phone not accepting messages right now 09-27-2017 at 08:30 AM",
|
2023-11-16 12:24:27 -08:00
|
|
|
|
False,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
"sms",
|
|
|
|
|
|
"permanent-failure",
|
2024-02-29 08:24:53 -08:00
|
|
|
|
"Not delivered 09-27-2017 at 08:30 AM",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
False,
|
|
|
|
|
|
),
|
2024-02-29 08:24:53 -08:00
|
|
|
|
("sms", "delivered", "Delivered 09-27-2017 at 08:30 AM", True),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
],
|
2017-10-02 12:34:10 +01:00
|
|
|
|
)
|
2019-01-07 12:02:24 +00:00
|
|
|
|
def test_sending_status_hint_displays_correctly_on_notifications_page(
|
2017-10-02 12:34:10 +01:00
|
|
|
|
client_request,
|
|
|
|
|
|
service_one,
|
2018-05-09 13:53:02 +01:00
|
|
|
|
mock_get_service_statistics,
|
2018-12-03 17:19:38 +00:00
|
|
|
|
mock_get_service_data_retention,
|
2019-12-13 14:27:56 +00:00
|
|
|
|
mock_get_no_api_keys,
|
2017-10-02 12:34:10 +01:00
|
|
|
|
message_type,
|
2018-10-11 10:54:39 +01:00
|
|
|
|
status,
|
|
|
|
|
|
expected_hint_status,
|
|
|
|
|
|
single_line,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker,
|
2017-10-02 12:34:10 +01:00
|
|
|
|
):
|
2020-01-07 15:24:33 +00:00
|
|
|
|
notifications = create_notifications(template_type=message_type, status=status)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.notification_api_client.get_notifications_for_service",
|
|
|
|
|
|
return_value=notifications,
|
|
|
|
|
|
)
|
2017-10-02 12:34:10 +01:00
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.view_notifications",
|
|
|
|
|
|
service_id=service_one["id"],
|
|
|
|
|
|
message_type=message_type,
|
2017-10-18 14:51:26 +01:00
|
|
|
|
)
|
2017-10-02 12:34:10 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert (
|
|
|
|
|
|
normalize_spaces(page.select(".table-field-right-aligned")[0].text)
|
|
|
|
|
|
== expected_hint_status
|
|
|
|
|
|
)
|
|
|
|
|
|
assert bool(page.select(".align-with-message-body")) is single_line
|