Debian Codegraph @

tests/test_typing_python39.py

raw
1 from fastapi import FastAPI
2 from fastapi.testclient import TestClient
3
4 from .utils import needs_py310
5
6
7 @needs_py310
8 def test_typing():
9 types = {
10 list[int]: [1, 2, 3],
11 dict[str, list[int]]: {"a": [1, 2, 3], "b": [4, 5, 6]},
12 set[int]: [1, 2, 3], # `set` is converted to `list`
13 tuple[int, ...]: [1, 2, 3], # `tuple` is converted to `list`
14 }
15 for test_type, expect in types.items():
16 app = FastAPI()
17
18 @app.post("/", response_model=test_type)
19 def post_endpoint(input: test_type):
20 return input
21
22 res = TestClient(app).post("/", json=expect)
23 assert res.status_code == 200, res.json()
24 assert res.json() == expect