| from __future__ import annotations |
|
|
| import unittest |
|
|
|
|
| try: |
| import fastapi |
| import gradio |
| from fastapi.testclient import TestClient |
|
|
| UI_DEPENDENCIES_AVAILABLE = True |
| except ImportError: |
| UI_DEPENDENCIES_AVAILABLE = False |
|
|
|
|
| @unittest.skipUnless(UI_DEPENDENCIES_AVAILABLE, "FastAPI and Gradio are not installed") |
| class UIRoutingTests(unittest.TestCase): |
| @classmethod |
| def setUpClass(cls) -> None: |
| from app import app |
|
|
| cls.client = TestClient(app) |
|
|
| def test_root_redirects_to_canonical_dashboard_url(self) -> None: |
| response = self.client.get("/", follow_redirects=False) |
| self.assertEqual(response.status_code, 302) |
| self.assertEqual(response.headers["location"], "/dashboard/") |
|
|
| def test_dashboard_html_uses_dashboard_root(self) -> None: |
| response = self.client.get("/dashboard/") |
| self.assertEqual(response.status_code, 200) |
| self.assertIn("/dashboard", response.text) |
|
|
| def test_mcp_discovery_reports_both_transports(self) -> None: |
| response = self.client.get("/mcp-health") |
| self.assertEqual(response.status_code, 200) |
| payload = response.json() |
| self.assertEqual(payload["custom_mcp_url"], "/mcp/") |
| self.assertEqual(payload["gradio_mcp_url"], "/dashboard/gradio_api/mcp/") |
| self.assertGreater(payload["custom_tool_count"], 0) |
|
|
|
|
| if __name__ == "__main__": |
| unittest.main() |
|
|