Skip to content

Commit c5f1ce8

Browse files
dbasunagclaude
andauthored
fix: label tests needed update to accomodate mcp labels (#1362)
* fix: label tests needed update to accomodate mcp labels Signed-off-by: Debarati Basu-Nag <dbasunag@redhat.com> Co-Authored-By: Claude <noreply@anthropic.com> * fix: address review comments Signed-off-by: Debarati Basu-Nag <dbasunag@redhat.com> Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c74eb5a commit c5f1ce8

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

tests/model_registry/model_catalog/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ def labels_configmap_patch(
374374
"name": "test-dynamic",
375375
"displayName": "Dynamic Test Label",
376376
"description": "A label added during test execution",
377+
"assetType": "models",
377378
},
378379
{
379380
"name": "mcp-test-label",
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from typing import Any
2+
3+
import pytest
4+
from kubernetes.dynamic import DynamicClient
5+
6+
from tests.model_registry.model_catalog.metadata.utils import get_labels_from_configmaps
7+
8+
9+
@pytest.fixture()
10+
def expected_labels_by_asset_type(
11+
request: pytest.FixtureRequest,
12+
admin_client: DynamicClient,
13+
model_registry_namespace: str,
14+
) -> list[dict[str, Any]]:
15+
"""Get expected labels from ConfigMaps, filtered by asset type from the test's parametrize."""
16+
asset_type = request.param
17+
all_labels = get_labels_from_configmaps(admin_client=admin_client, namespace=model_registry_namespace)
18+
return [label for label in all_labels if label.get("assetType") == asset_type]

tests/model_registry/model_catalog/metadata/test_labels_endpoint.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing import Any, Literal
22

33
import pytest
44
import structlog
@@ -19,27 +19,28 @@ class TestLabelsEndpoint:
1919
"""Test class for the model catalog labels endpoint."""
2020

2121
@pytest.mark.smoke
22+
@pytest.mark.parametrize(
23+
"expected_labels_by_asset_type, asset_type",
24+
[
25+
pytest.param("models", "models", id="test_models"),
26+
pytest.param("mcp_servers", "mcp_servers", id="test_mcp_servers"),
27+
],
28+
indirect=["expected_labels_by_asset_type"],
29+
)
2230
def test_labels_endpoint_default_data(
2331
self,
24-
admin_client: DynamicClient,
25-
model_registry_namespace: str,
2632
model_catalog_rest_url: list[str],
33+
expected_labels_by_asset_type: list[dict[str, Any]],
34+
asset_type: Literal["models", "mcp_servers"],
2735
):
2836
"""
2937
Smoke test: Validate default labels from ConfigMaps are returned by the endpoint.
3038
"""
31-
LOGGER.info("Testing labels endpoint with default data")
32-
33-
# Get expected labels from ConfigMaps
34-
expected_labels = get_labels_from_configmaps(admin_client=admin_client, namespace=model_registry_namespace)
35-
36-
# Get labels from API
39+
LOGGER.info(f"Testing labels endpoint with default data for asset type: {asset_type}")
3740
api_labels = get_labels_from_api(
38-
model_catalog_rest_url=model_catalog_rest_url[0], user_token=get_openshift_token()
41+
model_catalog_rest_url=model_catalog_rest_url[0], user_token=get_openshift_token(), asset_type=asset_type
3942
)
40-
41-
# Verify they match
42-
verify_labels_match(expected_labels=expected_labels, api_labels=api_labels)
43+
verify_labels_match(expected_labels=expected_labels_by_asset_type, api_labels=api_labels)
4344

4445
@pytest.mark.tier1
4546
def test_labels_endpoint_configmap_updates(
@@ -65,7 +66,7 @@ def _check_updated_labels():
6566

6667
# Split expected labels by asset type
6768
mcp_expected_labels = [label for label in all_expected_labels if label.get("assetType") == "mcp_servers"]
68-
model_expected_labels = [label for label in all_expected_labels if label not in mcp_expected_labels]
69+
model_expected_labels = [label for label in all_expected_labels if label.get("assetType") == "models"]
6970

7071
# Verify default /labels returns only model labels (no MCP cross-contamination)
7172
api_labels = get_labels_from_api(model_catalog_rest_url=url, user_token=token)

0 commit comments

Comments
 (0)