mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-21 12:30:49 -05:00
* ✨ Refactor parameter dependency using Pydantic Field * ⬆️ Upgrade required Pydantic version with latest Shape values * ✨ Add tutorials and code for using Enum and Optional * ✅ Add tests for tutorials with new types and extra cases * ♻️ Format, clean, and add annotations to dependencies.utils * 📝 Update tutorial for query parameters with list defaults * ✅ Add tests for query param with list default
30 lines
654 B
Python
30 lines
654 B
Python
from typing import List, 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(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(None)):
|
|
pass # pragma: no cover
|