Skip to content

Commit 30ce86c

Browse files
authored
test: validate model_type field in custom properties (#1016)
1 parent 4ae271b commit 30ce86c

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

tests/model_registry/model_catalog/metadata/test_custom_properties.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
from kubernetes.dynamic import DynamicClient
55
from simple_logger.logger import get_logger
66

7-
from tests.model_registry.model_catalog.constants import VALIDATED_CATALOG_ID
7+
from tests.model_registry.model_catalog.constants import VALIDATED_CATALOG_ID, REDHAT_AI_CATALOG_ID
88
from tests.model_registry.model_catalog.metadata.utils import (
99
extract_custom_property_values,
1010
validate_custom_properties_structure,
1111
validate_custom_properties_match_metadata,
1212
get_metadata_from_catalog_pod,
1313
)
14-
from tests.model_registry.utils import get_model_catalog_pod
14+
from tests.model_registry.utils import get_model_catalog_pod, execute_get_command
1515

1616
LOGGER = get_logger(name=__name__)
1717

@@ -68,3 +68,45 @@ def test_custom_properties_match_metadata(
6868
metadata = get_metadata_from_catalog_pod(model_catalog_pod=model_catalog_pods[0], model_name=model_name)
6969

7070
assert validate_custom_properties_match_metadata(api_props, metadata)
71+
72+
@pytest.mark.parametrize("catalog_id", [REDHAT_AI_CATALOG_ID, VALIDATED_CATALOG_ID])
73+
def test_model_type_field_in_custom_properties(
74+
self,
75+
catalog_id: str,
76+
model_catalog_rest_url: list[str],
77+
model_registry_rest_headers: dict[str, str],
78+
):
79+
"""
80+
RHOAIENG-41720: Test that all models have model_type with valid values: "generative", "predictive", "unknown".
81+
"""
82+
valid_model_types = {"generative", "predictive", "unknown"}
83+
84+
response = execute_get_command(
85+
url=f"{model_catalog_rest_url[0]}models?source={catalog_id}&pageSize=100",
86+
headers=model_registry_rest_headers,
87+
)
88+
models = response["items"]
89+
90+
LOGGER.info(f"Validating model_type field for {len(models)} models from catalog '{catalog_id}'")
91+
92+
validation_errors = []
93+
94+
for model in models:
95+
custom_properties = model.get("customProperties", {})
96+
97+
if "model_type" not in custom_properties:
98+
validation_errors.append(f"Model '{model.get('name')}' missing model_type in customProperties")
99+
continue
100+
101+
model_type_value = custom_properties["model_type"]["string_value"]
102+
if model_type_value not in valid_model_types:
103+
validation_errors.append(
104+
f"Model '{model.get('name')}' has invalid model_type: '{model_type_value}'. "
105+
f"Expected one of: {valid_model_types}"
106+
)
107+
108+
assert not validation_errors, (
109+
f"model_type validation failed for {len(validation_errors)} models:\n" + "\n".join(validation_errors)
110+
)
111+
112+
LOGGER.info(f"All {len(models)} models in catalog '{catalog_id}' have valid model_type values")

0 commit comments

Comments
 (0)