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
Provenance
- Commit
89a8100- Tree
e1f139e- Author
Josep Cugat <jcugat@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
8ed6904
10 files changed+79 added−80 removed
modified:httpx/_transports/asgi.py+3 added-3 removed
32 unmodified lines33 ```34 client = httpx.AsyncClient(app=app)35 ```36 37- 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:40 41 ```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 ```49 50 Arguments:51 122 unmodified linesmodified:httpx/_transports/wsgi.py+3 added-3 removed
23 unmodified lines24 ```25 client = httpx.Client(app=app)26 ```27 28- 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:31 32 ```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 ```40 41 Arguments:42 109 unmodified linesmodified:httpx/_models.py-3 removed
52 unmodified lines53 str_query_param,54 warn_deprecated,55 )56 57-if typing.TYPE_CHECKING: # pragma: no cover58- from ._dispatch.base import AsyncDispatcher # noqa: F40157 60-58 class URL:59 def __init__(60 self,61 url: URLTypes,1141 unmodified linesmodified:tests/client/test_auth.py+27 added-25 removed
25 unmodified lines26 return header_value.decode("ascii")27 return default28 29 30-class MockDispatch(httpcore.AsyncHTTPTransport):30+class 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 lines49 response_stream = JSONStream({"auth": authorization})50 return b"HTTP/1.1", self.status_code, b"", response_headers, response_stream51 52 53-class MockDigestAuthDispatch(httpcore.AsyncHTTPTransport):53+class MockDigestAuthTransport(httpcore.AsyncHTTPTransport):54 def __init__(55 self,56 algorithm: str = "SHA-256",57 send_response_after_attempt: int = 1,60 unmodified lines118 async def test_basic_auth() -> None:119 url = "https://example.org/"120 auth = ("tomchristie", "password123")121 122- client = AsyncClient(dispatch=MockDispatch())122+ client = AsyncClient(transport=MockTransport())123 response = await client.get(url, auth=auth)124 125 assert response.status_code == 200126 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}2 unmodified lines129 @pytest.mark.asyncio130 async def test_basic_auth_in_url() -> None:131 url = "https://tomchristie:password123@example.org/"132 133- client = AsyncClient(dispatch=MockDispatch())133+ client = AsyncClient(transport=MockTransport())134 response = await client.get(url)135 136 assert response.status_code == 200137 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}3 unmodified lines141 async def test_basic_auth_on_session() -> None:142 url = "https://example.org/"143 auth = ("tomchristie", "password123")144 145- client = AsyncClient(dispatch=MockDispatch(), auth=auth)145+ client = AsyncClient(transport=MockTransport(), auth=auth)146 response = await client.get(url)147 148 assert response.status_code == 200149 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}6 unmodified lines156 def auth(request: Request) -> Request:157 request.headers["Authorization"] = "Token 123"158 return request159 160- client = AsyncClient(dispatch=MockDispatch())160+ client = AsyncClient(transport=MockTransport())161 response = await client.get(url, auth=auth)162 163 assert response.status_code == 200164 assert response.json() == {"auth": "Token 123"}3 unmodified lines168 async def test_netrc_auth() -> None:169 os.environ["NETRC"] = "tests/.netrc"170 url = "http://netrcexample.org"171 172- client = AsyncClient(dispatch=MockDispatch())172+ client = AsyncClient(transport=MockTransport())173 response = await client.get(url)174 175 assert response.status_code == 200176 assert response.json() == {5 unmodified lines182 async def test_auth_header_has_priority_over_netrc() -> None:183 os.environ["NETRC"] = "tests/.netrc"184 url = "http://netrcexample.org"185 186- client = AsyncClient(dispatch=MockDispatch())186+ client = AsyncClient(transport=MockTransport())187 response = await client.get(url, headers={"Authorization": "Override"})188 189 assert response.status_code == 200190 assert response.json() == {"auth": "Override"}3 unmodified lines194 async def test_trust_env_auth() -> None:195 os.environ["NETRC"] = "tests/.netrc"196 url = "http://netrcexample.org"197 198- client = AsyncClient(dispatch=MockDispatch(), trust_env=False)198+ client = AsyncClient(transport=MockTransport(), trust_env=False)199 response = await client.get(url)200 201 assert response.status_code == 200202 assert response.json() == {"auth": None}203 204- client = AsyncClient(dispatch=MockDispatch(), trust_env=True)204+ client = AsyncClient(transport=MockTransport(), trust_env=True)205 response = await client.get(url)206 207 assert response.status_code == 200208 assert response.json() == {12 unmodified lines221 async def test_auth_hidden_header() -> None:222 url = "https://example.org/"223 auth = ("example-username", "example-password")224 225- client = AsyncClient(dispatch=MockDispatch())225+ client = AsyncClient(transport=MockTransport())226 response = await client.get(url, auth=auth)227 228 assert "'authorization': '[secure]'" in str(response.request.headers)229 1 unmodified line231 @pytest.mark.asyncio232 async 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 lines242 async 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")245 246- client = AsyncClient(dispatch=MockDispatch())246+ client = AsyncClient(transport=MockTransport())247 response = await client.get(url, auth=auth)248 249 assert response.status_code == 200250 assert response.json() == {"auth": None}6 unmodified lines257 auth = DigestAuth(username="tomchristie", password="password123")258 auth_header = b'Digest realm="realm@host.com",qop="auth",nonce="abc",opaque="xyz"'259 260 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)264 265 assert response.status_code == 2005 unmodified lines271 async def test_digest_auth_401_response_without_digest_auth_header() -> None:272 url = "https://example.org/"273 auth = DigestAuth(username="tomchristie", password="password123")274 275- 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)277 278 assert response.status_code == 401279 assert response.json() == {"auth": None}19 unmodified lines299 ) -> None:300 url = "https://example.org/"301 auth = DigestAuth(username="tomchristie", password="password123")302 303- client = AsyncClient(dispatch=MockDigestAuthDispatch(algorithm=algorithm))303+ client = AsyncClient(transport=MockDigestAuthTransport(algorithm=algorithm))304 response = await client.get(url, auth=auth)305 306 assert response.status_code == 200307 assert len(response.history) == 121 unmodified lines329 async def test_digest_auth_no_specified_qop() -> None:330 url = "https://example.org/"331 auth = DigestAuth(username="tomchristie", password="password123")332 333- client = AsyncClient(dispatch=MockDigestAuthDispatch(qop=""))333+ client = AsyncClient(transport=MockDigestAuthTransport(qop=""))334 response = await client.get(url, auth=auth)335 336 assert response.status_code == 200337 assert len(response.history) == 122 unmodified lines360 async 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")363 364- client = AsyncClient(dispatch=MockDigestAuthDispatch(qop=qop))364+ client = AsyncClient(transport=MockDigestAuthTransport(qop=qop))365 response = await client.get(url, auth=auth)366 367 assert response.status_code == 200368 assert len(response.history) == 12 unmodified lines371 @pytest.mark.asyncio372 async 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"))376 377 with pytest.raises(NotImplementedError):378 await client.get(url, auth=auth)379 1 unmodified line381 @pytest.mark.asyncio382 async 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"))386 387 with pytest.raises(ProtocolError):388 await client.get(url, auth=auth)389 2 unmodified lines392 async def test_digest_auth_incorrect_credentials() -> None:393 url = "https://example.org/"394 auth = DigestAuth(username="tomchristie", password="password123")395 396- 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)400 401 assert response.status_code == 401402 assert len(response.history) == 115 unmodified lines418 ) -> 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 )424 425 with pytest.raises(ProtocolError):426 await client.get(url, auth=auth)34 unmodified lines461 yield request462 463 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"))466 467 response = await client.get(url, auth=auth)468 assert response.status_code == 200469 assert response.json() == {"auth": "Repeat abc.abc"}12 unmodified lines482 @pytest.mark.asyncio483 async 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())487 488 async def streaming_body():489 yield b"Example request body" # pragma: nocover490 30 unmodified lines521 yield request522 523 url = "https://example.org/"524 auth = ResponseBodyAuth("xyz")523- client = AsyncClient(dispatch=MockDispatch())525+ client = AsyncClient(transport=MockTransport())526 527 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 lines15 return header_value.decode("ascii")16 return default17 18 19-class MockDispatch(httpcore.AsyncHTTPTransport):19+class MockTransport(httpcore.AsyncHTTPTransport):20 async def request(21 self,22 method: bytes,23 url: typing.Tuple[bytes, bytes, int, bytes],23 unmodified lines47 """48 url = "http://example.org/echo_cookies"49 cookies = {"example-name": "example-value"}50 51- client = AsyncClient(dispatch=MockDispatch())51+ client = AsyncClient(transport=MockTransport())52 response = await client.get(url, cookies=cookies)53 54 assert response.status_code == 20055 assert response.json() == {"cookies": "example-name=example-value"}27 unmodified lines83 rfc2109=False,84 )85 cookies.set_cookie(cookie)86 87- client = AsyncClient(dispatch=MockDispatch())87+ client = AsyncClient(transport=MockTransport())88 response = await client.get(url, cookies=cookies)89 90 assert response.status_code == 20091 assert response.json() == {"cookies": "example-name=example-value"}27 unmodified lines119 rfc2109=False,120 )121 cookies.set_cookie(cookie)122 123- client = AsyncClient(dispatch=MockDispatch())123+ client = AsyncClient(transport=MockTransport())124 client.cookies = cookies # type: ignore125 response = await client.get(url)126 127 assert response.status_code == 2009 unmodified lines137 url = "http://example.org/echo_cookies"138 cookies = Cookies()139 cookies["example-name"] = "example-value"140 141- client = AsyncClient(dispatch=MockDispatch())141+ client = AsyncClient(transport=MockTransport())142 response = await client.get(url, cookies=cookies)143 144 assert response.status_code == 200145 assert response.json() == {"cookies": "example-name=example-value"}2 unmodified lines148 @pytest.mark.asyncio149 async def test_get_cookie() -> None:150 url = "http://example.org/set_cookie"151 152- client = AsyncClient(dispatch=MockDispatch())152+ client = AsyncClient(transport=MockTransport())153 response = await client.get(url)154 155 assert response.status_code == 200156 assert response.cookies["example-name"] == "example-value"4 unmodified lines161 async 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())166 167 response = await client.get("http://example.org/echo_cookies")168 assert response.status_code == 200169 assert response.json() == {"cookies": None}9 unmodified linesmodified:tests/client/test_headers.py+7 added-7 removed
7 unmodified lines8 from httpx import AsyncClient, Headers, __version__9 from httpx._content_streams import ContentStream, JSONStream10 11 12-class MockDispatch(httpcore.AsyncHTTPTransport):12+class MockTransport(httpcore.AsyncHTTPTransport):13 async def request(14 self,15 method: bytes,16 url: typing.Tuple[bytes, bytes, int, bytes],17 unmodified lines34 """35 url = "http://example.org/echo_headers"36 headers = {"Example-Header": "example-value"}37 38- client = AsyncClient(dispatch=MockDispatch(), headers=headers)38+ client = AsyncClient(transport=MockTransport(), headers=headers)39 response = await client.get(url)40 41 assert response.status_code == 20042 assert response.json() == {12 unmodified lines55 async 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)61 62 assert response.status_code == 20063 assert response.json() == {12 unmodified lines76 async 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)82 83 assert response.status_code == 20084 assert response.json() == {10 unmodified lines95 96 @pytest.mark.asyncio97 async 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 lines141 be present.142 """143 url = "http://username:password@example.org:80/echo_headers"144 145- client = AsyncClient(dispatch=MockDispatch())145+ client = AsyncClient(transport=MockTransport())146 response = await client.get(url)147 148 assert response.status_code == 200149 assert response.json() == {15 unmodified lines165 the Host header.166 """167 url = "http://username:password@example.org:123/echo_headers"168 169- client = AsyncClient(dispatch=MockDispatch())169+ client = AsyncClient(transport=MockTransport())170 response = await client.get(url)171 172 assert response.status_code == 200173 assert response.json() == {9 unmodified linesmodified:tests/client/test_queryparams.py+2 added-2 removed
5 unmodified lines6 from httpx import URL, AsyncClient, Headers, QueryParams7 from httpx._content_streams import ContentStream, JSONStream8 9 10-class MockDispatch(httpcore.AsyncHTTPTransport):10+class MockTransport(httpcore.AsyncHTTPTransport):11 async def request(12 self,13 method: bytes,14 url: typing.Tuple[bytes, bytes, int, bytes],29 unmodified lines44 async 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)50 51 assert response.status_code == 20052 assert response.url == URL(2 unmodified linesmodified:tests/client/test_redirects.py+24 added-24 removed
23 unmodified lines24 return header_value.decode("ascii")25 return default26 27 28-class MockDispatch(httpcore.AsyncHTTPTransport):28+class MockTransport(httpcore.AsyncHTTPTransport):29 async def request(30 self,31 method: bytes,32 url: typing.Tuple[bytes, bytes, int, bytes],123 unmodified lines156 157 158 @pytest.mark.usefixtures("async_environment")159 async 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 line166 167 168 @pytest.mark.usefixtures("async_environment")169 async 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) == 1175 176 177 @pytest.mark.usefixtures("async_environment")178 async 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) == 1184 185 186 @pytest.mark.usefixtures("async_environment")187 async 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) == 1193 194 195 @pytest.mark.usefixtures("async_environment")196 async 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_OTHER9 unmodified lines211 212 213 @pytest.mark.usefixtures("async_environment")214 async 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) == 11 unmodified line221 222 @pytest.mark.usefixtures("async_environment")223 async 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) == 1230 231 232 @pytest.mark.usefixtures("async_environment")233 async 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) == 1239 240 241 @pytest.mark.usefixtures("async_environment")242 async 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) == 1248 249 250 @pytest.mark.usefixtures("async_environment")251 async 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) == 208 unmodified lines265 266 267 @pytest.mark.usefixtures("async_environment")268 async 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")272 273 274 @pytest.mark.usefixtures("async_environment")275 async 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 line282 283 284 @pytest.mark.usefixtures("async_environment")285 async 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")289 290 291 @pytest.mark.usefixtures("async_environment")292 async 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 line299 300 301 @pytest.mark.usefixtures("async_environment")302 async 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 lines312 async 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 lines326 async 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 lines337 338 339 @pytest.mark.usefixtures("async_environment")340 async 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_PERMANENTLY1 unmodified line347 348 349 @pytest.mark.usefixtures("async_environment")350 async def test_cannot_redirect_streaming_body():351- client = AsyncClient(dispatch=MockDispatch())351+ client = AsyncClient(transport=MockTransport())352 url = "https://example.org/redirect_body"353 354 async def streaming_body():355 yield b"Example request body"3 unmodified lines359 360 361 @pytest.mark.usefixtures("async_environment")362 async 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")367 368 369-class MockCookieDispatch(httpcore.AsyncHTTPTransport):369+class MockCookieTransport(httpcore.AsyncHTTPTransport):370 async def request(371 self,372 method: bytes,373 url: typing.Tuple[bytes, bytes, int, bytes],42 unmodified lines416 417 418 @pytest.mark.usefixtures("async_environment")419 async def test_redirect_cookie_behavior():420- client = AsyncClient(dispatch=MockCookieDispatch())420+ client = AsyncClient(transport=MockCookieTransport())421 422 # The client is not logged in.423 response = await client.get("https://example.com/")424 assert response.url == "https://example.com/"21 unmodified lines446 447 448 @pytest.mark.usefixtures("async_environment")449 async 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 lines12 from httpx._content_streams import AsyncIteratorStream, encode13 from httpx._utils import format_form_param14 15 16-class MockDispatch(httpcore.AsyncHTTPTransport):16+class MockTransport(httpcore.AsyncHTTPTransport):17 async def request(18 self,19 method: bytes,20 url: typing.Tuple[bytes, bytes, int, bytes],13 unmodified lines34 35 @pytest.mark.parametrize(("value,output"), (("abc", b"abc"), (b"abc", b"abc")))36 @pytest.mark.asyncio37 async def test_multipart(value, output):38- client = httpx.AsyncClient(dispatch=MockDispatch())38+ client = httpx.AsyncClient(transport=MockTransport())39 40 # 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 lines58 59 @pytest.mark.parametrize(("key"), (b"abc", 1, 2.3, None))60 @pytest.mark.asyncio61 async 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 lines69 70 @pytest.mark.parametrize(("value"), (1, 2.3, None, [None, "abc"], {None: "abc"}))71 @pytest.mark.asyncio72 async 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 line79 80 81 @pytest.mark.asyncio82 async def test_multipart_file_tuple():83- client = httpx.AsyncClient(dispatch=MockDispatch())83+ client = httpx.AsyncClient(transport=MockTransport())84 85 # 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 linesmodified:tests/test_timeouts.py+1 added-1 removed
32 unmodified lines33 34 35 @pytest.mark.usefixtures("async_environment")36 async 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)39 40 async with httpx.AsyncClient(pool_limits=pool_limits, timeout=timeout) as client:41 async with client.stream("GET", server.url):2 unmodified lines