mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-25 07:08:11 -05:00
* ✨ Do not require default value in Query(), Path(), Header(), etc * 📝 Update source examples for docs with default and required values * ✅ Update tests with new default values and not required Ellipsis * 📝 Update docs for Query params and update info about default value, required, Ellipsis
54 lines
1.2 KiB
Python
54 lines
1.2 KiB
Python
from typing import Dict, List, Optional, Tuple
|
|
|
|
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/")
|
|
def read_items(q: List[Item] = Query(default=None)):
|
|
pass # pragma: no cover
|
|
|
|
|
|
def test_invalid_tuple():
|
|
with pytest.raises(AssertionError):
|
|
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):
|
|
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):
|
|
app = FastAPI()
|
|
|
|
class Item(BaseModel):
|
|
title: str
|
|
|
|
@app.get("/items/")
|
|
def read_items(q: Optional[dict] = Query(default=None)):
|
|
pass # pragma: no cover
|