| 1 |
import functools |
| 2 |
|
| 3 |
from fastapi import FastAPI |
| 4 |
from fastapi.testclient import TestClient |
| 5 |
|
| 6 |
from .forward_reference_type import forwardref_method |
| 7 |
|
| 8 |
|
| 9 |
def passthrough(f): |
| 10 |
@functools.wraps(f) |
| 11 |
def method(*args, **kwargs): |
| 12 |
return f(*args, **kwargs) |
| 13 |
|
| 14 |
return method |
| 15 |
|
| 16 |
|
| 17 |
def test_wrapped_method_type_inference(): |
| 18 |
""" |
| 19 |
Regression test ensuring that when a method imported from another module |
| 20 |
is decorated with something that sets the __wrapped__ attribute (functools.wraps), |
| 21 |
then the types are still processed correctly, including dereferencing of forward |
| 22 |
references. |
| 23 |
""" |
| 24 |
app = FastAPI() |
| 25 |
client = TestClient(app) |
| 26 |
app.post("/endpoint")(passthrough(forwardref_method)) |
| 27 |
app.post("/endpoint2")(passthrough(passthrough(forwardref_method))) |
| 28 |
with client: |
| 29 |
response = client.post("/endpoint", json={"input": {"x": 0}}) |
| 30 |
response2 = client.post("/endpoint2", json={"input": {"x": 0}}) |
| 31 |
assert response.json() == response2.json() == {"x": 1} |