lqs
d20566fe07
Some checks failed
Test / lint (push) Has been cancelled
Test / test (pydantic-v1, 3.10) (push) Has been cancelled
Test / test (pydantic-v1, 3.11) (push) Has been cancelled
Test / test (pydantic-v1, 3.12) (push) Has been cancelled
Test / test (pydantic-v1, 3.8) (push) Has been cancelled
Test / test (pydantic-v1, 3.9) (push) Has been cancelled
Test / test (pydantic-v2, 3.10) (push) Has been cancelled
Test / test (pydantic-v2, 3.11) (push) Has been cancelled
Test / test (pydantic-v2, 3.12) (push) Has been cancelled
Test / test (pydantic-v2, 3.8) (push) Has been cancelled
Test / test (pydantic-v2, 3.9) (push) Has been cancelled
Test / coverage-combine (push) Has been cancelled
Test / check (push) Has been cancelled
Issue Manager / issue-manager (push) Has been cancelled
Label Approved / label-approved (push) Has been cancelled
25 lines
709 B
Python
25 lines
709 B
Python
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
from .utils import needs_py310
|
|
|
|
|
|
@needs_py310
|
|
def test_typing():
|
|
types = {
|
|
list[int]: [1, 2, 3],
|
|
dict[str, list[int]]: {"a": [1, 2, 3], "b": [4, 5, 6]},
|
|
set[int]: [1, 2, 3], # `set` is converted to `list`
|
|
tuple[int, ...]: [1, 2, 3], # `tuple` is converted to `list`
|
|
}
|
|
for test_type, expect in types.items():
|
|
app = FastAPI()
|
|
|
|
@app.post("/", response_model=test_type)
|
|
def post_endpoint(input: test_type):
|
|
return input
|
|
|
|
res = TestClient(app).post("/", json=expect)
|
|
assert res.status_code == 200, res.json()
|
|
assert res.json() == expect
|