Increased test coverage & cleanup (#1003)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Remove unused/untested headers copy() method Last usage was removed in #804 * Remove unused premature_close server endpoint Last usage was removed in #804 * Increased test coverage * Revert removal of headers copy() method Documented and added tests for it.
authored by Josep Cugat · committed by GitHub · parent 89a8100 · Browse files · 7 files·+81 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
Diff stats
7 files+81 added−17 removed
- tests:+79 added−16 removed
- other:+2 added−1 removed
Provenance
- Commit
8c84210- Tree
ed5c5fc- Author
Josep Cugat <jcugat@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
89a8100
7 files changed+81 added−17 removed
modified:docs/api.md+2 added-1 removed
149 unmodified linesExpand all15015115215315415415515615715815915 unmodified lines149 unmodified linesExpand all>>> headers['content-type']'application/json'```
* `def __init__(self, headers)`* `def __init__(self, headers, encoding=None)`* `def copy()` - **Headers**
## `Cookies`
*A dict-like cookie store.*15 unmodified linesmodified:tests/client/test_async_client.py+34 added
1 from datetime import timedelta2 3+import httpcore4 import pytest5 6 import httpx7+from httpx import ASGIDispatch8 9 10 @pytest.mark.usefixtures("async_environment")11 async def test_get(server):8 unmodified lines20 assert response.elapsed > timedelta(seconds=0)21 22 23 @pytest.mark.usefixtures("async_environment")24+async def test_get_invalid_url(server):25+ async with httpx.AsyncClient() as client:26+ with pytest.raises(httpx.InvalidURL):27+ await client.get("invalid://example.org")28+29+30+@pytest.mark.usefixtures("async_environment")31 async def test_build_request(server):32 url = server.url.copy_with(path="/echo_headers")33 headers = {"Custom-header": "value"}34 async with httpx.AsyncClient() as client:121 unmodified lines156 )157 158 assert response.status_code == 200159 assert response.content == data160+161+162+def test_dispatch_deprecated():163+ dispatch = httpcore.AsyncHTTPTransport()164+165+ with pytest.warns(DeprecationWarning) as record:166+ client = httpx.AsyncClient(dispatch=dispatch)167+168+ assert client.transport is dispatch169+ assert len(record) == 1170+ assert record[0].message.args[0] == (171+ "The dispatch argument is deprecated since v0.13 and will be "172+ "removed in a future release, please use 'transport'"173+ )174+175+176+def test_asgi_dispatch_deprecated():177+ with pytest.warns(DeprecationWarning) as record:178+ ASGIDispatch(None)179+180+ assert len(record) == 1181+ assert (182+ record[0].message.args[0]183+ == "ASGIDispatch is deprecated, please use ASGITransport"184+ )modified:tests/client/test_client.py+29 added-1 removed
1 from datetime import timedelta2 3+import httpcore4 import pytest5 6 import httpx7+from httpx import WSGIDispatch8 9 10 def test_get(server):11 url = server.url92 unmodified lines104 def test_raise_for_status(server):105 with httpx.Client() as client:106 for status_code in (200, 400, 404, 500, 505):107 response = client.request(106- "GET", server.url.copy_with(path="/status/{}".format(status_code))108+ "GET", server.url.copy_with(path=f"/status/{status_code}")109 )110 if 400 <= status_code < 600:111 with pytest.raises(httpx.HTTPError) as exc_info:112 response.raise_for_status()113 assert exc_info.value.response == response114+ assert exc_info.value.request.url.path == f"/status/{status_code}"115 else:116 assert response.raise_for_status() is None # type: ignore117 118 45 unmodified lines164 url = client.merge_url("http://www.paypal.com")165 166 assert url.scheme == "https"167 assert url.is_ssl168+169+170+def test_dispatch_deprecated():171+ dispatch = httpcore.SyncHTTPTransport()172+173+ with pytest.warns(DeprecationWarning) as record:174+ client = httpx.Client(dispatch=dispatch)175+176+ assert client.transport is dispatch177+ assert len(record) == 1178+ assert record[0].message.args[0] == (179+ "The dispatch argument is deprecated since v0.13 and will be "180+ "removed in a future release, please use 'transport'"181+ )182+183+184+def test_wsgi_dispatch_deprecated():185+ with pytest.warns(DeprecationWarning) as record:186+ WSGIDispatch(None)187+188+ assert len(record) == 1189+ assert (190+ record[0].message.args[0]191+ == "WSGIDispatch is deprecated, please use WSGITransport"192+ )modified:tests/client/test_proxies.py+3 added-2 removed
103 unmodified lines104 None,105 ),106 ],107 )108+@pytest.mark.parametrize("client_class", [httpx.Client, httpx.AsyncClient])108-def test_proxies_environ(monkeypatch, url, env, expected):109+def test_proxies_environ(monkeypatch, client_class, url, env, expected):110 for name, value in env.items():111 monkeypatch.setenv(name, value)112 112- client = httpx.AsyncClient()113+ client = client_class()114 transport = client.transport_for_url(httpx.URL(url))115 116 if expected is None:117 assert transport == client.transport2 unmodified linesmodified:tests/models/test_headers.py+8 added-1 removed
44 unmodified lines45 assert dict(h) == {"b": "4"}46 assert h.raw == [(b"b", b"4")]47 48 49-def test_copy_headers():49+def test_copy_headers_method():50 headers = httpx.Headers({"custom": "example"})51+ headers_copy = headers.copy()52+ assert headers == headers_copy53+ assert headers is not headers_copy54+55+56+def test_copy_headers_init():57+ headers = httpx.Headers({"custom": "example"})58 headers_copy = httpx.Headers(headers)59 assert headers == headers_copy60 61 111 unmodified linesmodified:tests/models/test_url.py+5 added
190 unmodified lines191 assert origin.host == "example.com"192 assert origin.port == 443193 194 195+def test_origin_repr():196+ origin = Origin("https://example.com:8080")197+ assert str(origin) == "Origin(scheme='https' host='example.com' port=8080)"198+199+200 def test_url_copywith_for_authority():201 copy_with_kwargs = {202 "username": "username",203 "password": "password",8 unmodified linesmodified:tests/conftest.py-12 removed
74 unmodified lines75 async def app(scope, receive, send):76 assert scope["type"] == "http"77 if scope["path"].startswith("/slow_response"):78 await slow_response(scope, receive, send)79- elif scope["path"].startswith("/premature_close"):80- await premature_close(scope, receive, send)79 elif scope["path"].startswith("/status"):80 await status_code(scope, receive, send)81 elif scope["path"].startswith("/echo_body"):82 await echo_body(scope, receive, send)27 unmodified lines110 )111 await send({"type": "http.response.body", "body": b"Hello, world!"})112 113 116-async def premature_close(scope, receive, send):117- await send(118- {119- "type": "http.response.start",120- "status": 200,121- "headers": [[b"content-type", b"text/plain"]],122- }123- )124-125-114 async def status_code(scope, receive, send):115 status_code = int(scope["path"].replace("/status/", ""))116 await send(117 {176 unmodified lines