From dba96e7a722995406edeedd4713bd01ad3ec5685 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sun, 28 Jun 2026 14:19:03 -0500 Subject: [PATCH] ui redirects --- src/transcription/app.py | 11 +++++++++ tests/ui/test_pages_registration.py | 36 +++++++++++++++++++---------- tests/ui/test_upload_page.py | 14 +++++++++++ 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/transcription/app.py b/src/transcription/app.py index 02f5cdf..d1df106 100644 --- a/src/transcription/app.py +++ b/src/transcription/app.py @@ -6,6 +6,8 @@ from contextlib import AsyncExitStack from contextlib import asynccontextmanager from fastapi import FastAPI +from fastapi import status +from fastapi.responses import RedirectResponse from .api.errors import register_error_handlers from .api.health import router as health_router @@ -50,6 +52,15 @@ async def _lifespan(app: FastAPI): def create_app() -> FastAPI: """Create and configure the FastAPI application.""" app = FastAPI(title="Transcription", lifespan=_lifespan) + + @app.get("/", include_in_schema=False) + async def root_redirect() -> RedirectResponse: + return RedirectResponse(url="/ui", status_code=status.HTTP_307_TEMPORARY_REDIRECT) + + @app.get("/ui", include_in_schema=False) + async def ui_redirect() -> RedirectResponse: + return RedirectResponse(url="/ui/upload", status_code=status.HTTP_307_TEMPORARY_REDIRECT) + register_error_handlers(app) register_pages(app) app.include_router(health_router) diff --git a/tests/ui/test_pages_registration.py b/tests/ui/test_pages_registration.py index 6dbcacb..4d7bec1 100644 --- a/tests/ui/test_pages_registration.py +++ b/tests/ui/test_pages_registration.py @@ -1,8 +1,7 @@ """Tests for UI page registration wiring.""" -from fastapi import FastAPI -from fastapi.testclient import TestClient import pytest +from fastapi import FastAPI from transcription.ui import register_pages @@ -11,16 +10,29 @@ from transcription.ui import register_pages class TestPageRegistration: """Verify page registration and route wiring.""" - def test_register_pages_adds_expected_routes(self): - """register_pages wires upload and jobs routes into the app.""" + def test_register_pages_wires_upload_jobs_and_mount(self, monkeypatch): + """register_pages registers pages and mounts NiceGUI at /ui.""" + calls: list[str] = [] + + def _record_upload() -> None: + calls.append("upload") + + def _record_jobs() -> None: + calls.append("jobs") + + def _record_run_with( + _app: FastAPI, + *, + mount_path: str, + show_welcome_message: bool, + ) -> None: + calls.append(f"run_with:{mount_path}:{show_welcome_message}") + + monkeypatch.setattr("transcription.ui.register_upload_page", _record_upload) + monkeypatch.setattr("transcription.ui.register_jobs_page", _record_jobs) + monkeypatch.setattr("transcription.ui.ui.run_with", _record_run_with) + app = FastAPI() register_pages(app) - app.add_api_route("/healthz", lambda: {"status": "ok"}, methods=["GET"]) - client = TestClient(app) - ui_response = client.get("/ui") - health_response = client.get("/healthz") - - assert ui_response.status_code == 200 - assert health_response.status_code == 200 - assert health_response.json() == {"status": "ok"} + assert calls == ["upload", "jobs", "run_with:/ui:False"] diff --git a/tests/ui/test_upload_page.py b/tests/ui/test_upload_page.py index a7f0d2f..dffcb09 100644 --- a/tests/ui/test_upload_page.py +++ b/tests/ui/test_upload_page.py @@ -31,6 +31,20 @@ def client(tmp_path: Path): class TestPageRendering: """Verify the upload page is available and includes the main controls.""" + def test_root_redirects_to_ui(self, client): + """GET / redirects to the UI mount point.""" + response = client.get("/", follow_redirects=False) + + assert response.status_code == 307 + assert response.headers["location"] == "/ui" + + def test_ui_redirects_to_upload(self, client): + """GET /ui redirects to the upload page.""" + response = client.get("/ui", follow_redirects=False) + + assert response.status_code == 307 + assert response.headers["location"] == "/ui/upload" + def test_upload_page_renders_expected_controls(self, client): """GET /ui/upload returns the page shell and upload controls.""" response = client.get("/ui/upload")