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

Function test_request_without_setting_receive

tests/test_requests.py:219–238  ·  view source on GitHub ↗

If Request is instantiated without the receive channel, then .body() is not available.

(
    test_client_factory: TestClientFactory,
)

Source from the content-addressed store, hash-verified

217
218
219def test_request_without_setting_receive(
220 test_client_factory: TestClientFactory,
221) -> None:
222 """
223 If Request is instantiated without the receive channel, then .body()
224 is not available.
225 """
226
227 async def app(scope: Scope, receive: Receive, send: Send) -> None:
228 request = Request(scope)
229 try:
230 data = await request.json()
231 except RuntimeError:
232 data = "Receive channel not available"
233 response = JSONResponse({"json": data})
234 await response(scope, receive, send)
235
236 client = test_client_factory(app)
237 response = client.post("/", json={"a": "123"})
238 assert response.json() == {"json": "Receive channel not available"}
239
240
241def test_request_disconnect(

Callers

nothing calls this directly

Calls 3

test_client_factoryFunction · 0.85
jsonMethod · 0.80
postMethod · 0.45

Tested by

no test coverage detected