2019-05-30 17:40:43 +04:00
|
|
|
import pytest
|
|
|
|
|
from fastapi import FastAPI, Query
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_invalid_sequence():
|
2026-02-04 14:24:59 +01:00
|
|
|
with pytest.raises(
|
|
|
|
|
AssertionError,
|
|
|
|
|
match="Query parameter 'q' must be one of the supported types",
|
|
|
|
|
):
|
2019-05-30 17:40:43 +04:00
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
class Item(BaseModel):
|
|
|
|
|
title: str
|
|
|
|
|
|
|
|
|
|
@app.get("/items/")
|
2025-12-17 13:25:59 -08:00
|
|
|
def read_items(q: list[Item] = Query(default=None)):
|
2019-05-30 17:40:43 +04:00
|
|
|
pass # pragma: no cover
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_invalid_tuple():
|
2026-02-04 14:24:59 +01:00
|
|
|
with pytest.raises(
|
|
|
|
|
AssertionError,
|
|
|
|
|
match="Query parameter 'q' must be one of the supported types",
|
|
|
|
|
):
|
2019-05-30 17:40:43 +04:00
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
class Item(BaseModel):
|
|
|
|
|
title: str
|
|
|
|
|
|
|
|
|
|
@app.get("/items/")
|
2025-12-17 13:25:59 -08:00
|
|
|
def read_items(q: tuple[Item, Item] = Query(default=None)):
|
2019-05-30 17:40:43 +04:00
|
|
|
pass # pragma: no cover
|
2019-06-03 21:59:40 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_invalid_dict():
|
2026-02-04 14:24:59 +01:00
|
|
|
with pytest.raises(
|
|
|
|
|
AssertionError,
|
|
|
|
|
match="Query parameter 'q' must be one of the supported types",
|
|
|
|
|
):
|
2019-06-03 21:59:40 +04:00
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
class Item(BaseModel):
|
|
|
|
|
title: str
|
|
|
|
|
|
|
|
|
|
@app.get("/items/")
|
2025-12-17 13:25:59 -08:00
|
|
|
def read_items(q: dict[str, Item] = Query(default=None)):
|
2019-06-03 21:59:40 +04:00
|
|
|
pass # pragma: no cover
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_invalid_simple_dict():
|
2026-02-04 14:24:59 +01:00
|
|
|
with pytest.raises(
|
|
|
|
|
AssertionError,
|
|
|
|
|
match="Query parameter 'q' must be one of the supported types",
|
|
|
|
|
):
|
2019-06-03 21:59:40 +04:00
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
class Item(BaseModel):
|
|
|
|
|
title: str
|
|
|
|
|
|
|
|
|
|
@app.get("/items/")
|
2026-02-17 01:59:14 -08:00
|
|
|
def read_items(q: dict | None = Query(default=None)):
|
2019-06-03 21:59:40 +04:00
|
|
|
pass # pragma: no cover
|