Upload 61 files
Browse files- tests/test_ui_routing.py +36 -0
tests/test_ui_routing.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import unittest
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
try:
|
| 7 |
+
import fastapi # noqa: F401
|
| 8 |
+
import gradio # noqa: F401
|
| 9 |
+
from fastapi.testclient import TestClient
|
| 10 |
+
|
| 11 |
+
UI_DEPENDENCIES_AVAILABLE = True
|
| 12 |
+
except ImportError:
|
| 13 |
+
UI_DEPENDENCIES_AVAILABLE = False
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@unittest.skipUnless(UI_DEPENDENCIES_AVAILABLE, "FastAPI and Gradio are not installed")
|
| 17 |
+
class UIRoutingTests(unittest.TestCase):
|
| 18 |
+
@classmethod
|
| 19 |
+
def setUpClass(cls) -> None:
|
| 20 |
+
from app import app
|
| 21 |
+
|
| 22 |
+
cls.client = TestClient(app)
|
| 23 |
+
|
| 24 |
+
def test_root_redirects_to_canonical_dashboard_url(self) -> None:
|
| 25 |
+
response = self.client.get("/", follow_redirects=False)
|
| 26 |
+
self.assertEqual(response.status_code, 302)
|
| 27 |
+
self.assertEqual(response.headers["location"], "/dashboard/")
|
| 28 |
+
|
| 29 |
+
def test_dashboard_html_uses_dashboard_root(self) -> None:
|
| 30 |
+
response = self.client.get("/dashboard/")
|
| 31 |
+
self.assertEqual(response.status_code, 200)
|
| 32 |
+
self.assertIn("/dashboard", response.text)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
unittest.main()
|