test_http2.py
This file
Path
tests/dispatch/test_http2.py
139 lines · 4.5 KiB · Python
Last changed by
Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
History of this fileTake it
The walk stopped after 200 commits: lines older than e1ecb36 point at it.
Carefulness with encoding everywhereTom Christiebefore adoptione1ecb36
lines 1–2why, one step back1import json2Add missing async test cases (#269)Florimond Mancabefore adoptiona4b93b9
lines 3–4why, one step back3from httpx import AsyncClient, Client, Response4Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
line 5why, one step back5from .utils import MockHTTP2BackendCarefulness with encoding everywhereTom Christiebefore adoptione1ecb36
lines 6–7why, one step back67Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
line 8why, one step back8def app(request):LintingTom Christiebefore adoption8f4abe0
lines 9–16why, one step back9 content = json.dumps(10 {11 "method": request.method,12 "path": request.url.path,13 "body": request.content.decode(),14 }15 ).encode()16 headers = {"Content-Length": str(len(content))}Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
line 17why, one step back17 return Response(200, headers=headers, content=content)Carefulness with encoding everywhereTom Christiebefore adoptione1ecb36
lines 18–19why, one step back1819Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 20–21why, one step back20def test_http2_get_request():21 backend = MockHTTP2Backend(app=app)Carefulness with encoding everywhereTom Christiebefore adoptione1ecb36
line 22why, one step back22Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 23–24why, one step back23 with Client(backend=backend) as client:24 response = client.get("http://example.org")Carefulness with encoding everywhereTom Christiebefore adoptione1ecb36
lines 25–29why, one step back2526 assert response.status_code == 20027 assert json.loads(response.content) == {"method": "GET", "path": "/", "body": ""}2829Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 30–31why, one step back30async def test_async_http2_get_request(backend):31 backend = MockHTTP2Backend(app=app, backend=backend)Add missing async test cases (#269)Florimond Mancabefore adoptiona4b93b9
lines 32–39why, one step back3233 async with AsyncClient(backend=backend) as client:34 response = await client.get("http://example.org")3536 assert response.status_code == 20037 assert json.loads(response.content) == {"method": "GET", "path": "/", "body": ""}3839Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 40–41why, one step back40def test_http2_post_request():41 backend = MockHTTP2Backend(app=app)Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 42why, one step back42Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 43–44why, one step back43 with Client(backend=backend) as client:44 response = client.post("http://example.org", data=b"<data>")Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 45why, one step back45Carefulness with encoding everywhereTom Christiebefore adoptione1ecb36
lines 46–53why, one step back46 assert response.status_code == 20047 assert json.loads(response.content) == {48 "method": "POST",49 "path": "/",50 "body": "<data>",51 }5253Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 54–55why, one step back54async def test_async_http2_post_request(backend):55 backend = MockHTTP2Backend(app=app, backend=backend)Add missing async test cases (#269)Florimond Mancabefore adoptiona4b93b9
lines 56–67why, one step back5657 async with AsyncClient(backend=backend) as client:58 response = await client.post("http://example.org", data=b"<data>")5960 assert response.status_code == 20061 assert json.loads(response.content) == {62 "method": "POST",63 "path": "/",64 "body": "<data>",65 }6667Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 68–69why, one step back68def test_http2_multiple_requests():69 backend = MockHTTP2Backend(app=app)Carefulness with encoding everywhereTom Christiebefore adoptione1ecb36
line 70why, one step back70Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 71–74why, one step back71 with Client(backend=backend) as client:72 response_1 = client.get("http://example.org/1")73 response_2 = client.get("http://example.org/2")74 response_3 = client.get("http://example.org/3")Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 75why, one step back75Carefulness with encoding everywhereTom Christiebefore adoptione1ecb36
lines 76–83why, one step back76 assert response_1.status_code == 20077 assert json.loads(response_1.content) == {"method": "GET", "path": "/1", "body": ""}7879 assert response_2.status_code == 20080 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}8182 assert response_3.status_code == 20083 assert json.loads(response_3.content) == {"method": "GET", "path": "/3", "body": ""}Check for connection aliveness on pool re-acquiry (#111)Tom Christiebefore adoption025240c
lines 84–85why, one step back8485Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 86–87why, one step back86async def test_async_http2_multiple_requests(backend):87 backend = MockHTTP2Backend(app=app, backend=backend)Add missing async test cases (#269)Florimond Mancabefore adoptiona4b93b9
lines 88–103why, one step back8889 async with AsyncClient(backend=backend) as client:90 response_1 = await client.get("http://example.org/1")91 response_2 = await client.get("http://example.org/2")92 response_3 = await client.get("http://example.org/3")9394 assert response_1.status_code == 20095 assert json.loads(response_1.content) == {"method": "GET", "path": "/1", "body": ""}9697 assert response_2.status_code == 20098 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}99100 assert response_3.status_code == 200101 assert json.loads(response_3.content) == {"method": "GET", "path": "/3", "body": ""}102103Check for connection aliveness on pool re-acquiry (#111)Tom Christiebefore adoption025240c
lines 104–112why, one step back104def test_http2_reconnect():105 """106 If a connection has been dropped between requests, then we should107 be seemlessly reconnected.108 """109 backend = MockHTTP2Backend(app=app)110111 with Client(backend=backend) as client:112 response_1 = client.get("http://example.org/1")Check disconnections on connection reacquiry (#145)Tom Christiebefore adoptionec365c0
line 113why, one step back113 backend.server.close_connection = TrueCheck for connection aliveness on pool re-acquiry (#111)Tom Christiebefore adoption025240c
line 114why, one step back114 response_2 = client.get("http://example.org/2")Add missing async test cases (#269)Florimond Mancabefore adoptiona4b93b9
lines 115–122why, one step back115116 assert response_1.status_code == 200117 assert json.loads(response_1.content) == {"method": "GET", "path": "/1", "body": ""}118119 assert response_2.status_code == 200120 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}121122Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 123why, one step back123async def test_async_http2_reconnect(backend):Add missing async test cases (#269)Florimond Mancabefore adoptiona4b93b9
lines 124–127why, one step back124 """125 If a connection has been dropped between requests, then we should126 be seemlessly reconnected.127 """Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 128why, one step back128 backend = MockHTTP2Backend(app=app, backend=backend)Add missing async test cases (#269)Florimond Mancabefore adoptiona4b93b9
lines 129–133why, one step back129130 async with AsyncClient(backend=backend) as client:131 response_1 = await client.get("http://example.org/1")132 backend.server.close_connection = True133 response_2 = await client.get("http://example.org/2")Check for connection aliveness on pool re-acquiry (#111)Tom Christiebefore adoption025240c
lines 134–139why, one step back134135 assert response_1.status_code == 200136 assert json.loads(response_1.content) == {"method": "GET", "path": "/1", "body": ""}137138 assert response_2.status_code == 200139 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}