Files
fastapi/tests/test_invalid_sequence_param.py
Sebastián Ramírez faee822574 🎨 Upgrade typing syntax for Python 3.10 (#14932)
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tiangolo <1326112+tiangolo@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-17 09:59:14 +00:00

64 lines
1.5 KiB
Python

import pytest
from fastapi import FastAPI, Query
from pydantic import BaseModel
def test_invalid_sequence():
with pytest.raises(
AssertionError,
match="Query parameter 'q' must be one of the supported types",
):
app = FastAPI()
class Item(BaseModel):
title: str
@app.get("/items/")
def read_items(q: list[Item] = Query(default=None)):
pass # pragma: no cover
def test_invalid_tuple():
with pytest.raises(
AssertionError,
match="Query parameter 'q' must be one of the supported types",
):
app = FastAPI()
class Item(BaseModel):
title: str
@app.get("/items/")
def read_items(q: tuple[Item, Item] = Query(default=None)):
pass # pragma: no cover
def test_invalid_dict():
with pytest.raises(
AssertionError,
match="Query parameter 'q' must be one of the supported types",
):
app = FastAPI()
class Item(BaseModel):
title: str
@app.get("/items/")
def read_items(q: dict[str, Item] = Query(default=None)):
pass # pragma: no cover
def test_invalid_simple_dict():
with pytest.raises(
AssertionError,
match="Query parameter 'q' must be one of the supported types",
):
app = FastAPI()
class Item(BaseModel):
title: str
@app.get("/items/")
def read_items(q: dict | None = Query(default=None)):
pass # pragma: no cover