Skip to content

Commit 8a391cf

Browse files
committed
split test
1 parent 51362fe commit 8a391cf

File tree

1 file changed

+81
-4
lines changed

1 file changed

+81
-4
lines changed

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

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,82 @@ async def _delete_project(client: TestClient, project: dict) -> ClientResponse:
260260

261261

262262
@pytest.mark.parametrize(*standard_role_response())
263+
async def test_share_project_user_roles(
264+
mock_dynamic_scheduler: None,
265+
client: TestClient,
266+
logged_user: dict,
267+
primary_group: dict[str, str],
268+
standard_groups: list[dict[str, str]],
269+
all_group: dict[str, str],
270+
user_role: UserRole,
271+
expected: ExpectedResponse,
272+
storage_subsystem_mock,
273+
mocked_dynamic_services_interface: dict[str, mock.Mock],
274+
project_db_cleaner,
275+
request_create_project: Callable[..., Awaitable[ProjectDict]],
276+
exit_stack: contextlib.AsyncExitStack,
277+
):
278+
# Use-case: test how different user roles can access shared projects
279+
# Test with full access rights for all roles
280+
share_rights = {"read": True, "write": True, "delete": True}
281+
282+
# create a project with full access rights for the all_group
283+
new_project = await request_create_project(
284+
client,
285+
expected.accepted,
286+
expected.created,
287+
logged_user,
288+
primary_group,
289+
project={"accessRights": {str(all_group["gid"]): share_rights}},
290+
)
291+
if new_project:
292+
assert new_project["accessRights"] == {
293+
f"{primary_group['gid']}": {"read": True, "write": True, "delete": True},
294+
f"{(all_group['gid'])}": share_rights,
295+
}
296+
297+
# user 1 can always get to his project
298+
await assert_get_same_project(client, new_project, expected.ok)
299+
300+
# get another user logged in now
301+
await log_client_in(
302+
client,
303+
{"role": user_role.name},
304+
enable_check=user_role != UserRole.ANONYMOUS,
305+
exit_stack=exit_stack,
306+
)
307+
if new_project:
308+
# user 2 can get the project if they have proper role permissions
309+
await assert_get_same_project(
310+
client,
311+
new_project,
312+
expected.ok,
313+
)
314+
315+
# user 2 can list projects if they have proper role permissions
316+
list_projects = await _list_projects(client, expected.ok)
317+
expected_project_count = 1 if user_role != UserRole.ANONYMOUS else 0
318+
assert len(list_projects) == expected_project_count
319+
320+
# user 2 can update the project if they have proper role permissions
321+
project_update = deepcopy(new_project)
322+
project_update["name"] = "my super name"
323+
project_update.pop("accessRights")
324+
await _replace_project(
325+
client,
326+
project_update,
327+
expected.no_content,
328+
)
329+
330+
# user 2 can delete projects if they have proper role permissions
331+
resp = await _delete_project(client, new_project)
332+
await assert_status(
333+
resp,
334+
expected_status_code=expected.no_content,
335+
)
336+
337+
338+
@pytest.mark.parametrize(*standard_user_role_response())
263339
@pytest.mark.parametrize(
264340
"share_rights",
265341
[
@@ -268,9 +344,9 @@ async def _delete_project(client: TestClient, project: dict) -> ClientResponse:
268344
{"read": True, "write": False, "delete": False},
269345
{"read": False, "write": False, "delete": False},
270346
],
271-
ids=str,
347+
ids=["full_access", "no_delete", "read_only", "no_access"],
272348
)
273-
async def test_share_project(
349+
async def test_share_project_access_rights(
274350
mock_dynamic_scheduler: None,
275351
client: TestClient,
276352
logged_user: dict,
@@ -286,9 +362,10 @@ async def test_share_project(
286362
request_create_project: Callable[..., Awaitable[ProjectDict]],
287363
exit_stack: contextlib.AsyncExitStack,
288364
):
289-
# Use-case: the user shares some projects with a group
365+
# Use-case: test how different access rights affect project sharing
366+
# Test with USER role only but different access rights
290367

291-
# create a few projects
368+
# create a project with specific access rights
292369
new_project = await request_create_project(
293370
client,
294371
expected.accepted,

0 commit comments

Comments
 (0)