2020-06-28 20:13:30 +02:00
|
|
|
from typing import Dict, List, Optional, Tuple
|
2019-05-30 17:40:43 +04:00
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
from fastapi import FastAPI, Query
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_invalid_sequence():
|
|
|
|
|
with pytest.raises(AssertionError):
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
class Item(BaseModel):
|
|
|
|
|
title: str
|
|
|
|
|
|
|
|
|
|
@app.get("/items/")
|
2022-05-13 18:38:22 -05: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():
|
|
|
|
|
with pytest.raises(AssertionError):
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
class Item(BaseModel):
|
|
|
|
|
title: str
|
|
|
|
|
|
|
|
|
|
@app.get("/items/")
|
2022-05-13 18:38:22 -05: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():
|
|
|
|
|
with pytest.raises(AssertionError):
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
class Item(BaseModel):
|
|
|
|
|
title: str
|
|
|
|
|
|
|
|
|
|
@app.get("/items/")
|
2022-05-13 18:38:22 -05: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():
|
|
|
|
|
with pytest.raises(AssertionError):
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
class Item(BaseModel):
|
|
|
|
|
title: str
|
|
|
|
|
|
|
|
|
|
@app.get("/items/")
|
2022-05-13 18:38:22 -05:00
|
|
|
def read_items(q: Optional[dict] = Query(default=None)):
|
2019-06-03 21:59:40 +04:00
|
|
|
pass # pragma: no cover
|