Skip to content

Commit 8e1ab69

Browse files
authored
test: reorganize sorting tests into dedicated module (#922)
Restructured model catalog sorting tests into a dedicated `sorting/` subpackage
1 parent 2472b3a commit 8e1ab69

7 files changed

Lines changed: 372 additions & 345 deletions

File tree

tests/model_registry/model_catalog/sorting/__init__.py

Whitespace-only changes.

tests/model_registry/model_catalog/test_sorting_functionality.py renamed to tests/model_registry/model_catalog/sorting/test_model_artifacts_sorting.py

Lines changed: 1 addition & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import random
44
from ocp_resources.config_map import ConfigMap
55
from simple_logger.logger import get_logger
6-
from tests.model_registry.model_catalog.utils import (
7-
get_models_from_catalog_api,
8-
get_sources_with_sorting,
6+
from tests.model_registry.model_catalog.sorting.utils import (
97
get_artifacts_with_sorting,
108
validate_items_sorted_correctly,
119
verify_custom_properties_sorted,
@@ -17,113 +15,6 @@
1715
pytestmark = [pytest.mark.usefixtures("updated_dsc_component_state_scope_session", "model_registry_namespace")]
1816

1917

20-
class TestModelsSorting:
21-
"""Test sorting functionality for FindModels endpoint"""
22-
23-
@pytest.mark.parametrize(
24-
"order_by,sort_order",
25-
[
26-
("ID", "ASC"),
27-
("ID", "DESC"),
28-
pytest.param(
29-
"NAME",
30-
"ASC",
31-
marks=pytest.mark.xfail(
32-
reason="RHOAIENG-38056: Backend bug - NAME sorting not implemented, falls back to ID sorting"
33-
),
34-
),
35-
pytest.param(
36-
"NAME",
37-
"DESC",
38-
marks=pytest.mark.xfail(
39-
reason="RHOAIENG-38056: Backend bug - NAME sorting not implemented, falls back to ID sorting"
40-
),
41-
),
42-
("CREATE_TIME", "ASC"),
43-
("CREATE_TIME", "DESC"),
44-
("LAST_UPDATE_TIME", "ASC"),
45-
("LAST_UPDATE_TIME", "DESC"),
46-
],
47-
)
48-
def test_models_sorting_works_correctly(
49-
self: Self,
50-
enabled_model_catalog_config_map: ConfigMap,
51-
order_by: str,
52-
sort_order: str,
53-
model_catalog_rest_url: list[str],
54-
model_registry_rest_headers: dict[str, str],
55-
):
56-
"""
57-
RHOAIENG-37260: Test models endpoint sorts correctly by field and order
58-
"""
59-
LOGGER.info(f"Testing models sorting: orderBy={order_by}, sortOrder={sort_order}")
60-
61-
response = get_models_from_catalog_api(
62-
model_catalog_rest_url=model_catalog_rest_url,
63-
model_registry_rest_headers=model_registry_rest_headers,
64-
order_by=order_by,
65-
sort_order=sort_order,
66-
)
67-
68-
assert validate_items_sorted_correctly(response["items"], order_by, sort_order)
69-
70-
71-
class TestSourcesSorting:
72-
"""Test sorting functionality for FindSources endpoint"""
73-
74-
@pytest.mark.parametrize(
75-
"order_by,sort_order",
76-
[
77-
("ID", "ASC"),
78-
("ID", "DESC"),
79-
("NAME", "ASC"),
80-
("NAME", "DESC"),
81-
],
82-
)
83-
def test_sources_sorting_works_correctly(
84-
self: Self,
85-
enabled_model_catalog_config_map: ConfigMap,
86-
order_by: str,
87-
sort_order: str,
88-
model_catalog_rest_url: list[str],
89-
model_registry_rest_headers: dict[str, str],
90-
):
91-
"""
92-
RHOAIENG-37260: Test sources endpoint sorts correctly by supported fields
93-
"""
94-
LOGGER.info(f"Testing sources sorting: orderBy={order_by}, sortOrder={sort_order}")
95-
96-
response = get_sources_with_sorting(
97-
model_catalog_rest_url=model_catalog_rest_url,
98-
model_registry_rest_headers=model_registry_rest_headers,
99-
order_by=order_by,
100-
sort_order=sort_order,
101-
)
102-
103-
assert validate_items_sorted_correctly(response["items"], order_by, sort_order)
104-
105-
@pytest.mark.parametrize("unsupported_field", ["CREATE_TIME", "LAST_UPDATE_TIME"])
106-
def test_sources_rejects_unsupported_fields(
107-
self: Self,
108-
enabled_model_catalog_config_map: ConfigMap,
109-
unsupported_field: str,
110-
model_catalog_rest_url: list[str],
111-
model_registry_rest_headers: dict[str, str],
112-
):
113-
"""
114-
RHOAIENG-37260: Test sources endpoint rejects fields it doesn't support
115-
"""
116-
LOGGER.info(f"Testing sources rejection of unsupported field: {unsupported_field}")
117-
118-
with pytest.raises(Exception, match="unsupported order by field"):
119-
get_sources_with_sorting(
120-
model_catalog_rest_url=model_catalog_rest_url,
121-
model_registry_rest_headers=model_registry_rest_headers,
122-
order_by=unsupported_field,
123-
sort_order="ASC",
124-
)
125-
126-
12718
# More than 1 artifact are available only in downstream
12819
@pytest.mark.downstream_only
12920
class TestArtifactsSorting:
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import pytest
2+
from typing import Self
3+
from ocp_resources.config_map import ConfigMap
4+
from simple_logger.logger import get_logger
5+
from tests.model_registry.model_catalog.utils import get_models_from_catalog_api
6+
from tests.model_registry.model_catalog.sorting.utils import validate_items_sorted_correctly
7+
8+
LOGGER = get_logger(name=__name__)
9+
10+
pytestmark = [pytest.mark.usefixtures("updated_dsc_component_state_scope_session", "model_registry_namespace")]
11+
12+
13+
class TestModelsSorting:
14+
"""Test sorting functionality for FindModels endpoint"""
15+
16+
@pytest.mark.parametrize(
17+
"order_by,sort_order",
18+
[
19+
("ID", "ASC"),
20+
("ID", "DESC"),
21+
pytest.param(
22+
"NAME",
23+
"ASC",
24+
marks=pytest.mark.xfail(
25+
reason="RHOAIENG-38056: Backend bug - NAME sorting not implemented, falls back to ID sorting"
26+
),
27+
),
28+
pytest.param(
29+
"NAME",
30+
"DESC",
31+
marks=pytest.mark.xfail(
32+
reason="RHOAIENG-38056: Backend bug - NAME sorting not implemented, falls back to ID sorting"
33+
),
34+
),
35+
("CREATE_TIME", "ASC"),
36+
("CREATE_TIME", "DESC"),
37+
("LAST_UPDATE_TIME", "ASC"),
38+
("LAST_UPDATE_TIME", "DESC"),
39+
],
40+
)
41+
def test_models_sorting_works_correctly(
42+
self: Self,
43+
enabled_model_catalog_config_map: ConfigMap,
44+
order_by: str,
45+
sort_order: str,
46+
model_catalog_rest_url: list[str],
47+
model_registry_rest_headers: dict[str, str],
48+
):
49+
"""
50+
RHOAIENG-37260: Test models endpoint sorts correctly by field and order
51+
"""
52+
LOGGER.info(f"Testing models sorting: orderBy={order_by}, sortOrder={sort_order}")
53+
54+
response = get_models_from_catalog_api(
55+
model_catalog_rest_url=model_catalog_rest_url,
56+
model_registry_rest_headers=model_registry_rest_headers,
57+
order_by=order_by,
58+
sort_order=sort_order,
59+
)
60+
61+
assert validate_items_sorted_correctly(response["items"], order_by, sort_order)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import pytest
2+
from typing import Self
3+
from ocp_resources.config_map import ConfigMap
4+
from simple_logger.logger import get_logger
5+
from tests.model_registry.model_catalog.sorting.utils import (
6+
get_sources_with_sorting,
7+
validate_items_sorted_correctly,
8+
)
9+
10+
LOGGER = get_logger(name=__name__)
11+
12+
pytestmark = [pytest.mark.usefixtures("updated_dsc_component_state_scope_session", "model_registry_namespace")]
13+
14+
15+
class TestSourcesSorting:
16+
"""Test sorting functionality for FindSources endpoint"""
17+
18+
@pytest.mark.parametrize(
19+
"order_by,sort_order",
20+
[
21+
("ID", "ASC"),
22+
("ID", "DESC"),
23+
("NAME", "ASC"),
24+
("NAME", "DESC"),
25+
],
26+
)
27+
def test_sources_sorting_works_correctly(
28+
self: Self,
29+
enabled_model_catalog_config_map: ConfigMap,
30+
order_by: str,
31+
sort_order: str,
32+
model_catalog_rest_url: list[str],
33+
model_registry_rest_headers: dict[str, str],
34+
):
35+
"""
36+
RHOAIENG-37260: Test sources endpoint sorts correctly by supported fields
37+
"""
38+
LOGGER.info(f"Testing sources sorting: orderBy={order_by}, sortOrder={sort_order}")
39+
40+
response = get_sources_with_sorting(
41+
model_catalog_rest_url=model_catalog_rest_url,
42+
model_registry_rest_headers=model_registry_rest_headers,
43+
order_by=order_by,
44+
sort_order=sort_order,
45+
)
46+
47+
assert validate_items_sorted_correctly(response["items"], order_by, sort_order)
48+
49+
@pytest.mark.parametrize("unsupported_field", ["CREATE_TIME", "LAST_UPDATE_TIME"])
50+
def test_sources_rejects_unsupported_fields(
51+
self: Self,
52+
enabled_model_catalog_config_map: ConfigMap,
53+
unsupported_field: str,
54+
model_catalog_rest_url: list[str],
55+
model_registry_rest_headers: dict[str, str],
56+
):
57+
"""
58+
RHOAIENG-37260: Test sources endpoint rejects fields it doesn't support
59+
"""
60+
LOGGER.info(f"Testing sources rejection of unsupported field: {unsupported_field}")
61+
62+
with pytest.raises(Exception, match="unsupported order by field"):
63+
get_sources_with_sorting(
64+
model_catalog_rest_url=model_catalog_rest_url,
65+
model_registry_rest_headers=model_registry_rest_headers,
66+
order_by=unsupported_field,
67+
sort_order="ASC",
68+
)

0 commit comments

Comments
 (0)