Firetext tests

This commit is contained in:
Ken Tsang
2017-07-03 14:10:04 +01:00
committed by venusbb
parent 5a82fe0a70
commit e96a67c59b
2 changed files with 61 additions and 23 deletions

View File

@@ -67,7 +67,6 @@ def receive_firetext_sms():
}), 200 }), 200
service = potential_services[0] service = potential_services[0]
inbound = create_inbound_sms_object(service=service, inbound = create_inbound_sms_object(service=service,
content=post_data["message"], content=post_data["message"],
from_number=post_data['source'], from_number=post_data['source'],

View File

@@ -17,49 +17,88 @@ from tests.app.db import create_service
from tests.app.conftest import sample_service from tests.app.conftest import sample_service
def test_receive_notification_returns_received_to_mmg(client, mocker, sample_service_full_permissions): @pytest.mark.parametrize('provider,headers,data,expected_response', [
mocked = mocker.patch("app.notifications.receive_notifications.tasks.send_inbound_sms_to_service.apply_async") (
data = {"ID": "1234", 'mmg',
[('Content-Type', 'application/json')],
json.dumps({
"ID": "1234",
"MSISDN": "447700900855", "MSISDN": "447700900855",
"Message": "Some message to notify", "Message": "Some message to notify",
"Trigger": "Trigger?", "Trigger": "Trigger?",
"Number": "testing", "Number": "testing",
"Channel": "SMS", "Channel": "SMS",
"DateRecieved": "2012-06-27 12:33:00" "DateRecieved": "2012-06-27 12:33:00"
} }),
response = client.post(path='/notifications/sms/receive/mmg', 'RECEIVED'
data=json.dumps(data), ),
headers=[('Content-Type', 'application/json')]) (
'firetext',
None,
{
"Message": "Some message to notify",
"source": "Source",
"time": "2012-06-27 12:33:00",
"destination": "447700900856"
},
'{\n "status": "ok"\n}'
),
])
def test_receive_notification_returns_received_to_mmg(
client, mocker, sample_service_full_permissions, provider, headers, data, expected_response):
mocked = mocker.patch("app.notifications.receive_notifications.tasks.send_inbound_sms_to_service.apply_async")
response = client.post(path='/notifications/sms/receive/{}'.format(provider),
data=data,
headers=headers)
assert response.status_code == 200 assert response.status_code == 200
assert response.get_data(as_text=True) == 'RECEIVED' assert response.get_data(as_text=True) == expected_response
inbound_sms_id = InboundSms.query.all()[0].id inbound_sms_id = InboundSms.query.all()[0].id
mocked.assert_called_once_with( mocked.assert_called_once_with(
[str(inbound_sms_id), str(sample_service_full_permissions.id)], queue="notify-internal-tasks") [str(inbound_sms_id), str(sample_service_full_permissions.id)], queue="notify-internal-tasks")
@pytest.mark.parametrize('permissions', [ @pytest.mark.parametrize('provider,headers,data,expected_response', [
([SMS_TYPE]), (
([INBOUND_SMS_TYPE]), 'mmg',
]) [('Content-Type', 'application/json')],
def test_receive_notification_without_permissions_does_not_create_inbound( json.dumps({
client, mocker, notify_db, notify_db_session, permissions): "ID": "1234",
service = sample_service(notify_db, notify_db_session, permissions=permissions)
mocked = mocker.patch("app.notifications.receive_notifications.tasks.send_inbound_sms_to_service.apply_async")
data = {"ID": "1234",
"MSISDN": "447700900855", "MSISDN": "447700900855",
"Message": "Some message to notify", "Message": "Some message to notify",
"Trigger": "Trigger?", "Trigger": "Trigger?",
"Number": "testing", "Number": "testing",
"Channel": "SMS", "Channel": "SMS",
"DateRecieved": "2012-06-27 12:33:00" "DateRecieved": "2012-06-27 12:33:00"
} }),
response = client.post(path='/notifications/sms/receive/mmg', 'RECEIVED'
data=json.dumps(data), ),
headers=[('Content-Type', 'application/json')]) (
'firetext',
None,
{
"Message": "Some message to notify",
"source": "Source",
"time": "2012-06-27 12:33:00",
"destination": "447700900856"
},
'{\n "status": "ok"\n}'
),
])
@pytest.mark.parametrize('permissions', [
([SMS_TYPE]),
([INBOUND_SMS_TYPE]),
])
def test_receive_notification_without_permissions_does_not_create_inbound(
client, mocker, notify_db, notify_db_session, permissions, provider, headers, data, expected_response):
service = sample_service(notify_db, notify_db_session, permissions=permissions)
mocked = mocker.patch("app.notifications.receive_notifications.tasks.send_inbound_sms_to_service.apply_async")
response = client.post(path='/notifications/sms/receive/{}'.format(provider),
data=data,
headers=headers)
assert response.status_code == 200 assert response.status_code == 200
assert response.get_data(as_text=True) == 'RECEIVED' assert response.get_data(as_text=True) == expected_response
assert len(InboundSms.query.all()) == 0 assert len(InboundSms.query.all()) == 0
assert mocked.called is False assert mocked.called is False