Ejemplo n.º 1
0
def test__execute__no_exception_named_args__returns_value():
    retrier = HTTPRetrier()
    value = 'hello'

    return_value = retrier.execute(_get_value, return_value=value)

    assert return_value == value
Ejemplo n.º 2
0
def test__execute__no_exception_named_args_set_second_arg__returns_value():
    retrier = HTTPRetrier()
    value = 'hello'

    return_values = retrier.execute(_get_values, value2=value)

    assert return_values[0] is None
    assert return_values[1] == value
Ejemplo n.º 3
0
def test__execute__raises_403_http_exception__no_retries_and_raises(mocker):
    retrier = HTTPRetrier(2, 1)

    db = DatabricksAPI(host='HOST', token='TOKEN')
    mock_request = mocker.patch.object(db.client.session, 'request')
    mock_resp = requests.models.Response()
    mock_resp.status_code = 403
    mock_request.return_value = mock_resp

    with pytest.raises(HTTPError):
        return_value = retrier.execute(db.jobs.get_run_output, 1)
    assert retrier._tries == 0
Ejemplo n.º 4
0
def test__execute__raises_invalid_state_http_exception__retries_twice_and_raises(
        mocker):
    retrier = HTTPRetrier(2, 1)

    db = DatabricksAPI(host='HOST', token='TOKEN')
    mock_request = mocker.patch.object(db.client.session, 'request')
    response_body = " { 'error_code': 'INVALID_STATE', 'message': 'Run result is empty. " + \
                    " There may have been issues while saving or reading results.'} "

    mock_resp = requests.models.Response()
    mock_resp.status_code = 400
    mock_resp.raw = io.BytesIO(bytes(response_body, 'utf-8'))
    mock_request.return_value = mock_resp

    with pytest.raises(HTTPError):
        return_value = retrier.execute(db.jobs.get_run_output, 1)
    assert retrier._tries == 2
Ejemplo n.º 5
0
def test__execute__raises_non_http_exception__exception_arises(mocker):
    retrier = HTTPRetrier()
    raiser = ExceptionRaiser(0, ValueError)

    with pytest.raises(ValueError):
        return_value = retrier.execute(raiser.execute)