make sure inbound sms page doesn't break if you receive a blank inbound message

This commit is contained in:
Leo Hemsted
2017-09-27 17:38:42 +01:00
parent f9390b4fc5
commit b1e809e82a
2 changed files with 38 additions and 9 deletions

View File

@@ -73,7 +73,10 @@ def get_sms_thread(service_id, user_number):
'inbound': is_inbound,
'content': SMSPreviewTemplate(
{
'content': notification.get('content') or notification['template']['content']
'content': (
notification['content'] if is_inbound else
notification['template']['content']
)
},
notification.get('personalisation'),
downgrade_non_gsm_characters=(not is_inbound),

View File

@@ -1,19 +1,19 @@
from datetime import datetime
import json
import pytest
from bs4 import BeautifulSoup
from bs4 import BeautifulSoup
from flask import (
url_for,
)
from notifications_python_client.errors import HTTPError
from freezegun import freeze_time
from tests.conftest import (
SERVICE_ONE_ID,
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
@@ -78,6 +78,7 @@ def test_view_conversation(
fake_uuid,
outbound_redacted,
expected_outbound_content,
mock_get_inbound_sms
):
mock_get_notifications(
@@ -88,10 +89,6 @@ def test_view_conversation(
redact_personalisation=outbound_redacted,
)
mock_get_inbound_sms(
mocker
)
page = client_request.get(
'main.conversation',
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'}
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