|
14 | 14 | from models_library.products import ProductName |
15 | 15 | from models_library.rest_pagination import MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE |
16 | 16 | from models_library.services_history import ServiceRelease |
17 | | -from models_library.services_regex import ( |
18 | | - DYNAMIC_SERVICE_KEY_PREFIX, |
19 | | -) |
20 | 17 | from models_library.services_types import ServiceKey, ServiceVersion |
21 | 18 | from models_library.users import UserID |
22 | 19 | from packaging import version |
@@ -131,6 +128,35 @@ async def test_rpc_list_services_paginated_with_no_services_returns_empty_page( |
131 | 128 | assert page.meta.total == 0 |
132 | 129 |
|
133 | 130 |
|
| 131 | +async def test_rpc_list_services_paginated_with_filters( |
| 132 | + background_sync_task_mocked: None, |
| 133 | + mocked_director_rest_api: MockRouter, |
| 134 | + rpc_client: RabbitMQRPCClient, |
| 135 | + product_name: ProductName, |
| 136 | + user_id: UserID, |
| 137 | + app: FastAPI, |
| 138 | +): |
| 139 | + assert app |
| 140 | + |
| 141 | + # only computational services introduced by the background_sync_task_mocked |
| 142 | + page = await list_services_paginated( |
| 143 | + rpc_client, |
| 144 | + product_name=product_name, |
| 145 | + user_id=user_id, |
| 146 | + filters={"service_type": "computational"}, |
| 147 | + ) |
| 148 | + assert page.meta.total == page.meta.count |
| 149 | + assert page.meta.total > 0 |
| 150 | + |
| 151 | + page = await list_services_paginated( |
| 152 | + rpc_client, |
| 153 | + product_name=product_name, |
| 154 | + user_id=user_id, |
| 155 | + filters={"service_type": "dynamic"}, |
| 156 | + ) |
| 157 | + assert page.meta.total == 0 |
| 158 | + |
| 159 | + |
134 | 160 | async def test_rpc_catalog_client( |
135 | 161 | background_sync_task_mocked: None, |
136 | 162 | mocked_director_rest_api: MockRouter, |
@@ -556,68 +582,3 @@ async def test_rpc_list_my_service_history_paginated( |
556 | 582 | assert len(release_history) == 2 |
557 | 583 | assert release_history[0].version == service_version_2, "expected newest first" |
558 | 584 | assert release_history[1].version == service_version_1 |
559 | | - |
560 | | - |
561 | | -async def test_rpc_list_services_paginated_with_filters( |
562 | | - background_sync_task_mocked: None, |
563 | | - mocked_director_rest_api: MockRouter, |
564 | | - rpc_client: RabbitMQRPCClient, |
565 | | - product_name: ProductName, |
566 | | - user_id: UserID, |
567 | | - app: FastAPI, |
568 | | - create_fake_service_data: Callable, |
569 | | - services_db_tables_injector: Callable, |
570 | | -): |
571 | | - assert app |
572 | | - |
573 | | - # only computational services introduced by the background_sync_task_mocked |
574 | | - page = await list_services_paginated( |
575 | | - rpc_client, |
576 | | - product_name=product_name, |
577 | | - user_id=user_id, |
578 | | - filters={"service_type": "computational"}, |
579 | | - ) |
580 | | - assert page.meta.total == page.meta.count |
581 | | - assert page.meta.total > 0 |
582 | | - |
583 | | - page = await list_services_paginated( |
584 | | - rpc_client, |
585 | | - product_name=product_name, |
586 | | - user_id=user_id, |
587 | | - filters={"service_type": "dynamic"}, |
588 | | - ) |
589 | | - assert page.meta.total == 0 |
590 | | - |
591 | | - # Create fake services with different types |
592 | | - service_key_1 = f"{DYNAMIC_SERVICE_KEY_PREFIX}/test-filter-service" |
593 | | - service_version = "1.2.3" |
594 | | - |
595 | | - fake_services = [ |
596 | | - create_fake_service_data( |
597 | | - service_key_1, |
598 | | - service_version, |
599 | | - team_access=None, |
600 | | - everyone_access=None, |
601 | | - product=product_name, |
602 | | - ), |
603 | | - ] |
604 | | - |
605 | | - # Inject fake services into the database |
606 | | - await services_db_tables_injector(fake_services) |
607 | | - |
608 | | - # Apply a filter to match only computational services |
609 | | - page = await list_services_paginated( |
610 | | - rpc_client, |
611 | | - product_name=product_name, |
612 | | - user_id=user_id, |
613 | | - filters={"service_type": "dynamic"}, |
614 | | - ) |
615 | | - |
616 | | - # Validate the response |
617 | | - assert page.meta.total == 1 |
618 | | - assert page.meta.count == 1 |
619 | | - assert len(page.data) == 1 |
620 | | - assert page.data[0].key == service_key_1 |
621 | | - assert page.data[0].service_type == "frontend" |
622 | | - assert page.links.next is None |
623 | | - assert page.links.prev is None |
0 commit comments