mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-18 06:21:43 -05:00
@@ -41,56 +41,65 @@ def test_receive_notification_returns_received_to_mmg(client, mocker, sample_ser
|
||||
[str(inbound_sms_id), str(sample_service_full_permissions.id)], queue="notify-internal-tasks")
|
||||
|
||||
|
||||
@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"
|
||||
}),
|
||||
'RECEIVED'
|
||||
),
|
||||
(
|
||||
'firetext',
|
||||
None,
|
||||
{
|
||||
"Message": "Some message to notify",
|
||||
"source": "Source",
|
||||
"time": "2012-06-27 12:33:00",
|
||||
"destination": "447700900855"
|
||||
},
|
||||
'{\n "status": "ok"\n}'
|
||||
),
|
||||
])
|
||||
@pytest.mark.parametrize('permissions', [
|
||||
([SMS_TYPE]),
|
||||
([INBOUND_SMS_TYPE]),
|
||||
[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)
|
||||
mocker.patch("app.notifications.receive_notifications.dao_fetch_services_by_sms_sender",
|
||||
return_value=[service])
|
||||
mocked_send_inbound_sms = mocker.patch(
|
||||
"app.notifications.receive_notifications.tasks.send_inbound_sms_to_service.apply_async")
|
||||
mocked_has_permissions = mocker.patch(
|
||||
"app.notifications.receive_notifications.has_inbound_sms_permissions", return_value=False)
|
||||
|
||||
response = client.post(path='/notifications/sms/receive/{}'.format(provider),
|
||||
data=data,
|
||||
headers=headers)
|
||||
def test_receive_notification_from_mmg_without_permissions_does_not_persist(
|
||||
client,
|
||||
mocker,
|
||||
notify_db_session,
|
||||
permissions
|
||||
):
|
||||
mocked = mocker.patch("app.notifications.receive_notifications.tasks.send_inbound_sms_to_service.apply_async")
|
||||
service = create_service(sms_sender='07111111111', service_permissions=permissions)
|
||||
data = {
|
||||
"ID": "1234",
|
||||
"MSISDN": "07111111111",
|
||||
"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')]
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.get_data(as_text=True) == expected_response
|
||||
assert len(InboundSms.query.all()) == 0
|
||||
assert mocked_has_permissions.called
|
||||
mocked_send_inbound_sms.assert_not_called()
|
||||
assert response.get_data(as_text=True) == 'RECEIVED'
|
||||
assert InboundSms.query.count() == 0
|
||||
assert mocked.called is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize('permissions', [
|
||||
[SMS_TYPE],
|
||||
[INBOUND_SMS_TYPE],
|
||||
])
|
||||
def test_receive_notification_from_firetext_without_permissions_does_not_persist(
|
||||
client,
|
||||
mocker,
|
||||
notify_db_session,
|
||||
permissions
|
||||
):
|
||||
service = create_service(sms_sender='07111111111', service_permissions=permissions)
|
||||
mocked = mocker.patch("app.notifications.receive_notifications.tasks.send_inbound_sms_to_service.apply_async")
|
||||
|
||||
data = "source=07999999999&destination=07111111111&message=this is a message&time=2017-01-01 12:00:00"
|
||||
response = client.post(
|
||||
path='/notifications/sms/receive/firetext',
|
||||
data=data,
|
||||
headers=[('Content-Type', 'application/x-www-form-urlencoded')]
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
result = json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert result['status'] == 'ok'
|
||||
assert InboundSms.query.count() == 0
|
||||
assert mocked.called is False
|
||||
|
||||
|
||||
def test_receive_notification_without_permissions_does_not_create_inbound_even_with_inbound_number_set(
|
||||
|
||||
Reference in New Issue
Block a user