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

Function test_request_body_then_stream

tests/test_requests.py:148–161  ·  tests/test_requests.py::test_request_body_then_stream
(test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

146
147
148def test_request_body_then_stream(test_client_factory: TestClientFactory) -> None:
149 async def app(scope: Scope, receive: Receive, send: Send) -> None:
150 request = Request(scope, receive)
151 body = await request.body()
152 chunks = bclass="st">""
153 async for chunk in request.stream():
154 chunks += chunk
155 response = JSONResponse({class="st">"body": body.decode(), class="st">"stream": chunks.decode()})
156 await response(scope, receive, send)
157
158 client = test_client_factory(app)
159
160 response = client.post(class="st">"/", data=class="st">"abc") class="cm"># type: ignore
161 assert response.json() == {class="st">"body": class="st">"abc", class="st">"stream": class="st">"abc"}
162
163
164def test_request_stream_then_body(test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 3

test_client_factoryFunction · 0.85
jsonMethod · 0.80
postMethod · 0.45

Tested by

no test coverage detected