MCPcopy Index your code
hub / github.com/fastapi/fastapi / test_response_dependency_chain

Function test_response_dependency_chain

tests/test_response_dependency.py:71–94  ·  view source on GitHub ↗

Response dependency should work in a chain of dependencies.

()

Source from the content-addressed store, hash-verified

69
70
71def test_response_dependency_chain():
72 """Response dependency should work in a chain of dependencies."""
73 app = FastAPI()
74
75 def first_modifier(response: Response) -> Response:
76 response.headers["X-First"] = "1"
77 return response
78
79 def second_modifier(
80 response: Annotated[Response, Depends(first_modifier)],
81 ) -> Response:
82 response.headers["X-Second"] = "2"
83 return response
84
85 @app.get("/")
86 def endpoint(response: Annotated[Response, Depends(second_modifier)]):
87 return {"status": "ok"}
88
89 client = TestClient(app)
90 resp = client.get("/")
91
92 assert resp.status_code == 200
93 assert resp.headers.get("X-First") == "1"
94 assert resp.headers.get("X-Second") == "2"
95
96
97def test_response_dependency_returns_different_response_instance():

Callers

nothing calls this directly

Calls 2

FastAPIClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…