Skip to content

Commit 04552ad

Browse files
committed
Move version tests to separate file
Signed-off-by: Mihai Criveti <[email protected]>
1 parent 5471b29 commit 04552ad

File tree

2 files changed

+87
-27
lines changed

2 files changed

+87
-27
lines changed

tests/unit/mcpgateway/test_main.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -71,33 +71,6 @@ def test_ready_check(self, test_client):
7171
assert response.status_code == 200
7272
assert response.json()["status"] == "ready"
7373

74-
# Version/admin UI ---------------------------------------------------- #
75-
def test_version_partial_html(self, test_client, auth_headers):
76-
"""Test that /version?partial=true returns an HTML fragment with core info."""
77-
response = test_client.get("/version?partial=true", headers=auth_headers)
78-
assert response.status_code == 200
79-
assert "text/html" in response.headers["content-type"]
80-
81-
content = response.text
82-
# basic sanity checks on returned fragment
83-
assert "<div" in content # should be wrapped in a div
84-
assert "App:" in content # contains application metadata
85-
86-
def test_admin_ui_contains_version_tab(self, test_client, auth_headers):
87-
response = test_client.get("/admin", headers=auth_headers)
88-
assert response.status_code == 200
89-
assert 'id="tab-version-info"' in response.text
90-
assert "Version and Environment Info" in response.text
91-
92-
def test_version_partial_htmx_load(self, test_client, auth_headers):
93-
"""Test an HTMX load for /version?partial=true returns the same HTML fragment."""
94-
response = test_client.get("/version?partial=true", headers=auth_headers)
95-
assert response.status_code == 200
96-
97-
content = response.text
98-
assert "<div" in content # HTML present
99-
assert "App:" in content # metadata present
100-
10174
# Root redirect ------------------------------------------------------- #
10275
def test_root_redirect(self, test_client):
10376
response = test_client.get("/", follow_redirects=False) # ← param name
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Integration tests for /version and the Version tab in the Admin UI.
4+
5+
Copyright 2025
6+
SPDX-License-Identifier: Apache-2.0
7+
Author: Mihai Criveti
8+
"""
9+
10+
import base64
11+
12+
import pytest
13+
from fastapi.testclient import TestClient
14+
15+
from mcpgateway.config import settings # pulls credentials from config
16+
from mcpgateway.main import app # FastAPI application instance
17+
18+
# --------------------------------------------------------------------------- #
19+
# Fixtures #
20+
# --------------------------------------------------------------------------- #
21+
22+
23+
@pytest.fixture(scope="module")
24+
def test_client() -> TestClient:
25+
"""Provide a live TestClient for the FastAPI app."""
26+
with TestClient(app) as client:
27+
yield client
28+
29+
30+
@pytest.fixture
31+
def auth_headers() -> dict[str, str]:
32+
"""
33+
Build a Basic-Auth header from *current* config settings so the tests keep
34+
working even if credentials change via environment variables or .env file.
35+
"""
36+
raw = f"{settings.basic_auth_user}:{settings.basic_auth_password}".encode()
37+
return {"Authorization": "Basic " + base64.b64encode(raw).decode()}
38+
39+
40+
# --------------------------------------------------------------------------- #
41+
# Tests #
42+
# --------------------------------------------------------------------------- #
43+
44+
45+
def test_version_partial_html(test_client: TestClient, auth_headers: dict):
46+
"""
47+
/version?partial=true must return an HTML fragment with core meta-info.
48+
"""
49+
resp = test_client.get("/version?partial=true", headers=auth_headers)
50+
assert resp.status_code == 200
51+
assert resp.headers["content-type"].startswith("text/html")
52+
53+
html = resp.text
54+
assert "<div" in html # fragment is wrapped in a div
55+
assert "App:" in html # application metadata present
56+
57+
58+
def test_admin_ui_contains_version_tab(test_client: TestClient, auth_headers: dict):
59+
"""
60+
Full Admin UI should expose the Version & Environment tab stub.
61+
"""
62+
resp = test_client.get("/admin", headers=auth_headers)
63+
assert resp.status_code == 200
64+
page = resp.text
65+
assert 'id="tab-version-info"' in page
66+
assert "Version and Environment Info" in page
67+
68+
69+
@pytest.mark.parametrize("hx_request", [False, True])
70+
def test_version_partial_htmx_load(
71+
test_client: TestClient,
72+
auth_headers: dict,
73+
hx_request: bool,
74+
):
75+
"""
76+
HTMX-initiated and normal GETs should return the same HTML fragment.
77+
"""
78+
headers = auth_headers.copy()
79+
if hx_request:
80+
headers["HX-Request"] = "true" # header HTMX automatically adds
81+
82+
resp = test_client.get("/version?partial=true", headers=headers)
83+
assert resp.status_code == 200
84+
85+
fragment = resp.text
86+
assert "<div" in fragment
87+
assert "App:" in fragment

0 commit comments

Comments
 (0)