MCPcopy
hub / github.com/encode/starlette / test_request_stream

Function test_request_stream

tests/test_requests.py:101–119  ·  tests/test_requests.py::test_request_stream
(test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

99
100
101def test_request_stream(test_client_factory: TestClientFactory) -> None:
102 async def app(scope: Scope, receive: Receive, send: Send) -> None:
103 request = Request(scope, receive)
104 body = bclass="st">""
105 async for chunk in request.stream():
106 body += chunk
107 response = JSONResponse({class="st">"body": body.decode()})
108 await response(scope, receive, send)
109
110 client = test_client_factory(app)
111
112 response = client.get(class="st">"/")
113 assert response.json() == {class="st">"body": class="st">""}
114
115 response = client.post(class="st">"/", json={class="st">"a": class="st">"123"})
116 assert response.json() == {class="st">"body": &class="cm">#x27;{class="st">"a":class="st">"123"}'}
117
118 response = client.post(class="st">"/", data=class="st">"abc") class="cm"># type: ignore
119 assert response.json() == {class="st">"body": class="st">"abc"}
120
121
122def test_request_form_urlencoded(test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 4

test_client_factoryFunction · 0.85
jsonMethod · 0.80
getMethod · 0.45
postMethod · 0.45

Tested by

no test coverage detected