Skip to content

Commit

Permalink
🐛 Fix listing folders in workspace (ITISFoundation#6718)
Browse files Browse the repository at this point in the history
Co-authored-by: Odei Maiz <[email protected]>
  • Loading branch information
matusdrobuliak66 and odeimaiz authored Nov 13, 2024
1 parent e6e2c70 commit a4b7c7a
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ async def list_( # pylint: disable=too-many-arguments,too-many-branches
& (folders_v2.c.user_id.is_(None))
)
)

if workspace_query.workspace_scope == WorkspaceScope.SHARED:
shared_workspace_query = shared_workspace_query.where(
folders_v2.c.workspace_id == workspace_query.workspace_id
)

else:
shared_workspace_query = None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,98 @@ async def test_workspaces_delete_folders(
resp = await client.get(url)
data, _ = await assert_status(resp, status.HTTP_200_OK)
assert len(data) == 0


@pytest.mark.parametrize("user_role,expected", [(UserRole.USER, status.HTTP_200_OK)])
async def test_listing_folders_and_projects_in_workspace__multiple_workspaces_created(
client: TestClient,
logged_user: UserInfoDict,
user_project: ProjectDict,
expected: HTTPStatus,
mock_catalog_api_get_services_for_user_in_product: MockerFixture,
fake_project: ProjectDict,
workspaces_clean_db: None,
):
assert client.app

# create a new workspace
url = client.app.router["create_workspace"].url_for()
resp = await client.post(
url.path,
json={
"name": "My first workspace",
"description": "Custom description",
"thumbnail": None,
},
)
added_workspace_1, _ = await assert_status(resp, status.HTTP_201_CREATED)

# Create project in workspace
project_data = deepcopy(fake_project)
project_data["workspace_id"] = f"{added_workspace_1['workspaceId']}"
project = await create_project(
client.app,
project_data,
user_id=logged_user["id"],
product_name="osparc",
)

# Create folder in workspace
url = client.app.router["create_folder"].url_for()
resp = await client.post(
url.path,
json={
"name": "Original user folder",
"workspaceId": f"{added_workspace_1['workspaceId']}",
},
)
first_folder, _ = await assert_status(resp, status.HTTP_201_CREATED)

# create a new workspace
url = client.app.router["create_workspace"].url_for()
resp = await client.post(
url.path,
json={
"name": "My first workspace",
"description": "Custom description",
"thumbnail": None,
},
)
added_workspace_2, _ = await assert_status(resp, status.HTTP_201_CREATED)

# Create project in workspace
project_data = deepcopy(fake_project)
project_data["workspace_id"] = f"{added_workspace_2['workspaceId']}"
project = await create_project(
client.app,
project_data,
user_id=logged_user["id"],
product_name="osparc",
)

# Create folder in workspace
url = client.app.router["create_folder"].url_for()
resp = await client.post(
url.path,
json={
"name": "Original user folder",
"workspaceId": f"{added_workspace_2['workspaceId']}",
},
)
first_folder, _ = await assert_status(resp, status.HTTP_201_CREATED)

# List projects in workspace 1
base_url = client.app.router["list_projects"].url_for()
url = base_url.with_query({"workspace_id": f"{added_workspace_1['workspaceId']}"})
resp = await client.get(url)
data, _ = await assert_status(resp, status.HTTP_200_OK)
assert len(data) == 1

# List folders in workspace 1
base_url = client.app.router["list_folders"].url_for()
url = base_url.with_query(
{"workspace_id": f"{added_workspace_1['workspaceId']}", "folder_id": "null"}
)
resp = await client.get(url)
data, _ = await assert_status(resp, status.HTTP_200_OK)
assert len(data) == 1

0 comments on commit a4b7c7a

Please sign in to comment.