Coverage for tests / test_router_redirect_slashes.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1from fastapi import APIRouter, FastAPI 1ghij

2from fastapi.testclient import TestClient 1ghij

3 

4 

5def test_redirect_slashes_enabled(): 1ghij

6 app = FastAPI() 1abc

7 router = APIRouter() 1abc

8 

9 @router.get("/hello/") 1abc

10 def hello_page() -> str: 1abc

11 return "Hello, World!" 1abc

12 

13 app.include_router(router) 1abc

14 

15 client = TestClient(app) 1abc

16 

17 response = client.get("/hello/", follow_redirects=False) 1abc

18 assert response.status_code == 200 1abc

19 

20 response = client.get("/hello", follow_redirects=False) 1abc

21 assert response.status_code == 307 1abc

22 

23 

24def test_redirect_slashes_disabled(): 1ghij

25 app = FastAPI(redirect_slashes=False) 1def

26 router = APIRouter() 1def

27 

28 @router.get("/hello/") 1def

29 def hello_page() -> str: 1def

30 return "Hello, World!" 1def

31 

32 app.include_router(router) 1def

33 

34 client = TestClient(app) 1def

35 

36 response = client.get("/hello/", follow_redirects=False) 1def

37 assert response.status_code == 200 1def

38 

39 response = client.get("/hello", follow_redirects=False) 1def

40 assert response.status_code == 404 1def