Skip to content

Commit 1e1e28f

Browse files
authored
test: add source label search validation (#730)
Add comprehensive tests for model catalog search functionality including: - Search by source label (Red Hat AI and Red Hat AI Validated) - Invalid source label handling - Combined source label queries - Model matching with source filters Refactor existing fixtures to support parameterized source selection for better test reusability across different catalog sources.
1 parent 79b1dea commit 1e1e28f

File tree

4 files changed

+142
-11
lines changed

4 files changed

+142
-11
lines changed

tests/model_registry/model_catalog/conftest.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,14 @@ def user_token_for_api_calls(
147147

148148

149149
@pytest.fixture(scope="class")
150-
def randomly_picked_model_from_default_catalog(
151-
model_catalog_rest_url: list[str], user_token_for_api_calls: str
150+
def randomly_picked_model(
151+
model_catalog_rest_url: list[str], user_token_for_api_calls: str, request: pytest.FixtureRequest
152152
) -> dict[Any, Any]:
153-
url = f"{model_catalog_rest_url[0]}models?source={REDHAT_AI_CATALOG_ID}&pageSize=100"
153+
"""Pick a random model"""
154+
param = getattr(request, "param", {})
155+
source = param.get("source", REDHAT_AI_CATALOG_ID)
156+
LOGGER.info(f"Picking random model from {source}")
157+
url = f"{model_catalog_rest_url[0]}models?source={source}&pageSize=100"
154158
result = execute_get_command(
155159
url=url,
156160
headers=get_rest_headers(token=user_token_for_api_calls),

tests/model_registry/model_catalog/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@
2727
}
2828
REDHAT_AI_CATALOG_ID: str = next(iter(DEFAULT_CATALOGS))
2929
DEFAULT_CATALOG_FILE: str = DEFAULT_CATALOGS[REDHAT_AI_CATALOG_ID]["properties"]["yamlCatalogPath"]
30+
VALIDATED_CATALOG_ID: str = tuple(DEFAULT_CATALOGS.keys())[1]
31+
32+
REDHATI_AI_FILTER: str = "Red+Hat+AI"
33+
REDHATI_AI_VALIDATED_FILTER = "Red+Hat+AI+Validated"

tests/model_registry/model_catalog/test_default_model_catalog.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,41 +156,41 @@ def test_model_catalog_default_catalog_sources(
156156
def test_model_default_catalog_get_models_by_source(
157157
self: Self,
158158
model_catalog_rest_url: list[str],
159-
randomly_picked_model_from_default_catalog: dict[Any, Any],
159+
randomly_picked_model: dict[Any, Any],
160160
):
161161
"""
162162
Validate a specific user can access models api for model catalog associated with a default source
163163
"""
164-
LOGGER.info(f"picked model: {randomly_picked_model_from_default_catalog}")
165-
assert randomly_picked_model_from_default_catalog
164+
LOGGER.info(f"picked model: {randomly_picked_model}")
165+
assert randomly_picked_model
166166

167167
def test_model_default_catalog_get_model_by_name(
168168
self: Self,
169169
model_catalog_rest_url: list[str],
170170
user_token_for_api_calls: str,
171-
randomly_picked_model_from_default_catalog: dict[Any, Any],
171+
randomly_picked_model: dict[Any, Any],
172172
):
173173
"""
174174
Validate a specific user can access get Model by name associated with a default source
175175
"""
176-
model_name = randomly_picked_model_from_default_catalog["name"]
176+
model_name = randomly_picked_model["name"]
177177
result = execute_get_command(
178178
url=f"{model_catalog_rest_url[0]}sources/{REDHAT_AI_CATALOG_ID}/models/{model_name}",
179179
headers=get_rest_headers(token=user_token_for_api_calls),
180180
)
181-
differences = list(diff(randomly_picked_model_from_default_catalog, result))
181+
differences = list(diff(randomly_picked_model, result))
182182
assert not differences, f"Expected no differences in model information for {model_name}: {differences}"
183183

184184
def test_model_default_catalog_get_model_artifact(
185185
self: Self,
186186
model_catalog_rest_url: list[str],
187187
user_token_for_api_calls: str,
188-
randomly_picked_model_from_default_catalog: dict[Any, Any],
188+
randomly_picked_model: dict[Any, Any],
189189
):
190190
"""
191191
Validate a specific user can access get Model artifacts for model associated with default source
192192
"""
193-
model_name = randomly_picked_model_from_default_catalog["name"]
193+
model_name = randomly_picked_model["name"]
194194
result = execute_get_command(
195195
url=f"{model_catalog_rest_url[0]}sources/{REDHAT_AI_CATALOG_ID}/models/{model_name}/artifacts",
196196
headers=get_rest_headers(token=user_token_for_api_calls),
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import pytest
2+
from dictdiffer import diff
3+
4+
from simple_logger.logger import get_logger
5+
from typing import Self, Any
6+
from tests.model_registry.model_catalog.constants import (
7+
REDHATI_AI_FILTER,
8+
REDHATI_AI_VALIDATED_FILTER,
9+
REDHAT_AI_CATALOG_ID,
10+
VALIDATED_CATALOG_ID,
11+
)
12+
from tests.model_registry.model_catalog.utils import (
13+
execute_get_command,
14+
)
15+
16+
LOGGER = get_logger(name=__name__)
17+
pytestmark = [
18+
pytest.mark.usefixtures("updated_dsc_component_state_scope_session", "model_registry_namespace", "test_idp_user")
19+
]
20+
21+
22+
class TestSearchModelCatalog:
23+
@pytest.mark.smoke
24+
def test_search_model_catalog_source_label(
25+
self: Self, model_catalog_rest_url: list[str], model_registry_rest_headers: str
26+
):
27+
"""
28+
RHOAIENG-33656: Validate search model catalog by source label
29+
"""
30+
31+
result = execute_get_command(
32+
url=f"{model_catalog_rest_url[0]}models?sourceLabel={REDHATI_AI_FILTER}&pageSize=100",
33+
headers=model_registry_rest_headers,
34+
)
35+
redhai_ai_filter_moldels_size = result["size"]
36+
37+
result = execute_get_command(
38+
url=f"{model_catalog_rest_url[0]}models?sourceLabel={REDHATI_AI_VALIDATED_FILTER}&pageSize=100",
39+
headers=model_registry_rest_headers,
40+
)
41+
redhai_ai_validated_filter_models_size = result["size"]
42+
43+
result = execute_get_command(
44+
url=f"{model_catalog_rest_url[0]}models?pageSize=100", headers=model_registry_rest_headers
45+
)
46+
no_filtered_models_size = result["size"]
47+
48+
result = execute_get_command(
49+
url=(
50+
f"{model_catalog_rest_url[0]}models?"
51+
f"sourceLabel={REDHATI_AI_VALIDATED_FILTER},{REDHATI_AI_FILTER}&pageSize=100"
52+
),
53+
headers=model_registry_rest_headers,
54+
)
55+
both_filtered_models_size = result["size"]
56+
57+
assert no_filtered_models_size == both_filtered_models_size
58+
assert redhai_ai_filter_moldels_size + redhai_ai_validated_filter_models_size == both_filtered_models_size
59+
60+
def test_search_model_catalog_invalid_source_label(
61+
self: Self, model_catalog_rest_url: list[str], model_registry_rest_headers: str
62+
):
63+
"""
64+
RHOAIENG-33656:
65+
Validate search model catalog by invalid source label
66+
"""
67+
68+
result = execute_get_command(
69+
url=f"{model_catalog_rest_url[0]}/models?sourceLabel=null&pageSize=100", headers=model_registry_rest_headers
70+
)
71+
null_size = result["size"]
72+
73+
result = execute_get_command(
74+
url=f"{model_catalog_rest_url[0]}/models?sourceLabel=invalid&pageSize=100",
75+
headers=model_registry_rest_headers,
76+
)
77+
invalid_size = result["size"]
78+
79+
assert null_size == invalid_size == 0, (
80+
"Expected 0 models for null and invalid source label found {null_size} and {invalid_size}"
81+
)
82+
83+
@pytest.mark.parametrize(
84+
"randomly_picked_model,source_filter",
85+
[
86+
pytest.param(
87+
{"source": VALIDATED_CATALOG_ID},
88+
REDHATI_AI_VALIDATED_FILTER,
89+
id="test_search_model_catalog_redhat_ai_validated",
90+
),
91+
pytest.param(
92+
{"source": REDHAT_AI_CATALOG_ID}, REDHATI_AI_FILTER, id="test_search_model_catalog_redhat_ai_default"
93+
),
94+
],
95+
indirect=["randomly_picked_model"],
96+
)
97+
def test_search_model_catalog_match(
98+
self: Self,
99+
model_catalog_rest_url: list[str],
100+
model_registry_rest_headers: str,
101+
randomly_picked_model: dict[Any, Any],
102+
source_filter: str,
103+
):
104+
"""
105+
RHOAIENG-33656: Validate search model catalog by match
106+
"""
107+
random_model = randomly_picked_model
108+
random_model_name = random_model["name"]
109+
LOGGER.info(f"random_model_name: {random_model_name}")
110+
result = execute_get_command(
111+
url=(
112+
f"{model_catalog_rest_url[0]}/models?"
113+
f"sourceLabel={source_filter}&"
114+
f"filterQuery=name='{random_model_name}'&pageSize=100"
115+
),
116+
headers=model_registry_rest_headers,
117+
)
118+
assert random_model_name == result["items"][0]["name"]
119+
assert result["size"] == 1
120+
121+
differences = list(diff(random_model, result["items"][0]))
122+
assert not differences, f"Expected no differences in model information for {random_model_name}: {differences}"
123+
LOGGER.info("Model information matches")

0 commit comments

Comments
 (0)