Skip to content

Commit 347a341

Browse files
authored
Merge branch 'main' into QE_refactoring-tags
2 parents c51eba9 + 785168e commit 347a341

4 files changed

Lines changed: 142 additions & 0 deletions

File tree

tests/model_registry/mcp_servers/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
CALCULATOR_SERVER_NAME: str = "calculator"
2+
CALCULATOR_PROVIDER: str = "Math Community"
13
MCP_CATALOG_SOURCE_ID: str = "test_mcp_servers"
24
MCP_CATALOG_SOURCE_NAME: str = "Test MCP Servers"
35
MCP_CATALOG_API_PATH: str = "/api/mcp_catalog/v1alpha1/"

tests/model_registry/mcp_servers/search/__init__.py

Whitespace-only changes.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
from typing import Self
2+
3+
import pytest
4+
from simple_logger.logger import get_logger
5+
6+
from tests.model_registry.mcp_servers.constants import CALCULATOR_PROVIDER, CALCULATOR_SERVER_NAME
7+
from tests.model_registry.utils import execute_get_command
8+
9+
LOGGER = get_logger(name=__name__)
10+
11+
12+
@pytest.mark.usefixtures("mcp_servers_configmap_patch")
13+
class TestMCPServerFiltering:
14+
"""RHOAIENG-51584: Tests for MCP server filterQuery functionality."""
15+
16+
@pytest.mark.parametrize(
17+
"filter_query, expected_count, expected_name, field_check",
18+
[
19+
pytest.param(
20+
f"provider='{CALCULATOR_PROVIDER}'",
21+
1,
22+
CALCULATOR_SERVER_NAME,
23+
("provider", CALCULATOR_PROVIDER),
24+
id="by_provider",
25+
),
26+
pytest.param("tags='math'", 1, CALCULATOR_SERVER_NAME, None, id="by_tags"),
27+
],
28+
)
29+
def test_filter_by_field(
30+
self: Self,
31+
mcp_catalog_rest_urls: list[str],
32+
model_registry_rest_headers: dict[str, str],
33+
filter_query: str,
34+
expected_count: int,
35+
expected_name: str,
36+
field_check: tuple[str, str] | None,
37+
):
38+
"""TC-API-003, TC-API-005: Test filtering MCP servers by provider and tags."""
39+
response = execute_get_command(
40+
url=f"{mcp_catalog_rest_urls[0]}mcp_servers",
41+
headers=model_registry_rest_headers,
42+
params={"filterQuery": filter_query},
43+
)
44+
items = response.get("items", [])
45+
assert len(items) == expected_count, (
46+
f"Expected {expected_count} server(s) for '{filter_query}', got {len(items)}"
47+
)
48+
assert items[0]["name"] == expected_name
49+
if field_check:
50+
assert items[0][field_check[0]] == field_check[1]
51+
52+
def test_filter_options(
53+
self: Self,
54+
mcp_catalog_rest_urls: list[str],
55+
model_registry_rest_headers: dict[str, str],
56+
):
57+
"""TC-API-026: Test that filter_options endpoint returns available filter fields."""
58+
url = f"{mcp_catalog_rest_urls[0]}mcp_servers/filter_options"
59+
LOGGER.info(f"Requesting filter_options from: {url}")
60+
61+
response = execute_get_command(
62+
url=url,
63+
headers=model_registry_rest_headers,
64+
)
65+
LOGGER.info(f"filter_options full response: {response}")
66+
67+
filters = response["filters"]
68+
69+
expected_filter_fields = {"description", "provider", "license", "tags"}
70+
actual_filter_fields = set(filters.keys())
71+
assert expected_filter_fields == actual_filter_fields
72+
73+
def test_pagination_with_filters(
74+
self: Self,
75+
mcp_catalog_rest_urls: list[str],
76+
model_registry_rest_headers: dict[str, str],
77+
):
78+
"""TC-API-032: Test that pagination works correctly with filterQuery."""
79+
base_url = f"{mcp_catalog_rest_urls[0]}mcp_servers"
80+
filter_query = "license='MIT'"
81+
82+
# First page
83+
response = execute_get_command(
84+
url=base_url,
85+
headers=model_registry_rest_headers,
86+
params={"filterQuery": filter_query, "pageSize": "1"},
87+
)
88+
first_page_items = response.get("items", [])
89+
assert len(first_page_items) == 1, f"Expected 1 item on first page, got {len(first_page_items)}"
90+
next_page_token = response.get("nextPageToken")
91+
assert next_page_token, "Expected nextPageToken for second page"
92+
93+
# Second page
94+
response = execute_get_command(
95+
url=base_url,
96+
headers=model_registry_rest_headers,
97+
params={"filterQuery": filter_query, "pageSize": "1", "nextPageToken": next_page_token},
98+
)
99+
second_page_items = response.get("items", [])
100+
assert len(second_page_items) == 1, f"Expected 1 item on second page, got {len(second_page_items)}"
101+
102+
collected_names = {first_page_items[0]["name"], second_page_items[0]["name"]}
103+
assert collected_names == {"weather-api", CALCULATOR_SERVER_NAME}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from typing import Self
2+
3+
import pytest
4+
from simple_logger.logger import get_logger
5+
6+
from tests.model_registry.utils import execute_get_command
7+
8+
LOGGER = get_logger(name=__name__)
9+
10+
11+
@pytest.mark.usefixtures("mcp_servers_configmap_patch")
12+
class TestMCPServerOrdering:
13+
"""RHOAIENG-51584: Tests for MCP server ordering functionality."""
14+
15+
@pytest.mark.xfail(reason="RHOAIENG-52448: sortOrder/orderBy not working, fix in PR #2367")
16+
@pytest.mark.parametrize(
17+
"sort_order",
18+
[
19+
pytest.param("ASC", id="ascending"),
20+
pytest.param("DESC", id="descending"),
21+
],
22+
)
23+
def test_ordering_by_name(
24+
self: Self,
25+
mcp_catalog_rest_urls: list[str],
26+
model_registry_rest_headers: dict[str, str],
27+
sort_order: str,
28+
):
29+
"""TC-API-014: Test ordering MCP servers by name ASC/DESC."""
30+
response = execute_get_command(
31+
url=f"{mcp_catalog_rest_urls[0]}mcp_servers",
32+
headers=model_registry_rest_headers,
33+
params={"orderBy": "name", "sortOrder": sort_order},
34+
)
35+
actual_names = [s["name"] for s in response.get("items", [])]
36+
expected_names = sorted(actual_names, reverse=(sort_order == "DESC"))
37+
assert actual_names == expected_names

0 commit comments

Comments
 (0)