Browse Source

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

pull/5077/head
Lucas Wiman 3 years ago
parent
commit
c3591b32b9
  1. 2
      tests/forward_reference_type.py
  2. 10
      tests/test_wrapped_method_forward_reference.py

2
tests/forward_reference_type.py

@ -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):

10
tests/test_wrapped_method_forward_reference.py

@ -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}

Loading…
Cancel
Save