mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-08 08:28:15 -04:00
Fix import conflict
This commit is contained in:
@@ -7,64 +7,57 @@ from flask import (
|
|||||||
from notifications_python_client.errors import HTTPError
|
from notifications_python_client.errors import HTTPError
|
||||||
from tests.conftest import (
|
from tests.conftest import (
|
||||||
SERVICE_ONE_ID,
|
SERVICE_ONE_ID,
|
||||||
mock_get_notifications,
|
|
||||||
normalize_spaces,
|
normalize_spaces,
|
||||||
|
mock_get_notifications,
|
||||||
|
mock_get_inbound_sms,
|
||||||
)
|
)
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
from app.main.views.conversation import get_user_number
|
from app.main.views.conversation import get_user_number
|
||||||
|
|
||||||
|
|
||||||
@mock.patch(
|
def test_get_user_phone_number_when_only_inbound_exists(mocker):
|
||||||
'app.main.views.conversation.service_api_client.get_inbound_sms_by_id',
|
|
||||||
return_value={
|
mock_get_inbound_sms = mocker.patch(
|
||||||
'user_number': '4407900900123'
|
'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,
|
mock_get_notification = mocker.patch(
|
||||||
)
|
'app.main.views.conversation.notification_api_client.get_notification',
|
||||||
def test_get_user_phone_number_when_only_inbound_exists(
|
side_effect=HTTPError,
|
||||||
mock_get_notification,
|
)
|
||||||
mock_get_inbound_sms,
|
|
||||||
):
|
|
||||||
assert get_user_number('service', 'notification') == '07900 900123'
|
assert get_user_number('service', 'notification') == '07900 900123'
|
||||||
mock_get_inbound_sms.assert_called_once_with('service', 'notification')
|
mock_get_inbound_sms.assert_called_once_with('service', 'notification')
|
||||||
assert mock_get_notification.called is False
|
assert mock_get_notification.called is False
|
||||||
|
|
||||||
|
|
||||||
@mock.patch(
|
def test_get_user_phone_number_when_only_outbound_exists(mocker):
|
||||||
'app.main.views.conversation.service_api_client.get_inbound_sms_by_id',
|
mock_get_inbound_sms = mocker.patch(
|
||||||
side_effect=HTTPError,
|
'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',
|
mock_get_notification = mocker.patch(
|
||||||
return_value={
|
'app.main.views.conversation.notification_api_client.get_notification',
|
||||||
'to': '15550000000'
|
return_value={
|
||||||
}
|
'to': '15550000000'
|
||||||
)
|
}
|
||||||
def test_get_user_phone_number_when_only_outbound_exists(
|
)
|
||||||
mock_get_notification,
|
|
||||||
mock_get_inbound_sms,
|
|
||||||
):
|
|
||||||
assert get_user_number('service', 'notification') == '+1 555-000-0000'
|
assert get_user_number('service', 'notification') == '+1 555-000-0000'
|
||||||
mock_get_inbound_sms.assert_called_once_with('service', 'notification')
|
mock_get_inbound_sms.assert_called_once_with('service', 'notification')
|
||||||
mock_get_notification.assert_called_once_with('service', 'notification')
|
mock_get_notification.assert_called_once_with('service', 'notification')
|
||||||
|
|
||||||
|
|
||||||
@mock.patch(
|
def test_get_user_phone_number_raises_if_both_API_requests_fail(mocker):
|
||||||
'app.main.views.conversation.service_api_client.get_inbound_sms_by_id',
|
mock_get_inbound_sms = mocker.patch(
|
||||||
side_effect=HTTPError,
|
'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',
|
mock_get_notification = mocker.patch(
|
||||||
side_effect=HTTPError,
|
'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,
|
|
||||||
):
|
|
||||||
with pytest.raises(HTTPError):
|
with pytest.raises(HTTPError):
|
||||||
get_user_number('service', 'notification')
|
get_user_number('service', 'notification')
|
||||||
mock_get_inbound_sms.assert_called_once_with('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")
|
@freeze_time("2012-01-01 00:00:00")
|
||||||
def test_view_conversation(
|
def test_view_conversation(
|
||||||
logged_in_client,
|
client_request,
|
||||||
mocker,
|
mocker,
|
||||||
api_user_active,
|
api_user_active,
|
||||||
fake_uuid,
|
|
||||||
mock_get_notification,
|
mock_get_notification,
|
||||||
mock_get_inbound_sms,
|
fake_uuid,
|
||||||
outbound_redacted,
|
outbound_redacted,
|
||||||
expected_outbound_content,
|
expected_outbound_content,
|
||||||
):
|
):
|
||||||
@@ -95,13 +87,16 @@ def test_view_conversation(
|
|||||||
redact_personalisation=outbound_redacted,
|
redact_personalisation=outbound_redacted,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = logged_in_client.get(url_for(
|
mock_get_inbound_sms(
|
||||||
|
mocker
|
||||||
|
)
|
||||||
|
|
||||||
|
page = client_request.get(
|
||||||
'main.conversation',
|
'main.conversation',
|
||||||
service_id=SERVICE_ONE_ID,
|
service_id=SERVICE_ONE_ID,
|
||||||
notification_id=fake_uuid,
|
notification_id=fake_uuid,
|
||||||
))
|
_test_page_title=False,
|
||||||
assert response.status_code == 200
|
)
|
||||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
|
||||||
|
|
||||||
messages = page.select('.sms-message-wrapper')
|
messages = page.select('.sms-message-wrapper')
|
||||||
statuses = page.select('.sms-message-status')
|
statuses = page.select('.sms-message-status')
|
||||||
|
|||||||
Reference in New Issue
Block a user