Make tests more end-to-end to keep code coverage high.

This commit is contained in:
Lucas Wiman 2022-06-24 12:00:01 -07:00
parent c1691f5d94
commit c3591b32b9
2 changed files with 9 additions and 3 deletions

View File

@ -2,7 +2,7 @@ from pydantic import BaseModel
def forwardref_method(input: "ForwardRef") -> "ForwardRef":
return ForwardRef()
return ForwardRef(x=input.x + 1)
class ForwardRef(BaseModel):

View File

@ -1,6 +1,7 @@
import functools
from fastapi import FastAPI
from fastapi.testclient import TestClient
from .forward_reference_type import forwardref_method
@ -21,5 +22,10 @@ def test_wrapped_method_type_inference():
references.
"""
app = FastAPI()
app.get("/endpoint")(passthrough(forwardref_method))
app.get("/endpoint2")(passthrough(passthrough(forwardref_method)))
client = TestClient(app)
app.post("/endpoint")(passthrough(forwardref_method))
app.post("/endpoint2")(passthrough(passthrough(forwardref_method)))
with client:
response = client.post("/endpoint", json={"input": {"x": 0}})
response2 = client.post("/endpoint2", json={"input": {"x": 0}})
assert response.json() == response2.json() == {"x": 1}