Skip to content

Commit fc51ade

Browse files
committed
fixes tests
1 parent 93fac30 commit fc51ade

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

packages/models-library/src/models_library/licensed_items.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class LicensedItemDB(BaseModel):
4141

4242

4343
class LicensedItemUpdateDB(BaseModel):
44-
name: str | None = None
44+
licensed_resource_name: str | None = None
4545
pricing_plan_id: PricingPlanId | None = None
46+
4647
trash: bool | None = None

services/web/server/src/simcore_service_webserver/licenses/_licensed_items_repository.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ async def list_(
7171
offset: NonNegativeInt,
7272
limit: NonNegativeInt,
7373
order_by: OrderBy,
74+
# filters
7475
trashed: Literal["exclude", "only", "include"] = "exclude",
7576
inactive: Literal["exclude", "only", "include"] = "exclude",
7677
) -> tuple[int, list[LicensedItemDB]]:
@@ -87,12 +88,12 @@ async def list_(
8788
elif trashed == "only":
8889
base_query = base_query.where(licensed_items.c.trashed.is_not(None))
8990

90-
if inactive == "exclude":
91+
if inactive == "only":
9192
base_query = base_query.where(
9293
licensed_items.c.product_name.is_(None)
9394
| licensed_items.c.licensed_item_id.is_(None)
9495
)
95-
elif inactive == "only":
96+
elif inactive == "exclude":
9697
base_query = base_query.where(
9798
licensed_items.c.product_name.is_not(None)
9899
& licensed_items.c.licensed_item_id.is_not(None)

services/web/server/tests/unit/with_dbs/04/licenses/test_licensed_items_repository.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
import arrow
88
import pytest
99
from aiohttp.test_utils import TestClient
10-
from models_library.licensed_items import (
11-
LicensedItemDB,
12-
LicensedItemUpdateDB,
13-
LicensedResourceType,
14-
)
10+
from models_library.licensed_items import LicensedItemUpdateDB, LicensedResourceType
1511
from models_library.rest_ordering import OrderBy
1612
from pytest_simcore.helpers.webserver_login import UserInfoDict
1713
from simcore_service_webserver.db.models import UserRole
@@ -33,65 +29,66 @@ async def test_licensed_items_db_crud(
3329
pricing_plan_id: int,
3430
):
3531
assert client.app
36-
37-
output: tuple[int, list[LicensedItemDB]] = await _licensed_items_repository.list_(
32+
total_count, items = await _licensed_items_repository.list_(
3833
client.app,
3934
product_name=osparc_product_name,
4035
offset=0,
4136
limit=10,
4237
order_by=OrderBy(field="modified"),
4338
)
44-
assert output[0] == 0
39+
assert total_count == 0
40+
assert not items
4541

46-
licensed_item_db = await _licensed_items_repository.create(
42+
got = await _licensed_items_repository.create(
4743
client.app,
4844
product_name=osparc_product_name,
4945
licensed_resource_name="Model A",
5046
licensed_resource_type=LicensedResourceType.VIP_MODEL,
5147
pricing_plan_id=pricing_plan_id,
5248
)
53-
_licensed_item_id = licensed_item_db.licensed_item_id
49+
licensed_item_id = got.licensed_item_id
5450

55-
output: tuple[int, list[LicensedItemDB]] = await _licensed_items_repository.list_(
51+
total_count, items = await _licensed_items_repository.list_(
5652
client.app,
5753
product_name=osparc_product_name,
5854
offset=0,
5955
limit=10,
6056
order_by=OrderBy(field="modified"),
6157
)
62-
assert output[0] == 1
58+
assert total_count == 1
59+
assert items[0].licensed_item_id == licensed_item_id
6360

64-
licensed_item_db = await _licensed_items_repository.get(
61+
got = await _licensed_items_repository.get(
6562
client.app,
66-
licensed_item_id=_licensed_item_id,
63+
licensed_item_id=licensed_item_id,
6764
product_name=osparc_product_name,
6865
)
69-
assert licensed_item_db.licensed_resource_name == "Model A"
66+
assert got.licensed_resource_name == "Model A"
7067

7168
await _licensed_items_repository.update(
7269
client.app,
73-
licensed_item_id=_licensed_item_id,
70+
licensed_item_id=licensed_item_id,
7471
product_name=osparc_product_name,
75-
updates=LicensedItemUpdateDB(name="Model B"),
72+
updates=LicensedItemUpdateDB(licensed_resource_name="Model B"),
7673
)
7774

78-
licensed_item_db = await _licensed_items_repository.get(
75+
got = await _licensed_items_repository.get(
7976
client.app,
80-
licensed_item_id=_licensed_item_id,
77+
licensed_item_id=licensed_item_id,
8178
product_name=osparc_product_name,
8279
)
83-
assert licensed_item_db.licensed_resource_name == "Model B"
80+
assert got.licensed_resource_name == "Model B"
8481

85-
licensed_item_db = await _licensed_items_repository.delete(
82+
got = await _licensed_items_repository.delete(
8683
client.app,
87-
licensed_item_id=_licensed_item_id,
84+
licensed_item_id=licensed_item_id,
8885
product_name=osparc_product_name,
8986
)
9087

9188
with pytest.raises(LicensedItemNotFoundError):
9289
await _licensed_items_repository.get(
9390
client.app,
94-
licensed_item_id=_licensed_item_id,
91+
licensed_item_id=licensed_item_id,
9592
product_name=osparc_product_name,
9693
)
9794

0 commit comments

Comments
 (0)