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

Function test_file_response_with_pathsend

tests/test_responses.py:367–395  ·  tests/test_responses.py::test_file_response_with_pathsend
(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 / class="st">"xyz"
369 content = bclass="st">"<file content>" * 1000
370 with open(path, class="st">"wb") as file:
371 file.write(content)
372
373 app = FileResponse(path=path, filename=class="st">"example.png")
374
375 async def receive() -> Message: class="cm"># type: ignore[empty-body]
376 ... class="cm"># pragma: no cover
377
378 async def send(message: Message) -> None:
379 if message[class="st">"type"] == class="st">"http.response.start":
380 assert message[class="st">"status"] == status.HTTP_200_OK
381 headers = Headers(raw=message[class="st">"headers"])
382 assert headers[class="st">"content-type"] == class="st">"image/png"
383 assert class="st">"content-length" in headers
384 assert class="st">"content-disposition" in headers
385 assert class="st">"last-modified" in headers
386 assert class="st">"etag" in headers
387 elif message[class="st">"type"] == class="st">"http.response.pathsend": class="cm"># pragma: no branch
388 assert message[class="st">"path"] == str(path)
389
390 class="cm"># Since the TestClient doesn't support `pathsend`, we need to test this directly.
391 await app(
392 {class="st">"type": class="st">"http", class="st">"method": class="st">"get", class="st">"headers": [], class="st">"extensions": {class="st">"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