Skip to content

Commit 23f1a19

Browse files
committed
fix: normalize model names in sorting tests
Strip source prefixes from database queries and exclude unsortable model-artifact items from sorting validation to match API response format. Signed-off-by: fege <fmosca@redhat.com>
1 parent ea3d10b commit 23f1a19

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

tests/model_registry/model_catalog/db_constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
# Models are ordered by their overall_average (accuracy) value from artifact properties.
196196
# Only returns the model name column for easy comparison with API results.
197197
GET_MODELS_BY_ACCURACY_DB_QUERY = """
198-
SELECT c.name
198+
SELECT SPLIT_PART(c.name, ':', 2) AS name
199199
FROM "ArtifactProperty" ap
200200
JOIN "Artifact" a ON a.id = ap.artifact_id
201201
JOIN "Attribution" attr ON attr.artifact_id = a.id
@@ -210,7 +210,7 @@
210210
# Models are ordered by their overall_average (accuracy) value from artifact properties.
211211
# The tasks field is stored as a JSON array, so we use LIKE pattern matching
212212
GET_MODELS_BY_ACCURACY_WITH_TASK_FILTER_DB_QUERY = """
213-
SELECT c.name
213+
SELECT SPLIT_PART(c.name, ':', 2) AS name
214214
FROM "ArtifactProperty" ap
215215
JOIN "Artifact" a ON a.id = ap.artifact_id
216216
JOIN "Attribution" attr ON attr.artifact_id = a.id

tests/model_registry/model_catalog/huggingface/test_huggingface_model_sorting.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ def test_huggingface_models_sorting_works_correctly(
4949
sort_order=sort_order,
5050
model_catalog_rest_url=model_catalog_rest_url,
5151
model_registry_rest_headers=model_registry_rest_headers,
52+
source_label="HuggingFace Source mixed",
5253
)

tests/model_registry/model_catalog/sorting/test_model_artifacts_sorting.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ def test_artifacts_sorting_works_correctly(
9494
sort_order=sort_order,
9595
)
9696

97-
assert validate_items_sorted_correctly(response["items"], order_by, sort_order)
97+
# Exclude model-artifact items as they lack sortable fields like "name"
98+
items = [item for item in response["items"] if item.get("artifactType") != "model-artifact"]
99+
assert validate_items_sorted_correctly(items, order_by, sort_order)
98100

99101

100102
@pytest.mark.downstream_only

tests/model_registry/model_catalog/sorting/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ def assert_model_sorting(
517517
sort_order: str | None,
518518
model_catalog_rest_url: list[str],
519519
model_registry_rest_headers: dict[str, str],
520+
source_label: str | None = None,
520521
) -> None:
521522
LOGGER.info(f"Testing models sorting: orderBy={order_by}, sortOrder={sort_order}")
522523

@@ -525,6 +526,7 @@ def assert_model_sorting(
525526
model_registry_rest_headers=model_registry_rest_headers,
526527
order_by=order_by,
527528
sort_order=sort_order,
529+
source_label=source_label,
528530
)
529531

530532
assert validate_items_sorted_correctly(items=response["items"], field=order_by, order=sort_order)

0 commit comments

Comments
 (0)