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

Function test_request_body

tests/test_requests.py:82–98  ·  tests/test_requests.py::test_request_body
(test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

80
81
82def test_request_body(test_client_factory: TestClientFactory) -> None:
83 async def app(scope: Scope, receive: Receive, send: Send) -> None:
84 request = Request(scope, receive)
85 body = await request.body()
86 response = JSONResponse({class="st">"body": body.decode()})
87 await response(scope, receive, send)
88
89 client = test_client_factory(app)
90
91 response = client.get(class="st">"/")
92 assert response.json() == {class="st">"body": class="st">""}
93
94 response = client.post(class="st">"/", json={class="st">"a": class="st">"123"})
95 assert response.json() == {class="st">"body": &class="cm">#x27;{class="st">"a":class="st">"123"}'}
96
97 response = client.post(class="st">"/", data=class="st">"abc") class="cm"># type: ignore
98 assert response.json() == {class="st">"body": class="st">"abc"}
99
100
101def test_request_stream(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