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

Function test_file_response_with_range_header

tests/test_responses.py:350–363  ·  view source on GitHub ↗
(tmp_path: Path, test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

348
349
350def test_file_response_with_range_header(tmp_path: Path, test_client_factory: TestClientFactory) -> None:
351 content = b"file content"
352 filename = "hello.txt"
353 path = tmp_path / filename
354 path.write_bytes(content)
355 etag = '"a_non_autogenerated_etag"'
356 app = FileResponse(path=path, filename=filename, headers={"etag": etag})
357 client = test_client_factory(app)
358 response = client.get("/", headers={"range": "bytes=0-4", "if-range": etag})
359 assert response.status_code == status.HTTP_206_PARTIAL_CONTENT
360 assert response.content == content[:5]
361 assert response.headers["etag"] == etag
362 assert response.headers["content-length"] == "5"
363 assert response.headers["content-range"] == f"bytes 0-4/{len(content)}"
364
365
366@pytest.mark.anyio

Callers

nothing calls this directly

Calls 3

FileResponseClass · 0.90
test_client_factoryFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected