Coverage for tests/test_router_prefix_with_template.py: 100%

13 statements  

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

1from fastapi import APIRouter, FastAPI 1abcde

2from fastapi.testclient import TestClient 1abcde

3 

4app = FastAPI() 1abcde

5 

6router = APIRouter() 1abcde

7 

8 

9@router.get("/users/{id}") 1abcde

10def read_user(segment: str, id: str): 1abcde

11 return {"segment": segment, "id": id} 1abcde

12 

13 

14app.include_router(router, prefix="/{segment}") 1abcde

15 

16 

17client = TestClient(app) 1abcde

18 

19 

20def test_get(): 1abcde

21 response = client.get("/seg/users/foo") 1abcde

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

23 assert response.json() == {"segment": "seg", "id": "foo"} 1abcde