Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/model_registry/model_catalog/metadata/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from typing import Any

import pytest
from kubernetes.dynamic import DynamicClient

from tests.model_registry.model_catalog.metadata.utils import get_labels_from_configmaps


@pytest.fixture()
def expected_labels_by_asset_type(
admin_client: DynamicClient,
model_registry_namespace: str,
) -> dict[str, list[dict[str, Any]]]:
"""Get expected labels from ConfigMaps, split by asset type."""
all_labels = get_labels_from_configmaps(admin_client=admin_client, namespace=model_registry_namespace)
mcp_labels = [label for label in all_labels if label.get("assetType") == "mcp_servers"]
model_labels = [label for label in all_labels if label not in mcp_labels]
Comment thread
kami619 marked this conversation as resolved.
Outdated
return {"models": model_labels, "mcp_servers": mcp_labels}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, Literal

import pytest
import structlog
Expand All @@ -19,27 +19,27 @@ class TestLabelsEndpoint:
"""Test class for the model catalog labels endpoint."""

@pytest.mark.smoke
@pytest.mark.parametrize(
"asset_type",
[
pytest.param("models", id="models"),
pytest.param("mcp_servers", id="mcp_servers"),
],
)
Comment on lines +22 to +29
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably we should test the case when no asset type is passed. It should return model labels if we are consistent with the other endpoints that have asset_type

def test_labels_endpoint_default_data(
self,
admin_client: DynamicClient,
model_registry_namespace: str,
model_catalog_rest_url: list[str],
expected_labels_by_asset_type: dict[str, list[dict[str, Any]]],
asset_type: Literal["models", "mcp_servers"],
Comment thread
coderabbitai[bot] marked this conversation as resolved.
):
Comment thread
dbasunag marked this conversation as resolved.
"""
Smoke test: Validate default labels from ConfigMaps are returned by the endpoint.
"""
LOGGER.info("Testing labels endpoint with default data")

# Get expected labels from ConfigMaps
expected_labels = get_labels_from_configmaps(admin_client=admin_client, namespace=model_registry_namespace)

# Get labels from API
LOGGER.info(f"Testing labels endpoint with default data for asset type: {asset_type}")
api_labels = get_labels_from_api(
model_catalog_rest_url=model_catalog_rest_url[0], user_token=get_openshift_token()
model_catalog_rest_url=model_catalog_rest_url[0], user_token=get_openshift_token(), asset_type=asset_type
)

# Verify they match
verify_labels_match(expected_labels=expected_labels, api_labels=api_labels)
verify_labels_match(expected_labels=expected_labels_by_asset_type[asset_type], api_labels=api_labels)

@pytest.mark.tier1
def test_labels_endpoint_configmap_updates(
Expand Down