Browse Source

Add test to demonstrate bug

pull/11160/head
Ricardo Madriz 1 year ago
parent
commit
0e4cdb3bc7
  1. 36
      tests/test_root_path_redirects.py

36
tests/test_root_path_redirects.py

@ -0,0 +1,36 @@
from fastapi import APIRouter, FastAPI
from fastapi.testclient import TestClient
def test_redirects_without_root_path():
app = FastAPI()
router = APIRouter()
@router.get("/hello/")
def hello_page() -> str:
return "Hello, World!"
app.include_router(router)
client = TestClient(app, base_url="http://testserver")
response = client.get("/hello", follow_redirects=False)
assert response.status_code == 307
assert response.headers["location"] == "http://testserver/hello/"
def test_redirects_with_root_path():
app = FastAPI(root_path="/api")
router = APIRouter()
@router.get("/hello/")
def hello_page() -> str:
return "Hello, World!"
app.include_router(router)
client = TestClient(app, base_url="http://testserver")
response = client.get("/hello", follow_redirects=False)
assert response.status_code == 307
assert response.headers["location"] == "http://testserver/api/hello/"
Loading…
Cancel
Save