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
Provenance
- Commit
28c7205- Tree
43426a2- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
534400e
9 files changed+289 added−329 removed
modified:tests/client/test_cookies.py+25 added-32 removed
1 import typing2 from http.cookiejar import Cookie, CookieJar3 4 import httpcore5-import pytest5 7-from httpx import AsyncClient, Cookies6+import httpx7 from httpx._content_streams import ByteStream, ContentStream, JSONStream8 9 10 def get_header_value(headers, key, default=None):3 unmodified lines14 return header_value.decode("ascii")15 return default16 17 19-class MockTransport(httpcore.AsyncHTTPTransport):20- async def request(18+class 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 lines39 else:40 raise NotImplementedError() # pragma: no cover41 42 44-@pytest.mark.asyncio45-async def test_set_cookie() -> None:43+def 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"}49 52- 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)52 53 assert response.status_code == 20054 assert response.json() == {"cookies": "example-name=example-value"}55 56 59-@pytest.mark.asyncio60-async def test_set_cookie_with_cookiejar() -> None:57+def test_set_cookie_with_cookiejar() -> None:58 """59 Send a request including a cookie, using a `CookieJar` instance.60 """61 19 unmodified lines81 rfc2109=False,82 )83 cookies.set_cookie(cookie)84 88- 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)87 88 assert response.status_code == 20089 assert response.json() == {"cookies": "example-name=example-value"}90 91 95-@pytest.mark.asyncio96-async def test_setting_client_cookies_to_cookiejar() -> None:92+def test_setting_client_cookies_to_cookiejar() -> None:93 """94 Send a request including a cookie, using a `CookieJar` instance.95 """96 19 unmodified lines116 rfc2109=False,117 )118 cookies.set_cookie(cookie)119 124- 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)123 124 assert response.status_code == 200125 assert response.json() == {"cookies": "example-name=example-value"}126 127 132-@pytest.mark.asyncio133-async def test_set_cookie_with_cookies_model() -> None:128+def test_set_cookie_with_cookies_model() -> None:129 """130 Send a request including a cookie, using a `Cookies` instance.131 """132 133 url = "http://example.org/echo_cookies"139- cookies = Cookies()134+ cookies = httpx.Cookies()135 cookies["example-name"] = "example-value"136 142- 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)139 140 assert response.status_code == 200141 assert response.json() == {"cookies": "example-name=example-value"}142 143 149-@pytest.mark.asyncio150-async def test_get_cookie() -> None:144+def test_get_cookie() -> None:145 url = "http://example.org/set_cookie"146 153- client = AsyncClient(transport=MockTransport())154- response = await client.get(url)147+ client = httpx.Client(transport=MockTransport())148+ response = client.get(url)149 150 assert response.status_code == 200151 assert response.cookies["example-name"] == "example-value"152 assert client.cookies["example-name"] == "example-value"153 154 161-@pytest.mark.asyncio162-async def test_cookie_persistence() -> None:155+def 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())160 168- 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}164 172- 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"169 177- 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 lines4 5 import httpcore6 import pytest7 8-from httpx import AsyncClient, Headers, Request, __version__8+import httpx9 from httpx._content_streams import ContentStream, JSONStream10 11 12-class MockTransport(httpcore.AsyncHTTPTransport):13- async def request(12+class 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 lines27 body = JSONStream({"headers": headers_dict})28 return b"HTTP/1.1", 200, b"OK", [], body29 30 31-@pytest.mark.asyncio32-async def test_client_header():31+def 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"}37 39- 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)40 41 assert response.status_code == 20042 assert response.json() == {43 "headers": {1 unmodified line45 "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 }52 53 55-@pytest.mark.asyncio56-async def test_header_merge():54+def 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)60 61 assert response.status_code == 20062 assert response.json() == {63 "headers": {6 unmodified lines70 }71 }72 73 76-@pytest.mark.asyncio77-async def test_header_merge_conflicting_headers():74+def 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)80 81 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 }92 93 97-@pytest.mark.asyncio98-async def test_header_update():94+def 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)102 103 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 }113 114 assert second_response.status_code == 2009 unmodified lines124 }125 126 127 def 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"]131 132 137-@pytest.mark.asyncio138-async def test_host_with_auth_and_port_in_url():133+def 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"140 146- client = AsyncClient(transport=MockTransport())147- response = await client.get(url)141+ client = httpx.Client(transport=MockTransport())142+ response = client.get(url)143 144 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 }155 156 162-@pytest.mark.asyncio163-async def test_host_with_non_default_port_in_url():157+def 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"163 170- client = AsyncClient(transport=MockTransport())171- response = await client.get(url)164+ client = httpx.Client(transport=MockTransport())165+ response = client.get(url)166 167 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 }178 179 180 def 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.headersmodified:tests/client/test_properties.py+16 added-16 removed
1-from httpx import URL, AsyncClient, Cookies, Headers, Timeout1+import httpx2 3 4 def 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/")9 10 11 def 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/")16 17 18 def 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/")23 24 25 def 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"30 31 32 def 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"39 40 41 def test_client_timeout():42 expected_timeout = 12.043- client = AsyncClient()43+ client = httpx.Client()44 45 client.timeout = expected_timeout # type: ignore46 47- 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_timeoutmodified:tests/client/test_proxies.py+14 added-10 removed
35 unmodified lines36 ),37 ],38 )39 def test_proxies_parameter(proxies, expected_proxies):40- client = httpx.AsyncClient(proxies=proxies)40+ client = httpx.Client(proxies=proxies)41 42 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)48 49 assert len(expected_proxies) == len(client._proxies)50 58 unmodified lines109 ),110 ],111 )112 def 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))115 116 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)121 122 123 @pytest.mark.asyncio124 async 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()129 130 131 def 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()136 137 138 def 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")141 142 143 @pytest.mark.parametrize(144 ["url", "env", "expected"],115 unmodified lines260 ],261 )262 def 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)265 266 warning_message = str(block.pop(DeprecationWarning))267 268 assert expected_scheme in warning_messagemodified:tests/client/test_queryparams.py+14 added-16 removed
1 import typing2 3 import httpcore4-import pytest4 6-from httpx import URL, AsyncClient, QueryParams5+import httpx6 from httpx._content_streams import ContentStream, JSONStream7 8 10-class MockTransport(httpcore.AsyncHTTPTransport):11- async def request(9+class 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 line21 return b"HTTP/1.1", 200, b"OK", [], body22 23 24 def 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"28 29 30 def 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"34 36- 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"39 40 42-@pytest.mark.asyncio43-async def test_client_queryparams_echo():41+def 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)47 48 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 lines4 5 import httpcore6 import pytest7 8-from httpx import (9- URL,10- AsyncClient,11- Client,12- NotRedirectResponse,13- RemoteProtocolError,14- RequestBodyUnavailable,15- TooManyRedirects,16- UnsupportedProtocol,17- codes,18-)19-from httpx._content_streams import AsyncIteratorStream, ByteStream, ContentStream8+import httpx9+from httpx._content_streams import ByteStream, ContentStream, IteratorStream10 11 12 def get_header_value(headers, key, default=None):13 lookup = key.encode("ascii").lower()19 unmodified lines33 raise httpcore.UnsupportedProtocol(f"Scheme {scheme!r} not supported.")34 35 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"")38 39 elif path == b"/redirect_301":40 51- async def body():41+ def body():42 yield b"<a href='https://example.org/'>here</a>"43 54- 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, stream48 49 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"")53 54 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"")58 59 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"")63 64 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"")68 69 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"")73 74 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"")78 79 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"")90 91 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"")95 96 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"")100 101 elif path == b"/cross_domain_target":3 unmodified lines105 stream = ByteStream(json.dumps({"headers": headers_dict}).encode())106 return b"HTTP/1.1", 200, b"OK", [], stream107 108 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"")112 113 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"")117 118 elif path == b"/redirect_body_target":11 unmodified lines130 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!")141 142 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 lines172 ]:173 return self._request(*args, **kwargs)174 175 186-@pytest.mark.usefixtures("async_environment")187-async def test_no_redirect():188- client = AsyncClient(transport=AsyncMockTransport())176+def 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()183 184 196-@pytest.mark.usefixtures("async_environment")197-async 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/")185+def 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) == 1191 192 205-@pytest.mark.usefixtures("async_environment")206-async 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/")193+def 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) == 1199 200 214-@pytest.mark.usefixtures("async_environment")215-async 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/")201+def 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) == 1207 208 223-@pytest.mark.usefixtures("async_environment")224-async 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")209+def 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) == 0216 234- 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) == 1222 223 241-@pytest.mark.asyncio242-async def test_head_redirect():224+def 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 == ""235 236 255-@pytest.mark.usefixtures("async_environment")256-async 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/")237+def 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) == 1243 244 264-@pytest.mark.usefixtures("async_environment")265-async def test_malformed_redirect():245+def 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) == 1252 253 274-@pytest.mark.usefixtures("async_environment")275-async def test_invalid_redirect():276- client = AsyncClient(transport=AsyncMockTransport())277- with pytest.raises(RemoteProtocolError):278- await client.get("http://example.org/invalid_redirect")254+def test_invalid_redirect():255+ client = httpx.Client(transport=SyncMockTransport())256+ with pytest.raises(httpx.RemoteProtocolError):257+ client.get("http://example.org/invalid_redirect")258 259 281-@pytest.mark.usefixtures("async_environment")282-async 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/")260+def 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) == 1266 267 290-@pytest.mark.usefixtures("async_environment")291-async 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")268+def 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) == 1274 275 299-@pytest.mark.usefixtures("async_environment")300-async 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")276+def 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) == 1290 291 292 @pytest.mark.usefixtures("async_environment")293 async 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")297 298 299 @pytest.mark.usefixtures("async_environment")300 async 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()307 308 309 def 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")313 314 315 def 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()322 323 348-@pytest.mark.usefixtures("async_environment")349-async def test_redirect_loop():350- client = AsyncClient(transport=AsyncMockTransport())351- with pytest.raises(TooManyRedirects):352- await client.get("https://example.org/redirect_loop")324+def test_redirect_loop():325+ client = httpx.Client(transport=SyncMockTransport())326+ with pytest.raises(httpx.TooManyRedirects):327+ client.get("https://example.org/redirect_loop")328 329 355-@pytest.mark.usefixtures("async_environment")356-async def test_cross_domain_redirect():357- client = AsyncClient(transport=AsyncMockTransport())330+def 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"]337 338 365-@pytest.mark.usefixtures("async_environment")366-async def test_same_domain_redirect():367- client = AsyncClient(transport=AsyncMockTransport())339+def 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"346 347 375-@pytest.mark.usefixtures("async_environment")376-async def test_body_redirect():348+def 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"]359 360 389-@pytest.mark.usefixtures("async_environment")390-async def test_no_body_redirect():361+def 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"]372 373 403-@pytest.mark.usefixtures("async_environment")404-async def test_can_stream_if_no_redirect():405- client = AsyncClient(transport=AsyncMockTransport())374+def 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/"381 382 413-@pytest.mark.usefixtures("async_environment")414-async def test_cannot_redirect_streaming_body():415- client = AsyncClient(transport=AsyncMockTransport())383+def test_cannot_redirect_streaming_body():384+ client = httpx.Client(transport=SyncMockTransport())385 url = "https://example.org/redirect_body"386 418- async def streaming_body():387+ def streaming_body():388 yield b"Example request body" # pragma: nocover389 421- 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())392 393 425-@pytest.mark.usefixtures("async_environment")426-async def test_cross_subdomain_redirect():427- client = AsyncClient(transport=AsyncMockTransport())394+def 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")399 400 433-class MockCookieTransport(httpcore.AsyncHTTPTransport):434- async def request(401+class 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 lines418 content = b"Not logged in"419 return b"HTTP/1.1", 200, b"OK", [], ByteStream(content)420 421 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 lines433 return b"HTTP/1.1", status_code, b"See Other", headers, ByteStream(b"")434 435 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 lines447 ]448 return b"HTTP/1.1", status_code, b"See Other", headers, ByteStream(b"")449 450 483-@pytest.mark.usefixtures("async_environment")484-async def test_redirect_cookie_behavior():485- client = AsyncClient(transport=MockCookieTransport())451+def test_redirect_cookie_behavior():452+ client = httpx.Client(transport=MockCookieTransport())453 454 # 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"458 459 # 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"463 464 # 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"468 469 # 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"473 474 # 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"478 479 513-@pytest.mark.usefixtures("async_environment")514-async 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")480+def 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
1 import pytest2 3-from httpx import QueryParams3+import httpx4 5 6 @pytest.mark.parametrize(7 "source",3 unmodified lines11 {"a": ("123", "456"), "b": 789},12 ],13 )14 def 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 lines31 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"49 46- q = QueryParams([("a", "123"), ("a", "456")])47- assert QueryParams(q) == q50+ q = httpx.QueryParams([("a", "123"), ("a", "456")])51+ assert httpx.QueryParams(q) == q52 53 54 def test_queryparam_types():51- q = QueryParams(None)55+ q = httpx.QueryParams(None)56 assert str(q) == ""57 54- q = QueryParams({"a": True})58+ q = httpx.QueryParams({"a": True})59 assert str(q) == "a=true"60 57- q = QueryParams({"a": False})61+ q = httpx.QueryParams({"a": False})62 assert str(q) == "a=false"63 60- q = QueryParams({"a": ""})64+ q = httpx.QueryParams({"a": ""})65 assert str(q) == "a="66 63- q = QueryParams({"a": None})67+ q = httpx.QueryParams({"a": None})68 assert str(q) == "a="69 66- q = QueryParams({"a": 1.23})70+ q = httpx.QueryParams({"a": 1.23})71 assert str(q) == "a=1.23"72 69- q = QueryParams({"a": 123})73+ q = httpx.QueryParams({"a": 123})74 assert str(q) == "a=123"75 72- q = QueryParams({"a": [1, 2]})76+ q = httpx.QueryParams({"a": [1, 2]})77 assert str(q) == "a=1&a=2"78 79 80 def test_queryparam_setters():77- q = QueryParams({"a": 1})81+ q = httpx.QueryParams({"a": 1})82 q.update([])83 84 assert str(q) == "a=1"85 82- q = QueryParams([("a", 1), ("a", 2)])86+ q = httpx.QueryParams([("a", 1), ("a", 2)])87 q["a"] = "3"88 assert str(q) == "a=3"89 86- 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)93 94 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 lines19 yield b"Hello, "20 yield b"world!"21 22 23-@pytest.mark.asyncio24-async def test_response():23+def test_response():24 response = httpx.Response(200, content=b"Hello, world!", request=REQUEST)25 26 assert response.status_code == 20027 assert response.reason_phrase == "OK"370 unmodified linesmodified:tests/models/test_url.py+18 added-16 removed
1 import pytest2 3-from httpx import URL, InvalidURL3+import httpx4 5 6 @pytest.mark.parametrize(7 "given,idna,host,scheme,port",44 unmodified lines52 "https_with_custom_port",53 ],54 )55 def 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 == port61 62 63 def 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 lines73 repr(url) == "URL('https://example.org:123/path/to/somewhere?abc=123#anchor')"74 )75 76 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"79 80 81 def 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) == url85 86 87 def 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"90 91- 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"95 96 97 def 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 lines115 116 https://tools.ietf.org/html/rfc3986#section-5.4117 """118 117- url = URL("http://example.com/b/c/d;p?q")119+ url = httpx.URL("http://example.com/b/c/d;p?q")120 121 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 lines165 166 167 def 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 )172 173 url_set = set(urls)174 6 unmodified lines181 "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 lines193 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@ %"202 203 204 def test_url_invalid():203- with pytest.raises(InvalidURL):204- URL("https://😇/")205+ with pytest.raises(httpx.InvalidURL):206+ httpx.URL("https://😇/")