Skip to content

Commit e68e158

Browse files
committed
changing from ProjectLocked to ProjectShareState
1 parent 81a0c5c commit e68e158

File tree

7 files changed

+60
-41
lines changed

7 files changed

+60
-41
lines changed

services/web/server/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ async def _creator(
420420
# has project state
421421
assert not ProjectState(
422422
**new_project.get("state", {})
423-
).locked.value, "Newly created projects should be unlocked"
423+
).share_state.locked, "Newly created projects should be unlocked"
424424

425425
# updated fields
426426
assert expected_data["uuid"] != new_project["uuid"]

services/web/server/tests/unit/with_dbs/02/test_projects_crud_handlers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ async def test_list_projects(
211211

212212
assert not ProjectState(
213213
**project_state
214-
).locked.value, "Templates are not locked"
214+
).share_state.locked, "Templates are not locked"
215215
assert ProjectPermalink.model_validate(project_permalink)
216216

217217
# standard project
@@ -240,7 +240,7 @@ async def test_list_projects(
240240
assert got == {k: user_project[k] for k in got}
241241
assert not ProjectState(
242242
**project_state
243-
).locked.value, "Single user does not lock"
243+
).share_state.locked, "Single user does not lock"
244244
assert project_permalink is None
245245

246246
# GET /v0/projects?type=template
@@ -258,7 +258,7 @@ async def test_list_projects(
258258
assert got == {k: template_project[k] for k in got}
259259
assert not ProjectState(
260260
**project_state
261-
).locked.value, "Templates are not locked"
261+
).share_state.locked, "Templates are not locked"
262262
assert ProjectPermalink.model_validate(project_permalink)
263263

264264

services/web/server/tests/unit/with_dbs/02/test_projects_states_handlers.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
from models_library.projects import ProjectID
3636
from models_library.projects_access import Owner
3737
from models_library.projects_state import (
38-
ProjectLocked,
3938
ProjectRunningState,
39+
ProjectShareState,
4040
ProjectState,
4141
ProjectStatus,
4242
RunningState,
@@ -1016,7 +1016,7 @@ async def test_get_active_project(
10161016
client.app, ProjectID(user_project["uuid"])
10171017
)
10181018
assert not error
1019-
assert ProjectState(**data.pop("state")).locked.value
1019+
assert ProjectState(**data.pop("state")).share_state.locked
10201020
data.pop("folderId")
10211021

10221022
user_project_last_change_date = user_project.pop("lastChangeDate")
@@ -1298,7 +1298,9 @@ async def test_open_shared_project_2_users_locked(
12981298
)
12991299
# expected is that the project is closed and unlocked
13001300
expected_project_state_client_1 = ProjectState(
1301-
locked=ProjectLocked(value=False, status=ProjectStatus.CLOSED),
1301+
share_state=ProjectShareState(
1302+
locked=False, status=ProjectStatus.CLOSED, current_user_groupids=[]
1303+
),
13021304
state=ProjectRunningState(value=RunningState.NOT_STARTED),
13031305
)
13041306
for _client_id in [client_id1, None]:
@@ -1320,9 +1322,11 @@ async def test_open_shared_project_2_users_locked(
13201322
first_name=logged_user.get("first_name"),
13211323
last_name=logged_user.get("last_name"),
13221324
)
1323-
expected_project_state_client_1.locked.value = True
1324-
expected_project_state_client_1.locked.status = ProjectStatus.OPENED
1325-
expected_project_state_client_1.locked.owner = owner1
1325+
expected_project_state_client_1.share_state.locked = True
1326+
expected_project_state_client_1.share_state.status = ProjectStatus.OPENED
1327+
expected_project_state_client_1.share_state.current_user_groupids = logged_user[
1328+
"primary_gid"
1329+
]
13261330
# NOTE: there are 2 calls since we are part of the primary group and the all group
13271331
await _assert_project_state_updated(
13281332
mock_project_state_updated_handler,
@@ -1358,7 +1362,7 @@ async def test_open_shared_project_2_users_locked(
13581362
expected.locked if user_role != UserRole.GUEST else status.HTTP_423_LOCKED,
13591363
)
13601364
expected_project_state_client_2 = deepcopy(expected_project_state_client_1)
1361-
expected_project_state_client_2.locked.status = ProjectStatus.OPENED
1365+
expected_project_state_client_2.share_state.status = ProjectStatus.OPENED
13621366

13631367
await _state_project(
13641368
client_2,
@@ -1372,7 +1376,9 @@ async def test_open_shared_project_2_users_locked(
13721376
if not any(user_role == role for role in [UserRole.ANONYMOUS, UserRole.GUEST]):
13731377
# Guests cannot close projects
13741378
expected_project_state_client_1 = ProjectState(
1375-
locked=ProjectLocked(value=False, status=ProjectStatus.CLOSED),
1379+
share_state=ProjectShareState(
1380+
locked=False, status=ProjectStatus.CLOSED, current_user_groupids=[]
1381+
),
13761382
state=ProjectRunningState(value=RunningState.NOT_STARTED),
13771383
)
13781384

@@ -1385,8 +1391,12 @@ async def test_open_shared_project_2_users_locked(
13851391
[
13861392
expected_project_state_client_1.model_copy(
13871393
update={
1388-
"locked": ProjectLocked(
1389-
value=True, status=ProjectStatus.CLOSING, owner=owner1
1394+
"share_state": ProjectShareState(
1395+
locked=True,
1396+
status=ProjectStatus.CLOSING,
1397+
current_user_groupids=[
1398+
owner1.user_id
1399+
], # this should be the group of that user
13901400
)
13911401
}
13921402
)
@@ -1418,17 +1428,21 @@ async def test_open_shared_project_2_users_locked(
14181428
expected.ok if user_role != UserRole.GUEST else status.HTTP_423_LOCKED,
14191429
)
14201430
if not any(user_role == role for role in [UserRole.ANONYMOUS, UserRole.GUEST]):
1421-
expected_project_state_client_2.locked.value = True
1422-
expected_project_state_client_2.locked.status = ProjectStatus.OPENED
1431+
expected_project_state_client_2.share_state.locked = True
1432+
expected_project_state_client_2.share_state.status = ProjectStatus.OPENED
14231433
owner2 = Owner(
14241434
user_id=PositiveInt(user_2["id"]),
14251435
first_name=user_2.get("first_name", None),
14261436
last_name=user_2.get("last_name", None),
14271437
)
1428-
expected_project_state_client_2.locked.owner = owner2
1429-
expected_project_state_client_1.locked.value = True
1430-
expected_project_state_client_1.locked.status = ProjectStatus.OPENED
1431-
expected_project_state_client_1.locked.owner = owner2
1438+
expected_project_state_client_2.share_state.current_user_groupids = [
1439+
owner2.user_id
1440+
] # this should be the group of that user
1441+
expected_project_state_client_1.share_state.locked = True
1442+
expected_project_state_client_1.share_state.status = ProjectStatus.OPENED
1443+
expected_project_state_client_1.share_state.current_user_groupids = [
1444+
owner2.user_id
1445+
] # this should be the group of that user
14321446
# NOTE: there are 3 calls since we are part of the primary group and the all group
14331447
await _assert_project_state_updated(
14341448
mock_project_state_updated_handler,
@@ -1532,11 +1546,11 @@ async def test_open_shared_project_at_same_time(
15321546
project_status = ProjectState(**data.pop("state"))
15331547
data.pop("folderId")
15341548
assert data == {k: shared_project[k] for k in data}
1535-
assert project_status.locked.value
1536-
assert project_status.locked.owner
1537-
assert project_status.locked.owner.first_name in [
1549+
assert project_status.share_state.locked
1550+
assert project_status.share_state.current_user_groupids
1551+
assert project_status.share_state.current_user_groupids in [
15381552
c["user"]["first_name"] for c in clients
1539-
]
1553+
] # TODO: this will fail
15401554

15411555
assert num_assertions == NUMBER_OF_ADDITIONAL_CLIENTS
15421556

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from models_library.groups import EVERYONE_GROUP_ID
1616
from models_library.products import ProductName
1717
from models_library.projects_state import (
18-
ProjectLocked,
1918
ProjectRunningState,
19+
ProjectShareState,
2020
ProjectState,
2121
ProjectStatus,
2222
RunningState,
@@ -81,7 +81,9 @@ async def test_tags_to_studies(
8181
user_project["tags"] = [tag["id"] for tag in added_tags]
8282
user_project["state"] = jsonable_encoder(
8383
ProjectState(
84-
locked=ProjectLocked(value=False, status=ProjectStatus.CLOSED),
84+
share_state=ProjectShareState(
85+
locked=False, status=ProjectStatus.CLOSED, current_user_groupids=[]
86+
),
8587
state=ProjectRunningState(value=RunningState.UNKNOWN),
8688
),
8789
exclude_unset=True,

services/web/server/tests/unit/with_dbs/04/garbage_collector/test_resource_manager.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -573,13 +573,9 @@ async def test_interactive_services_remain_after_websocket_reconnection_from_2_t
573573
{
574574
"project_uuid": empty_user_project["uuid"],
575575
"data": {
576-
"locked": {
577-
"value": False,
578-
"owner": {
579-
"user_id": user_id,
580-
"first_name": logged_user.get("first_name", None),
581-
"last_name": logged_user.get("last_name", None),
582-
},
576+
"shareState": {
577+
"locked": False,
578+
"currentUserGroupids": [user_id], # TODO: change this
583579
"status": "OPENED",
584580
},
585581
"state": {"value": "NOT_STARTED"},

services/web/server/tests/unit/with_dbs/04/studies_dispatcher/test_studies_dispatcher_handlers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from aiohttp.test_utils import TestClient, TestServer
1717
from aioresponses import aioresponses
1818
from common_library.users_enums import UserRole
19-
from models_library.projects_state import ProjectLocked, ProjectStatus
19+
from models_library.projects_state import ProjectStatus
2020
from pydantic import BaseModel, ByteSize, TypeAdapter
2121
from pytest_mock import MockerFixture
2222
from pytest_simcore.helpers.assert_checks import assert_status
@@ -299,8 +299,10 @@ def mocks_on_projects_api(mocker) -> None:
299299
All projects in this module are UNLOCKED
300300
"""
301301
mocker.patch(
302-
"simcore_service_webserver.projects._projects_service._get_project_lock_state",
303-
return_value=ProjectLocked(value=False, status=ProjectStatus.CLOSED),
302+
"simcore_service_webserver.projects._projects_service._get_project_share_state",
303+
return_value=ProjectShareState(
304+
locked=False, status=ProjectStatus.CLOSED, current_user_groupids=[]
305+
),
304306
)
305307

306308

@@ -424,7 +426,7 @@ async def test_dispatch_study_anonymously(
424426

425427
# guest user only a copy of the template project
426428
url = client.app.router["list_projects"].url_for()
427-
response = await client.get(f'{url.with_query(type="user")}')
429+
response = await client.get(f"{url.with_query(type='user')}")
428430

429431
payload = await response.json()
430432
assert response.status == 200, payload
@@ -481,7 +483,7 @@ async def test_dispatch_logged_in_user(
481483

482484
# guest user only a copy of the template project
483485
url = client.app.router["list_projects"].url_for()
484-
response = await client.get(f'{url.with_query(type="user")}')
486+
response = await client.get(f"{url.with_query(type='user')}")
485487

486488
payload = await response.json()
487489
assert response.status == 200, payload

services/web/server/tests/unit/with_dbs/04/studies_dispatcher/test_studies_dispatcher_studies_access.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
from faker import Faker
2222
from models_library.api_schemas_rpc_async_jobs.async_jobs import AsyncJobStatus
2323
from models_library.progress_bar import ProgressReport
24-
from models_library.projects_state import ProjectLocked, ProjectStatus
24+
from models_library.projects_state import (
25+
ProjectShareState,
26+
ProjectStatus,
27+
)
2528
from models_library.users import UserID
2629
from pytest_mock import MockerFixture
2730
from pytest_simcore.aioresponses_mocker import AioResponsesMock
@@ -144,8 +147,10 @@ def mocks_on_projects_api(mocker: MockerFixture) -> None:
144147
All projects in this module are UNLOCKED
145148
"""
146149
mocker.patch(
147-
"simcore_service_webserver.projects._projects_service._get_project_lock_state",
148-
return_value=ProjectLocked(value=False, status=ProjectStatus.CLOSED),
150+
"simcore_service_webserver.projects._projects_service._get_project_share_state",
151+
return_value=ProjectShareState(
152+
locked=False, status=ProjectStatus.CLOSED, current_user_groupids=[]
153+
),
149154
)
150155

151156

0 commit comments

Comments
 (0)