|
| 1 | +# pylint: disable=redefined-outer-name |
| 2 | +# pylint: disable=unused-argument |
| 3 | +# pylint: disable=unused-variable |
| 4 | +# pylint: disable=too-many-arguments |
| 5 | +# pylint: disable=too-many-statements |
| 6 | + |
| 7 | + |
| 8 | +from http import HTTPStatus |
| 9 | + |
| 10 | +import pytest |
| 11 | +from aiohttp.test_utils import TestClient |
| 12 | +from models_library.api_schemas_webserver.folders_v2 import FolderGet |
| 13 | +from pytest_simcore.helpers.assert_checks import assert_status |
| 14 | +from pytest_simcore.helpers.webserver_login import LoggedUser, UserInfoDict |
| 15 | +from pytest_simcore.helpers.webserver_parametrizations import ( |
| 16 | + ExpectedResponse, |
| 17 | + standard_role_response, |
| 18 | +) |
| 19 | +from servicelib.aiohttp import status |
| 20 | +from simcore_service_webserver.db.models import UserRole |
| 21 | +from simcore_service_webserver.projects.models import ProjectDict |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.parametrize(*standard_role_response(), ids=str) |
| 25 | +async def test_folders_user_role_permissions( |
| 26 | + client: TestClient, |
| 27 | + logged_user: UserInfoDict, |
| 28 | + user_project: ProjectDict, |
| 29 | + expected: ExpectedResponse, |
| 30 | +): |
| 31 | + assert client.app |
| 32 | + |
| 33 | + url = client.app.router["list_folders_full_search"].url_for() |
| 34 | + resp = await client.get(f"{url}") |
| 35 | + await assert_status(resp, expected.ok) |
| 36 | + |
| 37 | + |
| 38 | +@pytest.mark.parametrize("user_role,expected", [(UserRole.USER, status.HTTP_200_OK)]) |
| 39 | +async def test_folders_full_search( |
| 40 | + client: TestClient, |
| 41 | + logged_user: UserInfoDict, |
| 42 | + user_project: ProjectDict, |
| 43 | + expected: HTTPStatus, |
| 44 | +): |
| 45 | + assert client.app |
| 46 | + |
| 47 | + # list full folder search |
| 48 | + url = client.app.router["list_folders_full_search"].url_for() |
| 49 | + resp = await client.get(f"{url}") |
| 50 | + data, _ = await assert_status(resp, status.HTTP_200_OK) |
| 51 | + assert data == [] |
| 52 | + |
| 53 | + # create a new folder |
| 54 | + url = client.app.router["create_folder"].url_for() |
| 55 | + resp = await client.post(f"{url}", json={"name": "My first folder"}) |
| 56 | + root_folder, _ = await assert_status(resp, status.HTTP_201_CREATED) |
| 57 | + |
| 58 | + # create a subfolder folder |
| 59 | + url = client.app.router["create_folder"].url_for() |
| 60 | + resp = await client.post( |
| 61 | + f"{url}", |
| 62 | + json={ |
| 63 | + "name": "My subfolder", |
| 64 | + "parentFolderId": root_folder["folderId"], |
| 65 | + }, |
| 66 | + ) |
| 67 | + subfolder_folder, _ = await assert_status(resp, status.HTTP_201_CREATED) |
| 68 | + |
| 69 | + # list full folder search |
| 70 | + url = client.app.router["list_folders_full_search"].url_for() |
| 71 | + resp = await client.get(f"{url}") |
| 72 | + data, _ = await assert_status(resp, status.HTTP_200_OK) |
| 73 | + assert len(data) == 2 |
| 74 | + |
| 75 | + # create a sub sub folder |
| 76 | + url = client.app.router["create_folder"].url_for() |
| 77 | + resp = await client.post( |
| 78 | + f"{url}", |
| 79 | + json={ |
| 80 | + "name": "My sub sub folder", |
| 81 | + "parentFolderId": subfolder_folder["folderId"], |
| 82 | + }, |
| 83 | + ) |
| 84 | + subsubfolder_folder, _ = await assert_status(resp, status.HTTP_201_CREATED) |
| 85 | + |
| 86 | + # move sub sub folder to root folder |
| 87 | + url = client.app.router["replace_folder"].url_for( |
| 88 | + folder_id=f"{subsubfolder_folder['folderId']}" |
| 89 | + ) |
| 90 | + resp = await client.put( |
| 91 | + f"{url}", |
| 92 | + json={ |
| 93 | + "name": "My Updated Folder", |
| 94 | + "parentFolderId": None, |
| 95 | + }, |
| 96 | + ) |
| 97 | + data, _ = await assert_status(resp, status.HTTP_200_OK) |
| 98 | + assert FolderGet.parse_obj(data) |
| 99 | + |
| 100 | + # list full folder search |
| 101 | + url = client.app.router["list_folders_full_search"].url_for() |
| 102 | + resp = await client.get(f"{url}") |
| 103 | + data, _ = await assert_status(resp, status.HTTP_200_OK) |
| 104 | + assert len(data) == 3 |
| 105 | + |
| 106 | + # Create new user |
| 107 | + async with LoggedUser(client) as new_logged_user: |
| 108 | + # list full folder search |
| 109 | + url = client.app.router["list_folders_full_search"].url_for() |
| 110 | + resp = await client.get(f"{url}") |
| 111 | + data, _ = await assert_status(resp, status.HTTP_200_OK) |
| 112 | + assert data == [] |
| 113 | + |
| 114 | + # create a new folder |
| 115 | + url = client.app.router["create_folder"].url_for() |
| 116 | + resp = await client.post(f"{url}", json={"name": "New user folder"}) |
| 117 | + new_user_folder, _ = await assert_status(resp, status.HTTP_201_CREATED) |
| 118 | + |
| 119 | + # list full folder search |
| 120 | + url = client.app.router["list_folders_full_search"].url_for() |
| 121 | + resp = await client.get(f"{url}") |
| 122 | + data, _ = await assert_status(resp, status.HTTP_200_OK) |
| 123 | + assert len(data) == 1 |
0 commit comments