(tmp_path: Path)
| 251 | |
| 252 | @pytest.mark.anyio |
| 253 | async def test_file_response_on_head_method(tmp_path: Path) -> None: |
| 254 | path = tmp_path / "xyz" |
| 255 | content = b"<file content>" * 1000 |
| 256 | path.write_bytes(content) |
| 257 | |
| 258 | app = FileResponse(path=path, filename="example.png") |
| 259 | |
| 260 | async def receive() -> Message: # type: ignore[empty-body] |
| 261 | ... # pragma: no cover |
| 262 | |
| 263 | async def send(message: Message) -> None: |
| 264 | if message["type"] == "http.response.start": |
| 265 | assert message["status"] == status.HTTP_200_OK |
| 266 | headers = Headers(raw=message["headers"]) |
| 267 | assert headers["content-type"] == "image/png" |
| 268 | assert "content-length" in headers |
| 269 | assert "content-disposition" in headers |
| 270 | assert "last-modified" in headers |
| 271 | assert "etag" in headers |
| 272 | elif message["type"] == "http.response.body": # pragma: no branch |
| 273 | assert message["body"] == b"" |
| 274 | assert message["more_body"] is False |
| 275 | |
| 276 | # Since the TestClient drops the response body on HEAD requests, we need to test |
| 277 | # this directly. |
| 278 | await app({"type": "http", "method": "head", "headers": [(b"key", b"value")]}, receive, send) |
| 279 | |
| 280 | |
| 281 | def test_file_response_set_media_type(tmp_path: Path, test_client_factory: TestClientFactory) -> None: |
nothing calls this directly
no test coverage detected