File size: 1,442 Bytes
6c6fa04 99d5f49 6c6fa04 | 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 41 42 43 44 45 | from __future__ import annotations
import unittest
try:
import fastapi # noqa: F401
import gradio # noqa: F401
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()
|