test_http2.py
This file
Path
tests/dispatch/test_http2.py
61 lines · 1.7 KiB · Python
Last changed by
LintingTom Christiebefore adoption8f4abe0
History of this fileTake it
Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 1–4why, one step back1import json23import pytest4Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
line 5why, one step back5from httpcore import Client, ResponseLintingTom Christiebefore adoption8f4abe0
line 6why, one step back6Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
line 7why, one step back7from .utils import MockHTTP2BackendRejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 8–9why, one step back89Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
line 10why, one step back10def app(request):LintingTom Christiebefore adoption8f4abe0
lines 11–18why, one step back11 content = json.dumps(12 {13 "method": request.method,14 "path": request.url.path,15 "body": request.content.decode(),16 }17 ).encode()18 headers = {"Content-Length": str(len(content))}Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
line 19why, one step back19 return Response(200, headers=headers, content=content)Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 20–21why, one step back2021Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 22–23why, one step back22def test_http2_get_request():23 backend = MockHTTP2Backend(app=app)Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
line 24why, one step back24Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 25–26why, one step back25 with Client(backend=backend) as client:26 response = client.get("http://example.org")Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 27–28why, one step back2728 assert response.status_code == 200Response.contentTom Christiebefore adoption4c55113
line 29why, one step back29 assert json.loads(response.content) == {"method": "GET", "path": "/", "body": ""}Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 30–31why, one step back3031Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 32–33why, one step back32def test_http2_post_request():33 backend = MockHTTP2Backend(app=app)Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 34why, one step back34Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 35–36why, one step back35 with Client(backend=backend) as client:36 response = client.post("http://example.org", data=b"<data>")Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 37why, one step back37Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
line 38why, one step back38 assert response.status_code == 200Response.contentTom Christiebefore adoption4c55113
line 39why, one step back39 assert json.loads(response.content) == {Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 40–45why, one step back40 "method": "POST",41 "path": "/",42 "body": "<data>",43 }4445Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 46–47why, one step back46def test_http2_multiple_requests():47 backend = MockHTTP2Backend(app=app)Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
line 48why, one step back48Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 49–52why, one step back49 with Client(backend=backend) as client:50 response_1 = client.get("http://example.org/1")51 response_2 = client.get("http://example.org/2")52 response_3 = client.get("http://example.org/3")Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 53why, one step back53Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
line 54why, one step back54 assert response_1.status_code == 200Response.contentTom Christiebefore adoption4c55113
line 55why, one step back55 assert json.loads(response_1.content) == {"method": "GET", "path": "/1", "body": ""}Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 56–57why, one step back5657 assert response_2.status_code == 200Response.contentTom Christiebefore adoption4c55113
line 58why, one step back58 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 59–60why, one step back5960 assert response_3.status_code == 200Response.contentTom Christiebefore adoption4c55113
line 61why, one step back61 assert json.loads(response_3.content) == {"method": "GET", "path": "/3", "body": ""}