|
3 | 3 | # pylint: disable=unused-variable |
4 | 4 | # pylint: disable=too-many-arguments |
5 | 5 | # pylint: disable=too-many-statements |
6 | | -from http import HTTPStatus |
7 | 6 |
|
8 | 7 | import pytest |
9 | 8 | from aiohttp.test_utils import TestClient |
|
14 | 13 | ) |
15 | 14 | from models_library.rest_ordering import OrderBy |
16 | 15 | from pytest_simcore.helpers.webserver_login import UserInfoDict |
17 | | -from servicelib.aiohttp import status |
18 | 16 | from simcore_service_webserver.db.models import UserRole |
19 | 17 | from simcore_service_webserver.licenses import _licensed_items_repository |
20 | 18 | from simcore_service_webserver.licenses.errors import LicensedItemNotFoundError |
21 | 19 | from simcore_service_webserver.projects.models import ProjectDict |
22 | 20 |
|
23 | 21 |
|
24 | | -@pytest.mark.parametrize("user_role,expected", [(UserRole.USER, status.HTTP_200_OK)]) |
| 22 | +@pytest.fixture |
| 23 | +def user_role() -> UserRole: |
| 24 | + return UserRole.USER |
| 25 | + |
| 26 | + |
25 | 27 | async def test_licensed_items_db_crud( |
26 | 28 | client: TestClient, |
27 | 29 | logged_user: UserInfoDict, |
28 | 30 | user_project: ProjectDict, |
29 | 31 | osparc_product_name: str, |
30 | | - expected: HTTPStatus, |
31 | 32 | pricing_plan_id: int, |
32 | 33 | ): |
33 | 34 | assert client.app |
@@ -92,3 +93,88 @@ async def test_licensed_items_db_crud( |
92 | 93 | licensed_item_id=_licensed_item_id, |
93 | 94 | product_name=osparc_product_name, |
94 | 95 | ) |
| 96 | + |
| 97 | + |
| 98 | +async def test_licensed_items_db_trash( |
| 99 | + client: TestClient, |
| 100 | + logged_user: UserInfoDict, |
| 101 | + user_project: ProjectDict, |
| 102 | + osparc_product_name: str, |
| 103 | + pricing_plan_id: int, |
| 104 | +): |
| 105 | + assert client.app |
| 106 | + |
| 107 | + # Create two licensed items |
| 108 | + licensed_item_db1 = await _licensed_items_repository.create( |
| 109 | + client.app, |
| 110 | + product_name=osparc_product_name, |
| 111 | + name="Model A", |
| 112 | + licensed_resource_type=LicensedResourceType.VIP_MODEL, |
| 113 | + pricing_plan_id=pricing_plan_id, |
| 114 | + ) |
| 115 | + licensed_item_id1 = licensed_item_db1.licensed_item_id |
| 116 | + |
| 117 | + licensed_item_db2 = await _licensed_items_repository.create( |
| 118 | + client.app, |
| 119 | + product_name=osparc_product_name, |
| 120 | + name="Model B", |
| 121 | + licensed_resource_type=LicensedResourceType.VIP_MODEL, |
| 122 | + pricing_plan_id=pricing_plan_id, |
| 123 | + ) |
| 124 | + licensed_item_id2 = licensed_item_db2.licensed_item_id |
| 125 | + |
| 126 | + # Trash one licensed item |
| 127 | + await _licensed_items_repository.update( |
| 128 | + client.app, |
| 129 | + licensed_item_id=licensed_item_id1, |
| 130 | + product_name=osparc_product_name, |
| 131 | + updates=LicensedItemUpdateDB(trash=True), |
| 132 | + ) |
| 133 | + |
| 134 | + # List with filter_trashed include |
| 135 | + output_include: tuple[ |
| 136 | + int, list[LicensedItemDB] |
| 137 | + ] = await _licensed_items_repository.list_( |
| 138 | + client.app, |
| 139 | + product_name=osparc_product_name, |
| 140 | + offset=0, |
| 141 | + limit=10, |
| 142 | + order_by=OrderBy(field="modified"), |
| 143 | + filter_trashed="include", |
| 144 | + ) |
| 145 | + assert len(output_include[1]) == 2 |
| 146 | + |
| 147 | + # List with filter_trashed exclude |
| 148 | + output_exclude: tuple[ |
| 149 | + int, list[LicensedItemDB] |
| 150 | + ] = await _licensed_items_repository.list_( |
| 151 | + client.app, |
| 152 | + product_name=osparc_product_name, |
| 153 | + offset=0, |
| 154 | + limit=10, |
| 155 | + order_by=OrderBy(field="modified"), |
| 156 | + filter_trashed="exclude", |
| 157 | + ) |
| 158 | + assert len(output_exclude[1]) == 1 |
| 159 | + assert output_exclude[1][0].licensed_item_id == licensed_item_id2 |
| 160 | + |
| 161 | + # List with filter_trashed all |
| 162 | + output_all: tuple[ |
| 163 | + int, list[LicensedItemDB] |
| 164 | + ] = await _licensed_items_repository.list_( |
| 165 | + client.app, |
| 166 | + product_name=osparc_product_name, |
| 167 | + offset=0, |
| 168 | + limit=10, |
| 169 | + order_by=OrderBy(field="modified"), |
| 170 | + filter_trashed="all", |
| 171 | + ) |
| 172 | + assert len(output_all[1]) == 2 |
| 173 | + |
| 174 | + # Get the trashed licensed item |
| 175 | + trashed_item = await _licensed_items_repository.get( |
| 176 | + client.app, |
| 177 | + licensed_item_id=licensed_item_id1, |
| 178 | + product_name=osparc_product_name, |
| 179 | + ) |
| 180 | + assert trashed_item.trashed is True |
0 commit comments