mirror of https://github.com/tiangolo/fastapi.git
Remove code examples for Python 3.8 in `bigger_applications`
This commit is contained in:
parent
36850d9d90
commit
15d6644ec3
|
|
@ -1,12 +0,0 @@
|
||||||
from fastapi import Header, HTTPException
|
|
||||||
from typing_extensions import Annotated
|
|
||||||
|
|
||||||
|
|
||||||
async def get_token_header(x_token: Annotated[str, Header()]):
|
|
||||||
if x_token != "fake-super-secret-token":
|
|
||||||
raise HTTPException(status_code=400, detail="X-Token header invalid")
|
|
||||||
|
|
||||||
|
|
||||||
async def get_query_token(token: str):
|
|
||||||
if token != "jessica":
|
|
||||||
raise HTTPException(status_code=400, detail="No Jessica token provided")
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
from fastapi import APIRouter
|
|
||||||
|
|
||||||
router = APIRouter()
|
|
||||||
|
|
||||||
|
|
||||||
@router.post("/")
|
|
||||||
async def update_admin():
|
|
||||||
return {"message": "Admin getting schwifty"}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
from fastapi import Depends, FastAPI
|
|
||||||
|
|
||||||
from .dependencies import get_query_token, get_token_header
|
|
||||||
from .internal import admin
|
|
||||||
from .routers import items, users
|
|
||||||
|
|
||||||
app = FastAPI(dependencies=[Depends(get_query_token)])
|
|
||||||
|
|
||||||
|
|
||||||
app.include_router(users.router)
|
|
||||||
app.include_router(items.router)
|
|
||||||
app.include_router(
|
|
||||||
admin.router,
|
|
||||||
prefix="/admin",
|
|
||||||
tags=["admin"],
|
|
||||||
dependencies=[Depends(get_token_header)],
|
|
||||||
responses={418: {"description": "I'm a teapot"}},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
|
||||||
async def root():
|
|
||||||
return {"message": "Hello Bigger Applications!"}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
from fastapi import APIRouter, Depends, HTTPException
|
|
||||||
|
|
||||||
from ..dependencies import get_token_header
|
|
||||||
|
|
||||||
router = APIRouter(
|
|
||||||
prefix="/items",
|
|
||||||
tags=["items"],
|
|
||||||
dependencies=[Depends(get_token_header)],
|
|
||||||
responses={404: {"description": "Not found"}},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
fake_items_db = {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/")
|
|
||||||
async def read_items():
|
|
||||||
return fake_items_db
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{item_id}")
|
|
||||||
async def read_item(item_id: str):
|
|
||||||
if item_id not in fake_items_db:
|
|
||||||
raise HTTPException(status_code=404, detail="Item not found")
|
|
||||||
return {"name": fake_items_db[item_id]["name"], "item_id": item_id}
|
|
||||||
|
|
||||||
|
|
||||||
@router.put(
|
|
||||||
"/{item_id}",
|
|
||||||
tags=["custom"],
|
|
||||||
responses={403: {"description": "Operation forbidden"}},
|
|
||||||
)
|
|
||||||
async def update_item(item_id: str):
|
|
||||||
if item_id != "plumbus":
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403, detail="You can only update the item: plumbus"
|
|
||||||
)
|
|
||||||
return {"item_id": item_id, "name": "The great Plumbus"}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
from fastapi import APIRouter
|
|
||||||
|
|
||||||
router = APIRouter()
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/users/", tags=["users"])
|
|
||||||
async def read_users():
|
|
||||||
return [{"username": "Rick"}, {"username": "Morty"}]
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/users/me", tags=["users"])
|
|
||||||
async def read_user_me():
|
|
||||||
return {"username": "fakecurrentuser"}
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/users/{username}", tags=["users"])
|
|
||||||
async def read_user(username: str):
|
|
||||||
return {"username": username}
|
|
||||||
|
|
@ -4,15 +4,12 @@ import pytest
|
||||||
from dirty_equals import IsDict
|
from dirty_equals import IsDict
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
from ...utils import needs_py39
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(
|
@pytest.fixture(
|
||||||
name="client",
|
name="client",
|
||||||
params=[
|
params=[
|
||||||
"app_an.main",
|
"app_py39.main",
|
||||||
pytest.param("app_an_py39.main", marks=needs_py39),
|
"app_an_py39.main",
|
||||||
"app.main",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def get_client(request: pytest.FixtureRequest):
|
def get_client(request: pytest.FixtureRequest):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue