mirror of https://github.com/tiangolo/fastapi.git
24 lines
515 B
Python
24 lines
515 B
Python
from fastapi import APIRouter, FastAPI
|
|
from starlette.requests import Request
|
|
from starlette.responses import JSONResponse
|
|
from starlette.testclient import TestClient
|
|
|
|
app = FastAPI()
|
|
router = APIRouter()
|
|
|
|
|
|
@router.route("/items/")
|
|
def read_items(request: Request):
|
|
return JSONResponse({"hello": "world"})
|
|
|
|
|
|
app.include_router(router)
|
|
|
|
client = TestClient(app)
|
|
|
|
|
|
def test_sub_router():
|
|
response = client.get("/items/")
|
|
assert response.status_code == 200
|
|
assert response.json() == {"hello": "world"}
|