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
1import json23import pytest45from httpcore import Client, Response67from .utils import MockHTTP2Backend8910def app(request):11 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))}19 return Response(200, headers=headers, content=content)202122def test_http2_get_request():23 backend = MockHTTP2Backend(app=app)2425 with Client(backend=backend) as client:26 response = client.get("http://example.org")2728 assert response.status_code == 20029 assert json.loads(response.content) == {"method": "GET", "path": "/", "body": ""}303132def test_http2_post_request():33 backend = MockHTTP2Backend(app=app)3435 with Client(backend=backend) as client:36 response = client.post("http://example.org", data=b"<data>")3738 assert response.status_code == 20039 assert json.loads(response.content) == {40 "method": "POST",41 "path": "/",42 "body": "<data>",43 }444546def test_http2_multiple_requests():47 backend = MockHTTP2Backend(app=app)4849 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")5354 assert response_1.status_code == 20055 assert json.loads(response_1.content) == {"method": "GET", "path": "/1", "body": ""}5657 assert response_2.status_code == 20058 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}5960 assert response_3.status_code == 20061 assert json.loads(response_3.content) == {"method": "GET", "path": "/3", "body": ""}