diff --git a/tests/app/main/views/test_conversation.py b/tests/app/main/views/test_conversation.py index 014e7810d..605054c32 100644 --- a/tests/app/main/views/test_conversation.py +++ b/tests/app/main/views/test_conversation.py @@ -7,64 +7,57 @@ from flask import ( from notifications_python_client.errors import HTTPError from tests.conftest import ( SERVICE_ONE_ID, - mock_get_notifications, normalize_spaces, + mock_get_notifications, + mock_get_inbound_sms, ) from freezegun import freeze_time from unittest import mock from app.main.views.conversation import get_user_number -@mock.patch( - 'app.main.views.conversation.service_api_client.get_inbound_sms_by_id', - return_value={ - 'user_number': '4407900900123' - } -) -@mock.patch( - 'app.main.views.conversation.notification_api_client.get_notification', - side_effect=HTTPError, -) -def test_get_user_phone_number_when_only_inbound_exists( - mock_get_notification, - mock_get_inbound_sms, -): +def test_get_user_phone_number_when_only_inbound_exists(mocker): + + mock_get_inbound_sms = mocker.patch( + 'app.main.views.conversation.service_api_client.get_inbound_sms_by_id', + return_value={ + 'user_number': '4407900900123' + } + ) + mock_get_notification = mocker.patch( + 'app.main.views.conversation.notification_api_client.get_notification', + side_effect=HTTPError, + ) assert get_user_number('service', 'notification') == '07900 900123' mock_get_inbound_sms.assert_called_once_with('service', 'notification') assert mock_get_notification.called is False -@mock.patch( - 'app.main.views.conversation.service_api_client.get_inbound_sms_by_id', - side_effect=HTTPError, -) -@mock.patch( - 'app.main.views.conversation.notification_api_client.get_notification', - return_value={ - 'to': '15550000000' - } -) -def test_get_user_phone_number_when_only_outbound_exists( - mock_get_notification, - mock_get_inbound_sms, -): +def test_get_user_phone_number_when_only_outbound_exists(mocker): + mock_get_inbound_sms = mocker.patch( + 'app.main.views.conversation.service_api_client.get_inbound_sms_by_id', + side_effect=HTTPError, + ) + mock_get_notification = mocker.patch( + 'app.main.views.conversation.notification_api_client.get_notification', + return_value={ + 'to': '15550000000' + } + ) assert get_user_number('service', 'notification') == '+1 555-000-0000' mock_get_inbound_sms.assert_called_once_with('service', 'notification') mock_get_notification.assert_called_once_with('service', 'notification') -@mock.patch( - 'app.main.views.conversation.service_api_client.get_inbound_sms_by_id', - side_effect=HTTPError, -) -@mock.patch( - 'app.main.views.conversation.notification_api_client.get_notification', - side_effect=HTTPError, -) -def test_get_user_phone_number_raises_if_both_API_requests_fail( - mock_get_notification, - mock_get_inbound_sms, -): +def test_get_user_phone_number_raises_if_both_API_requests_fail(mocker): + mock_get_inbound_sms = mocker.patch( + 'app.main.views.conversation.service_api_client.get_inbound_sms_by_id', + side_effect=HTTPError, + ) + mock_get_notification = mocker.patch( + 'app.main.views.conversation.notification_api_client.get_notification', + side_effect=HTTPError, + ) with pytest.raises(HTTPError): get_user_number('service', 'notification') mock_get_inbound_sms.assert_called_once_with('service', 'notification') @@ -77,12 +70,11 @@ def test_get_user_phone_number_raises_if_both_API_requests_fail( ]) @freeze_time("2012-01-01 00:00:00") def test_view_conversation( - logged_in_client, + client_request, mocker, api_user_active, - fake_uuid, mock_get_notification, - mock_get_inbound_sms, + fake_uuid, outbound_redacted, expected_outbound_content, ): @@ -95,13 +87,16 @@ def test_view_conversation( redact_personalisation=outbound_redacted, ) - response = logged_in_client.get(url_for( + mock_get_inbound_sms( + mocker + ) + + page = client_request.get( 'main.conversation', service_id=SERVICE_ONE_ID, notification_id=fake_uuid, - )) - assert response.status_code == 200 - page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') + _test_page_title=False, + ) messages = page.select('.sms-message-wrapper') statuses = page.select('.sms-message-status')