Don't send the SMS if we have failed to save in the database

This commit is contained in:
Martyn Inglis
2016-02-16 17:42:04 +00:00
parent 0933e5c647
commit a2341be0e2
4 changed files with 26 additions and 23 deletions

View File

@@ -1,8 +1,11 @@
import uuid
import pytest
from app.celery.tasks import send_sms
from app import twilio_client
from app.clients.sms.twilio import TwilioClientException
from app.dao import notifications_dao
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.orm.exc import NoResultFound
def test_should_send_template_to_correct_sms_provider_and_persist(sample_template, mocker):
@@ -58,6 +61,7 @@ def test_should_not_send_sms_if_db_peristance_failed(sample_template, mocker):
}
mocker.patch('app.encryption.decrypt', return_value=notification)
mocker.patch('app.twilio_client.send_sms', side_effect=TwilioClientException())
mocker.patch('app.db.session.add', side_effect=SQLAlchemyError())
notification_id = uuid.uuid4()
@@ -66,9 +70,7 @@ def test_should_not_send_sms_if_db_peristance_failed(sample_template, mocker):
notification_id,
"encrypted-in-reality")
twilio_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'
assert persisted_notification.template_id == sample_template.id
assert persisted_notification.status == 'failed'
twilio_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)

View File

@@ -9,6 +9,7 @@ from app.dao.jobs_dao import save_job
from app.dao.notifications_dao import save_notification
import uuid
@pytest.fixture(scope='function')
def service_factory(notify_db, notify_db_session):
class ServiceFactory(object):