Merge branch 'master' into celery-send-sms-code

Conflicts:
	tests/app/celery/test_tasks.py
This commit is contained in:
Rebecca Law
2016-02-17 15:43:57 +00:00
7 changed files with 74 additions and 11 deletions

View File

@@ -3,6 +3,9 @@ import pytest
from app.celery.tasks import (send_sms, send_sms_code)
from app import twilio_client, encryption
from app.clients.sms.twilio import TwilioClientException
from app.celery.tasks import send_sms
from app import firetext_client
from app.clients.sms.firetext import FiretextClientException
from app.dao import notifications_dao
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.orm.exc import NoResultFound
@@ -14,7 +17,7 @@ def test_should_send_template_to_correct_sms_provider_and_persist(sample_templat
"to": "+441234123123"
}
mocker.patch('app.encryption.decrypt', return_value=notification)
mocker.patch('app.twilio_client.send_sms')
mocker.patch('app.firetext_client.send_sms')
notification_id = uuid.uuid4()
@@ -23,7 +26,7 @@ def test_should_send_template_to_correct_sms_provider_and_persist(sample_templat
notification_id,
"encrypted-in-reality")
twilio_client.send_sms.assert_called_once_with("+441234123123", sample_template.content)
firetext_client.send_sms.assert_called_once_with("+441234123123", sample_template.content)
persisted_notification = notifications_dao.get_notification(sample_template.service_id, notification_id)
assert persisted_notification.id == notification_id
assert persisted_notification.to == '+441234123123'
@@ -37,7 +40,7 @@ def test_should_persist_notification_as_failed_if_sms_client_fails(sample_templa
"to": "+441234123123"
}
mocker.patch('app.encryption.decrypt', return_value=notification)
mocker.patch('app.twilio_client.send_sms', side_effect=TwilioClientException())
mocker.patch('app.firetext_client.send_sms', side_effect=FiretextClientException())
notification_id = uuid.uuid4()
@@ -46,7 +49,7 @@ def test_should_persist_notification_as_failed_if_sms_client_fails(sample_templa
notification_id,
"encrypted-in-reality")
twilio_client.send_sms.assert_called_once_with("+441234123123", sample_template.content)
firetext_client.send_sms.assert_called_once_with("+441234123123", sample_template.content)
persisted_notification = notifications_dao.get_notification(sample_template.service_id, notification_id)
assert persisted_notification.id == notification_id
assert persisted_notification.to == '+441234123123'
@@ -60,7 +63,7 @@ def test_should_not_send_sms_if_db_peristance_failed(sample_template, mocker):
"to": "+441234123123"
}
mocker.patch('app.encryption.decrypt', return_value=notification)
mocker.patch('app.twilio_client.send_sms', side_effect=TwilioClientException())
mocker.patch('app.firetext_client.send_sms', side_effect=FiretextClientException())
mocker.patch('app.db.session.add', side_effect=SQLAlchemyError())
notification_id = uuid.uuid4()
@@ -70,7 +73,7 @@ def test_should_not_send_sms_if_db_peristance_failed(sample_template, mocker):
notification_id,
"encrypted-in-reality")
twilio_client.send_sms.assert_not_called()
firetext_client.send_sms.assert_not_called()
with pytest.raises(NoResultFound) as e:
notifications_dao.get_notification(sample_template.service_id, notification_id)
assert 'No row was found for one' in str(e.value)