Switch providers ONLY on provider exception

This commit is contained in:
Imdad Ahad
2017-01-20 16:14:29 +00:00
parent d466265a9d
commit 0a277b26b6
3 changed files with 36 additions and 14 deletions

View File

@@ -124,10 +124,27 @@ def test_should_technical_error_and_not_retry_if_invalid_email(sample_notificati
def test_send_sms_should_switch_providers_on_provider_failure(sample_notification, mocker):
mocker.patch('app.delivery.send_to_providers.send_sms_to_provider', side_effect=Exception("Provider Exception"))
switch_provider_mock = mocker.patch('app.celery.provider_tasks.dao_toggle_sms_provider')
provider_to_use = mocker.patch('app.delivery.send_to_providers.provider_to_use')
provider_to_use.return_value.send_sms.side_effect = Exception('Error')
switch_provider_mock = mocker.patch('app.delivery.send_to_providers.dao_toggle_sms_provider')
mocker.patch('app.celery.provider_tasks.deliver_sms.retry')
deliver_sms(sample_notification.service_id)
deliver_sms(sample_notification.id)
assert switch_provider_mock.called is True
def test_send_sms_should_not_switch_providers_on_non_provider_failure(
sample_notification,
mocker
):
mocker.patch(
'app.delivery.send_to_providers.send_sms_to_provider',
side_effect=Exception("Non Provider Exception")
)
switch_provider_mock = mocker.patch('app.delivery.send_to_providers.dao_toggle_sms_provider')
mocker.patch('app.celery.provider_tasks.deliver_sms.retry')
deliver_sms(sample_notification.id)
assert switch_provider_mock.called is False