2017-07-07 15:34:06 +01:00
|
|
|
|
import json
|
2020-01-30 14:01:13 +00:00
|
|
|
|
import re
|
2018-02-20 11:22:17 +00:00
|
|
|
|
from datetime import datetime
|
2018-05-03 15:40:24 +01:00
|
|
|
|
from unittest.mock import Mock
|
2017-05-24 13:19:31 +01:00
|
|
|
|
|
2018-02-20 11:22:17 +00:00
|
|
|
|
import pytest
|
|
|
|
|
|
from flask import url_for
|
2017-09-27 17:38:42 +01:00
|
|
|
|
from freezegun import freeze_time
|
2018-02-20 11:22:17 +00:00
|
|
|
|
from notifications_python_client.errors import HTTPError
|
2018-04-25 14:12:58 +01:00
|
|
|
|
|
|
|
|
|
|
from app.main.views.conversation import get_user_number
|
2017-05-24 13:19:31 +01:00
|
|
|
|
from tests.conftest import (
|
|
|
|
|
|
SERVICE_ONE_ID,
|
2019-03-19 18:30:05 +00:00
|
|
|
|
_template,
|
2020-01-07 15:24:33 +00:00
|
|
|
|
create_notifications,
|
2018-02-20 11:22:17 +00:00
|
|
|
|
normalize_spaces,
|
2017-05-24 13:19:31 +01:00
|
|
|
|
)
|
2018-02-20 11:22:17 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
INV_PARENT_FOLDER_ID = "7e979e79-d970-43a5-ac69-b625a8d147b0"
|
|
|
|
|
|
VIS_PARENT_FOLDER_ID = "bbbb222b-2b22-2b22-222b-b222b22b2222"
|
2019-03-19 18:30:05 +00:00
|
|
|
|
|
2017-06-14 15:37:57 +01:00
|
|
|
|
|
2017-07-07 13:32:07 +01:00
|
|
|
|
def test_get_user_phone_number_when_only_inbound_exists(mocker):
|
|
|
|
|
|
mock_get_inbound_sms = mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.main.views.conversation.service_api_client.get_inbound_sms_by_id",
|
|
|
|
|
|
return_value={"user_number": "2028675305", "notify_number": "2028675309"},
|
2017-07-07 13:32:07 +01:00
|
|
|
|
)
|
|
|
|
|
|
mock_get_notification = mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.main.views.conversation.notification_api_client.get_notification",
|
2018-05-03 15:40:24 +01:00
|
|
|
|
side_effect=HTTPError(response=Mock(status_code=404)),
|
2017-07-07 13:32:07 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert get_user_number("service", "notification") == "(202) 867-5305"
|
|
|
|
|
|
mock_get_inbound_sms.assert_called_once_with("service", "notification")
|
2017-06-14 15:37:57 +01:00
|
|
|
|
assert mock_get_notification.called is False
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-07 13:32:07 +01:00
|
|
|
|
def test_get_user_phone_number_when_only_outbound_exists(mocker):
|
|
|
|
|
|
mock_get_inbound_sms = mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.main.views.conversation.service_api_client.get_inbound_sms_by_id",
|
2018-05-03 15:40:24 +01:00
|
|
|
|
side_effect=HTTPError(response=Mock(status_code=404)),
|
2017-07-07 13:32:07 +01:00
|
|
|
|
)
|
|
|
|
|
|
mock_get_notification = mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.main.views.conversation.notification_api_client.get_notification",
|
|
|
|
|
|
return_value={"to": "2028675309"},
|
2017-07-07 13:32:07 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert get_user_number("service", "notification") == "(202) 867-5309"
|
|
|
|
|
|
mock_get_inbound_sms.assert_called_once_with("service", "notification")
|
|
|
|
|
|
mock_get_notification.assert_called_once_with("service", "notification")
|
2017-06-14 15:37:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-10-27 10:56:03 +01:00
|
|
|
|
def test_get_user_phone_number_raises_if_both_api_requests_fail(mocker):
|
2017-07-07 13:32:07 +01:00
|
|
|
|
mock_get_inbound_sms = mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.main.views.conversation.service_api_client.get_inbound_sms_by_id",
|
2018-05-03 15:40:24 +01:00
|
|
|
|
side_effect=HTTPError(response=Mock(status_code=404)),
|
2017-07-07 13:32:07 +01:00
|
|
|
|
)
|
|
|
|
|
|
mock_get_notification = mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.main.views.conversation.notification_api_client.get_notification",
|
2018-05-03 15:40:24 +01:00
|
|
|
|
side_effect=HTTPError(response=Mock(status_code=404)),
|
2017-07-07 13:32:07 +01:00
|
|
|
|
)
|
2017-06-14 15:37:57 +01:00
|
|
|
|
with pytest.raises(HTTPError):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
get_user_number("service", "notification")
|
|
|
|
|
|
mock_get_inbound_sms.assert_called_once_with("service", "notification")
|
|
|
|
|
|
mock_get_notification.assert_called_once_with("service", "notification")
|
2017-05-24 13:19:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize(
|
2023-09-15 09:48:35 -04:00
|
|
|
|
("outbound_redacted", "expected_outbound_content"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
[
|
|
|
|
|
|
(True, "Hello hidden"),
|
|
|
|
|
|
(False, "Hello Jo"),
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2023-11-16 12:24:27 -08:00
|
|
|
|
@freeze_time("2012-01-01 05:00:00")
|
2017-05-24 13:19:31 +01:00
|
|
|
|
def test_view_conversation(
|
2017-07-07 13:32:07 +01:00
|
|
|
|
client_request,
|
2017-07-07 10:04:49 +01:00
|
|
|
|
mocker,
|
2018-05-03 15:40:24 +01:00
|
|
|
|
mock_get_inbound_sms_by_id_with_no_messages,
|
2017-05-24 13:19:31 +01:00
|
|
|
|
mock_get_notification,
|
2017-07-07 13:32:07 +01:00
|
|
|
|
fake_uuid,
|
2017-07-07 10:04:49 +01:00
|
|
|
|
outbound_redacted,
|
|
|
|
|
|
expected_outbound_content,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_get_inbound_sms,
|
2017-05-24 13:19:31 +01:00
|
|
|
|
):
|
2020-01-07 15:24:33 +00:00
|
|
|
|
notifications = create_notifications(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
content="Hello ((name))",
|
|
|
|
|
|
personalisation={"name": "Jo"},
|
2017-07-07 10:04:49 +01:00
|
|
|
|
redact_personalisation=outbound_redacted,
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock = mocker.patch(
|
|
|
|
|
|
"app.notification_api_client.get_notifications_for_service",
|
|
|
|
|
|
return_value=notifications,
|
|
|
|
|
|
)
|
2017-07-07 10:04:49 +01:00
|
|
|
|
|
2017-07-07 13:32:07 +01:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.conversation",
|
2017-05-24 13:19:31 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
2020-02-18 13:15:57 +00:00
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select_one("title").text) == (
|
|
|
|
|
|
"Received text message – service one – Notify.gov"
|
2017-07-07 13:32:07 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select_one("h1").text) == ("2021234567")
|
2017-05-24 13:19:31 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
messages = page.select(".sms-message-wrapper")
|
|
|
|
|
|
statuses = page.select(".sms-message-status")
|
2017-05-24 13:19:31 +01:00
|
|
|
|
|
2017-06-07 15:46:34 +01:00
|
|
|
|
assert len(messages) == 13
|
|
|
|
|
|
assert len(statuses) == 13
|
2017-06-14 15:43:42 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
for index, expected in enumerate(
|
|
|
|
|
|
[
|
|
|
|
|
|
(
|
|
|
|
|
|
"message-8",
|
2024-08-23 12:59:00 -07:00
|
|
|
|
"yesterday at 14:59 America/New_York",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
"message-7",
|
2024-08-23 12:59:00 -07:00
|
|
|
|
"yesterday at 14:59 America/New_York",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
"message-6",
|
2024-08-23 12:59:00 -07:00
|
|
|
|
"yesterday at 16:59 America/New_York",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
"message-5",
|
2024-08-23 12:59:00 -07:00
|
|
|
|
"yesterday at 18:59 America/New_York",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
"message-4",
|
2024-08-23 12:59:00 -07:00
|
|
|
|
"yesterday at 20:59 America/New_York",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
"message-3",
|
2024-08-23 12:59:00 -07:00
|
|
|
|
"yesterday at 22:59 America/New_York",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
"message-2",
|
2024-08-23 12:59:00 -07:00
|
|
|
|
"yesterday at 22:59 America/New_York",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
"message-1",
|
2024-08-23 12:59:00 -07:00
|
|
|
|
"yesterday at 23:00 America/New_York",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
expected_outbound_content,
|
2024-08-23 12:59:00 -07:00
|
|
|
|
"yesterday at 00:00 America/New_York",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
expected_outbound_content,
|
2024-08-23 12:59:00 -07:00
|
|
|
|
"yesterday at 00:00 America/New_York",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
expected_outbound_content,
|
2024-08-23 12:59:00 -07:00
|
|
|
|
"yesterday at 00:00 America/New_York",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
expected_outbound_content,
|
2024-08-23 12:59:00 -07:00
|
|
|
|
"yesterday at 00:00 America/New_York",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
expected_outbound_content,
|
2024-08-23 12:59:00 -07:00
|
|
|
|
"yesterday at 00:00 America/New_York",
|
2023-08-25 09:12:23 -07:00
|
|
|
|
),
|
|
|
|
|
|
]
|
|
|
|
|
|
):
|
2017-06-14 15:43:42 +01:00
|
|
|
|
assert (
|
|
|
|
|
|
normalize_spaces(messages[index].text),
|
|
|
|
|
|
normalize_spaces(statuses[index].text),
|
|
|
|
|
|
) == expected
|
2017-07-07 15:34:06 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_get_inbound_sms.assert_called_once_with(
|
|
|
|
|
|
SERVICE_ONE_ID, user_number="2021234567"
|
|
|
|
|
|
)
|
|
|
|
|
|
mock.assert_called_once_with(SERVICE_ONE_ID, to="2021234567", template_type="sms")
|
2018-03-12 13:28:20 +00:00
|
|
|
|
|
2017-07-07 15:34:06 +01:00
|
|
|
|
|
|
|
|
|
|
def test_view_conversation_updates(
|
2021-12-31 12:08:14 +00:00
|
|
|
|
client_request,
|
2017-07-07 15:34:06 +01:00
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
2018-05-03 15:40:24 +01:00
|
|
|
|
mock_get_inbound_sms_by_id_with_no_messages,
|
2017-07-07 15:34:06 +01:00
|
|
|
|
mock_get_notification,
|
|
|
|
|
|
):
|
2018-05-03 15:40:24 +01:00
|
|
|
|
mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.main.views.conversation.service_api_client.get_inbound_sms_by_id",
|
2018-05-03 15:40:24 +01:00
|
|
|
|
side_effect=HTTPError(response=Mock(status_code=404)),
|
|
|
|
|
|
)
|
2017-07-07 15:34:06 +01:00
|
|
|
|
mock_get_partials = mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.main.views.conversation.get_conversation_partials",
|
|
|
|
|
|
return_value={"messages": "foo"},
|
2017-07-07 15:34:06 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2021-12-31 12:08:14 +00:00
|
|
|
|
response = client_request.get_response(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.conversation_updates",
|
2017-07-07 15:34:06 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
2021-12-31 12:08:14 +00:00
|
|
|
|
)
|
2017-07-07 15:34:06 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert json.loads(response.get_data(as_text=True)) == {"messages": "foo"}
|
2017-07-07 15:34:06 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_get_partials.assert_called_once_with(SERVICE_ONE_ID, "2021234567")
|
2017-09-27 17:38:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time("2012-01-01 00:00:00")
|
|
|
|
|
|
def test_view_conversation_with_empty_inbound(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
2018-05-03 15:40:24 +01:00
|
|
|
|
mock_get_inbound_sms_by_id_with_no_messages,
|
2017-09-27 17:38:42 +01:00
|
|
|
|
mock_get_notification,
|
|
|
|
|
|
mock_get_notifications_with_no_notifications,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
fake_uuid,
|
2017-09-27 17:38:42 +01:00
|
|
|
|
):
|
|
|
|
|
|
mock_get_inbound_sms = mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.main.views.conversation.service_api_client.get_inbound_sms",
|
2018-03-21 15:08:03 +00:00
|
|
|
|
return_value={
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"has_next": False,
|
|
|
|
|
|
"data": [
|
|
|
|
|
|
{
|
|
|
|
|
|
"user_number": "2028675301",
|
|
|
|
|
|
"notify_number": "2028675309",
|
|
|
|
|
|
"content": "",
|
|
|
|
|
|
"created_at": datetime.utcnow().isoformat(),
|
|
|
|
|
|
"id": fake_uuid,
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
2017-09-27 17:38:42 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.conversation",
|
2017-09-27 17:38:42 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
2020-02-18 13:15:57 +00:00
|
|
|
|
_test_page_title=False,
|
2017-09-27 17:38:42 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
messages = page.select(".sms-message-wrapper")
|
2017-09-27 17:38:42 +01:00
|
|
|
|
assert len(messages) == 1
|
2017-10-18 14:51:26 +01:00
|
|
|
|
assert mock_get_inbound_sms.called is True
|
2017-10-15 12:59:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_conversation_links_to_reply(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
2018-05-03 15:40:24 +01:00
|
|
|
|
mock_get_inbound_sms_by_id_with_no_messages,
|
2017-10-15 12:59:36 +01:00
|
|
|
|
mock_get_notification,
|
|
|
|
|
|
mock_get_notifications,
|
|
|
|
|
|
mock_get_inbound_sms,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.conversation",
|
2017-10-15 12:59:36 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
2020-02-18 13:15:57 +00:00
|
|
|
|
_test_page_title=False,
|
2017-10-15 12:59:36 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select("main p")[-1].select_one("a")["href"] == (
|
2017-10-15 12:59:36 +01:00
|
|
|
|
url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
".conversation_reply",
|
2017-10-15 12:59:36 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-02-14 16:27:13 +00:00
|
|
|
|
def test_conversation_reply_shows_link_to_add_templates_if_service_has_no_templates(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_templates_when_no_templates_exist,
|
2019-03-19 18:30:05 +00:00
|
|
|
|
mock_get_template_folders,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
active_user_with_permissions,
|
2019-02-14 16:27:13 +00:00
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.conversation_reply",
|
2019-02-14 16:27:13 +00:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
page_text = page.find("p", class_="bottom-gutter").text
|
|
|
|
|
|
link = page.find("a", text=re.compile("Add a new template"))["href"]
|
2019-02-14 16:27:13 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert (
|
|
|
|
|
|
normalize_spaces(page_text)
|
|
|
|
|
|
== "You need a template before you can send text messages."
|
|
|
|
|
|
)
|
2019-02-14 16:27:13 +00:00
|
|
|
|
assert link == url_for(
|
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
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-15 12:59:36 +01:00
|
|
|
|
def test_conversation_reply_shows_templates(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
2019-03-19 18:30:05 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_template_folders,
|
2019-03-21 15:57:52 +00:00
|
|
|
|
active_user_with_permissions,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
service_one,
|
2017-10-15 12:59:36 +01:00
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
all_templates = {
|
|
|
|
|
|
"data": [
|
|
|
|
|
|
_template("sms", "sms_template_one", parent=INV_PARENT_FOLDER_ID),
|
|
|
|
|
|
_template("sms", "sms_template_two"),
|
|
|
|
|
|
_template("sms", "sms_template_three", parent=VIS_PARENT_FOLDER_ID),
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.service_api_client.get_service_templates", return_value=all_templates
|
|
|
|
|
|
)
|
2019-03-19 18:30:05 +00:00
|
|
|
|
mock_get_template_folders.return_value = [
|
|
|
|
|
|
{
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"name": "Parent 1 - invisible",
|
|
|
|
|
|
"id": INV_PARENT_FOLDER_ID,
|
|
|
|
|
|
"parent_id": None,
|
|
|
|
|
|
"users_with_permission": [],
|
2019-03-19 18:30:05 +00:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"name": "Parent 2 - visible",
|
|
|
|
|
|
"id": VIS_PARENT_FOLDER_ID,
|
|
|
|
|
|
"parent_id": None,
|
|
|
|
|
|
"users_with_permission": [active_user_with_permissions["id"]],
|
2019-03-19 18:30:05 +00:00
|
|
|
|
},
|
|
|
|
|
|
]
|
2017-10-15 12:59:36 +01:00
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.conversation_reply",
|
2017-10-15 12:59:36 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
link = page.select(".template-list-item-without-ancestors")
|
2019-03-21 15:57:52 +00:00
|
|
|
|
assert normalize_spaces(link[0].text) == "Parent 2 - visible 1 template"
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(link[1].text) == "sms_template_two Text message template"
|
|
|
|
|
|
|
|
|
|
|
|
assert (
|
|
|
|
|
|
link[0]
|
|
|
|
|
|
.select_one("a")["href"]
|
|
|
|
|
|
.startswith(
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
"main.conversation_reply",
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
|
|
|
|
|
from_folder=VIS_PARENT_FOLDER_ID,
|
|
|
|
|
|
)
|
2019-03-21 15:57:52 +00:00
|
|
|
|
)
|
2018-08-16 16:15:34 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert (
|
|
|
|
|
|
link[1]
|
|
|
|
|
|
.select_one("a")["href"]
|
|
|
|
|
|
.startswith(
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
"main.conversation_reply_with_template",
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
|
|
|
|
|
template_id="",
|
|
|
|
|
|
)
|
2019-03-21 15:57:52 +00:00
|
|
|
|
)
|
|
|
|
|
|
)
|
2018-08-16 16:15:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
2019-03-21 15:57:52 +00:00
|
|
|
|
def test_conversation_reply_shows_live_search(
|
2018-08-16 16:15:34 +01:00
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_get_service_templates,
|
2019-03-19 18:30:05 +00:00
|
|
|
|
mock_get_template_folders,
|
2018-08-16 16:15:34 +01:00
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.conversation_reply",
|
2018-08-16 16:15:34 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert page.select(".live-search")
|
2018-08-16 16:15:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-10-15 13:40:49 +01:00
|
|
|
|
def test_conversation_reply_redirects_with_phone_number_from_notification(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
fake_uuid,
|
2018-05-03 15:40:24 +01:00
|
|
|
|
mock_get_inbound_sms_by_id_with_no_messages,
|
2017-10-15 13:40:49 +01:00
|
|
|
|
mock_get_notification,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.conversation_reply_with_template",
|
2017-10-15 13:40:49 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
notification_id=fake_uuid,
|
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
|
_follow_redirects=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
for element, expected_text in [
|
2024-02-08 18:43:17 -08:00
|
|
|
|
("h1", "Select delivery time"),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
(".sms-message-recipient", "To: 2021234567"),
|
|
|
|
|
|
(
|
|
|
|
|
|
".sms-message-wrapper",
|
|
|
|
|
|
"service one: Template <em>content</em> with & entity",
|
|
|
|
|
|
),
|
2017-10-15 13:40:49 +01:00
|
|
|
|
]:
|
|
|
|
|
|
assert normalize_spaces(page.select_one(element).text) == expected_text
|
2017-11-23 15:08:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_user_phone_number_when_not_a_standard_phone_number(mocker):
|
|
|
|
|
|
mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.main.views.conversation.service_api_client.get_inbound_sms_by_id",
|
|
|
|
|
|
return_value={"user_number": "ALPHANUM3R1C", "notify_number": "2028675309"},
|
2017-11-23 15:08:11 +00:00
|
|
|
|
)
|
|
|
|
|
|
mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.main.views.conversation.notification_api_client.get_notification",
|
2017-11-23 15:08:11 +00:00
|
|
|
|
side_effect=HTTPError,
|
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert get_user_number("service", "notification") == "ALPHANUM3R1C"
|