forked from opendatahub-io/opendatahub-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_named_queries.py
More file actions
89 lines (81 loc) · 3.16 KB
/
test_named_queries.py
File metadata and controls
89 lines (81 loc) · 3.16 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from typing import Self
import pytest
from tests.model_registry.mcp_servers.constants import CALCULATOR_PROVIDER, CALCULATOR_SERVER_NAME
from tests.model_registry.utils import execute_get_command
from utilities.opendatahub_logger import get_logger
LOGGER = get_logger(name=__name__)
@pytest.mark.usefixtures("mcp_servers_configmap_patch")
class TestMCPServerNamedQueries:
"""Tests for MCP server named query functionality."""
@pytest.mark.parametrize(
"named_query, expected_custom_properties",
[
pytest.param(
"production_ready",
{"verifiedSource": True},
id="production_ready",
),
pytest.param(
"security_focused",
{"sast": True, "readOnlyTools": True},
id="security_focused",
),
],
)
def test_named_query_execution(
self: Self,
mcp_catalog_rest_urls: list[str],
model_registry_rest_headers: dict[str, str],
named_query: str,
expected_custom_properties: dict[str, bool],
):
"""TC-API-011: Test executing a named query filters servers by custom properties."""
response = execute_get_command(
url=f"{mcp_catalog_rest_urls[0]}mcp_servers",
headers=model_registry_rest_headers,
params={"namedQuery": named_query},
)
items = response["items"]
assert len(items) == 1, f"Expected 1 server matching '{named_query}', got {len(items)}"
assert items[0]["name"] == CALCULATOR_SERVER_NAME
custom_props = items[0]["customProperties"]
for prop_name, expected_value in expected_custom_properties.items():
assert custom_props.get(prop_name, {}).get("bool_value") is expected_value, (
f"Expected {prop_name}={expected_value}, got {custom_props.get(prop_name)}"
)
@pytest.mark.parametrize(
"filter_query, expected_count, expected_names",
[
pytest.param(
f"provider='{CALCULATOR_PROVIDER}'",
1,
{CALCULATOR_SERVER_NAME},
id="matching_overlap",
),
pytest.param(
"provider='Weather Community'",
0,
set(),
id="no_overlap",
),
],
)
def test_named_query_combined_with_filter_query(
self: Self,
mcp_catalog_rest_urls: list[str],
model_registry_rest_headers: dict[str, str],
filter_query: str,
expected_count: int,
expected_names: set[str],
):
"""TC-API-013: Test combining namedQuery with filterQuery."""
response = execute_get_command(
url=f"{mcp_catalog_rest_urls[0]}mcp_servers",
headers=model_registry_rest_headers,
params={"namedQuery": "production_ready", "filterQuery": filter_query},
)
items = response["items"]
assert len(items) == expected_count, (
f"Expected {expected_count} server(s) for namedQuery + '{filter_query}', got {len(items)}"
)
assert {server["name"] for server in items} == expected_names