-
-
Notifications
You must be signed in to change notification settings - Fork 858
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate
app=...
in favor of explicit WSGITransport
/`ASGITranspo…
…rt`. (#3050) * Deprecate app=... in favour of explicit WSGITransport/ASGITransport * Linting * Linting * Update WSGITransport and ASGITransport docs * Deprecate app * Drop deprecation tests * Add CHANGELOG * Deprecate 'app=...' shortcut, rather than removing it. * Update CHANGELOG * Fix test_asgi.test_deprecated_shortcut
- Loading branch information
1 parent
6f46152
commit cabd1c0
Showing
6 changed files
with
145 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,7 +92,8 @@ async def test_asgi_transport_no_body(): | |
|
||
@pytest.mark.anyio | ||
async def test_asgi(): | ||
async with httpx.AsyncClient(app=hello_world) as client: | ||
transport = httpx.ASGITransport(app=hello_world) | ||
async with httpx.AsyncClient(transport=transport) as client: | ||
response = await client.get("http://www.example.org/") | ||
|
||
assert response.status_code == 200 | ||
|
@@ -101,7 +102,8 @@ async def test_asgi(): | |
|
||
@pytest.mark.anyio | ||
async def test_asgi_urlencoded_path(): | ||
async with httpx.AsyncClient(app=echo_path) as client: | ||
transport = httpx.ASGITransport(app=echo_path) | ||
async with httpx.AsyncClient(transport=transport) as client: | ||
url = httpx.URL("http://www.example.org/").copy_with(path="/[email protected]") | ||
response = await client.get(url) | ||
|
||
|
@@ -111,7 +113,8 @@ async def test_asgi_urlencoded_path(): | |
|
||
@pytest.mark.anyio | ||
async def test_asgi_raw_path(): | ||
async with httpx.AsyncClient(app=echo_raw_path) as client: | ||
transport = httpx.ASGITransport(app=echo_raw_path) | ||
async with httpx.AsyncClient(transport=transport) as client: | ||
url = httpx.URL("http://www.example.org/").copy_with(path="/[email protected]") | ||
response = await client.get(url) | ||
|
||
|
@@ -124,7 +127,8 @@ async def test_asgi_raw_path_should_not_include_querystring_portion(): | |
""" | ||
See https://github.com/encode/httpx/issues/2810 | ||
""" | ||
async with httpx.AsyncClient(app=echo_raw_path) as client: | ||
transport = httpx.ASGITransport(app=echo_raw_path) | ||
async with httpx.AsyncClient(transport=transport) as client: | ||
url = httpx.URL("http://www.example.org/path?query") | ||
response = await client.get(url) | ||
|
||
|
@@ -134,7 +138,8 @@ async def test_asgi_raw_path_should_not_include_querystring_portion(): | |
|
||
@pytest.mark.anyio | ||
async def test_asgi_upload(): | ||
async with httpx.AsyncClient(app=echo_body) as client: | ||
transport = httpx.ASGITransport(app=echo_body) | ||
async with httpx.AsyncClient(transport=transport) as client: | ||
response = await client.post("http://www.example.org/", content=b"example") | ||
|
||
assert response.status_code == 200 | ||
|
@@ -143,7 +148,8 @@ async def test_asgi_upload(): | |
|
||
@pytest.mark.anyio | ||
async def test_asgi_headers(): | ||
async with httpx.AsyncClient(app=echo_headers) as client: | ||
transport = httpx.ASGITransport(app=echo_headers) | ||
async with httpx.AsyncClient(transport=transport) as client: | ||
response = await client.get("http://www.example.org/") | ||
|
||
assert response.status_code == 200 | ||
|
@@ -160,14 +166,16 @@ async def test_asgi_headers(): | |
|
||
@pytest.mark.anyio | ||
async def test_asgi_exc(): | ||
async with httpx.AsyncClient(app=raise_exc) as client: | ||
transport = httpx.ASGITransport(app=raise_exc) | ||
async with httpx.AsyncClient(transport=transport) as client: | ||
with pytest.raises(RuntimeError): | ||
await client.get("http://www.example.org/") | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_asgi_exc_after_response(): | ||
async with httpx.AsyncClient(app=raise_exc_after_response) as client: | ||
transport = httpx.ASGITransport(app=raise_exc_after_response) | ||
async with httpx.AsyncClient(transport=transport) as client: | ||
with pytest.raises(RuntimeError): | ||
await client.get("http://www.example.org/") | ||
|
||
|
@@ -199,7 +207,8 @@ async def read_body(scope, receive, send): | |
message = await receive() | ||
disconnect = message.get("type") == "http.disconnect" | ||
|
||
async with httpx.AsyncClient(app=read_body) as client: | ||
transport = httpx.ASGITransport(app=read_body) | ||
async with httpx.AsyncClient(transport=transport) as client: | ||
response = await client.post("http://www.example.org/", content=b"example") | ||
|
||
assert response.status_code == 200 | ||
|
@@ -213,3 +222,13 @@ async def test_asgi_exc_no_raise(): | |
response = await client.get("http://www.example.org/") | ||
|
||
assert response.status_code == 500 | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_deprecated_shortcut(): | ||
""" | ||
The `app=...` shortcut is now deprecated. | ||
Use the explicit transport style instead. | ||
""" | ||
with pytest.warns(DeprecationWarning): | ||
httpx.AsyncClient(app=hello_world) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters