Skip to content

Commit 94b6e5f

Browse files
committed
setup specs in tests
1 parent bf8f922 commit 94b6e5f

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Not found
2+
# Not enough access rights
3+
#

services/web/server/src/simcore_service_webserver/tags/schemas.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ class TagUpdate(InputSchema):
2525
name: str | None = None
2626
description: str | None = None
2727
color: ColorStr | None = None
28+
order: int | None = None
2829

2930

3031
class TagCreate(InputSchema):
3132
name: str
3233
description: str | None = None
3334
color: ColorStr
35+
order: int | None = None
3436

3537

3638
class TagAccessRights(OutputSchema):

services/web/server/tests/unit/with_dbs/03/tags/test_tags.py

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from servicelib.aiohttp import status
2727
from simcore_postgres_database.models.tags import tags
2828
from simcore_service_webserver.db.models import UserRole
29-
from simcore_service_webserver.db.plugin import get_aiopg_engine
29+
from simcore_service_webserver.db.plugin import get_database_engine
3030
from simcore_service_webserver.projects.models import ProjectDict
3131

3232

@@ -122,7 +122,7 @@ async def test_tags_to_studies(
122122
@pytest.fixture
123123
async def everybody_tag_id(client: TestClient) -> AsyncIterator[int]:
124124
assert client.app
125-
engine = get_aiopg_engine(client.app)
125+
engine = get_database_engine(client.app)
126126
assert engine
127127

128128
async with engine.acquire() as conn:
@@ -178,8 +178,10 @@ async def test_create_and_update_tags(
178178

179179
assert user_role == UserRole.USER
180180

181+
# (1) create tag
182+
url = client.app.router["create_tag"].url_for()
181183
resp = await client.post(
182-
f"{client.app.router['create_tag'].url_for()}",
184+
f"{url}",
183185
json={"name": "T", "color": "#f00"},
184186
)
185187
created, _ = await assert_status(resp, status.HTTP_200_OK)
@@ -192,6 +194,7 @@ async def test_create_and_update_tags(
192194
"accessRights": {"read": True, "write": True, "delete": True},
193195
}
194196

197+
# (2) update created tag
195198
url = client.app.router["update_tag"].url_for(tag_id=f"{created['id']}")
196199
resp = await client.patch(
197200
f"{url}",
@@ -202,10 +205,72 @@ async def test_create_and_update_tags(
202205
created.update(description="This is my tag")
203206
assert updated == created
204207

208+
# (3) Cannot update tag because it has not enough access rights
205209
url = client.app.router["update_tag"].url_for(tag_id=f"{everybody_tag_id}")
206210
resp = await client.patch(
207211
f"{url}",
208212
json={"description": "I have NO WRITE ACCESS TO THIS TAG"},
209213
)
210-
_, error = await assert_status(resp, status.HTTP_401_UNAUTHORIZED)
214+
_, error = await assert_status(resp, status.HTTP_403_FORBIDDEN)
211215
assert error
216+
217+
218+
async def test_create_tags_with_order_index(
219+
client: TestClient,
220+
logged_user: UserInfoDict,
221+
user_role: UserRole,
222+
_clean_tags_table: None,
223+
):
224+
assert client.app
225+
226+
assert user_role == UserRole.USER
227+
228+
# (1) create tags but set the order in reverse order of creation
229+
url = client.app.router["create_tag"].url_for()
230+
num_tags = 3
231+
expected_tags: list[Any] = [None] * num_tags
232+
for creation_index, priority_index in enumerate(range(num_tags, 0, -1)):
233+
resp = await client.post(
234+
f"{url}",
235+
json={
236+
"name": f"T{creation_index}-{priority_index}",
237+
"description": f"{creation_index=}, {priority_index=}",
238+
"color": "#f00",
239+
"priority": priority_index,
240+
},
241+
)
242+
created, _ = await assert_status(resp, status.HTTP_200_OK)
243+
expected_tags[priority_index] = created
244+
245+
url = client.app.router["list_tags"].url_for()
246+
resp = await client.get(f"{url}")
247+
got, _ = await assert_status(resp, status.HTTP_200_OK)
248+
assert got == expected_tags
249+
250+
# (2) lets update all priorities in reverse order
251+
for new_order_index, tag in enumerate(reversed(expected_tags)):
252+
url = client.app.router["update_tag"].url_for(tag_id=f"{tag['id']}")
253+
resp = await client.patch(
254+
f"{url}",
255+
json={"priority": new_order_index},
256+
)
257+
updated, _ = await assert_status(resp, status.HTTP_200_OK)
258+
# NOTE: priority is not included in TagGet for now
259+
assert updated == tag
260+
261+
url = client.app.router["list_tags"].url_for()
262+
resp = await client.get(f"{url}")
263+
got, _ = await assert_status(resp, status.HTTP_200_OK)
264+
assert got == expected_tags[::-1]
265+
266+
# (3) new tag without priority should get last (because is last created)
267+
resp = await client.post(
268+
f"{url}",
269+
json={"name": "New", "description": "w/o priority"},
270+
)
271+
last_created, _ = await assert_status(resp, status.HTTP_200_OK)
272+
273+
url = client.app.router["list_tags"].url_for()
274+
resp = await client.get(f"{url}")
275+
got, _ = await assert_status(resp, status.HTTP_200_OK)
276+
assert got == [expected_tags[::-1], last_created]

0 commit comments

Comments
 (0)