Skip to content
Myr

Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)

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

* Prefer httpx.Client over httpx.AsyncClient in test cases, unless required. * Prefer httpx.Client in test_headers * Consistent httpx imports and httpx.Client usage * Use 'import httpx' consistently in tests. Prefer httpx.Client.

authored by Tom Christie · committed by GitHub · parent 534400e · Browse files · 9 files+289 added−329 removed
This commit

State

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

Diff stats

9 files+289 added−329 removed

  • tests:+289 added−329 removed

9 files+289 added−329 removed

modified:tests/client/test_cookies.py+25 added-32 removed
1import typing2from http.cookiejar import Cookie, CookieJar34import httpcore5import pytest57from httpx import AsyncClient, Cookies6import httpx7from httpx._content_streams import ByteStream, ContentStream, JSONStream8910def get_header_value(headers, key, default=None):
3 unmodified lines
14 return header_value.decode("ascii")15 return default161719class MockTransport(httpcore.AsyncHTTPTransport):20 async def request(18class MockTransport(httpcore.SyncHTTPTransport):19 def request(20 self,21 method: bytes,22 url: typing.Tuple[bytes, bytes, typing.Optional[int], bytes],23 headers: typing.List[typing.Tuple[bytes, bytes]] = None,25 stream: httpcore.AsyncByteStream = None,24 stream: httpcore.SyncByteStream = None,25 timeout: typing.Mapping[str, typing.Optional[float]] = None,26 ) -> typing.Tuple[27 bytes, int, bytes, typing.List[typing.Tuple[bytes, bytes]], ContentStream28 ]:
10 unmodified lines
39 else:40 raise NotImplementedError() # pragma: no cover414244@pytest.mark.asyncio45async def test_set_cookie() -> None:43def test_set_cookie() -> None:44 """45 Send a request including a cookie.46 """47 url = "http://example.org/echo_cookies"48 cookies = {"example-name": "example-value"}4952 client = AsyncClient(transport=MockTransport())53 response = await client.get(url, cookies=cookies)50 client = httpx.Client(transport=MockTransport())51 response = client.get(url, cookies=cookies)5253 assert response.status_code == 20054 assert response.json() == {"cookies": "example-name=example-value"}555659@pytest.mark.asyncio60async def test_set_cookie_with_cookiejar() -> None:57def test_set_cookie_with_cookiejar() -> None:58 """59 Send a request including a cookie, using a `CookieJar` instance.60 """61
19 unmodified lines
81 rfc2109=False,82 )83 cookies.set_cookie(cookie)8488 client = AsyncClient(transport=MockTransport())89 response = await client.get(url, cookies=cookies)85 client = httpx.Client(transport=MockTransport())86 response = client.get(url, cookies=cookies)8788 assert response.status_code == 20089 assert response.json() == {"cookies": "example-name=example-value"}909195@pytest.mark.asyncio96async def test_setting_client_cookies_to_cookiejar() -> None:92def test_setting_client_cookies_to_cookiejar() -> None:93 """94 Send a request including a cookie, using a `CookieJar` instance.95 """96
19 unmodified lines
116 rfc2109=False,117 )118 cookies.set_cookie(cookie)119124 client = AsyncClient(transport=MockTransport())120 client = httpx.Client(transport=MockTransport())121 client.cookies = cookies # type: ignore126 response = await client.get(url)122 response = client.get(url)123124 assert response.status_code == 200125 assert response.json() == {"cookies": "example-name=example-value"}126127132@pytest.mark.asyncio133async def test_set_cookie_with_cookies_model() -> None:128def test_set_cookie_with_cookies_model() -> None:129 """130 Send a request including a cookie, using a `Cookies` instance.131 """132133 url = "http://example.org/echo_cookies"139 cookies = Cookies()134 cookies = httpx.Cookies()135 cookies["example-name"] = "example-value"136142 client = AsyncClient(transport=MockTransport())143 response = await client.get(url, cookies=cookies)137 client = httpx.Client(transport=MockTransport())138 response = client.get(url, cookies=cookies)139140 assert response.status_code == 200141 assert response.json() == {"cookies": "example-name=example-value"}142143149@pytest.mark.asyncio150async def test_get_cookie() -> None:144def test_get_cookie() -> None:145 url = "http://example.org/set_cookie"146153 client = AsyncClient(transport=MockTransport())154 response = await client.get(url)147 client = httpx.Client(transport=MockTransport())148 response = client.get(url)149150 assert response.status_code == 200151 assert response.cookies["example-name"] == "example-value"152 assert client.cookies["example-name"] == "example-value"153154161@pytest.mark.asyncio162async def test_cookie_persistence() -> None:155def test_cookie_persistence() -> None:156 """157 Ensure that Client instances persist cookies between requests.158 """166 client = AsyncClient(transport=MockTransport())159 client = httpx.Client(transport=MockTransport())160168 response = await client.get("http://example.org/echo_cookies")161 response = client.get("http://example.org/echo_cookies")162 assert response.status_code == 200163 assert response.json() == {"cookies": None}164172 response = await client.get("http://example.org/set_cookie")165 response = client.get("http://example.org/set_cookie")166 assert response.status_code == 200167 assert response.cookies["example-name"] == "example-value"168 assert client.cookies["example-name"] == "example-value"169177 response = await client.get("http://example.org/echo_cookies")170 response = client.get("http://example.org/echo_cookies")171 assert response.status_code == 200172 assert response.json() == {"cookies": "example-name=example-value"}
modified:tests/client/test_headers.py+30 added-36 removed
3 unmodified lines
45import httpcore6import pytest78from httpx import AsyncClient, Headers, Request, __version__8import httpx9from httpx._content_streams import ContentStream, JSONStream101112class MockTransport(httpcore.AsyncHTTPTransport):13 async def request(12class MockTransport(httpcore.SyncHTTPTransport):13 def request(14 self,15 method: bytes,16 url: typing.Tuple[bytes, bytes, typing.Optional[int], bytes],17 headers: typing.List[typing.Tuple[bytes, bytes]] = None,18 stream: httpcore.AsyncByteStream = None,18 stream: httpcore.SyncByteStream = None,19 timeout: typing.Mapping[str, typing.Optional[float]] = None,20 ) -> typing.Tuple[21 bytes, int, bytes, typing.List[typing.Tuple[bytes, bytes]], ContentStream22 ]:
4 unmodified lines
27 body = JSONStream({"headers": headers_dict})28 return b"HTTP/1.1", 200, b"OK", [], body293031@pytest.mark.asyncio32async def test_client_header():31def test_client_header():32 """33 Set a header in the Client.34 """35 url = "http://example.org/echo_headers"36 headers = {"Example-Header": "example-value"}3739 client = AsyncClient(transport=MockTransport(), headers=headers)40 response = await client.get(url)38 client = httpx.Client(transport=MockTransport(), headers=headers)39 response = client.get(url)4041 assert response.status_code == 20042 assert response.json() == {43 "headers": {
1 unmodified line
45 "accept-encoding": "gzip, deflate, br",46 "connection": "keep-alive",47 "example-header": "example-value",48 "host": "example.org",50 "user-agent": f"python-httpx/{__version__}",49 "user-agent": f"python-httpx/{httpx.__version__}",50 }51 }525355@pytest.mark.asyncio56async def test_header_merge():54def test_header_merge():55 url = "http://example.org/echo_headers"56 client_headers = {"User-Agent": "python-myclient/0.2.1"}57 request_headers = {"X-Auth-Token": "FooBarBazToken"}60 client = AsyncClient(transport=MockTransport(), headers=client_headers)61 response = await client.get(url, headers=request_headers)58 client = httpx.Client(transport=MockTransport(), headers=client_headers)59 response = client.get(url, headers=request_headers)6061 assert response.status_code == 20062 assert response.json() == {63 "headers": {
6 unmodified lines
70 }71 }727376@pytest.mark.asyncio77async def test_header_merge_conflicting_headers():74def test_header_merge_conflicting_headers():75 url = "http://example.org/echo_headers"76 client_headers = {"X-Auth-Token": "FooBar"}77 request_headers = {"X-Auth-Token": "BazToken"}81 client = AsyncClient(transport=MockTransport(), headers=client_headers)82 response = await client.get(url, headers=request_headers)78 client = httpx.Client(transport=MockTransport(), headers=client_headers)79 response = client.get(url, headers=request_headers)8081 assert response.status_code == 20082 assert response.json() == {83 "headers": {84 "accept": "*/*",85 "accept-encoding": "gzip, deflate, br",86 "connection": "keep-alive",87 "host": "example.org",91 "user-agent": f"python-httpx/{__version__}",88 "user-agent": f"python-httpx/{httpx.__version__}",89 "x-auth-token": "BazToken",90 }91 }929397@pytest.mark.asyncio98async def test_header_update():94def test_header_update():95 url = "http://example.org/echo_headers"100 client = AsyncClient(transport=MockTransport())101 first_response = await client.get(url)96 client = httpx.Client(transport=MockTransport())97 first_response = client.get(url)98 client.headers.update(99 {"User-Agent": "python-myclient/0.2.1", "Another-Header": "AThing"}100 )105 second_response = await client.get(url)101 second_response = client.get(url)102103 assert first_response.status_code == 200104 assert first_response.json() == {105 "headers": {106 "accept": "*/*",107 "accept-encoding": "gzip, deflate, br",108 "connection": "keep-alive",109 "host": "example.org",114 "user-agent": f"python-httpx/{__version__}",110 "user-agent": f"python-httpx/{httpx.__version__}",111 }112 }113114 assert second_response.status_code == 200
9 unmodified lines
124 }125126127def test_header_does_not_exist():132 headers = Headers({"foo": "bar"})128 headers = httpx.Headers({"foo": "bar"})129 with pytest.raises(KeyError):130 del headers["baz"]131132137@pytest.mark.asyncio138async def test_host_with_auth_and_port_in_url():133def test_host_with_auth_and_port_in_url():134 """135 The Host header should only include the hostname, or hostname:port136 (for non-default ports only). Any userinfo or default port should not137 be present.138 """139 url = "http://username:password@example.org:80/echo_headers"140146 client = AsyncClient(transport=MockTransport())147 response = await client.get(url)141 client = httpx.Client(transport=MockTransport())142 response = client.get(url)143144 assert response.status_code == 200145 assert response.json() == {146 "headers": {147 "accept": "*/*",148 "accept-encoding": "gzip, deflate, br",149 "connection": "keep-alive",150 "host": "example.org",156 "user-agent": f"python-httpx/{__version__}",151 "user-agent": f"python-httpx/{httpx.__version__}",152 "authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",153 }154 }155156162@pytest.mark.asyncio163async def test_host_with_non_default_port_in_url():157def test_host_with_non_default_port_in_url():158 """159 If the URL includes a non-default port, then it should be included in160 the Host header.161 """162 url = "http://username:password@example.org:123/echo_headers"163170 client = AsyncClient(transport=MockTransport())171 response = await client.get(url)164 client = httpx.Client(transport=MockTransport())165 response = client.get(url)166167 assert response.status_code == 200168 assert response.json() == {169 "headers": {170 "accept": "*/*",171 "accept-encoding": "gzip, deflate, br",172 "connection": "keep-alive",173 "host": "example.org:123",180 "user-agent": f"python-httpx/{__version__}",174 "user-agent": f"python-httpx/{httpx.__version__}",175 "authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",176 }177 }178179180def test_request_auto_headers():187 request = Request("GET", "https://www.example.org/")181 request = httpx.Request("GET", "https://www.example.org/")182 assert "host" in request.headers
modified:tests/client/test_properties.py+16 added-16 removed
1from httpx import URL, AsyncClient, Cookies, Headers, Timeout1import httpx234def test_client_base_url():5 client = AsyncClient()5 client = httpx.Client()6 client.base_url = "https://www.example.org/" # type: ignore7 assert isinstance(client.base_url, URL)8 assert client.base_url == URL("https://www.example.org/")7 assert isinstance(client.base_url, httpx.URL)8 assert client.base_url == httpx.URL("https://www.example.org/")91011def test_client_base_url_without_trailing_slash():12 client = AsyncClient()12 client = httpx.Client()13 client.base_url = "https://www.example.org/path" # type: ignore14 assert isinstance(client.base_url, URL)15 assert client.base_url == URL("https://www.example.org/path/")14 assert isinstance(client.base_url, httpx.URL)15 assert client.base_url == httpx.URL("https://www.example.org/path/")161718def test_client_base_url_with_trailing_slash():19 client = AsyncClient()19 client = httpx.Client()20 client.base_url = "https://www.example.org/path/" # type: ignore21 assert isinstance(client.base_url, URL)22 assert client.base_url == URL("https://www.example.org/path/")21 assert isinstance(client.base_url, httpx.URL)22 assert client.base_url == httpx.URL("https://www.example.org/path/")232425def test_client_headers():26 client = AsyncClient()26 client = httpx.Client()27 client.headers = {"a": "b"} # type: ignore28 assert isinstance(client.headers, Headers)28 assert isinstance(client.headers, httpx.Headers)29 assert client.headers["A"] == "b"303132def test_client_cookies():33 client = AsyncClient()33 client = httpx.Client()34 client.cookies = {"a": "b"} # type: ignore35 assert isinstance(client.cookies, Cookies)35 assert isinstance(client.cookies, httpx.Cookies)36 mycookies = list(client.cookies.jar)37 assert len(mycookies) == 138 assert mycookies[0].name == "a" and mycookies[0].value == "b"394041def test_client_timeout():42 expected_timeout = 12.043 client = AsyncClient()43 client = httpx.Client()4445 client.timeout = expected_timeout # type: ignore4647 assert isinstance(client.timeout, Timeout)47 assert isinstance(client.timeout, httpx.Timeout)48 assert client.timeout.connect == expected_timeout49 assert client.timeout.read == expected_timeout50 assert client.timeout.write == expected_timeout51 assert client.timeout.pool == expected_timeout
modified:tests/client/test_proxies.py+14 added-10 removed
35 unmodified lines
36 ),37 ],38)39def test_proxies_parameter(proxies, expected_proxies):40 client = httpx.AsyncClient(proxies=proxies)40 client = httpx.Client(proxies=proxies)4142 for proxy_key, url in expected_proxies:43 pattern = URLPattern(proxy_key)44 assert pattern in client._proxies45 proxy = client._proxies[pattern]46 assert isinstance(proxy, httpcore.AsyncHTTPProxy)46 assert isinstance(proxy, httpcore.SyncHTTPProxy)47 assert proxy.proxy_origin == url_to_origin(url)4849 assert len(expected_proxies) == len(client._proxies)50
58 unmodified lines
109 ),110 ],111)112def test_transport_for_request(url, proxies, expected):113 client = httpx.AsyncClient(proxies=proxies)113 client = httpx.Client(proxies=proxies)114 transport = client._transport_for_url(httpx.URL(url))115116 if expected is None:117 assert transport is client._transport118 else:119 assert isinstance(transport, httpcore.AsyncHTTPProxy)119 assert isinstance(transport, httpcore.SyncHTTPProxy)120 assert transport.proxy_origin == url_to_origin(expected)121122123@pytest.mark.asyncio124async def test_async_proxy_close():125 client = httpx.AsyncClient(proxies={"all://": PROXY_URL})126 await client.aclose()125 try:126 client = httpx.AsyncClient(proxies={"all://": PROXY_URL})127 finally:128 await client.aclose()129130131def test_sync_proxy_close():130 client = httpx.Client(proxies={"all://": PROXY_URL})131 client.close()132 try:133 client = httpx.Client(proxies={"all://": PROXY_URL})134 finally:135 client.close()136137138def test_unsupported_proxy_scheme():139 with pytest.raises(ValueError):136 httpx.AsyncClient(proxies="ftp://127.0.0.1")140 httpx.Client(proxies="ftp://127.0.0.1")141142143@pytest.mark.parametrize(144 ["url", "env", "expected"],
115 unmodified lines
260 ],261)262def test_for_deprecated_proxy_params(proxies, expected_scheme):263 with pytest.deprecated_call() as block:260 httpx.AsyncClient(proxies=proxies)264 httpx.Client(proxies=proxies)265266 warning_message = str(block.pop(DeprecationWarning))267268 assert expected_scheme in warning_message
modified:tests/client/test_queryparams.py+14 added-16 removed
1import typing23import httpcore4import pytest46from httpx import URL, AsyncClient, QueryParams5import httpx6from httpx._content_streams import ContentStream, JSONStream7810class MockTransport(httpcore.AsyncHTTPTransport):11 async def request(9class MockTransport(httpcore.SyncHTTPTransport):10 def request(11 self,12 method: bytes,13 url: typing.Tuple[bytes, bytes, typing.Optional[int], bytes],14 headers: typing.List[typing.Tuple[bytes, bytes]] = None,16 stream: httpcore.AsyncByteStream = None,15 stream: httpcore.SyncByteStream = None,16 timeout: typing.Mapping[str, typing.Optional[float]] = None,17 ) -> typing.Tuple[18 bytes, int, bytes, typing.List[typing.Tuple[bytes, bytes]], ContentStream19 ]:
1 unmodified line
21 return b"HTTP/1.1", 200, b"OK", [], body222324def test_client_queryparams():26 client = AsyncClient(params={"a": "b"})27 assert isinstance(client.params, QueryParams)25 client = httpx.Client(params={"a": "b"})26 assert isinstance(client.params, httpx.QueryParams)27 assert client.params["a"] == "b"282930def test_client_queryparams_string():32 client = AsyncClient(params="a=b")33 assert isinstance(client.params, QueryParams)31 client = httpx.Client(params="a=b")32 assert isinstance(client.params, httpx.QueryParams)33 assert client.params["a"] == "b"3436 client = AsyncClient()35 client = httpx.Client()36 client.params = "a=b" # type: ignore38 assert isinstance(client.params, QueryParams)37 assert isinstance(client.params, httpx.QueryParams)38 assert client.params["a"] == "b"394042@pytest.mark.asyncio43async def test_client_queryparams_echo():41def test_client_queryparams_echo():42 url = "http://example.org/echo_queryparams"43 client_queryparams = "first=str"44 request_queryparams = {"second": "dict"}47 client = AsyncClient(transport=MockTransport(), params=client_queryparams)48 response = await client.get(url, params=request_queryparams)45 client = httpx.Client(transport=MockTransport(), params=client_queryparams)46 response = client.get(url, params=request_queryparams)4748 assert response.status_code == 20051 assert response.url == URL(49 assert response.url == httpx.URL(50 "http://example.org/echo_queryparams?first=str&second=dict"51 )
modified:tests/client/test_redirects.py+145 added-179 removed
3 unmodified lines
45import httpcore6import pytest78from httpx import (9 URL,10 AsyncClient,11 Client,12 NotRedirectResponse,13 RemoteProtocolError,14 RequestBodyUnavailable,15 TooManyRedirects,16 UnsupportedProtocol,17 codes,18)19from httpx._content_streams import AsyncIteratorStream, ByteStream, ContentStream8import httpx9from httpx._content_streams import ByteStream, ContentStream, IteratorStream101112def get_header_value(headers, key, default=None):13 lookup = key.encode("ascii").lower()
19 unmodified lines
33 raise httpcore.UnsupportedProtocol(f"Scheme {scheme!r} not supported.")3435 path, _, query = path.partition(b"?")36 if path == b"/no_redirect":47 return b"HTTP/1.1", codes.OK, b"OK", [], ByteStream(b"")37 return b"HTTP/1.1", httpx.codes.OK, b"OK", [], ByteStream(b"")3839 elif path == b"/redirect_301":4051 async def body():41 def body():42 yield b"<a href='https://example.org/'>here</a>"4354 status_code = codes.MOVED_PERMANENTLY44 status_code = httpx.codes.MOVED_PERMANENTLY45 headers = [(b"location", b"https://example.org/")]56 stream = AsyncIteratorStream(aiterator=body())46 stream = IteratorStream(iterator=body())47 return b"HTTP/1.1", status_code, b"Moved Permanently", headers, stream4849 elif path == b"/redirect_302":60 status_code = codes.FOUND50 status_code = httpx.codes.FOUND51 headers = [(b"location", b"https://example.org/")]52 return b"HTTP/1.1", status_code, b"Found", headers, ByteStream(b"")5354 elif path == b"/redirect_303":65 status_code = codes.SEE_OTHER55 status_code = httpx.codes.SEE_OTHER56 headers = [(b"location", b"https://example.org/")]57 return b"HTTP/1.1", status_code, b"See Other", headers, ByteStream(b"")5859 elif path == b"/relative_redirect":70 status_code = codes.SEE_OTHER60 status_code = httpx.codes.SEE_OTHER61 headers = [(b"location", b"/")]62 return b"HTTP/1.1", status_code, b"See Other", headers, ByteStream(b"")6364 elif path == b"/malformed_redirect":75 status_code = codes.SEE_OTHER65 status_code = httpx.codes.SEE_OTHER66 headers = [(b"location", b"https://:443/")]67 return b"HTTP/1.1", status_code, b"See Other", headers, ByteStream(b"")6869 elif path == b"/invalid_redirect":80 status_code = codes.SEE_OTHER70 status_code = httpx.codes.SEE_OTHER71 headers = [(b"location", "https://😇/".encode("utf-8"))]72 return b"HTTP/1.1", status_code, b"See Other", headers, ByteStream(b"")7374 elif path == b"/no_scheme_redirect":85 status_code = codes.SEE_OTHER75 status_code = httpx.codes.SEE_OTHER76 headers = [(b"location", b"//example.org/")]77 return b"HTTP/1.1", status_code, b"See Other", headers, ByteStream(b"")7879 elif path == b"/multiple_redirects":80 params = parse_qs(query.decode("ascii"))81 count = int(params.get("count", "0")[0])82 redirect_count = count - 193 code = codes.SEE_OTHER if count else codes.OK83 code = httpx.codes.SEE_OTHER if count else httpx.codes.OK84 phrase = b"See Other" if count else b"OK"85 location = b"/multiple_redirects"86 if redirect_count:87 location += b"?count=" + str(redirect_count).encode("ascii")88 headers = [(b"location", location)] if count else []89 return b"HTTP/1.1", code, phrase, headers, ByteStream(b"")9091 if path == b"/redirect_loop":102 code = codes.SEE_OTHER92 code = httpx.codes.SEE_OTHER93 headers = [(b"location", b"/redirect_loop")]94 return b"HTTP/1.1", code, b"See Other", headers, ByteStream(b"")9596 elif path == b"/cross_domain":107 code = codes.SEE_OTHER97 code = httpx.codes.SEE_OTHER98 headers = [(b"location", b"https://example.org/cross_domain_target")]99 return b"HTTP/1.1", code, b"See Other", headers, ByteStream(b"")100101 elif path == b"/cross_domain_target":
3 unmodified lines
105 stream = ByteStream(json.dumps({"headers": headers_dict}).encode())106 return b"HTTP/1.1", 200, b"OK", [], stream107108 elif path == b"/redirect_body":119 code = codes.PERMANENT_REDIRECT109 code = httpx.codes.PERMANENT_REDIRECT110 headers = [(b"location", b"/redirect_body_target")]111 return b"HTTP/1.1", code, b"Permanent Redirect", headers, ByteStream(b"")112113 elif path == b"/redirect_no_body":124 code = codes.SEE_OTHER114 code = httpx.codes.SEE_OTHER115 headers = [(b"location", b"/redirect_body_target")]116 return b"HTTP/1.1", code, b"See Other", headers, ByteStream(b"")117118 elif path == b"/redirect_body_target":
11 unmodified lines
130 if host != "www.example.org":131 headers = [(b"location", b"https://www.example.org/cross_subdomain")]132 return (133 b"HTTP/1.1",144 codes.PERMANENT_REDIRECT,134 httpx.codes.PERMANENT_REDIRECT,135 b"Permanent Redirect",136 headers,137 ByteStream(b""),138 )139 else:140 return b"HTTP/1.1", 200, b"OK", [], ByteStream(b"Hello, world!")141142 elif path == b"/redirect_custom_scheme":153 status_code = codes.MOVED_PERMANENTLY143 status_code = httpx.codes.MOVED_PERMANENTLY144 headers = [(b"location", b"market://details?id=42")]145 return (146 b"HTTP/1.1",147 status_code,
24 unmodified lines
172 ]:173 return self._request(*args, **kwargs)174175186@pytest.mark.usefixtures("async_environment")187async def test_no_redirect():188 client = AsyncClient(transport=AsyncMockTransport())176def test_no_redirect():177 client = httpx.Client(transport=SyncMockTransport())178 url = "https://example.com/no_redirect"190 response = await client.get(url)179 response = client.get(url)180 assert response.status_code == 200192 with pytest.raises(NotRedirectResponse):193 await response.anext()181 with pytest.raises(httpx.NotRedirectResponse):182 response.next()183184196@pytest.mark.usefixtures("async_environment")197async def test_redirect_301():198 client = AsyncClient(transport=AsyncMockTransport())199 response = await client.post("https://example.org/redirect_301")200 assert response.status_code == codes.OK201 assert response.url == URL("https://example.org/")185def test_redirect_301():186 client = httpx.Client(transport=SyncMockTransport())187 response = client.post("https://example.org/redirect_301")188 assert response.status_code == httpx.codes.OK189 assert response.url == httpx.URL("https://example.org/")190 assert len(response.history) == 1191192205@pytest.mark.usefixtures("async_environment")206async def test_redirect_302():207 client = AsyncClient(transport=AsyncMockTransport())208 response = await client.post("https://example.org/redirect_302")209 assert response.status_code == codes.OK210 assert response.url == URL("https://example.org/")193def test_redirect_302():194 client = httpx.Client(transport=SyncMockTransport())195 response = client.post("https://example.org/redirect_302")196 assert response.status_code == httpx.codes.OK197 assert response.url == httpx.URL("https://example.org/")198 assert len(response.history) == 1199200214@pytest.mark.usefixtures("async_environment")215async def test_redirect_303():216 client = AsyncClient(transport=AsyncMockTransport())217 response = await client.get("https://example.org/redirect_303")218 assert response.status_code == codes.OK219 assert response.url == URL("https://example.org/")201def test_redirect_303():202 client = httpx.Client(transport=SyncMockTransport())203 response = client.get("https://example.org/redirect_303")204 assert response.status_code == httpx.codes.OK205 assert response.url == httpx.URL("https://example.org/")206 assert len(response.history) == 1207208223@pytest.mark.usefixtures("async_environment")224async def test_disallow_redirects():225 client = AsyncClient(transport=AsyncMockTransport())226 response = await client.post(227 "https://example.org/redirect_303", allow_redirects=False228 )229 assert response.status_code == codes.SEE_OTHER230 assert response.url == URL("https://example.org/redirect_303")209def test_disallow_redirects():210 client = httpx.Client(transport=SyncMockTransport())211 response = client.post("https://example.org/redirect_303", allow_redirects=False)212 assert response.status_code == httpx.codes.SEE_OTHER213 assert response.url == httpx.URL("https://example.org/redirect_303")214 assert response.is_redirect is True215 assert len(response.history) == 0216234 response = await response.anext()235 assert response.status_code == codes.OK236 assert response.url == URL("https://example.org/")217 response = response.next()218 assert response.status_code == httpx.codes.OK219 assert response.url == httpx.URL("https://example.org/")220 assert response.is_redirect is False221 assert len(response.history) == 1222223241@pytest.mark.asyncio242async def test_head_redirect():224def test_head_redirect():225 """226 Contrary to Requests, redirects remain enabled by default for HEAD requests.227 """246 client = AsyncClient(transport=AsyncMockTransport())247 response = await client.head("https://example.org/redirect_302")248 assert response.status_code == codes.OK249 assert response.url == URL("https://example.org/")228 client = httpx.Client(transport=SyncMockTransport())229 response = client.head("https://example.org/redirect_302")230 assert response.status_code == httpx.codes.OK231 assert response.url == httpx.URL("https://example.org/")232 assert response.request.method == "HEAD"233 assert len(response.history) == 1234 assert response.text == ""235236255@pytest.mark.usefixtures("async_environment")256async def test_relative_redirect():257 client = AsyncClient(transport=AsyncMockTransport())258 response = await client.get("https://example.org/relative_redirect")259 assert response.status_code == codes.OK260 assert response.url == URL("https://example.org/")237def test_relative_redirect():238 client = httpx.Client(transport=SyncMockTransport())239 response = client.get("https://example.org/relative_redirect")240 assert response.status_code == httpx.codes.OK241 assert response.url == httpx.URL("https://example.org/")242 assert len(response.history) == 1243244264@pytest.mark.usefixtures("async_environment")265async def test_malformed_redirect():245def test_malformed_redirect():246 # https://github.com/encode/httpx/issues/771267 client = AsyncClient(transport=AsyncMockTransport())268 response = await client.get("http://example.org/malformed_redirect")269 assert response.status_code == codes.OK270 assert response.url == URL("https://example.org:443/")247 client = httpx.Client(transport=SyncMockTransport())248 response = client.get("http://example.org/malformed_redirect")249 assert response.status_code == httpx.codes.OK250 assert response.url == httpx.URL("https://example.org:443/")251 assert len(response.history) == 1252253274@pytest.mark.usefixtures("async_environment")275async def test_invalid_redirect():276 client = AsyncClient(transport=AsyncMockTransport())277 with pytest.raises(RemoteProtocolError):278 await client.get("http://example.org/invalid_redirect")254def test_invalid_redirect():255 client = httpx.Client(transport=SyncMockTransport())256 with pytest.raises(httpx.RemoteProtocolError):257 client.get("http://example.org/invalid_redirect")258259281@pytest.mark.usefixtures("async_environment")282async def test_no_scheme_redirect():283 client = AsyncClient(transport=AsyncMockTransport())284 response = await client.get("https://example.org/no_scheme_redirect")285 assert response.status_code == codes.OK286 assert response.url == URL("https://example.org/")260def test_no_scheme_redirect():261 client = httpx.Client(transport=SyncMockTransport())262 response = client.get("https://example.org/no_scheme_redirect")263 assert response.status_code == httpx.codes.OK264 assert response.url == httpx.URL("https://example.org/")265 assert len(response.history) == 1266267290@pytest.mark.usefixtures("async_environment")291async def test_fragment_redirect():292 client = AsyncClient(transport=AsyncMockTransport())293 response = await client.get("https://example.org/relative_redirect#fragment")294 assert response.status_code == codes.OK295 assert response.url == URL("https://example.org/#fragment")268def test_fragment_redirect():269 client = httpx.Client(transport=SyncMockTransport())270 response = client.get("https://example.org/relative_redirect#fragment")271 assert response.status_code == httpx.codes.OK272 assert response.url == httpx.URL("https://example.org/#fragment")273 assert len(response.history) == 1274275299@pytest.mark.usefixtures("async_environment")300async def test_multiple_redirects():301 client = AsyncClient(transport=AsyncMockTransport())302 response = await client.get("https://example.org/multiple_redirects?count=20")303 assert response.status_code == codes.OK304 assert response.url == URL("https://example.org/multiple_redirects")276def test_multiple_redirects():277 client = httpx.Client(transport=SyncMockTransport())278 response = client.get("https://example.org/multiple_redirects?count=20")279 assert response.status_code == httpx.codes.OK280 assert response.url == httpx.URL("https://example.org/multiple_redirects")281 assert len(response.history) == 20306 assert response.history[0].url == URL(282 assert response.history[0].url == httpx.URL(283 "https://example.org/multiple_redirects?count=20"284 )309 assert response.history[1].url == URL(285 assert response.history[1].url == httpx.URL(286 "https://example.org/multiple_redirects?count=19"287 )288 assert len(response.history[0].history) == 0289 assert len(response.history[1].history) == 1290291292@pytest.mark.usefixtures("async_environment")293async def test_async_too_many_redirects():318 client = AsyncClient(transport=AsyncMockTransport())319 with pytest.raises(TooManyRedirects):320 await client.get("https://example.org/multiple_redirects?count=21")294 async with httpx.AsyncClient(transport=AsyncMockTransport()) as client:295 with pytest.raises(httpx.TooManyRedirects):296 await client.get("https://example.org/multiple_redirects?count=21")297298299@pytest.mark.usefixtures("async_environment")300async def test_async_too_many_redirects_calling_next():325 client = AsyncClient(transport=AsyncMockTransport())326 url = "https://example.org/multiple_redirects?count=21"327 response = await client.get(url, allow_redirects=False)328 with pytest.raises(TooManyRedirects):329 while response.is_redirect:330 response = await response.anext()301 async with httpx.AsyncClient(transport=AsyncMockTransport()) as client:302 url = "https://example.org/multiple_redirects?count=21"303 response = await client.get(url, allow_redirects=False)304 with pytest.raises(httpx.TooManyRedirects):305 while response.is_redirect:306 response = await response.anext()307308309def test_sync_too_many_redirects():334 client = Client(transport=SyncMockTransport())335 with pytest.raises(TooManyRedirects):310 client = httpx.Client(transport=SyncMockTransport())311 with pytest.raises(httpx.TooManyRedirects):312 client.get("https://example.org/multiple_redirects?count=21")313314315def test_sync_too_many_redirects_calling_next():340 client = Client(transport=SyncMockTransport())316 client = httpx.Client(transport=SyncMockTransport())317 url = "https://example.org/multiple_redirects?count=21"318 response = client.get(url, allow_redirects=False)343 with pytest.raises(TooManyRedirects):319 with pytest.raises(httpx.TooManyRedirects):320 while response.is_redirect:321 response = response.next()322323348@pytest.mark.usefixtures("async_environment")349async def test_redirect_loop():350 client = AsyncClient(transport=AsyncMockTransport())351 with pytest.raises(TooManyRedirects):352 await client.get("https://example.org/redirect_loop")324def test_redirect_loop():325 client = httpx.Client(transport=SyncMockTransport())326 with pytest.raises(httpx.TooManyRedirects):327 client.get("https://example.org/redirect_loop")328329355@pytest.mark.usefixtures("async_environment")356async def test_cross_domain_redirect():357 client = AsyncClient(transport=AsyncMockTransport())330def test_cross_domain_redirect():331 client = httpx.Client(transport=SyncMockTransport())332 url = "https://example.com/cross_domain"333 headers = {"Authorization": "abc"}360 response = await client.get(url, headers=headers)361 assert response.url == URL("https://example.org/cross_domain_target")334 response = client.get(url, headers=headers)335 assert response.url == httpx.URL("https://example.org/cross_domain_target")336 assert "authorization" not in response.json()["headers"]337338365@pytest.mark.usefixtures("async_environment")366async def test_same_domain_redirect():367 client = AsyncClient(transport=AsyncMockTransport())339def test_same_domain_redirect():340 client = httpx.Client(transport=SyncMockTransport())341 url = "https://example.org/cross_domain"342 headers = {"Authorization": "abc"}370 response = await client.get(url, headers=headers)371 assert response.url == URL("https://example.org/cross_domain_target")343 response = client.get(url, headers=headers)344 assert response.url == httpx.URL("https://example.org/cross_domain_target")345 assert response.json()["headers"]["authorization"] == "abc"346347375@pytest.mark.usefixtures("async_environment")376async def test_body_redirect():348def test_body_redirect():349 """350 A 308 redirect should preserve the request body.351 """380 client = AsyncClient(transport=AsyncMockTransport())352 client = httpx.Client(transport=SyncMockTransport())353 url = "https://example.org/redirect_body"354 data = b"Example request body"383 response = await client.post(url, data=data)384 assert response.url == URL("https://example.org/redirect_body_target")355 response = client.post(url, data=data)356 assert response.url == httpx.URL("https://example.org/redirect_body_target")357 assert response.json()["body"] == "Example request body"358 assert "content-length" in response.json()["headers"]359360389@pytest.mark.usefixtures("async_environment")390async def test_no_body_redirect():361def test_no_body_redirect():362 """363 A 303 redirect should remove the request body.364 """394 client = AsyncClient(transport=AsyncMockTransport())365 client = httpx.Client(transport=SyncMockTransport())366 url = "https://example.org/redirect_no_body"367 data = b"Example request body"397 response = await client.post(url, data=data)398 assert response.url == URL("https://example.org/redirect_body_target")368 response = client.post(url, data=data)369 assert response.url == httpx.URL("https://example.org/redirect_body_target")370 assert response.json()["body"] == ""371 assert "content-length" not in response.json()["headers"]372373403@pytest.mark.usefixtures("async_environment")404async def test_can_stream_if_no_redirect():405 client = AsyncClient(transport=AsyncMockTransport())374def test_can_stream_if_no_redirect():375 client = httpx.Client(transport=SyncMockTransport())376 url = "https://example.org/redirect_301"407 async with client.stream("GET", url, allow_redirects=False) as response:377 with client.stream("GET", url, allow_redirects=False) as response:378 assert not response.is_closed409 assert response.status_code == codes.MOVED_PERMANENTLY379 assert response.status_code == httpx.codes.MOVED_PERMANENTLY380 assert response.headers["location"] == "https://example.org/"381382413@pytest.mark.usefixtures("async_environment")414async def test_cannot_redirect_streaming_body():415 client = AsyncClient(transport=AsyncMockTransport())383def test_cannot_redirect_streaming_body():384 client = httpx.Client(transport=SyncMockTransport())385 url = "https://example.org/redirect_body"386418 async def streaming_body():387 def streaming_body():388 yield b"Example request body" # pragma: nocover389421 with pytest.raises(RequestBodyUnavailable):422 await client.post(url, data=streaming_body())390 with pytest.raises(httpx.RequestBodyUnavailable):391 client.post(url, data=streaming_body())392393425@pytest.mark.usefixtures("async_environment")426async def test_cross_subdomain_redirect():427 client = AsyncClient(transport=AsyncMockTransport())394def test_cross_subdomain_redirect():395 client = httpx.Client(transport=SyncMockTransport())396 url = "https://example.com/cross_subdomain"429 response = await client.get(url)430 assert response.url == URL("https://www.example.org/cross_subdomain")397 response = client.get(url)398 assert response.url == httpx.URL("https://www.example.org/cross_subdomain")399400433class MockCookieTransport(httpcore.AsyncHTTPTransport):434 async def request(401class MockCookieTransport(httpcore.SyncHTTPTransport):402 def request(403 self,404 method: bytes,405 url: typing.Tuple[bytes, bytes, typing.Optional[int], bytes],406 headers: typing.List[typing.Tuple[bytes, bytes]] = None,439 stream: httpcore.AsyncByteStream = None,407 stream: httpcore.SyncByteStream = None,408 timeout: typing.Mapping[str, typing.Optional[float]] = None,409 ) -> typing.Tuple[410 bytes, int, bytes, typing.List[typing.Tuple[bytes, bytes]], ContentStream411 ]:
6 unmodified lines
418 content = b"Not logged in"419 return b"HTTP/1.1", 200, b"OK", [], ByteStream(content)420421 elif path == b"/login":454 status_code = codes.SEE_OTHER422 status_code = httpx.codes.SEE_OTHER423 headers = [424 (b"location", b"/"),425 (426 b"set-cookie",
6 unmodified lines
433 return b"HTTP/1.1", status_code, b"See Other", headers, ByteStream(b"")434435 else:436 assert path == b"/logout"469 status_code = codes.SEE_OTHER437 status_code = httpx.codes.SEE_OTHER438 headers = [439 (b"location", b"/"),440 (441 b"set-cookie",
5 unmodified lines
447 ]448 return b"HTTP/1.1", status_code, b"See Other", headers, ByteStream(b"")449450483@pytest.mark.usefixtures("async_environment")484async def test_redirect_cookie_behavior():485 client = AsyncClient(transport=MockCookieTransport())451def test_redirect_cookie_behavior():452 client = httpx.Client(transport=MockCookieTransport())453454 # The client is not logged in.488 response = await client.get("https://example.com/")455 response = client.get("https://example.com/")456 assert response.url == "https://example.com/"457 assert response.text == "Not logged in"458459 # Login redirects to the homepage, setting a session cookie.493 response = await client.post("https://example.com/login")460 response = client.post("https://example.com/login")461 assert response.url == "https://example.com/"462 assert response.text == "Logged in"463464 # The client is logged in.498 response = await client.get("https://example.com/")465 response = client.get("https://example.com/")466 assert response.url == "https://example.com/"467 assert response.text == "Logged in"468469 # Logout redirects to the homepage, expiring the session cookie.503 response = await client.post("https://example.com/logout")470 response = client.post("https://example.com/logout")471 assert response.url == "https://example.com/"472 assert response.text == "Not logged in"473474 # The client is not logged in.508 response = await client.get("https://example.com/")475 response = client.get("https://example.com/")476 assert response.url == "https://example.com/"477 assert response.text == "Not logged in"478479513@pytest.mark.usefixtures("async_environment")514async def test_redirect_custom_scheme():515 client = AsyncClient(transport=AsyncMockTransport())516 with pytest.raises(UnsupportedProtocol) as e:517 await client.post("https://example.org/redirect_custom_scheme")480def test_redirect_custom_scheme():481 client = httpx.Client(transport=SyncMockTransport())482 with pytest.raises(httpx.UnsupportedProtocol) as e:483 client.post("https://example.org/redirect_custom_scheme")484 assert str(e.value) == "Scheme b'market' not supported."
modified:tests/models/test_queryparams.py+26 added-22 removed
1import pytest23from httpx import QueryParams3import httpx456@pytest.mark.parametrize(7 "source",
3 unmodified lines
11 {"a": ("123", "456"), "b": 789},12 ],13)14def test_queryparams(source):15 q = QueryParams(source)15 q = httpx.QueryParams(source)16 assert "a" in q17 assert "A" not in q18 assert "c" not in q19 assert q["a"] == "456"
11 unmodified lines
31 assert list(q) == ["a", "b"]32 assert dict(q) == {"a": "456", "b": "789"}33 assert str(q) == "a=123&a=456&b=789"34 assert repr(q) == "QueryParams('a=123&a=456&b=789')"35 assert QueryParams({"a": "123", "b": "456"}) == QueryParams(35 assert httpx.QueryParams({"a": "123", "b": "456"}) == httpx.QueryParams(36 [("a", "123"), ("b", "456")]37 )38 assert QueryParams({"a": "123", "b": "456"}) == QueryParams("a=123&b=456")39 assert QueryParams({"a": "123", "b": "456"}) == QueryParams(38 assert httpx.QueryParams({"a": "123", "b": "456"}) == httpx.QueryParams(39 "a=123&b=456"40 )41 assert httpx.QueryParams({"a": "123", "b": "456"}) == httpx.QueryParams(42 {"b": "456", "a": "123"}43 )42 assert QueryParams() == QueryParams({})43 assert QueryParams([("a", "123"), ("a", "456")]) == QueryParams("a=123&a=456")44 assert QueryParams({"a": "123", "b": "456"}) != "invalid"44 assert httpx.QueryParams() == httpx.QueryParams({})45 assert httpx.QueryParams([("a", "123"), ("a", "456")]) == httpx.QueryParams(46 "a=123&a=456"47 )48 assert httpx.QueryParams({"a": "123", "b": "456"}) != "invalid"4946 q = QueryParams([("a", "123"), ("a", "456")])47 assert QueryParams(q) == q50 q = httpx.QueryParams([("a", "123"), ("a", "456")])51 assert httpx.QueryParams(q) == q525354def test_queryparam_types():51 q = QueryParams(None)55 q = httpx.QueryParams(None)56 assert str(q) == ""5754 q = QueryParams({"a": True})58 q = httpx.QueryParams({"a": True})59 assert str(q) == "a=true"6057 q = QueryParams({"a": False})61 q = httpx.QueryParams({"a": False})62 assert str(q) == "a=false"6360 q = QueryParams({"a": ""})64 q = httpx.QueryParams({"a": ""})65 assert str(q) == "a="6663 q = QueryParams({"a": None})67 q = httpx.QueryParams({"a": None})68 assert str(q) == "a="6966 q = QueryParams({"a": 1.23})70 q = httpx.QueryParams({"a": 1.23})71 assert str(q) == "a=1.23"7269 q = QueryParams({"a": 123})73 q = httpx.QueryParams({"a": 123})74 assert str(q) == "a=123"7572 q = QueryParams({"a": [1, 2]})76 q = httpx.QueryParams({"a": [1, 2]})77 assert str(q) == "a=1&a=2"787980def test_queryparam_setters():77 q = QueryParams({"a": 1})81 q = httpx.QueryParams({"a": 1})82 q.update([])8384 assert str(q) == "a=1"8582 q = QueryParams([("a", 1), ("a", 2)])86 q = httpx.QueryParams([("a", 1), ("a", 2)])87 q["a"] = "3"88 assert str(q) == "a=3"8986 q = QueryParams([("a", 1), ("b", 1)])87 u = QueryParams([("b", 2), ("b", 3)])90 q = httpx.QueryParams([("a", 1), ("b", 1)])91 u = httpx.QueryParams([("b", 2), ("b", 3)])92 q.update(u)9394 assert str(q) == "a=1&b=2&b=3"95 assert q["b"] == u["b"]
modified:tests/models/test_responses.py+1 added-2 removed
18 unmodified lines
19 yield b"Hello, "20 yield b"world!"212223@pytest.mark.asyncio24async def test_response():23def test_response():24 response = httpx.Response(200, content=b"Hello, world!", request=REQUEST)2526 assert response.status_code == 20027 assert response.reason_phrase == "OK"
370 unmodified lines
modified:tests/models/test_url.py+18 added-16 removed
1import pytest23from httpx import URL, InvalidURL3import httpx456@pytest.mark.parametrize(7 "given,idna,host,scheme,port",
44 unmodified lines
52 "https_with_custom_port",53 ],54)55def test_idna_url(given, idna, host, scheme, port):56 url = URL(given)57 assert url == URL(idna)56 url = httpx.URL(given)57 assert url == httpx.URL(idna)58 assert url.host == host59 assert url.scheme == scheme60 assert url.port == port616263def test_url():64 url = URL("https://example.org:123/path/to/somewhere?abc=123#anchor")64 url = httpx.URL("https://example.org:123/path/to/somewhere?abc=123#anchor")65 assert url.scheme == "https"66 assert url.host == "example.org"67 assert url.port == 12368 assert url.authority == "example.org:123"
4 unmodified lines
73 repr(url) == "URL('https://example.org:123/path/to/somewhere?abc=123#anchor')"74 )7576 new = url.copy_with(scheme="http", port=None)77 assert new == URL("http://example.org/path/to/somewhere?abc=123#anchor")77 assert new == httpx.URL("http://example.org/path/to/somewhere?abc=123#anchor")78 assert new.scheme == "http"798081def test_url_eq_str():82 url = URL("https://example.org:123/path/to/somewhere?abc=123#anchor")82 url = httpx.URL("https://example.org:123/path/to/somewhere?abc=123#anchor")83 assert url == "https://example.org:123/path/to/somewhere?abc=123#anchor"84 assert str(url) == url858687def test_url_params():88 url = URL("https://example.org:123/path/to/somewhere", params={"a": "123"})88 url = httpx.URL("https://example.org:123/path/to/somewhere", params={"a": "123"})89 assert str(url) == "https://example.org:123/path/to/somewhere?a=123"9091 url = URL("https://example.org:123/path/to/somewhere?b=456", params={"a": "123"})91 url = httpx.URL(92 "https://example.org:123/path/to/somewhere?b=456", params={"a": "123"}93 )94 assert str(url) == "https://example.org:123/path/to/somewhere?b=456&a=123"959697def test_url_join():98 """99 Some basic URL joining tests.100 """99 url = URL("https://example.org:123/path/to/somewhere")101 url = httpx.URL("https://example.org:123/path/to/somewhere")102 assert url.join("/somewhere-else") == "https://example.org:123/somewhere-else"103 assert (104 url.join("somewhere-else") == "https://example.org:123/path/to/somewhere-else"105 )
9 unmodified lines
115116 https://tools.ietf.org/html/rfc3986#section-5.4117 """118117 url = URL("http://example.com/b/c/d;p?q")119 url = httpx.URL("http://example.com/b/c/d;p?q")120121 assert url.join("g") == "http://example.com/b/c/g"122 assert url.join("./g") == "http://example.com/b/c/g"123 assert url.join("g/") == "http://example.com/b/c/g/"
41 unmodified lines
165166167def test_url_set():168 urls = (167 URL("http://example.org:123/path/to/somewhere"),168 URL("http://example.org:123/path/to/somewhere/else"),169 httpx.URL("http://example.org:123/path/to/somewhere"),170 httpx.URL("http://example.org:123/path/to/somewhere/else"),171 )172173 url_set = set(urls)174
6 unmodified lines
181 "password": "password",182 "port": 444,183 "host": "example.net",184 }183 url = URL("https://example.org")185 url = httpx.URL("https://example.org")186 new = url.copy_with(**copy_with_kwargs)187 for k, v in copy_with_kwargs.items():188 assert getattr(new, k) == v189 assert str(new) == "https://username:password@example.net:444"
3 unmodified lines
193 copy_with_kwargs = {194 "username": "tom@example.org",195 "password": "abc123@ %",196 }195 url = URL("https://example.org")197 url = httpx.URL("https://example.org")198 new = url.copy_with(**copy_with_kwargs)199 assert str(new) == "https://tom%40example.org:abc123%40%20%25@example.org"200 assert new.username == "tom@example.org"201 assert new.password == "abc123@ %"202203204def test_url_invalid():203 with pytest.raises(InvalidURL):204 URL("https://😇/")205 with pytest.raises(httpx.InvalidURL):206 httpx.URL("https://😇/")