update dependencies

This commit is contained in:
Leo Hemsted
2017-08-18 15:39:39 +01:00
parent 953e2ae5bd
commit c36e50bef1
10 changed files with 90 additions and 82 deletions

View File

@@ -1186,7 +1186,7 @@ def test_send_inbound_sms_to_service_retries_if_request_returns_500(notify_api,
mocked.assert_called_with(
exc='Unable to send_inbound_sms_to_service for service_id: {} '
'and url: {}. \n500 Server Error: None'.format(sample_service.id, inbound_api.url),
'and url: {url}. \n500 Server Error: None for url: {url}'.format(sample_service.id, url=inbound_api.url),
queue="retry-tasks")

View File

@@ -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
@pytest.mark.parametrize('permissions,expected_response', [

View File

@@ -5,8 +5,8 @@ import boto3
import pytest
from alembic.command import upgrade
from alembic.config import Config
from flask.ext.migrate import Migrate, MigrateCommand
from flask.ext.script import Manager
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
from app import create_app, db
@@ -18,16 +18,16 @@ def notify_api():
# deattach server-error error handlers - error_handler_spec looks like:
# {'blueprint_name': {
# status_code: [error_handlers],
# None: [ tuples of (exception, )]
# None: { ExceptionClass: error_handler }
# }}
for error_handlers in app.error_handler_spec.values():
error_handlers.pop(500, None)
if None in error_handlers:
error_handlers[None] = [
exception_handler
for exception_handler in error_handlers[None]
if exception_handler[0] != Exception
]
error_handlers[None] = {
exc_class: error_handler
for exc_class, error_handler in error_handlers[None].items()
if exc_class != Exception
}
if error_handlers[None] == []:
error_handlers.pop(None)