mirror of https://github.com/tiangolo/fastapi.git
Remove code examples for Python 3.8 in `body_updates`
This commit is contained in:
parent
4ffc89e383
commit
6e42b84e6c
|
|
@ -1,34 +0,0 @@
|
||||||
from typing import List, Union
|
|
||||||
|
|
||||||
from fastapi import FastAPI
|
|
||||||
from fastapi.encoders import jsonable_encoder
|
|
||||||
from pydantic import BaseModel
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
|
|
||||||
class Item(BaseModel):
|
|
||||||
name: Union[str, None] = None
|
|
||||||
description: Union[str, None] = None
|
|
||||||
price: Union[float, None] = None
|
|
||||||
tax: float = 10.5
|
|
||||||
tags: List[str] = []
|
|
||||||
|
|
||||||
|
|
||||||
items = {
|
|
||||||
"foo": {"name": "Foo", "price": 50.2},
|
|
||||||
"bar": {"name": "Bar", "description": "The bartenders", "price": 62, "tax": 20.2},
|
|
||||||
"baz": {"name": "Baz", "description": None, "price": 50.2, "tax": 10.5, "tags": []},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/items/{item_id}", response_model=Item)
|
|
||||||
async def read_item(item_id: str):
|
|
||||||
return items[item_id]
|
|
||||||
|
|
||||||
|
|
||||||
@app.put("/items/{item_id}", response_model=Item)
|
|
||||||
async def update_item(item_id: str, item: Item):
|
|
||||||
update_item_encoded = jsonable_encoder(item)
|
|
||||||
items[item_id] = update_item_encoded
|
|
||||||
return update_item_encoded
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
from typing import List, Union
|
|
||||||
|
|
||||||
from fastapi import FastAPI
|
|
||||||
from fastapi.encoders import jsonable_encoder
|
|
||||||
from pydantic import BaseModel
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
|
|
||||||
class Item(BaseModel):
|
|
||||||
name: Union[str, None] = None
|
|
||||||
description: Union[str, None] = None
|
|
||||||
price: Union[float, None] = None
|
|
||||||
tax: float = 10.5
|
|
||||||
tags: List[str] = []
|
|
||||||
|
|
||||||
|
|
||||||
items = {
|
|
||||||
"foo": {"name": "Foo", "price": 50.2},
|
|
||||||
"bar": {"name": "Bar", "description": "The bartenders", "price": 62, "tax": 20.2},
|
|
||||||
"baz": {"name": "Baz", "description": None, "price": 50.2, "tax": 10.5, "tags": []},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/items/{item_id}", response_model=Item)
|
|
||||||
async def read_item(item_id: str):
|
|
||||||
return items[item_id]
|
|
||||||
|
|
||||||
|
|
||||||
@app.patch("/items/{item_id}", response_model=Item)
|
|
||||||
async def update_item(item_id: str, item: Item):
|
|
||||||
stored_item_data = items[item_id]
|
|
||||||
stored_item_model = Item(**stored_item_data)
|
|
||||||
update_data = item.dict(exclude_unset=True)
|
|
||||||
updated_item = stored_item_model.copy(update=update_data)
|
|
||||||
items[item_id] = jsonable_encoder(updated_item)
|
|
||||||
return updated_item
|
|
||||||
|
|
@ -3,15 +3,14 @@ import importlib
|
||||||
import pytest
|
import pytest
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
from ...utils import needs_py39, needs_py310, needs_pydanticv1, needs_pydanticv2
|
from ...utils import needs_py310, needs_pydanticv1, needs_pydanticv2
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(
|
@pytest.fixture(
|
||||||
name="client",
|
name="client",
|
||||||
params=[
|
params=[
|
||||||
"tutorial001",
|
"tutorial001_py39",
|
||||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||||
pytest.param("tutorial001_py39", marks=needs_py39),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def get_client(request: pytest.FixtureRequest):
|
def get_client(request: pytest.FixtureRequest):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue