mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Firetext tests
This commit is contained in:
@@ -17,49 +17,88 @@ from tests.app.db import create_service
|
||||
from tests.app.conftest import sample_service
|
||||
|
||||
|
||||
def test_receive_notification_returns_received_to_mmg(client, mocker, sample_service_full_permissions):
|
||||
mocked = mocker.patch("app.notifications.receive_notifications.tasks.send_inbound_sms_to_service.apply_async")
|
||||
data = {"ID": "1234",
|
||||
@pytest.mark.parametrize('provider,headers,data,expected_response', [
|
||||
(
|
||||
'mmg',
|
||||
[('Content-Type', 'application/json')],
|
||||
json.dumps({
|
||||
"ID": "1234",
|
||||
"MSISDN": "447700900855",
|
||||
"Message": "Some message to notify",
|
||||
"Trigger": "Trigger?",
|
||||
"Number": "testing",
|
||||
"Channel": "SMS",
|
||||
"DateRecieved": "2012-06-27 12:33:00"
|
||||
}
|
||||
response = client.post(path='/notifications/sms/receive/mmg',
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json')])
|
||||
}),
|
||||
'RECEIVED'
|
||||
),
|
||||
(
|
||||
'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.get_data(as_text=True) == 'RECEIVED'
|
||||
assert response.get_data(as_text=True) == expected_response
|
||||
inbound_sms_id = InboundSms.query.all()[0].id
|
||||
mocked.assert_called_once_with(
|
||||
[str(inbound_sms_id), str(sample_service_full_permissions.id)], queue="notify-internal-tasks")
|
||||
|
||||
|
||||
@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):
|
||||
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",
|
||||
@pytest.mark.parametrize('provider,headers,data,expected_response', [
|
||||
(
|
||||
'mmg',
|
||||
[('Content-Type', 'application/json')],
|
||||
json.dumps({
|
||||
"ID": "1234",
|
||||
"MSISDN": "447700900855",
|
||||
"Message": "Some message to notify",
|
||||
"Trigger": "Trigger?",
|
||||
"Number": "testing",
|
||||
"Channel": "SMS",
|
||||
"DateRecieved": "2012-06-27 12:33:00"
|
||||
}
|
||||
response = client.post(path='/notifications/sms/receive/mmg',
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json')])
|
||||
}),
|
||||
'RECEIVED'
|
||||
),
|
||||
(
|
||||
'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.get_data(as_text=True) == 'RECEIVED'
|
||||
assert response.get_data(as_text=True) == expected_response
|
||||
assert len(InboundSms.query.all()) == 0
|
||||
assert mocked.called is False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user