Coverage for docs_src / bigger_applications / app_an_py310 / routers / items.py: 100%
17 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
1from fastapi import APIRouter, Depends, HTTPException 1abcdefg
3from ..dependencies import get_token_header 1abcdefg
5router = APIRouter( 1abcdefg
6 prefix="/items",
7 tags=["items"],
8 dependencies=[Depends(get_token_header)],
9 responses={404: {"description": "Not found"}},
10)
13fake_items_db = {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}} 1abcdefg
16@router.get("/") 1abcdefg
17async def read_items(): 1abcdefg
18 return fake_items_db 1wxyz
21@router.get("/{item_id}") 1abcdefg
22async def read_item(item_id: str): 1abcdefg
23 if item_id not in fake_items_db: 1hijklmn
24 raise HTTPException(status_code=404, detail="Item not found") 1hAkm
25 return {"name": fake_items_db[item_id]["name"], "item_id": item_id} 1ijln
28@router.put( 1abcdefg
29 "/{item_id}",
30 tags=["custom"],
31 responses={403: {"description": "Operation forbidden"}},
32)
33async def update_item(item_id: str): 1abcdefg
34 if item_id != "plumbus": 1opqrstuv
35 raise HTTPException( 1prtv
36 status_code=403, detail="You can only update the item: plumbus"
37 )
38 return {"item_id": item_id, "name": "The great Plumbus"} 1oqsu