Coverage for tests / test_router_redirect_slashes.py: 100%
26 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
1from fastapi import APIRouter, FastAPI 1ijkl
2from fastapi.testclient import TestClient 1ijkl
5def test_redirect_slashes_enabled(): 1ijkl
6 app = FastAPI() 1abcd
7 router = APIRouter() 1abcd
9 @router.get("/hello/") 1abcd
10 def hello_page() -> str: 1abcd
11 return "Hello, World!" 1abcd
13 app.include_router(router) 1abcd
15 client = TestClient(app) 1abcd
17 response = client.get("/hello/", follow_redirects=False) 1abcd
18 assert response.status_code == 200 1abcd
20 response = client.get("/hello", follow_redirects=False) 1abcd
21 assert response.status_code == 307 1abcd
24def test_redirect_slashes_disabled(): 1ijkl
25 app = FastAPI(redirect_slashes=False) 1efgh
26 router = APIRouter() 1efgh
28 @router.get("/hello/") 1efgh
29 def hello_page() -> str: 1efgh
30 return "Hello, World!" 1efgh
32 app.include_router(router) 1efgh
34 client = TestClient(app) 1efgh
36 response = client.get("/hello/", follow_redirects=False) 1efgh
37 assert response.status_code == 200 1efgh
39 response = client.get("/hello", follow_redirects=False) 1efgh
40 assert response.status_code == 404 1efgh