Esempio n. 1
0
def test_circuit_decorator_with_args(circuitbreaker_mock):
    circuitbreaker_mock.return_value = None
    circuit(10, 20, KeyError, 'foobar')
    circuitbreaker_mock.assert_called_once_with(expected_exception=KeyError,
                                                failure_threshold=10,
                                                recovery_timeout=20,
                                                name='foobar')
Esempio n. 2
0
def test_circuit_decorator_with_args(circuitbreaker_mock):
    circuitbreaker_mock.return_value = None
    circuit(10, 20, KeyError, 'foobar')
    circuitbreaker_mock.assert_called_once_with(
        expected_exception=KeyError,
        failure_threshold=10,
        recovery_timeout=20,
        name='foobar'
    )
Esempio n. 3
0
def test_circuitbreaker_call_fallback_function_with_parameters():
    fallback = Mock(return_value=True)

    cb = circuit(name='with_fallback', fallback_function=fallback)

    # mock opened prop to see if fallback is called with correct parameters.
    cb.opened = lambda self: True
    func_decorated = cb.decorate(mocked_function)

    func_decorated('test2', test='test')

    # check args and kwargs are getting correctly to fallback function

    fallback.assert_called_once_with('test2', test='test')
Esempio n. 4
0
def test_circuit_decorator_without_args(circuitbreaker_mock):
    function = lambda: True
    circuit(function)
    circuitbreaker_mock.assert_called_once_with(function)
Esempio n. 5
0
def test_circuit_decorator_without_args(circuitbreaker_mock):
    function = lambda: True
    circuit(function)
    circuitbreaker_mock.assert_called_once_with(function)