test_http2.py
This file
Path
tests/dispatch/test_http2.py
78 lines · 2.3 KiB · Python
Last changed by
Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
History of this fileTake it
Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 1–2why, one step back1import json2Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 3why, one step back3from httpx import Client, ResponseLintingTom Christiebefore adoption8f4abe0
line 4why, one step back4Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
line 5why, one step back5from .utils import MockHTTP2BackendRejig test and tighten up models APITom Christiebefore adoptiondea4d42
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)Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
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)Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
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")Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 25–26why, one step back2526 assert response.status_code == 200Response.contentTom Christiebefore adoption4c55113
line 27why, one step back27 assert json.loads(response.content) == {"method": "GET", "path": "/", "body": ""}Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 28–29why, one step back2829Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 30–31why, one step back30def test_http2_post_request():31 backend = MockHTTP2Backend(app=app)Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 32why, one step back32Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 33–34why, one step back33 with Client(backend=backend) as client:34 response = client.post("http://example.org", data=b"<data>")Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 35why, one step back35Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
line 36why, one step back36 assert response.status_code == 200Response.contentTom Christiebefore adoption4c55113
line 37why, one step back37 assert json.loads(response.content) == {Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 38–43why, one step back38 "method": "POST",39 "path": "/",40 "body": "<data>",41 }4243Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 44–45why, one step back44def test_http2_multiple_requests():45 backend = MockHTTP2Backend(app=app)Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
line 46why, one step back46Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 47–50why, one step back47 with Client(backend=backend) as client:48 response_1 = client.get("http://example.org/1")49 response_2 = client.get("http://example.org/2")50 response_3 = client.get("http://example.org/3")Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 51why, one step back51Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
line 52why, one step back52 assert response_1.status_code == 200Response.contentTom Christiebefore adoption4c55113
line 53why, one step back53 assert json.loads(response_1.content) == {"method": "GET", "path": "/1", "body": ""}Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 54–55why, one step back5455 assert response_2.status_code == 200Response.contentTom Christiebefore adoption4c55113
line 56why, one step back56 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 57–58why, one step back5758 assert response_3.status_code == 200Response.contentTom Christiebefore adoption4c55113
line 59why, one step back59 assert json.loads(response_3.content) == {"method": "GET", "path": "/3", "body": ""}Check for connection aliveness on pool re-acquiry (#111)Tom Christiebefore adoption025240c
lines 60–78why, one step back606162def test_http2_reconnect():63 """64 If a connection has been dropped between requests, then we should65 be seemlessly reconnected.66 """67 backend = MockHTTP2Backend(app=app)6869 with Client(backend=backend) as client:70 response_1 = client.get("http://example.org/1")71 backend.server.raise_disconnect = True72 response_2 = client.get("http://example.org/2")7374 assert response_1.status_code == 20075 assert json.loads(response_1.content) == {"method": "GET", "path": "/1", "body": ""}7677 assert response_2.status_code == 20078 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}