Skip to content

Commit 528cb28

Browse files
authored
Fix Unit Tests to Handle UI-Disabled Mode closes #378 (#379)
Signed-off-by: Mihai Criveti <[email protected]>
1 parent 07076f1 commit 528cb28

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

tests/unit/mcpgateway/test_main.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import pytest
1919

2020
# First-Party
21+
from mcpgateway.config import settings
2122
from mcpgateway.models import InitializeResult, ResourceContent, ServerCapabilities
2223
from mcpgateway.schemas import (
2324
PromptRead,
@@ -209,10 +210,20 @@ def test_ready_check(self, test_client):
209210
assert response.json()["status"] == "ready"
210211

211212
def test_root_redirect(self, test_client):
212-
"""Test that root path redirects to admin UI."""
213+
"""Test that root path behavior depends on UI configuration."""
213214
response = test_client.get("/", follow_redirects=False)
214-
assert response.status_code == 303
215-
assert response.headers["location"] == "/admin"
215+
216+
# Check if UI is enabled
217+
if settings.mcpgateway_ui_enabled:
218+
# When UI is enabled, should redirect to admin
219+
assert response.status_code == 303
220+
assert response.headers["location"] == "/admin"
221+
else:
222+
# When UI is disabled, should return API info
223+
assert response.status_code == 200
224+
data = response.json()
225+
assert data["name"] == "MCP_Gateway"
226+
assert data["ui_enabled"] is False
216227

217228
def test_static_files(self, test_client):
218229
"""Test static file serving (when files don't exist)."""

tests/unit/mcpgateway/test_ui_version.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ def auth_headers() -> Dict[str, str]:
6767
# assert "App:" in html or "Application:" in html
6868

6969

70+
@pytest.mark.skipif(
71+
not settings.mcpgateway_ui_enabled,
72+
reason="Admin UI tests require MCPGATEWAY_UI_ENABLED=true"
73+
)
7074
def test_admin_ui_contains_version_tab(test_client: TestClient, auth_headers: Dict[str, str]):
71-
"""
72-
The Admin dashboard must contain the "Version & Environment Info" tab.
73-
"""
75+
"""The Admin dashboard must contain the "Version & Environment Info" tab."""
7476
resp = test_client.get("/admin", headers=auth_headers)
7577
assert resp.status_code == 200
7678
assert 'id="tab-version-info"' in resp.text

0 commit comments

Comments
 (0)