* First pass as switching dispatchers over to httpcore interface * Updates for httpcore interface * headers in dispatch API as plain list of bytes * Integrate against httpcore 0.6 * Integrate against httpcore interface * Drop UDS, since not supported by httpcore * Fix base class for mock dispatchers in tests * Merge master and mark as potential '0.13.dev0' release
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
import typing
|
|
|
|
import httpcore
|
|
import pytest
|
|
|
|
from httpx import URL, AsyncClient, Headers, QueryParams
|
|
from httpx._content_streams import ContentStream, JSONStream
|
|
|
|
|
|
class MockDispatch(httpcore.AsyncHTTPTransport):
|
|
async def request(
|
|
self,
|
|
method: bytes,
|
|
url: typing.Tuple[bytes, bytes, int, bytes],
|
|
headers: typing.List[typing.Tuple[bytes, bytes]],
|
|
stream: ContentStream,
|
|
timeout: typing.Dict[str, typing.Optional[float]] = None,
|
|
) -> typing.Tuple[
|
|
bytes, int, bytes, typing.List[typing.Tuple[bytes, bytes]], ContentStream
|
|
]:
|
|
headers = Headers()
|
|
body = JSONStream({"ok": "ok"})
|
|
return b"HTTP/1.1", 200, b"OK", headers, body
|
|
|
|
|
|
def test_client_queryparams():
|
|
client = AsyncClient(params={"a": "b"})
|
|
assert isinstance(client.params, QueryParams)
|
|
assert client.params["a"] == "b"
|
|
|
|
|
|
def test_client_queryparams_string():
|
|
client = AsyncClient(params="a=b")
|
|
assert isinstance(client.params, QueryParams)
|
|
assert client.params["a"] == "b"
|
|
|
|
client = AsyncClient()
|
|
client.params = "a=b"
|
|
assert isinstance(client.params, QueryParams)
|
|
assert client.params["a"] == "b"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_client_queryparams_echo():
|
|
url = "http://example.org/echo_queryparams"
|
|
client_queryparams = "first=str"
|
|
request_queryparams = {"second": "dict"}
|
|
client = AsyncClient(dispatch=MockDispatch(), params=client_queryparams)
|
|
response = await client.get(url, params=request_queryparams)
|
|
|
|
assert response.status_code == 200
|
|
assert response.url == URL(
|
|
"http://example.org/echo_queryparams?first=str&second=dict"
|
|
)
|