pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
65 lines
1.5 KiB
from typing import Optional
|
|
|
|
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: Optional[dict] = Query(default=None)):
|
|
pass # pragma: no cover
|
|
|