mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 07:38:26 -04:00
make sure inbound sms page doesn't break if you receive a blank inbound message
This commit is contained in:
@@ -73,7 +73,10 @@ def get_sms_thread(service_id, user_number):
|
|||||||
'inbound': is_inbound,
|
'inbound': is_inbound,
|
||||||
'content': SMSPreviewTemplate(
|
'content': SMSPreviewTemplate(
|
||||||
{
|
{
|
||||||
'content': notification.get('content') or notification['template']['content']
|
'content': (
|
||||||
|
notification['content'] if is_inbound else
|
||||||
|
notification['template']['content']
|
||||||
|
)
|
||||||
},
|
},
|
||||||
notification.get('personalisation'),
|
notification.get('personalisation'),
|
||||||
downgrade_non_gsm_characters=(not is_inbound),
|
downgrade_non_gsm_characters=(not is_inbound),
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
|
from datetime import datetime
|
||||||
import json
|
import json
|
||||||
import pytest
|
import pytest
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
|
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
from flask import (
|
from flask import (
|
||||||
url_for,
|
url_for,
|
||||||
)
|
)
|
||||||
from notifications_python_client.errors import HTTPError
|
from notifications_python_client.errors import HTTPError
|
||||||
|
from freezegun import freeze_time
|
||||||
|
|
||||||
from tests.conftest import (
|
from tests.conftest import (
|
||||||
SERVICE_ONE_ID,
|
SERVICE_ONE_ID,
|
||||||
normalize_spaces,
|
normalize_spaces,
|
||||||
mock_get_notifications,
|
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
|
from app.main.views.conversation import get_user_number
|
||||||
|
|
||||||
|
|
||||||
@@ -78,6 +78,7 @@ def test_view_conversation(
|
|||||||
fake_uuid,
|
fake_uuid,
|
||||||
outbound_redacted,
|
outbound_redacted,
|
||||||
expected_outbound_content,
|
expected_outbound_content,
|
||||||
|
mock_get_inbound_sms
|
||||||
):
|
):
|
||||||
|
|
||||||
mock_get_notifications(
|
mock_get_notifications(
|
||||||
@@ -88,10 +89,6 @@ def test_view_conversation(
|
|||||||
redact_personalisation=outbound_redacted,
|
redact_personalisation=outbound_redacted,
|
||||||
)
|
)
|
||||||
|
|
||||||
mock_get_inbound_sms(
|
|
||||||
mocker
|
|
||||||
)
|
|
||||||
|
|
||||||
page = client_request.get(
|
page = client_request.get(
|
||||||
'main.conversation',
|
'main.conversation',
|
||||||
service_id=SERVICE_ONE_ID,
|
service_id=SERVICE_ONE_ID,
|
||||||
@@ -186,3 +183,32 @@ def test_view_conversation_updates(
|
|||||||
assert json.loads(response.get_data(as_text=True)) == {'messages': 'foo'}
|
assert json.loads(response.get_data(as_text=True)) == {'messages': 'foo'}
|
||||||
|
|
||||||
mock_get_partials.assert_called_once_with(SERVICE_ONE_ID, '07123 456789')
|
mock_get_partials.assert_called_once_with(SERVICE_ONE_ID, '07123 456789')
|
||||||
|
|
||||||
|
|
||||||
|
@freeze_time("2012-01-01 00:00:00")
|
||||||
|
def test_view_conversation_with_empty_inbound(
|
||||||
|
client_request,
|
||||||
|
mocker,
|
||||||
|
api_user_active,
|
||||||
|
mock_get_notification,
|
||||||
|
mock_get_notifications_with_no_notifications,
|
||||||
|
fake_uuid
|
||||||
|
):
|
||||||
|
mock_get_inbound_sms = mocker.patch(
|
||||||
|
'app.main.views.conversation.service_api_client.get_inbound_sms',
|
||||||
|
return_value=[{
|
||||||
|
'user_number': '07900000001',
|
||||||
|
'content': '',
|
||||||
|
'created_at': datetime.utcnow().isoformat(),
|
||||||
|
'id': fake_uuid
|
||||||
|
}]
|
||||||
|
)
|
||||||
|
|
||||||
|
page = client_request.get(
|
||||||
|
'main.conversation',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
notification_id=fake_uuid,
|
||||||
|
)
|
||||||
|
|
||||||
|
messages = page.select('.sms-message-wrapper')
|
||||||
|
assert len(messages) == 1
|
||||||
|
|||||||
Reference in New Issue
Block a user