forked from fastapi/fastapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_router_redirect_slashes.py
More file actions
40 lines (26 loc) · 974 Bytes
/
test_router_redirect_slashes.py
File metadata and controls
40 lines (26 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from fastapi import APIRouter, FastAPI
from fastapi.testclient import TestClient
def test_redirect_slashes_enabled():
app = FastAPI()
router = APIRouter()
@router.get("/hello/")
def hello_page() -> str:
return "Hello, World!"
app.include_router(router)
client = TestClient(app)
response = client.get("/hello/", follow_redirects=False)
assert response.status_code == 200
response = client.get("/hello", follow_redirects=False)
assert response.status_code == 307
def test_redirect_slashes_disabled():
app = FastAPI(redirect_slashes=False)
router = APIRouter()
@router.get("/hello/")
def hello_page() -> str:
return "Hello, World!"
app.include_router(router)
client = TestClient(app)
response = client.get("/hello/", follow_redirects=False)
assert response.status_code == 200
response = client.get("/hello", follow_redirects=False)
assert response.status_code == 404