Replace remaining occurrences of dispatch with transport (#1010)

* Replace remaining occurrences of dispatch with transport

* Remove unused AsyncDispatcher

Was removed in #804

* Remove hard_limit warning in test
This commit is contained in:
Josep Cugat 2020-05-30 23:18:48 +02:00 committed by GitHub
parent 8ed6904646
commit 89a8100b6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 79 additions and 80 deletions

View File

@ -54,9 +54,6 @@ from ._utils import (
warn_deprecated,
)
if typing.TYPE_CHECKING: # pragma: no cover
from ._dispatch.base import AsyncDispatcher # noqa: F401
class URL:
def __init__(

View File

@ -34,17 +34,17 @@ class ASGITransport(httpcore.AsyncHTTPTransport):
client = httpx.AsyncClient(app=app)
```
Alternatively, you can setup the dispatch instance explicitly.
Alternatively, you can setup the transport instance explicitly.
This allows you to include any additional configuration arguments specific
to the ASGITransport class:
```
dispatch = httpx.ASGITransport(
transport = httpx.ASGITransport(
app=app,
root_path="/submount",
client=("1.2.3.4", 123)
)
client = httpx.AsyncClient(dispatch=dispatch)
client = httpx.AsyncClient(transport=transport)
```
Arguments:

View File

@ -25,17 +25,17 @@ class WSGITransport(httpcore.SyncHTTPTransport):
client = httpx.Client(app=app)
```
Alternatively, you can setup the dispatch instance explicitly.
Alternatively, you can setup the transport instance explicitly.
This allows you to include any additional configuration arguments specific
to the WSGITransport class:
```
dispatch = httpx.WSGITransport(
transport = httpx.WSGITransport(
app=app,
script_name="/submount",
remote_addr="1.2.3.4"
)
client = httpx.Client(dispatch=dispatch)
client = httpx.Client(transport=transport)
```
Arguments:

View File

@ -27,7 +27,7 @@ def get_header_value(headers, key, default=None):
return default
class MockDispatch(httpcore.AsyncHTTPTransport):
class MockTransport(httpcore.AsyncHTTPTransport):
def __init__(self, auth_header: bytes = b"", status_code: int = 200) -> None:
self.auth_header = auth_header
self.status_code = status_code
@ -50,7 +50,7 @@ class MockDispatch(httpcore.AsyncHTTPTransport):
return b"HTTP/1.1", self.status_code, b"", response_headers, response_stream
class MockDigestAuthDispatch(httpcore.AsyncHTTPTransport):
class MockDigestAuthTransport(httpcore.AsyncHTTPTransport):
def __init__(
self,
algorithm: str = "SHA-256",
@ -119,7 +119,7 @@ async def test_basic_auth() -> None:
url = "https://example.org/"
auth = ("tomchristie", "password123")
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get(url, auth=auth)
assert response.status_code == 200
@ -130,7 +130,7 @@ async def test_basic_auth() -> None:
async def test_basic_auth_in_url() -> None:
url = "https://tomchristie:password123@example.org/"
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get(url)
assert response.status_code == 200
@ -142,7 +142,7 @@ async def test_basic_auth_on_session() -> None:
url = "https://example.org/"
auth = ("tomchristie", "password123")
client = AsyncClient(dispatch=MockDispatch(), auth=auth)
client = AsyncClient(transport=MockTransport(), auth=auth)
response = await client.get(url)
assert response.status_code == 200
@ -157,7 +157,7 @@ async def test_custom_auth() -> None:
request.headers["Authorization"] = "Token 123"
return request
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get(url, auth=auth)
assert response.status_code == 200
@ -169,7 +169,7 @@ async def test_netrc_auth() -> None:
os.environ["NETRC"] = "tests/.netrc"
url = "http://netrcexample.org"
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get(url)
assert response.status_code == 200
@ -183,7 +183,7 @@ async def test_auth_header_has_priority_over_netrc() -> None:
os.environ["NETRC"] = "tests/.netrc"
url = "http://netrcexample.org"
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get(url, headers={"Authorization": "Override"})
assert response.status_code == 200
@ -195,13 +195,13 @@ async def test_trust_env_auth() -> None:
os.environ["NETRC"] = "tests/.netrc"
url = "http://netrcexample.org"
client = AsyncClient(dispatch=MockDispatch(), trust_env=False)
client = AsyncClient(transport=MockTransport(), trust_env=False)
response = await client.get(url)
assert response.status_code == 200
assert response.json() == {"auth": None}
client = AsyncClient(dispatch=MockDispatch(), trust_env=True)
client = AsyncClient(transport=MockTransport(), trust_env=True)
response = await client.get(url)
assert response.status_code == 200
@ -222,7 +222,7 @@ async def test_auth_hidden_header() -> None:
url = "https://example.org/"
auth = ("example-username", "example-password")
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get(url, auth=auth)
assert "'authorization': '[secure]'" in str(response.request.headers)
@ -232,7 +232,7 @@ async def test_auth_hidden_header() -> None:
async def test_auth_invalid_type() -> None:
url = "https://example.org/"
client = AsyncClient(
dispatch=MockDispatch(), auth="not a tuple, not a callable", # type: ignore
transport=MockTransport(), auth="not a tuple, not a callable", # type: ignore
)
with pytest.raises(TypeError):
await client.get(url)
@ -243,7 +243,7 @@ async def test_digest_auth_returns_no_auth_if_no_digest_header_in_response() ->
url = "https://example.org/"
auth = DigestAuth(username="tomchristie", password="password123")
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get(url, auth=auth)
assert response.status_code == 200
@ -258,7 +258,7 @@ async def test_digest_auth_200_response_including_digest_auth_header() -> None:
auth_header = b'Digest realm="realm@host.com",qop="auth",nonce="abc",opaque="xyz"'
client = AsyncClient(
dispatch=MockDispatch(auth_header=auth_header, status_code=200)
transport=MockTransport(auth_header=auth_header, status_code=200)
)
response = await client.get(url, auth=auth)
@ -272,7 +272,7 @@ async def test_digest_auth_401_response_without_digest_auth_header() -> None:
url = "https://example.org/"
auth = DigestAuth(username="tomchristie", password="password123")
client = AsyncClient(dispatch=MockDispatch(auth_header=b"", status_code=401))
client = AsyncClient(transport=MockTransport(auth_header=b"", status_code=401))
response = await client.get(url, auth=auth)
assert response.status_code == 401
@ -300,7 +300,7 @@ async def test_digest_auth(
url = "https://example.org/"
auth = DigestAuth(username="tomchristie", password="password123")
client = AsyncClient(dispatch=MockDigestAuthDispatch(algorithm=algorithm))
client = AsyncClient(transport=MockDigestAuthTransport(algorithm=algorithm))
response = await client.get(url, auth=auth)
assert response.status_code == 200
@ -330,7 +330,7 @@ async def test_digest_auth_no_specified_qop() -> None:
url = "https://example.org/"
auth = DigestAuth(username="tomchristie", password="password123")
client = AsyncClient(dispatch=MockDigestAuthDispatch(qop=""))
client = AsyncClient(transport=MockDigestAuthTransport(qop=""))
response = await client.get(url, auth=auth)
assert response.status_code == 200
@ -361,7 +361,7 @@ async def test_digest_auth_qop_including_spaces_and_auth_returns_auth(qop: str)
url = "https://example.org/"
auth = DigestAuth(username="tomchristie", password="password123")
client = AsyncClient(dispatch=MockDigestAuthDispatch(qop=qop))
client = AsyncClient(transport=MockDigestAuthTransport(qop=qop))
response = await client.get(url, auth=auth)
assert response.status_code == 200
@ -372,7 +372,7 @@ async def test_digest_auth_qop_including_spaces_and_auth_returns_auth(qop: str)
async def test_digest_auth_qop_auth_int_not_implemented() -> None:
url = "https://example.org/"
auth = DigestAuth(username="tomchristie", password="password123")
client = AsyncClient(dispatch=MockDigestAuthDispatch(qop="auth-int"))
client = AsyncClient(transport=MockDigestAuthTransport(qop="auth-int"))
with pytest.raises(NotImplementedError):
await client.get(url, auth=auth)
@ -382,7 +382,7 @@ async def test_digest_auth_qop_auth_int_not_implemented() -> None:
async def test_digest_auth_qop_must_be_auth_or_auth_int() -> None:
url = "https://example.org/"
auth = DigestAuth(username="tomchristie", password="password123")
client = AsyncClient(dispatch=MockDigestAuthDispatch(qop="not-auth"))
client = AsyncClient(transport=MockDigestAuthTransport(qop="not-auth"))
with pytest.raises(ProtocolError):
await client.get(url, auth=auth)
@ -393,7 +393,9 @@ async def test_digest_auth_incorrect_credentials() -> None:
url = "https://example.org/"
auth = DigestAuth(username="tomchristie", password="password123")
client = AsyncClient(dispatch=MockDigestAuthDispatch(send_response_after_attempt=2))
client = AsyncClient(
transport=MockDigestAuthTransport(send_response_after_attempt=2)
)
response = await client.get(url, auth=auth)
assert response.status_code == 401
@ -417,7 +419,7 @@ async def test_digest_auth_raises_protocol_error_on_malformed_header(
url = "https://example.org/"
auth = DigestAuth(username="tomchristie", password="password123")
client = AsyncClient(
dispatch=MockDispatch(auth_header=auth_header, status_code=401)
transport=MockTransport(auth_header=auth_header, status_code=401)
)
with pytest.raises(ProtocolError):
@ -460,7 +462,7 @@ async def test_auth_history() -> None:
url = "https://example.org/"
auth = RepeatAuth(repeat=2)
client = AsyncClient(dispatch=MockDispatch(auth_header=b"abc"))
client = AsyncClient(transport=MockTransport(auth_header=b"abc"))
response = await client.get(url, auth=auth)
assert response.status_code == 200
@ -481,7 +483,7 @@ async def test_auth_history() -> None:
async def test_digest_auth_unavailable_streaming_body():
url = "https://example.org/"
auth = DigestAuth(username="tomchristie", password="password123")
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
async def streaming_body():
yield b"Example request body" # pragma: nocover
@ -520,7 +522,7 @@ async def test_auth_reads_response_body() -> None:
url = "https://example.org/"
auth = ResponseBodyAuth("xyz")
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get(url, auth=auth)
assert response.status_code == 200

View File

@ -16,7 +16,7 @@ def get_header_value(headers, key, default=None):
return default
class MockDispatch(httpcore.AsyncHTTPTransport):
class MockTransport(httpcore.AsyncHTTPTransport):
async def request(
self,
method: bytes,
@ -48,7 +48,7 @@ async def test_set_cookie() -> None:
url = "http://example.org/echo_cookies"
cookies = {"example-name": "example-value"}
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get(url, cookies=cookies)
assert response.status_code == 200
@ -84,7 +84,7 @@ async def test_set_cookie_with_cookiejar() -> None:
)
cookies.set_cookie(cookie)
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get(url, cookies=cookies)
assert response.status_code == 200
@ -120,7 +120,7 @@ async def test_setting_client_cookies_to_cookiejar() -> None:
)
cookies.set_cookie(cookie)
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
client.cookies = cookies # type: ignore
response = await client.get(url)
@ -138,7 +138,7 @@ async def test_set_cookie_with_cookies_model() -> None:
cookies = Cookies()
cookies["example-name"] = "example-value"
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get(url, cookies=cookies)
assert response.status_code == 200
@ -149,7 +149,7 @@ async def test_set_cookie_with_cookies_model() -> None:
async def test_get_cookie() -> None:
url = "http://example.org/set_cookie"
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get(url)
assert response.status_code == 200
@ -162,7 +162,7 @@ async def test_cookie_persistence() -> None:
"""
Ensure that Client instances persist cookies between requests.
"""
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get("http://example.org/echo_cookies")
assert response.status_code == 200

View File

@ -9,7 +9,7 @@ from httpx import AsyncClient, Headers, __version__
from httpx._content_streams import ContentStream, JSONStream
class MockDispatch(httpcore.AsyncHTTPTransport):
class MockTransport(httpcore.AsyncHTTPTransport):
async def request(
self,
method: bytes,
@ -35,7 +35,7 @@ async def test_client_header():
url = "http://example.org/echo_headers"
headers = {"Example-Header": "example-value"}
client = AsyncClient(dispatch=MockDispatch(), headers=headers)
client = AsyncClient(transport=MockTransport(), headers=headers)
response = await client.get(url)
assert response.status_code == 200
@ -56,7 +56,7 @@ async def test_header_merge():
url = "http://example.org/echo_headers"
client_headers = {"User-Agent": "python-myclient/0.2.1"}
request_headers = {"X-Auth-Token": "FooBarBazToken"}
client = AsyncClient(dispatch=MockDispatch(), headers=client_headers)
client = AsyncClient(transport=MockTransport(), headers=client_headers)
response = await client.get(url, headers=request_headers)
assert response.status_code == 200
@ -77,7 +77,7 @@ async def test_header_merge_conflicting_headers():
url = "http://example.org/echo_headers"
client_headers = {"X-Auth-Token": "FooBar"}
request_headers = {"X-Auth-Token": "BazToken"}
client = AsyncClient(dispatch=MockDispatch(), headers=client_headers)
client = AsyncClient(transport=MockTransport(), headers=client_headers)
response = await client.get(url, headers=request_headers)
assert response.status_code == 200
@ -96,7 +96,7 @@ async def test_header_merge_conflicting_headers():
@pytest.mark.asyncio
async def test_header_update():
url = "http://example.org/echo_headers"
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
first_response = await client.get(url)
client.headers.update(
{"User-Agent": "python-myclient/0.2.1", "Another-Header": "AThing"}
@ -142,7 +142,7 @@ async def test_host_with_auth_and_port_in_url():
"""
url = "http://username:password@example.org:80/echo_headers"
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get(url)
assert response.status_code == 200
@ -166,7 +166,7 @@ async def test_host_with_non_default_port_in_url():
"""
url = "http://username:password@example.org:123/echo_headers"
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get(url)
assert response.status_code == 200

View File

@ -7,7 +7,7 @@ from httpx import URL, AsyncClient, Headers, QueryParams
from httpx._content_streams import ContentStream, JSONStream
class MockDispatch(httpcore.AsyncHTTPTransport):
class MockTransport(httpcore.AsyncHTTPTransport):
async def request(
self,
method: bytes,
@ -45,7 +45,7 @@ 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)
client = AsyncClient(transport=MockTransport(), params=client_queryparams)
response = await client.get(url, params=request_queryparams)
assert response.status_code == 200

View File

@ -25,7 +25,7 @@ def get_header_value(headers, key, default=None):
return default
class MockDispatch(httpcore.AsyncHTTPTransport):
class MockTransport(httpcore.AsyncHTTPTransport):
async def request(
self,
method: bytes,
@ -157,7 +157,7 @@ class MockDispatch(httpcore.AsyncHTTPTransport):
@pytest.mark.usefixtures("async_environment")
async def test_no_redirect():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
url = "https://example.com/no_redirect"
response = await client.get(url)
assert response.status_code == 200
@ -167,7 +167,7 @@ async def test_no_redirect():
@pytest.mark.usefixtures("async_environment")
async def test_redirect_301():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.post("https://example.org/redirect_301")
assert response.status_code == codes.OK
assert response.url == URL("https://example.org/")
@ -176,7 +176,7 @@ async def test_redirect_301():
@pytest.mark.usefixtures("async_environment")
async def test_redirect_302():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.post("https://example.org/redirect_302")
assert response.status_code == codes.OK
assert response.url == URL("https://example.org/")
@ -185,7 +185,7 @@ async def test_redirect_302():
@pytest.mark.usefixtures("async_environment")
async def test_redirect_303():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get("https://example.org/redirect_303")
assert response.status_code == codes.OK
assert response.url == URL("https://example.org/")
@ -194,7 +194,7 @@ async def test_redirect_303():
@pytest.mark.usefixtures("async_environment")
async def test_disallow_redirects():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.post(
"https://example.org/redirect_303", allow_redirects=False
)
@ -212,7 +212,7 @@ async def test_disallow_redirects():
@pytest.mark.usefixtures("async_environment")
async def test_relative_redirect():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get("https://example.org/relative_redirect")
assert response.status_code == codes.OK
assert response.url == URL("https://example.org/")
@ -222,7 +222,7 @@ async def test_relative_redirect():
@pytest.mark.usefixtures("async_environment")
async def test_malformed_redirect():
# https://github.com/encode/httpx/issues/771
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get("http://example.org/malformed_redirect")
assert response.status_code == codes.OK
assert response.url == URL("https://example.org/")
@ -231,7 +231,7 @@ async def test_malformed_redirect():
@pytest.mark.usefixtures("async_environment")
async def test_no_scheme_redirect():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get("https://example.org/no_scheme_redirect")
assert response.status_code == codes.OK
assert response.url == URL("https://example.org/")
@ -240,7 +240,7 @@ async def test_no_scheme_redirect():
@pytest.mark.usefixtures("async_environment")
async def test_fragment_redirect():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get("https://example.org/relative_redirect#fragment")
assert response.status_code == codes.OK
assert response.url == URL("https://example.org/#fragment")
@ -249,7 +249,7 @@ async def test_fragment_redirect():
@pytest.mark.usefixtures("async_environment")
async def test_multiple_redirects():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
response = await client.get("https://example.org/multiple_redirects?count=20")
assert response.status_code == codes.OK
assert response.url == URL("https://example.org/multiple_redirects")
@ -266,14 +266,14 @@ async def test_multiple_redirects():
@pytest.mark.usefixtures("async_environment")
async def test_too_many_redirects():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
with pytest.raises(TooManyRedirects):
await client.get("https://example.org/multiple_redirects?count=21")
@pytest.mark.usefixtures("async_environment")
async def test_too_many_redirects_calling_next():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
url = "https://example.org/multiple_redirects?count=21"
response = await client.get(url, allow_redirects=False)
with pytest.raises(TooManyRedirects):
@ -283,14 +283,14 @@ async def test_too_many_redirects_calling_next():
@pytest.mark.usefixtures("async_environment")
async def test_redirect_loop():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
with pytest.raises(TooManyRedirects):
await client.get("https://example.org/redirect_loop")
@pytest.mark.usefixtures("async_environment")
async def test_cross_domain_redirect():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
url = "https://example.com/cross_domain"
headers = {"Authorization": "abc"}
response = await client.get(url, headers=headers)
@ -300,7 +300,7 @@ async def test_cross_domain_redirect():
@pytest.mark.usefixtures("async_environment")
async def test_same_domain_redirect():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
url = "https://example.org/cross_domain"
headers = {"Authorization": "abc"}
response = await client.get(url, headers=headers)
@ -313,7 +313,7 @@ async def test_body_redirect():
"""
A 308 redirect should preserve the request body.
"""
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
url = "https://example.org/redirect_body"
data = b"Example request body"
response = await client.post(url, data=data)
@ -327,7 +327,7 @@ async def test_no_body_redirect():
"""
A 303 redirect should remove the request body.
"""
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
url = "https://example.org/redirect_no_body"
data = b"Example request body"
response = await client.post(url, data=data)
@ -338,7 +338,7 @@ async def test_no_body_redirect():
@pytest.mark.usefixtures("async_environment")
async def test_can_stream_if_no_redirect():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
url = "https://example.org/redirect_301"
async with client.stream("GET", url, allow_redirects=False) as response:
assert not response.is_closed
@ -348,7 +348,7 @@ async def test_can_stream_if_no_redirect():
@pytest.mark.usefixtures("async_environment")
async def test_cannot_redirect_streaming_body():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
url = "https://example.org/redirect_body"
async def streaming_body():
@ -360,13 +360,13 @@ async def test_cannot_redirect_streaming_body():
@pytest.mark.usefixtures("async_environment")
async def test_cross_subdomain_redirect():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
url = "https://example.com/cross_subdomain"
response = await client.get(url)
assert response.url == URL("https://www.example.org/cross_subdomain")
class MockCookieDispatch(httpcore.AsyncHTTPTransport):
class MockCookieTransport(httpcore.AsyncHTTPTransport):
async def request(
self,
method: bytes,
@ -417,7 +417,7 @@ class MockCookieDispatch(httpcore.AsyncHTTPTransport):
@pytest.mark.usefixtures("async_environment")
async def test_redirect_cookie_behavior():
client = AsyncClient(dispatch=MockCookieDispatch())
client = AsyncClient(transport=MockCookieTransport())
# The client is not logged in.
response = await client.get("https://example.com/")
@ -447,7 +447,7 @@ async def test_redirect_cookie_behavior():
@pytest.mark.usefixtures("async_environment")
async def test_redirect_custom_scheme():
client = AsyncClient(dispatch=MockDispatch())
client = AsyncClient(transport=MockTransport())
with pytest.raises(InvalidURL) as e:
await client.post("https://example.org/redirect_custom_scheme")
assert str(e.value) == 'Scheme "market" not supported.'

View File

@ -13,7 +13,7 @@ from httpx._content_streams import AsyncIteratorStream, encode
from httpx._utils import format_form_param
class MockDispatch(httpcore.AsyncHTTPTransport):
class MockTransport(httpcore.AsyncHTTPTransport):
async def request(
self,
method: bytes,
@ -35,7 +35,7 @@ class MockDispatch(httpcore.AsyncHTTPTransport):
@pytest.mark.parametrize(("value,output"), (("abc", b"abc"), (b"abc", b"abc")))
@pytest.mark.asyncio
async def test_multipart(value, output):
client = httpx.AsyncClient(dispatch=MockDispatch())
client = httpx.AsyncClient(transport=MockTransport())
# Test with a single-value 'data' argument, and a plain file 'files' argument.
data = {"text": value}
@ -59,7 +59,7 @@ async def test_multipart(value, output):
@pytest.mark.parametrize(("key"), (b"abc", 1, 2.3, None))
@pytest.mark.asyncio
async def test_multipart_invalid_key(key):
client = httpx.AsyncClient(dispatch=MockDispatch())
client = httpx.AsyncClient(transport=MockTransport())
data = {key: "abc"}
files = {"file": io.BytesIO(b"<file content>")}
with pytest.raises(TypeError) as e:
@ -70,7 +70,7 @@ async def test_multipart_invalid_key(key):
@pytest.mark.parametrize(("value"), (1, 2.3, None, [None, "abc"], {None: "abc"}))
@pytest.mark.asyncio
async def test_multipart_invalid_value(value):
client = httpx.AsyncClient(dispatch=MockDispatch())
client = httpx.AsyncClient(transport=MockTransport())
data = {"text": value}
files = {"file": io.BytesIO(b"<file content>")}
with pytest.raises(TypeError) as e:
@ -80,7 +80,7 @@ async def test_multipart_invalid_value(value):
@pytest.mark.asyncio
async def test_multipart_file_tuple():
client = httpx.AsyncClient(dispatch=MockDispatch())
client = httpx.AsyncClient(transport=MockTransport())
# Test with a list of values 'data' argument, and a tuple style 'files' argument.
data = {"text": ["abc"]}

View File

@ -34,7 +34,7 @@ async def test_connect_timeout(server):
@pytest.mark.usefixtures("async_environment")
async def test_pool_timeout(server):
pool_limits = httpx.PoolLimits(hard_limit=1)
pool_limits = httpx.PoolLimits(max_connections=1)
timeout = httpx.Timeout(pool_timeout=1e-4)
async with httpx.AsyncClient(pool_limits=pool_limits, timeout=timeout) as client: