test_http2.py
This file
Path
tests/dispatch/test_http2.py
167 lines · 5.3 KiB · Python
Last changed by
Fix bug in calculating maximum frame size (#153)IsaacBenghiatbefore adoptionab9cd0e
History of this fileTake it
The walk stopped after 200 commits: lines older than 3553625 point at it.
Merge pull request #43 from encode/badgesTom Christiebefore adoption3553625
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 MockHTTP2BackendMerge pull request #43 from encode/badgesTom Christiebefore adoption3553625
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)Merge pull request #43 from encode/badgesTom Christiebefore adoption3553625
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)Merge pull request #43 from encode/badgesTom Christiebefore adoption3553625
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")Merge pull request #43 from encode/badgesTom Christiebefore adoption3553625
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 back45Merge pull request #43 from encode/badgesTom Christiebefore adoption3553625
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 }6667Fix bug in calculating maximum frame size (#153)IsaacBenghiatbefore adoptionab9cd0e
lines 68–95why, one step back68def test_http2_large_post_request():69 backend = MockHTTP2Backend(app=app)7071 data = b"a" * 10000072 with Client(backend=backend) as client:73 response = client.post("http://example.org", data=data)74 assert response.status_code == 20075 assert json.loads(response.content) == {76 "method": "POST",77 "path": "/",78 "body": data.decode(),79 }808182async def test_async_http2_large_post_request(backend):83 backend = MockHTTP2Backend(app=app, backend=backend)8485 data = b"a" * 10000086 async with AsyncClient(backend=backend) as client:87 response = await client.post("http://example.org", data=data)88 assert response.status_code == 20089 assert json.loads(response.content) == {90 "method": "POST",91 "path": "/",92 "body": data.decode(),93 }9495Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 96–97why, one step back96def test_http2_multiple_requests():97 backend = MockHTTP2Backend(app=app)Merge pull request #43 from encode/badgesTom Christiebefore adoption3553625
line 98why, one step back98Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 99–102why, one step back99 with Client(backend=backend) as client:100 response_1 = client.get("http://example.org/1")101 response_2 = client.get("http://example.org/2")102 response_3 = client.get("http://example.org/3")Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 103why, one step back103Merge pull request #43 from encode/badgesTom Christiebefore adoption3553625
lines 104–111why, one step back104 assert response_1.status_code == 200105 assert json.loads(response_1.content) == {"method": "GET", "path": "/1", "body": ""}106107 assert response_2.status_code == 200108 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}109110 assert response_3.status_code == 200111 assert json.loads(response_3.content) == {"method": "GET", "path": "/3", "body": ""}Check for connection aliveness on pool re-acquiry (#111)Tom Christiebefore adoption025240c
lines 112–113why, one step back112113Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 114–115why, one step back114async def test_async_http2_multiple_requests(backend):115 backend = MockHTTP2Backend(app=app, backend=backend)Add missing async test cases (#269)Florimond Mancabefore adoptiona4b93b9
lines 116–131why, one step back116117 async with AsyncClient(backend=backend) as client:118 response_1 = await client.get("http://example.org/1")119 response_2 = await client.get("http://example.org/2")120 response_3 = await client.get("http://example.org/3")121122 assert response_1.status_code == 200123 assert json.loads(response_1.content) == {"method": "GET", "path": "/1", "body": ""}124125 assert response_2.status_code == 200126 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}127128 assert response_3.status_code == 200129 assert json.loads(response_3.content) == {"method": "GET", "path": "/3", "body": ""}130131Check for connection aliveness on pool re-acquiry (#111)Tom Christiebefore adoption025240c
lines 132–140why, one step back132def test_http2_reconnect():133 """134 If a connection has been dropped between requests, then we should135 be seemlessly reconnected.136 """137 backend = MockHTTP2Backend(app=app)138139 with Client(backend=backend) as client:140 response_1 = client.get("http://example.org/1")Check disconnections on connection reacquiry (#145)Tom Christiebefore adoptionec365c0
line 141why, one step back141 backend.server.close_connection = TrueCheck for connection aliveness on pool re-acquiry (#111)Tom Christiebefore adoption025240c
line 142why, one step back142 response_2 = client.get("http://example.org/2")Add missing async test cases (#269)Florimond Mancabefore adoptiona4b93b9
lines 143–150why, one step back143144 assert response_1.status_code == 200145 assert json.loads(response_1.content) == {"method": "GET", "path": "/1", "body": ""}146147 assert response_2.status_code == 200148 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}149150Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 151why, one step back151async def test_async_http2_reconnect(backend):Add missing async test cases (#269)Florimond Mancabefore adoptiona4b93b9
lines 152–155why, one step back152 """153 If a connection has been dropped between requests, then we should154 be seemlessly reconnected.155 """Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 156why, one step back156 backend = MockHTTP2Backend(app=app, backend=backend)Add missing async test cases (#269)Florimond Mancabefore adoptiona4b93b9
lines 157–161why, one step back157158 async with AsyncClient(backend=backend) as client:159 response_1 = await client.get("http://example.org/1")160 backend.server.close_connection = True161 response_2 = await client.get("http://example.org/2")Check for connection aliveness on pool re-acquiry (#111)Tom Christiebefore adoption025240c
lines 162–167why, one step back162163 assert response_1.status_code == 200164 assert json.loads(response_1.content) == {"method": "GET", "path": "/1", "body": ""}165166 assert response_2.status_code == 200167 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}