mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
Fixing test
This commit is contained in:
parent
39bf7a9f7c
commit
d99cf81386
1 changed files with 17 additions and 6 deletions
|
|
@ -2621,26 +2621,37 @@ def test_get_prompt_spec_for_db_prompt_with_versions():
|
|||
|
||||
def test_root_redirect_when_docs_url_not_root_and_redirect_url_set(monkeypatch):
|
||||
from litellm.proxy.proxy_server import cleanup_router_config_variables
|
||||
from litellm.proxy.utils import _get_docs_url
|
||||
from fastapi.responses import RedirectResponse
|
||||
|
||||
cleanup_router_config_variables()
|
||||
filepath = os.path.dirname(os.path.abspath(__file__))
|
||||
config_fp = f"{filepath}/test_configs/test_config_no_auth.yaml"
|
||||
# Ensure docs are mounted on a non-root path to trigger redirect logic
|
||||
monkeypatch.setenv("DOCS_URL", "/docs")
|
||||
|
||||
test_redirect_url = "/ui"
|
||||
monkeypatch.setenv("ROOT_REDIRECT_URL", test_redirect_url)
|
||||
|
||||
asyncio.run(initialize(config=config_fp, debug=True))
|
||||
|
||||
docs_url = getattr(app, "docs_url", None) or "/docs"
|
||||
docs_url = _get_docs_url()
|
||||
root_redirect_url = os.getenv("ROOT_REDIRECT_URL")
|
||||
|
||||
# Remove any existing "/" route that might interfere
|
||||
routes_to_remove = []
|
||||
for route in app.routes:
|
||||
if hasattr(route, "path") and route.path == "/":
|
||||
if hasattr(route, "methods") and "GET" in route.methods:
|
||||
routes_to_remove.append(route)
|
||||
elif not hasattr(route, "methods"): # Catch-all routes
|
||||
routes_to_remove.append(route)
|
||||
|
||||
for route in routes_to_remove:
|
||||
app.routes.remove(route)
|
||||
|
||||
# Add the redirect route if conditions are met (matching the actual implementation)
|
||||
if docs_url != "/" and root_redirect_url:
|
||||
for route in app.routes:
|
||||
if hasattr(route, "path") and route.path == "/" and hasattr(route, "methods") and "GET" in route.methods:
|
||||
app.routes.remove(route)
|
||||
break
|
||||
|
||||
@app.get("/", include_in_schema=False)
|
||||
async def root_redirect():
|
||||
return RedirectResponse(url=root_redirect_url)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue