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

Function test_file_response_with_pathsend

tests/test_responses.py:367–395  ·  view source on GitHub ↗
(tmpdir: Path)

Source from the content-addressed store, hash-verified

365
366@pytest.mark.anyio
367async def test_file_response_with_pathsend(tmpdir: Path) -> None:
368 path = tmpdir / "xyz"
369 content = b"<file content>" * 1000
370 with open(path, "wb") as file:
371 file.write(content)
372
373 app = FileResponse(path=path, filename="example.png")
374
375 async def receive() -> Message: # type: ignore[empty-body]
376 ... # pragma: no cover
377
378 async def send(message: Message) -> None:
379 if message["type"] == "http.response.start":
380 assert message["status"] == status.HTTP_200_OK
381 headers = Headers(raw=message["headers"])
382 assert headers["content-type"] == "image/png"
383 assert "content-length" in headers
384 assert "content-disposition" in headers
385 assert "last-modified" in headers
386 assert "etag" in headers
387 elif message["type"] == "http.response.pathsend": # pragma: no branch
388 assert message["path"] == str(path)
389
390 # Since the TestClient doesn't support `pathsend`, we need to test this directly.
391 await app(
392 {"type": "http", "method": "get", "headers": [], "extensions": {"http.response.pathsend": {}}},
393 receive,
394 send,
395 )
396
397
398def test_set_cookie(test_client_factory: TestClientFactory, monkeypatch: pytest.MonkeyPatch) -> None:

Callers

nothing calls this directly

Calls 3

FileResponseClass · 0.90
appFunction · 0.70
writeMethod · 0.45

Tested by

no test coverage detected