def test_api_versioned_url_is_built_properly(
        settings: transport.PTransportSettings, test_url: str,
        expected_url: str):
    """RequestsTransport.api_path should append the api version to the base url."""
    session = cast(requests.Session, Session(None, True))
    settings.base_url = test_url
    rtp = requests_transport.RequestsTransport(settings, session)
    assert rtp.api_path == expected_url
def test_request_error(settings):
    """Test network error response
    """
    session = cast(requests.Session, Session(None, True))
    test = requests_transport.RequestsTransport(settings, session)
    resp = test.request(transport.HttpMethod.GET, "/some/path")
    assert isinstance(resp, transport.Response)
    assert resp.value == b"(54, 'Connection reset by peer')"
    assert resp.ok is False
def test_request_not_ok(settings):
    """Test API error response
    """
    ret_val = Response(ok=False, text="Some API error")
    session = Session(ret_val)
    test = requests_transport.RequestsTransport(settings, session)
    resp = test.request(transport.HttpMethod.GET, "/some/path")
    assert isinstance(resp, transport.Response)
    assert resp.value == "Some API error"
    assert resp.ok is False
def test_request_ok(settings):
    """Test basic successful round trip
    """
    ret_val = Response(ok=True, text="yay!")
    session = Session(ret_val)
    test = requests_transport.RequestsTransport(settings, session)
    resp = test.request(transport.HttpMethod.GET, "/some/path")
    assert isinstance(resp, transport.Response)
    assert resp.value == "yay!"
    assert resp.ok is True
def test_request_ok(
    settings: transport.PTransportSettings,
    headers: MutableMapping[str, str],
    expected_response_mode: transport.ResponseMode,
    expected_encoding: str,
):
    """Test basic successful round trip
    """
    value = b"yay!"
    ret_val = Response(
        ok=True,
        content=value,
        headers=requests.structures.CaseInsensitiveDict(headers))
    session = cast(requests.Session, Session(ret_val))
    test = requests_transport.RequestsTransport(settings, session)
    resp = test.request(transport.HttpMethod.GET, "/some/path")
    assert isinstance(resp, transport.Response)
    assert resp.value == value
    assert resp.ok is True
    assert resp.response_mode == expected_response_mode
    assert resp.encoding == expected_encoding
def test_request_not_ok(
    settings: transport.TransportSettings,
    headers: MutableMapping[str, str],
    expected_response_mode: transport.ResponseMode,
    expected_encoding: str,
):
    """Test API error response
    """
    value = b"Some API error"
    ret_val = Response(
        ok=False,
        content=value,
        headers=requests.structures.CaseInsensitiveDict(headers),
    )
    session = cast(requests.Session, Session(ret_val))
    test = requests_transport.RequestsTransport(settings, session)
    resp = test.request(transport.HttpMethod.GET, "/some/path")
    assert isinstance(resp, transport.Response)
    assert resp.value == value
    assert resp.ok is False
    assert resp.response_mode == expected_response_mode
    assert resp.encoding == expected_encoding