Coverage for tests/test_include_route.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from fastapi import APIRouter, FastAPI, Request 1abcde

2from fastapi.responses import JSONResponse 1abcde

3from fastapi.testclient import TestClient 1abcde

4 

5app = FastAPI() 1abcde

6router = APIRouter() 1abcde

7 

8 

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

10def read_items(request: Request): 1abcde

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

12 

13 

14app.include_router(router) 1abcde

15 

16client = TestClient(app) 1abcde

17 

18 

19def test_sub_router(): 1abcde

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

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

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