|
|
|
@ -8,6 +8,9 @@ from fastapi import Depends, FastAPI |
|
|
|
from fastapi.concurrency import iterate_in_threadpool, run_in_threadpool |
|
|
|
from fastapi.testclient import TestClient |
|
|
|
|
|
|
|
from typing import Annotated, ForwardRef |
|
|
|
|
|
|
|
|
|
|
|
if sys.version_info >= (3, 13): # pragma: no cover |
|
|
|
from inspect import iscoroutinefunction |
|
|
|
else: # pragma: no cover |
|
|
|
@ -447,3 +450,21 @@ def test_class_dependency(route): |
|
|
|
response = client.get(route) |
|
|
|
assert response.status_code == 200, response.text |
|
|
|
assert response.json() is True |
|
|
|
|
|
|
|
def test_annotated_forwardref_dependency(): |
|
|
|
app = FastAPI() |
|
|
|
|
|
|
|
User = ForwardRef("User") |
|
|
|
|
|
|
|
def get_user() -> "User": |
|
|
|
return {"name": "amulya"} |
|
|
|
|
|
|
|
@app.get("/") |
|
|
|
def read_user(user: Annotated[User, Depends(get_user)]): |
|
|
|
return user |
|
|
|
|
|
|
|
client = TestClient(app) |
|
|
|
response = client.get("/") |
|
|
|
|
|
|
|
assert response.status_code == 200 |
|
|
|
assert response.json() == {"name": "amulya"} |
|
|
|
|