Coverage for tests/test_include_route.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-05-05 00:03 +0000

1from fastapi import APIRouter, FastAPI, Request 1abcdef

2from fastapi.responses import JSONResponse 1abcdef

3from fastapi.testclient import TestClient 1abcdef

4 

5app = FastAPI() 1abcdef

6router = APIRouter() 1abcdef

7 

8 

9@router.route("/items/") 1abcdef

10def read_items(request: Request): 1abcdef

11 return JSONResponse({"hello": "world"}) 1ghijkl

12 

13 

14app.include_router(router) 1abcdef

15 

16client = TestClient(app) 1abcdef

17 

18 

19def test_sub_router(): 1abcdef

20 response = client.get("/items/") 1ghijkl

21 assert response.status_code == 200, response.text 1ghijkl

22 assert response.json() == {"hello": "world"} 1ghijkl