|
3 | 3 | import random |
4 | 4 | from ocp_resources.config_map import ConfigMap |
5 | 5 | 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 ( |
9 | 7 | get_artifacts_with_sorting, |
10 | 8 | validate_items_sorted_correctly, |
11 | 9 | verify_custom_properties_sorted, |
|
17 | 15 | pytestmark = [pytest.mark.usefixtures("updated_dsc_component_state_scope_session", "model_registry_namespace")] |
18 | 16 |
|
19 | 17 |
|
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 | | - |
127 | 18 | # More than 1 artifact are available only in downstream |
128 | 19 | @pytest.mark.downstream_only |
129 | 20 | class TestArtifactsSorting: |
|
0 commit comments