Skip to content
Myr

Add missing async test cases (#269)

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

authored by Florimond Manca · committed by Seth Michael Larson · parent 46402dd · Browse files · 3 files+116 added−2 removed
This commit

State

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

Diff stats

3 files+116 added−2 removed

  • tests:+116 added−2 removed

3 files+116 added−2 removed

modified:tests/dispatch/test_http2.py+68 added-1 removed
1import json23from httpx import Client, Response3import pytest45from httpx import AsyncClient, Client, Response67from .utils import MockHTTP2Backend8910def app(request):
17 unmodified lines
28 assert response.status_code == 20029 assert json.loads(response.content) == {"method": "GET", "path": "/", "body": ""}303132@pytest.mark.asyncio33async def test_async_http2_get_request():34 backend = MockHTTP2Backend(app=app)3536 async with AsyncClient(backend=backend) as client:37 response = await client.get("http://example.org")3839 assert response.status_code == 20040 assert json.loads(response.content) == {"method": "GET", "path": "/", "body": ""}414243def test_http2_post_request():44 backend = MockHTTP2Backend(app=app)4546 with Client(backend=backend) as client:
6 unmodified lines
53 "body": "<data>",54 }555657@pytest.mark.asyncio58async def test_async_http2_post_request():59 backend = MockHTTP2Backend(app=app)6061 async with AsyncClient(backend=backend) as client:62 response = await client.post("http://example.org", data=b"<data>")6364 assert response.status_code == 20065 assert json.loads(response.content) == {66 "method": "POST",67 "path": "/",68 "body": "<data>",69 }707172def test_http2_multiple_requests():73 backend = MockHTTP2Backend(app=app)7475 with Client(backend=backend) as client:
10 unmodified lines
86 assert response_3.status_code == 20087 assert json.loads(response_3.content) == {"method": "GET", "path": "/3", "body": ""}888990@pytest.mark.asyncio91async def test_async_http2_multiple_requests():92 backend = MockHTTP2Backend(app=app)9394 async with AsyncClient(backend=backend) as client:95 response_1 = await client.get("http://example.org/1")96 response_2 = await client.get("http://example.org/2")97 response_3 = await client.get("http://example.org/3")9899 assert response_1.status_code == 200100 assert json.loads(response_1.content) == {"method": "GET", "path": "/1", "body": ""}101102 assert response_2.status_code == 200103 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}104105 assert response_3.status_code == 200106 assert json.loads(response_3.content) == {"method": "GET", "path": "/3", "body": ""}107108109def test_http2_reconnect():110 """111 If a connection has been dropped between requests, then we should112 be seemlessly reconnected.
9 unmodified lines
122 assert json.loads(response_1.content) == {"method": "GET", "path": "/1", "body": ""}123124 assert response_2.status_code == 200125 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}126127128@pytest.mark.asyncio129async def test_async_http2_reconnect():130 """131 If a connection has been dropped between requests, then we should132 be seemlessly reconnected.133 """134 backend = MockHTTP2Backend(app=app)135136 async with AsyncClient(backend=backend) as client:137 response_1 = await client.get("http://example.org/1")138 backend.server.close_connection = True139 response_2 = await client.get("http://example.org/2")140141 assert response_1.status_code == 200142 assert json.loads(response_1.content) == {"method": "GET", "path": "/1", "body": ""}143144 assert response_2.status_code == 200145 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}
modified:tests/dispatch/test_threaded.py+18 added-1 removed
1import json23import pytest45from httpx import (6 AsyncClient,7 CertTypes,8 Client,9 Dispatcher,10 Request,
30 unmodified lines
414243def test_threaded_dispatch():44 """42 Use a syncronous 'Dispatcher' class with the client.45 Use a synchronous 'Dispatcher' class with the client.46 Calls to the dispatcher will end up running within a thread pool.47 """48 url = "https://example.org/"49 with Client(dispatch=MockDispatch()) as client:
2 unmodified lines
52 assert response.status_code == 20053 assert response.json() == {"hello": "world"}545556@pytest.mark.asyncio57async def test_async_threaded_dispatch():58 """59 Use a synchronous 'Dispatcher' class with the async client.60 Calls to the dispatcher will end up running within a thread pool.61 """62 url = "https://example.org/"63 async with AsyncClient(dispatch=MockDispatch()) as client:64 response = await client.get(url)6566 assert response.status_code == 20067 assert response.json() == {"hello": "world"}686970def test_threaded_streaming_response():71 url = "https://example.org/streaming_response"72 with Client(dispatch=MockDispatch()) as client:73 response = client.get(url)
42 unmodified lines
modified:tests/test_asgi.py+30 added
44 unmodified lines
45 assert response.status_code == 20046 assert response.text == "Hello, World!"474849@pytest.mark.asyncio50async def test_asgi_async():51 client = httpx.AsyncClient(app=hello_world)52 response = await client.get("http://www.example.org/")53 assert response.status_code == 20054 assert response.text == "Hello, World!"555657def test_asgi_upload():58 client = httpx.Client(app=echo_body)59 response = client.post("http://www.example.org/", data=b"example")60 assert response.status_code == 20061 assert response.text == "example"626364@pytest.mark.asyncio65async def test_asgi_upload_async():66 client = httpx.AsyncClient(app=echo_body)67 response = await client.post("http://www.example.org/", data=b"example")68 assert response.status_code == 20069 assert response.text == "example"707172def test_asgi_exc():73 client = httpx.Client(app=raise_exc)74 with pytest.raises(ValueError):75 client.get("http://www.example.org/")767778@pytest.mark.asyncio79async def test_asgi_exc_async():80 client = httpx.AsyncClient(app=raise_exc)81 with pytest.raises(ValueError):82 await client.get("http://www.example.org/")838485def test_asgi_exc_after_response():86 client = httpx.Client(app=raise_exc_after_response)87 with pytest.raises(ValueError):88 client.get("http://www.example.org/")899091@pytest.mark.asyncio92async def test_asgi_exc_after_response_async():93 client = httpx.AsyncClient(app=raise_exc_after_response)94 with pytest.raises(ValueError):95 await client.get("http://www.example.org/")