Exemplo n.º 1
0
def test_transport_tuning(param_name, init_value, tune_value):
    init_kwargs = {param_name: init_value}
    transport = RequestsTransport(**init_kwargs)

    assert getattr(transport, param_name) == init_value

    tune_kwargs = {param_name: tune_value}
    with transport.tune(**tune_kwargs):
        assert getattr(transport, param_name) == tune_value

    assert getattr(transport, param_name) == init_value
Exemplo n.º 2
0
def test_retry_policy_ignores_malformed_retry_after(mocksleep, http_status):
    transport = RequestsTransport()
    checker = RetryCheckRunner(transport.retry_checks)

    dummy_response = mock.Mock()
    dummy_response.headers = {"Retry-After": "not-an-integer"}
    dummy_response.status_code = http_status
    ctx = RetryContext(1, response=dummy_response)

    assert checker.should_retry(ctx) is True
    mocksleep.assert_not_called()
    transport._retry_sleep(ctx)
    mocksleep.assert_called_once()
Exemplo n.º 3
0
def test_retry_policy_ignores_retry_after_too_high(mocksleep, http_status):
    # set explicit max sleep to confirm that the value is capped here
    transport = RequestsTransport(max_sleep=5)
    checker = RetryCheckRunner(transport.retry_checks)

    dummy_response = mock.Mock()
    dummy_response.headers = {"Retry-After": "20"}
    dummy_response.status_code = http_status
    ctx = RetryContext(1, response=dummy_response)

    assert checker.should_retry(ctx) is True
    mocksleep.assert_not_called()
    transport._retry_sleep(ctx)
    mocksleep.assert_called_once_with(5)
def test_will_not_modify_authz_header_without_authorizer():
    request = mock.Mock()
    request.headers = {}

    transport = RequestsTransport()
    transport._set_authz_header(None, request)
    assert request.headers == {}

    request.headers["Authorization"] = "foo bar"
    transport._set_authz_header(None, request)
    assert request.headers == {"Authorization": "foo bar"}
def test_will_null_authz_header_with_null_authorizer():
    request = mock.Mock()
    request.headers = {}

    transport = RequestsTransport()
    transport._set_authz_header(NullAuthorizer(), request)
    assert request.headers == {}

    request.headers["Authorization"] = "foo bar"
    transport._set_authz_header(NullAuthorizer(), request)
    assert request.headers == {}
Exemplo n.º 6
0
def test_default_retry_check_noop_on_exception(checkname, mocksleep):
    transport = RequestsTransport()
    method = getattr(transport, checkname)
    ctx = RetryContext(1, exception=Exception("foo"))
    assert method(ctx) is RetryCheckResult.no_decision