Ejemplo n.º 1
0
def test_should_call_send_sms_to_provider_from_deliver_sms_task(
        sample_notification, mocker):
    mocker.patch('app.delivery.send_to_providers.send_sms_to_provider')

    deliver_sms(sample_notification.id)
    app.delivery.send_to_providers.send_sms_to_provider.assert_called_with(
        sample_notification)
def test_should_go_into_technical_error_if_exceeds_retries_on_deliver_sms_task(sample_notification, mocker):
    mocker.patch('app.delivery.send_to_providers.send_sms_to_provider', side_effect=Exception("EXPECTED"))
    mocker.patch('app.celery.provider_tasks.deliver_sms.retry', side_effect=MaxRetriesExceededError())

    deliver_sms(sample_notification.id)

    provider_tasks.deliver_sms.retry.assert_called_with(queue='retry', countdown=10)

    assert sample_notification.status == 'technical-failure'
def test_should_call_send_sms_to_provider_from_deliver_sms_task(
        notify_db,
        notify_db_session,
        sample_notification,
        mocker):
    mocker.patch('app.delivery.send_to_providers.send_sms_to_provider')

    deliver_sms(sample_notification.id)
    app.delivery.send_to_providers.send_sms_to_provider.assert_called_with(sample_notification)
Ejemplo n.º 4
0
def test_should_add_to_retry_queue_if_notification_not_found_in_deliver_sms_task(
        notify_db_session, mocker):
    mocker.patch('app.delivery.send_to_providers.send_sms_to_provider')
    mocker.patch('app.celery.provider_tasks.deliver_sms.retry')

    notification_id = app.create_uuid()

    deliver_sms(notification_id)
    app.delivery.send_to_providers.send_sms_to_provider.assert_not_called()
    app.celery.provider_tasks.deliver_sms.retry.assert_called_with(
        queue="retry-tasks")
Ejemplo n.º 5
0
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
def test_should_go_into_technical_error_if_exceeds_retries_on_deliver_sms_task(sample_notification, mocker):
    mocker.patch('app.delivery.send_to_providers.send_sms_to_provider', side_effect=Exception("EXPECTED"))
    mocker.patch('app.celery.provider_tasks.deliver_sms.retry', side_effect=MaxRetriesExceededError())

    with pytest.raises(NotificationTechnicalFailureException) as e:
        deliver_sms(sample_notification.id)
    assert str(sample_notification.id) in str(e.value)

    provider_tasks.deliver_sms.retry.assert_called_with(queue="retry-tasks", countdown=0)

    assert sample_notification.status == 'technical-failure'
Ejemplo n.º 7
0
def test_send_sms_should_switch_providers_on_provider_failure(
        sample_notification, mocker):
    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.id)

    assert switch_provider_mock.called is True
def test_should_add_to_retry_queue_if_notification_not_found_in_deliver_sms_task(
        notify_db,
        notify_db_session,
        mocker):
    mocker.patch('app.delivery.send_to_providers.send_sms_to_provider')
    mocker.patch('app.celery.provider_tasks.deliver_sms.retry')

    notification_id = app.create_uuid()

    deliver_sms(notification_id)
    app.delivery.send_to_providers.send_sms_to_provider.assert_not_called()
    app.celery.provider_tasks.deliver_sms.retry.assert_called_with(queue="retry", countdown=10)
Ejemplo n.º 9
0
def test_should_retry_and_log_exception_for_non_SmsClientResponseException_exceptions_for_deliver_sms_task(
    sample_notification, mocker
):
    mocker.patch('app.delivery.send_to_providers.send_sms_to_provider', side_effect=Exception("something went wrong"))
    mocker.patch('app.celery.provider_tasks.deliver_sms.retry')
    mock_logger_exception = mocker.patch('app.celery.tasks.current_app.logger.exception')

    deliver_sms(sample_notification.id)

    assert provider_tasks.deliver_sms.retry.called is True
    assert sample_notification.status == 'created'
    assert mock_logger_exception.called
Ejemplo n.º 10
0
def test_should_queue_callback_task_if_non_retryable_exception_is_thrown(
        sample_notification, mocker):
    mocker.patch(
        'app.celery.provider_tasks.send_to_providers.send_sms_to_provider',
        side_effect=NonRetryableException('Exception'))

    mock_callback = mocker.patch(
        'app.celery.provider_tasks.check_and_queue_callback_task')

    deliver_sms(sample_notification.id)

    assert sample_notification.status == NOTIFICATION_PERMANENT_FAILURE
    mock_callback.assert_called_once_with(sample_notification)