Skip to content
Myr

Replace remaining occurrences of dispatch with transport (#1010)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Replace remaining occurrences of dispatch with transport * Remove unused AsyncDispatcher Was removed in #804 * Remove hard_limit warning in test

authored by Josep Cugat · committed by GitHub · parent 8ed6904 · Browse files · 10 files+79 added−80 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

10 files+79 added−80 removed

  • tests:+73 added−71 removed
  • other:+6 added−9 removed

10 files+79 added−80 removed

modified:httpx/_transports/asgi.py+3 added-3 removed
32 unmodified lines
33 ```34 client = httpx.AsyncClient(app=app)35 ```3637 Alternatively, you can setup the dispatch instance explicitly.37 Alternatively, you can setup the transport instance explicitly.38 This allows you to include any additional configuration arguments specific39 to the ASGITransport class:4041 ```42 dispatch = httpx.ASGITransport(42 transport = httpx.ASGITransport(43 app=app,44 root_path="/submount",45 client=("1.2.3.4", 123)46 )47 client = httpx.AsyncClient(dispatch=dispatch)47 client = httpx.AsyncClient(transport=transport)48 ```4950 Arguments:51
122 unmodified lines
modified:httpx/_transports/wsgi.py+3 added-3 removed
23 unmodified lines
24 ```25 client = httpx.Client(app=app)26 ```2728 Alternatively, you can setup the dispatch instance explicitly.28 Alternatively, you can setup the transport instance explicitly.29 This allows you to include any additional configuration arguments specific30 to the WSGITransport class:3132 ```33 dispatch = httpx.WSGITransport(33 transport = httpx.WSGITransport(34 app=app,35 script_name="/submount",36 remote_addr="1.2.3.4"37 )38 client = httpx.Client(dispatch=dispatch)38 client = httpx.Client(transport=transport)39 ```4041 Arguments:42
109 unmodified lines
modified:httpx/_models.py-3 removed
52 unmodified lines
53 str_query_param,54 warn_deprecated,55)5657if typing.TYPE_CHECKING: # pragma: no cover58 from ._dispatch.base import AsyncDispatcher # noqa: F401576058class URL:59 def __init__(60 self,61 url: URLTypes,
1141 unmodified lines
modified:tests/client/test_auth.py+27 added-25 removed
25 unmodified lines
26 return header_value.decode("ascii")27 return default282930class MockDispatch(httpcore.AsyncHTTPTransport):30class MockTransport(httpcore.AsyncHTTPTransport):31 def __init__(self, auth_header: bytes = b"", status_code: int = 200) -> None:32 self.auth_header = auth_header33 self.status_code = status_code34
14 unmodified lines
49 response_stream = JSONStream({"auth": authorization})50 return b"HTTP/1.1", self.status_code, b"", response_headers, response_stream515253class MockDigestAuthDispatch(httpcore.AsyncHTTPTransport):53class MockDigestAuthTransport(httpcore.AsyncHTTPTransport):54 def __init__(55 self,56 algorithm: str = "SHA-256",57 send_response_after_attempt: int = 1,
60 unmodified lines
118async def test_basic_auth() -> None:119 url = "https://example.org/"120 auth = ("tomchristie", "password123")121122 client = AsyncClient(dispatch=MockDispatch())122 client = AsyncClient(transport=MockTransport())123 response = await client.get(url, auth=auth)124125 assert response.status_code == 200126 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}
2 unmodified lines
129@pytest.mark.asyncio130async def test_basic_auth_in_url() -> None:131 url = "https://tomchristie:password123@example.org/"132133 client = AsyncClient(dispatch=MockDispatch())133 client = AsyncClient(transport=MockTransport())134 response = await client.get(url)135136 assert response.status_code == 200137 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}
3 unmodified lines
141async def test_basic_auth_on_session() -> None:142 url = "https://example.org/"143 auth = ("tomchristie", "password123")144145 client = AsyncClient(dispatch=MockDispatch(), auth=auth)145 client = AsyncClient(transport=MockTransport(), auth=auth)146 response = await client.get(url)147148 assert response.status_code == 200149 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}
6 unmodified lines
156 def auth(request: Request) -> Request:157 request.headers["Authorization"] = "Token 123"158 return request159160 client = AsyncClient(dispatch=MockDispatch())160 client = AsyncClient(transport=MockTransport())161 response = await client.get(url, auth=auth)162163 assert response.status_code == 200164 assert response.json() == {"auth": "Token 123"}
3 unmodified lines
168async def test_netrc_auth() -> None:169 os.environ["NETRC"] = "tests/.netrc"170 url = "http://netrcexample.org"171172 client = AsyncClient(dispatch=MockDispatch())172 client = AsyncClient(transport=MockTransport())173 response = await client.get(url)174175 assert response.status_code == 200176 assert response.json() == {
5 unmodified lines
182async def test_auth_header_has_priority_over_netrc() -> None:183 os.environ["NETRC"] = "tests/.netrc"184 url = "http://netrcexample.org"185186 client = AsyncClient(dispatch=MockDispatch())186 client = AsyncClient(transport=MockTransport())187 response = await client.get(url, headers={"Authorization": "Override"})188189 assert response.status_code == 200190 assert response.json() == {"auth": "Override"}
3 unmodified lines
194async def test_trust_env_auth() -> None:195 os.environ["NETRC"] = "tests/.netrc"196 url = "http://netrcexample.org"197198 client = AsyncClient(dispatch=MockDispatch(), trust_env=False)198 client = AsyncClient(transport=MockTransport(), trust_env=False)199 response = await client.get(url)200201 assert response.status_code == 200202 assert response.json() == {"auth": None}203204 client = AsyncClient(dispatch=MockDispatch(), trust_env=True)204 client = AsyncClient(transport=MockTransport(), trust_env=True)205 response = await client.get(url)206207 assert response.status_code == 200208 assert response.json() == {
12 unmodified lines
221async def test_auth_hidden_header() -> None:222 url = "https://example.org/"223 auth = ("example-username", "example-password")224225 client = AsyncClient(dispatch=MockDispatch())225 client = AsyncClient(transport=MockTransport())226 response = await client.get(url, auth=auth)227228 assert "'authorization': '[secure]'" in str(response.request.headers)229
1 unmodified line
231@pytest.mark.asyncio232async def test_auth_invalid_type() -> None:233 url = "https://example.org/"234 client = AsyncClient(235 dispatch=MockDispatch(), auth="not a tuple, not a callable", # type: ignore235 transport=MockTransport(), auth="not a tuple, not a callable", # type: ignore236 )237 with pytest.raises(TypeError):238 await client.get(url)239
2 unmodified lines
242async def test_digest_auth_returns_no_auth_if_no_digest_header_in_response() -> None:243 url = "https://example.org/"244 auth = DigestAuth(username="tomchristie", password="password123")245246 client = AsyncClient(dispatch=MockDispatch())246 client = AsyncClient(transport=MockTransport())247 response = await client.get(url, auth=auth)248249 assert response.status_code == 200250 assert response.json() == {"auth": None}
6 unmodified lines
257 auth = DigestAuth(username="tomchristie", password="password123")258 auth_header = b'Digest realm="realm@host.com",qop="auth",nonce="abc",opaque="xyz"'259260 client = AsyncClient(261 dispatch=MockDispatch(auth_header=auth_header, status_code=200)261 transport=MockTransport(auth_header=auth_header, status_code=200)262 )263 response = await client.get(url, auth=auth)264265 assert response.status_code == 200
5 unmodified lines
271async def test_digest_auth_401_response_without_digest_auth_header() -> None:272 url = "https://example.org/"273 auth = DigestAuth(username="tomchristie", password="password123")274275 client = AsyncClient(dispatch=MockDispatch(auth_header=b"", status_code=401))275 client = AsyncClient(transport=MockTransport(auth_header=b"", status_code=401))276 response = await client.get(url, auth=auth)277278 assert response.status_code == 401279 assert response.json() == {"auth": None}
19 unmodified lines
299) -> None:300 url = "https://example.org/"301 auth = DigestAuth(username="tomchristie", password="password123")302303 client = AsyncClient(dispatch=MockDigestAuthDispatch(algorithm=algorithm))303 client = AsyncClient(transport=MockDigestAuthTransport(algorithm=algorithm))304 response = await client.get(url, auth=auth)305306 assert response.status_code == 200307 assert len(response.history) == 1
21 unmodified lines
329async def test_digest_auth_no_specified_qop() -> None:330 url = "https://example.org/"331 auth = DigestAuth(username="tomchristie", password="password123")332333 client = AsyncClient(dispatch=MockDigestAuthDispatch(qop=""))333 client = AsyncClient(transport=MockDigestAuthTransport(qop=""))334 response = await client.get(url, auth=auth)335336 assert response.status_code == 200337 assert len(response.history) == 1
22 unmodified lines
360async def test_digest_auth_qop_including_spaces_and_auth_returns_auth(qop: str) -> None:361 url = "https://example.org/"362 auth = DigestAuth(username="tomchristie", password="password123")363364 client = AsyncClient(dispatch=MockDigestAuthDispatch(qop=qop))364 client = AsyncClient(transport=MockDigestAuthTransport(qop=qop))365 response = await client.get(url, auth=auth)366367 assert response.status_code == 200368 assert len(response.history) == 1
2 unmodified lines
371@pytest.mark.asyncio372async def test_digest_auth_qop_auth_int_not_implemented() -> None:373 url = "https://example.org/"374 auth = DigestAuth(username="tomchristie", password="password123")375 client = AsyncClient(dispatch=MockDigestAuthDispatch(qop="auth-int"))375 client = AsyncClient(transport=MockDigestAuthTransport(qop="auth-int"))376377 with pytest.raises(NotImplementedError):378 await client.get(url, auth=auth)379
1 unmodified line
381@pytest.mark.asyncio382async def test_digest_auth_qop_must_be_auth_or_auth_int() -> None:383 url = "https://example.org/"384 auth = DigestAuth(username="tomchristie", password="password123")385 client = AsyncClient(dispatch=MockDigestAuthDispatch(qop="not-auth"))385 client = AsyncClient(transport=MockDigestAuthTransport(qop="not-auth"))386387 with pytest.raises(ProtocolError):388 await client.get(url, auth=auth)389
2 unmodified lines
392async def test_digest_auth_incorrect_credentials() -> None:393 url = "https://example.org/"394 auth = DigestAuth(username="tomchristie", password="password123")395396 client = AsyncClient(dispatch=MockDigestAuthDispatch(send_response_after_attempt=2))396 client = AsyncClient(397 transport=MockDigestAuthTransport(send_response_after_attempt=2)398 )399 response = await client.get(url, auth=auth)400401 assert response.status_code == 401402 assert len(response.history) == 1
15 unmodified lines
418) -> None:419 url = "https://example.org/"420 auth = DigestAuth(username="tomchristie", password="password123")421 client = AsyncClient(420 dispatch=MockDispatch(auth_header=auth_header, status_code=401)422 transport=MockTransport(auth_header=auth_header, status_code=401)423 )424425 with pytest.raises(ProtocolError):426 await client.get(url, auth=auth)
34 unmodified lines
461 yield request462463 url = "https://example.org/"464 auth = RepeatAuth(repeat=2)463 client = AsyncClient(dispatch=MockDispatch(auth_header=b"abc"))465 client = AsyncClient(transport=MockTransport(auth_header=b"abc"))466467 response = await client.get(url, auth=auth)468 assert response.status_code == 200469 assert response.json() == {"auth": "Repeat abc.abc"}
12 unmodified lines
482@pytest.mark.asyncio483async def test_digest_auth_unavailable_streaming_body():484 url = "https://example.org/"485 auth = DigestAuth(username="tomchristie", password="password123")484 client = AsyncClient(dispatch=MockDispatch())486 client = AsyncClient(transport=MockTransport())487488 async def streaming_body():489 yield b"Example request body" # pragma: nocover490
30 unmodified lines
521 yield request522523 url = "https://example.org/"524 auth = ResponseBodyAuth("xyz")523 client = AsyncClient(dispatch=MockDispatch())525 client = AsyncClient(transport=MockTransport())526527 response = await client.get(url, auth=auth)528 assert response.status_code == 200529 assert response.json() == {"auth": '{"auth": "xyz"}'}
modified:tests/client/test_cookies.py+7 added-7 removed
14 unmodified lines
15 return header_value.decode("ascii")16 return default171819class MockDispatch(httpcore.AsyncHTTPTransport):19class MockTransport(httpcore.AsyncHTTPTransport):20 async def request(21 self,22 method: bytes,23 url: typing.Tuple[bytes, bytes, int, bytes],
23 unmodified lines
47 """48 url = "http://example.org/echo_cookies"49 cookies = {"example-name": "example-value"}5051 client = AsyncClient(dispatch=MockDispatch())51 client = AsyncClient(transport=MockTransport())52 response = await client.get(url, cookies=cookies)5354 assert response.status_code == 20055 assert response.json() == {"cookies": "example-name=example-value"}
27 unmodified lines
83 rfc2109=False,84 )85 cookies.set_cookie(cookie)8687 client = AsyncClient(dispatch=MockDispatch())87 client = AsyncClient(transport=MockTransport())88 response = await client.get(url, cookies=cookies)8990 assert response.status_code == 20091 assert response.json() == {"cookies": "example-name=example-value"}
27 unmodified lines
119 rfc2109=False,120 )121 cookies.set_cookie(cookie)122123 client = AsyncClient(dispatch=MockDispatch())123 client = AsyncClient(transport=MockTransport())124 client.cookies = cookies # type: ignore125 response = await client.get(url)126127 assert response.status_code == 200
9 unmodified lines
137 url = "http://example.org/echo_cookies"138 cookies = Cookies()139 cookies["example-name"] = "example-value"140141 client = AsyncClient(dispatch=MockDispatch())141 client = AsyncClient(transport=MockTransport())142 response = await client.get(url, cookies=cookies)143144 assert response.status_code == 200145 assert response.json() == {"cookies": "example-name=example-value"}
2 unmodified lines
148@pytest.mark.asyncio149async def test_get_cookie() -> None:150 url = "http://example.org/set_cookie"151152 client = AsyncClient(dispatch=MockDispatch())152 client = AsyncClient(transport=MockTransport())153 response = await client.get(url)154155 assert response.status_code == 200156 assert response.cookies["example-name"] == "example-value"
4 unmodified lines
161async def test_cookie_persistence() -> None:162 """163 Ensure that Client instances persist cookies between requests.164 """165 client = AsyncClient(dispatch=MockDispatch())165 client = AsyncClient(transport=MockTransport())166167 response = await client.get("http://example.org/echo_cookies")168 assert response.status_code == 200169 assert response.json() == {"cookies": None}
9 unmodified lines
modified:tests/client/test_headers.py+7 added-7 removed
7 unmodified lines
8from httpx import AsyncClient, Headers, __version__9from httpx._content_streams import ContentStream, JSONStream101112class MockDispatch(httpcore.AsyncHTTPTransport):12class MockTransport(httpcore.AsyncHTTPTransport):13 async def request(14 self,15 method: bytes,16 url: typing.Tuple[bytes, bytes, int, bytes],
17 unmodified lines
34 """35 url = "http://example.org/echo_headers"36 headers = {"Example-Header": "example-value"}3738 client = AsyncClient(dispatch=MockDispatch(), headers=headers)38 client = AsyncClient(transport=MockTransport(), headers=headers)39 response = await client.get(url)4041 assert response.status_code == 20042 assert response.json() == {
12 unmodified lines
55async def test_header_merge():56 url = "http://example.org/echo_headers"57 client_headers = {"User-Agent": "python-myclient/0.2.1"}58 request_headers = {"X-Auth-Token": "FooBarBazToken"}59 client = AsyncClient(dispatch=MockDispatch(), headers=client_headers)59 client = AsyncClient(transport=MockTransport(), headers=client_headers)60 response = await client.get(url, headers=request_headers)6162 assert response.status_code == 20063 assert response.json() == {
12 unmodified lines
76async def test_header_merge_conflicting_headers():77 url = "http://example.org/echo_headers"78 client_headers = {"X-Auth-Token": "FooBar"}79 request_headers = {"X-Auth-Token": "BazToken"}80 client = AsyncClient(dispatch=MockDispatch(), headers=client_headers)80 client = AsyncClient(transport=MockTransport(), headers=client_headers)81 response = await client.get(url, headers=request_headers)8283 assert response.status_code == 20084 assert response.json() == {
10 unmodified lines
9596@pytest.mark.asyncio97async def test_header_update():98 url = "http://example.org/echo_headers"99 client = AsyncClient(dispatch=MockDispatch())99 client = AsyncClient(transport=MockTransport())100 first_response = await client.get(url)101 client.headers.update(102 {"User-Agent": "python-myclient/0.2.1", "Another-Header": "AThing"}103 )
37 unmodified lines
141 be present.142 """143 url = "http://username:password@example.org:80/echo_headers"144145 client = AsyncClient(dispatch=MockDispatch())145 client = AsyncClient(transport=MockTransport())146 response = await client.get(url)147148 assert response.status_code == 200149 assert response.json() == {
15 unmodified lines
165 the Host header.166 """167 url = "http://username:password@example.org:123/echo_headers"168169 client = AsyncClient(dispatch=MockDispatch())169 client = AsyncClient(transport=MockTransport())170 response = await client.get(url)171172 assert response.status_code == 200173 assert response.json() == {
9 unmodified lines
modified:tests/client/test_queryparams.py+2 added-2 removed
5 unmodified lines
6from httpx import URL, AsyncClient, Headers, QueryParams7from httpx._content_streams import ContentStream, JSONStream8910class MockDispatch(httpcore.AsyncHTTPTransport):10class MockTransport(httpcore.AsyncHTTPTransport):11 async def request(12 self,13 method: bytes,14 url: typing.Tuple[bytes, bytes, int, bytes],
29 unmodified lines
44async def test_client_queryparams_echo():45 url = "http://example.org/echo_queryparams"46 client_queryparams = "first=str"47 request_queryparams = {"second": "dict"}48 client = AsyncClient(dispatch=MockDispatch(), params=client_queryparams)48 client = AsyncClient(transport=MockTransport(), params=client_queryparams)49 response = await client.get(url, params=request_queryparams)5051 assert response.status_code == 20052 assert response.url == URL(
2 unmodified lines
modified:tests/client/test_redirects.py+24 added-24 removed
23 unmodified lines
24 return header_value.decode("ascii")25 return default262728class MockDispatch(httpcore.AsyncHTTPTransport):28class MockTransport(httpcore.AsyncHTTPTransport):29 async def request(30 self,31 method: bytes,32 url: typing.Tuple[bytes, bytes, int, bytes],
123 unmodified lines
156157158@pytest.mark.usefixtures("async_environment")159async def test_no_redirect():160 client = AsyncClient(dispatch=MockDispatch())160 client = AsyncClient(transport=MockTransport())161 url = "https://example.com/no_redirect"162 response = await client.get(url)163 assert response.status_code == 200164 with pytest.raises(NotRedirectResponse):
1 unmodified line
166167168@pytest.mark.usefixtures("async_environment")169async def test_redirect_301():170 client = AsyncClient(dispatch=MockDispatch())170 client = AsyncClient(transport=MockTransport())171 response = await client.post("https://example.org/redirect_301")172 assert response.status_code == codes.OK173 assert response.url == URL("https://example.org/")174 assert len(response.history) == 1175176177@pytest.mark.usefixtures("async_environment")178async def test_redirect_302():179 client = AsyncClient(dispatch=MockDispatch())179 client = AsyncClient(transport=MockTransport())180 response = await client.post("https://example.org/redirect_302")181 assert response.status_code == codes.OK182 assert response.url == URL("https://example.org/")183 assert len(response.history) == 1184185186@pytest.mark.usefixtures("async_environment")187async def test_redirect_303():188 client = AsyncClient(dispatch=MockDispatch())188 client = AsyncClient(transport=MockTransport())189 response = await client.get("https://example.org/redirect_303")190 assert response.status_code == codes.OK191 assert response.url == URL("https://example.org/")192 assert len(response.history) == 1193194195@pytest.mark.usefixtures("async_environment")196async def test_disallow_redirects():197 client = AsyncClient(dispatch=MockDispatch())197 client = AsyncClient(transport=MockTransport())198 response = await client.post(199 "https://example.org/redirect_303", allow_redirects=False200 )201 assert response.status_code == codes.SEE_OTHER
9 unmodified lines
211212213@pytest.mark.usefixtures("async_environment")214async def test_relative_redirect():215 client = AsyncClient(dispatch=MockDispatch())215 client = AsyncClient(transport=MockTransport())216 response = await client.get("https://example.org/relative_redirect")217 assert response.status_code == codes.OK218 assert response.url == URL("https://example.org/")219 assert len(response.history) == 1
1 unmodified line
221222@pytest.mark.usefixtures("async_environment")223async def test_malformed_redirect():224 # https://github.com/encode/httpx/issues/771225 client = AsyncClient(dispatch=MockDispatch())225 client = AsyncClient(transport=MockTransport())226 response = await client.get("http://example.org/malformed_redirect")227 assert response.status_code == codes.OK228 assert response.url == URL("https://example.org/")229 assert len(response.history) == 1230231232@pytest.mark.usefixtures("async_environment")233async def test_no_scheme_redirect():234 client = AsyncClient(dispatch=MockDispatch())234 client = AsyncClient(transport=MockTransport())235 response = await client.get("https://example.org/no_scheme_redirect")236 assert response.status_code == codes.OK237 assert response.url == URL("https://example.org/")238 assert len(response.history) == 1239240241@pytest.mark.usefixtures("async_environment")242async def test_fragment_redirect():243 client = AsyncClient(dispatch=MockDispatch())243 client = AsyncClient(transport=MockTransport())244 response = await client.get("https://example.org/relative_redirect#fragment")245 assert response.status_code == codes.OK246 assert response.url == URL("https://example.org/#fragment")247 assert len(response.history) == 1248249250@pytest.mark.usefixtures("async_environment")251async def test_multiple_redirects():252 client = AsyncClient(dispatch=MockDispatch())252 client = AsyncClient(transport=MockTransport())253 response = await client.get("https://example.org/multiple_redirects?count=20")254 assert response.status_code == codes.OK255 assert response.url == URL("https://example.org/multiple_redirects")256 assert len(response.history) == 20
8 unmodified lines
265266267@pytest.mark.usefixtures("async_environment")268async def test_too_many_redirects():269 client = AsyncClient(dispatch=MockDispatch())269 client = AsyncClient(transport=MockTransport())270 with pytest.raises(TooManyRedirects):271 await client.get("https://example.org/multiple_redirects?count=21")272273274@pytest.mark.usefixtures("async_environment")275async def test_too_many_redirects_calling_next():276 client = AsyncClient(dispatch=MockDispatch())276 client = AsyncClient(transport=MockTransport())277 url = "https://example.org/multiple_redirects?count=21"278 response = await client.get(url, allow_redirects=False)279 with pytest.raises(TooManyRedirects):280 while response.is_redirect:
1 unmodified line
282283284@pytest.mark.usefixtures("async_environment")285async def test_redirect_loop():286 client = AsyncClient(dispatch=MockDispatch())286 client = AsyncClient(transport=MockTransport())287 with pytest.raises(TooManyRedirects):288 await client.get("https://example.org/redirect_loop")289290291@pytest.mark.usefixtures("async_environment")292async def test_cross_domain_redirect():293 client = AsyncClient(dispatch=MockDispatch())293 client = AsyncClient(transport=MockTransport())294 url = "https://example.com/cross_domain"295 headers = {"Authorization": "abc"}296 response = await client.get(url, headers=headers)297 assert response.url == URL("https://example.org/cross_domain_target")
1 unmodified line
299300301@pytest.mark.usefixtures("async_environment")302async def test_same_domain_redirect():303 client = AsyncClient(dispatch=MockDispatch())303 client = AsyncClient(transport=MockTransport())304 url = "https://example.org/cross_domain"305 headers = {"Authorization": "abc"}306 response = await client.get(url, headers=headers)307 assert response.url == URL("https://example.org/cross_domain_target")
4 unmodified lines
312async def test_body_redirect():313 """314 A 308 redirect should preserve the request body.315 """316 client = AsyncClient(dispatch=MockDispatch())316 client = AsyncClient(transport=MockTransport())317 url = "https://example.org/redirect_body"318 data = b"Example request body"319 response = await client.post(url, data=data)320 assert response.url == URL("https://example.org/redirect_body_target")
5 unmodified lines
326async def test_no_body_redirect():327 """328 A 303 redirect should remove the request body.329 """330 client = AsyncClient(dispatch=MockDispatch())330 client = AsyncClient(transport=MockTransport())331 url = "https://example.org/redirect_no_body"332 data = b"Example request body"333 response = await client.post(url, data=data)334 assert response.url == URL("https://example.org/redirect_body_target")
2 unmodified lines
337338339@pytest.mark.usefixtures("async_environment")340async def test_can_stream_if_no_redirect():341 client = AsyncClient(dispatch=MockDispatch())341 client = AsyncClient(transport=MockTransport())342 url = "https://example.org/redirect_301"343 async with client.stream("GET", url, allow_redirects=False) as response:344 assert not response.is_closed345 assert response.status_code == codes.MOVED_PERMANENTLY
1 unmodified line
347348349@pytest.mark.usefixtures("async_environment")350async def test_cannot_redirect_streaming_body():351 client = AsyncClient(dispatch=MockDispatch())351 client = AsyncClient(transport=MockTransport())352 url = "https://example.org/redirect_body"353354 async def streaming_body():355 yield b"Example request body"
3 unmodified lines
359360361@pytest.mark.usefixtures("async_environment")362async def test_cross_subdomain_redirect():363 client = AsyncClient(dispatch=MockDispatch())363 client = AsyncClient(transport=MockTransport())364 url = "https://example.com/cross_subdomain"365 response = await client.get(url)366 assert response.url == URL("https://www.example.org/cross_subdomain")367368369class MockCookieDispatch(httpcore.AsyncHTTPTransport):369class MockCookieTransport(httpcore.AsyncHTTPTransport):370 async def request(371 self,372 method: bytes,373 url: typing.Tuple[bytes, bytes, int, bytes],
42 unmodified lines
416417418@pytest.mark.usefixtures("async_environment")419async def test_redirect_cookie_behavior():420 client = AsyncClient(dispatch=MockCookieDispatch())420 client = AsyncClient(transport=MockCookieTransport())421422 # The client is not logged in.423 response = await client.get("https://example.com/")424 assert response.url == "https://example.com/"
21 unmodified lines
446447448@pytest.mark.usefixtures("async_environment")449async def test_redirect_custom_scheme():450 client = AsyncClient(dispatch=MockDispatch())450 client = AsyncClient(transport=MockTransport())451 with pytest.raises(InvalidURL) as e:452 await client.post("https://example.org/redirect_custom_scheme")453 assert str(e.value) == 'Scheme "market" not supported.'
modified:tests/test_multipart.py+5 added-5 removed
11 unmodified lines
12from httpx._content_streams import AsyncIteratorStream, encode13from httpx._utils import format_form_param141516class MockDispatch(httpcore.AsyncHTTPTransport):16class MockTransport(httpcore.AsyncHTTPTransport):17 async def request(18 self,19 method: bytes,20 url: typing.Tuple[bytes, bytes, int, bytes],
13 unmodified lines
3435@pytest.mark.parametrize(("value,output"), (("abc", b"abc"), (b"abc", b"abc")))36@pytest.mark.asyncio37async def test_multipart(value, output):38 client = httpx.AsyncClient(dispatch=MockDispatch())38 client = httpx.AsyncClient(transport=MockTransport())3940 # Test with a single-value 'data' argument, and a plain file 'files' argument.41 data = {"text": value}42 files = {"file": io.BytesIO(b"<file content>")}
15 unmodified lines
5859@pytest.mark.parametrize(("key"), (b"abc", 1, 2.3, None))60@pytest.mark.asyncio61async def test_multipart_invalid_key(key):62 client = httpx.AsyncClient(dispatch=MockDispatch())62 client = httpx.AsyncClient(transport=MockTransport())63 data = {key: "abc"}64 files = {"file": io.BytesIO(b"<file content>")}65 with pytest.raises(TypeError) as e:66 await client.post("http://127.0.0.1:8000/", data=data, files=files)
2 unmodified lines
6970@pytest.mark.parametrize(("value"), (1, 2.3, None, [None, "abc"], {None: "abc"}))71@pytest.mark.asyncio72async def test_multipart_invalid_value(value):73 client = httpx.AsyncClient(dispatch=MockDispatch())73 client = httpx.AsyncClient(transport=MockTransport())74 data = {"text": value}75 files = {"file": io.BytesIO(b"<file content>")}76 with pytest.raises(TypeError) as e:77 await client.post("http://127.0.0.1:8000/", data=data, files=files)
1 unmodified line
798081@pytest.mark.asyncio82async def test_multipart_file_tuple():83 client = httpx.AsyncClient(dispatch=MockDispatch())83 client = httpx.AsyncClient(transport=MockTransport())8485 # Test with a list of values 'data' argument, and a tuple style 'files' argument.86 data = {"text": ["abc"]}87 files = {"file": ("name.txt", io.BytesIO(b"<file content>"))}
178 unmodified lines
modified:tests/test_timeouts.py+1 added-1 removed
32 unmodified lines
333435@pytest.mark.usefixtures("async_environment")36async def test_pool_timeout(server):37 pool_limits = httpx.PoolLimits(hard_limit=1)37 pool_limits = httpx.PoolLimits(max_connections=1)38 timeout = httpx.Timeout(pool_timeout=1e-4)3940 async with httpx.AsyncClient(pool_limits=pool_limits, timeout=timeout) as client:41 async with client.stream("GET", server.url):
2 unmodified lines