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

Function test_staticfiles_head_with_middleware

tests/test_staticfiles.py:46–65  ·  view source on GitHub ↗

see https://github.com/Kludex/starlette/pull/935

(tmpdir: Path, test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

44
45
46def test_staticfiles_head_with_middleware(tmpdir: Path, test_client_factory: TestClientFactory) -> None:
47 """
48 see https://github.com/Kludex/starlette/pull/935
49 """
50 path = os.path.join(tmpdir, "example.txt")
51 with open(path, "w") as file:
52 file.write("x" * 100)
53
54 async def does_nothing_middleware(request: Request, call_next: RequestResponseEndpoint) -> Response:
55 response = await call_next(request)
56 return response
57
58 routes = [Mount("/static", app=StaticFiles(directory=tmpdir), name="static")]
59 middleware = [Middleware(BaseHTTPMiddleware, dispatch=does_nothing_middleware)]
60 app = Starlette(routes=routes, middleware=middleware)
61
62 client = test_client_factory(app)
63 response = client.head("/static/example.txt")
64 assert response.status_code == 200
65 assert response.headers.get("content-length") == "100"
66
67
68def test_staticfiles_with_package(test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 8

MountClass · 0.90
StaticFilesClass · 0.90
MiddlewareClass · 0.90
StarletteClass · 0.90
test_client_factoryFunction · 0.85
headMethod · 0.80
writeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected