From 7b7ba60bbe7677a797f24c3d2d8a114b9726f79b Mon Sep 17 00:00:00 2001 From: sh-andriy <105591819+sh-andriy@users.noreply.github.com> Date: Tue, 17 Dec 2024 18:14:15 +0200 Subject: [PATCH] [ENG-6672] | fixed bug when workspace item_type selected for Bitbucket (#181) --- addon_imps/storage/bitbucket.py | 15 +++++++------- addon_imps/tests/storage/test_bitbucket.py | 23 +++++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/addon_imps/storage/bitbucket.py b/addon_imps/storage/bitbucket.py index ca455d8e..6c4c1e71 100644 --- a/addon_imps/storage/bitbucket.py +++ b/addon_imps/storage/bitbucket.py @@ -53,10 +53,9 @@ async def build_wb_config(self) -> dict: "host": "api.bitbucket.org", } elif item_type_str == "workspace": - return { - "owner": actual_id, - "host": "api.bitbucket.org", - } + raise ValueError( + "Selecting only a workspace is not allowed. Please choose a repository." + ) else: raise ValueError( f"Unsupported item type for build_wb_config: {item_type_str}" @@ -81,6 +80,7 @@ async def list_root_items(self, page_cursor: str = "") -> storage.ItemSampleResu item_id=item_id, item_name=name, item_type=storage.ItemType.FOLDER, + can_be_root=False, ) ) return self._create_item_sample_result(items, json_data) @@ -98,6 +98,7 @@ async def get_item_info(self, item_id: str) -> storage.ItemResult: item_id=item_id, item_name=name, item_type=storage.ItemType.FOLDER, + can_be_root=False, ) elif item_type_str == "repository": repo_full_name, path_param = self._split_repo_full_name_and_path(actual_id) @@ -125,6 +126,7 @@ async def get_item_info(self, item_id: str) -> storage.ItemResult: item_id=item_id, item_name=item_name, item_type=item_type_value, + can_be_root=False, ) else: raise ValueError(f"Unknown item type: {item_type_str}") @@ -170,9 +172,7 @@ async def _list_workspace_child_items( item_id = self._make_item_id("repository", full_name) items.append( storage.ItemResult( - item_id=item_id, - item_name=name, - item_type=storage.ItemType.FOLDER, + item_id=item_id, item_name=name, item_type=storage.ItemType.FOLDER ) ) return self._create_item_sample_result(items, json_data) @@ -209,6 +209,7 @@ async def _list_repository_child_items( item_id=item_id_value, item_name=item_name, item_type=item_type_value, + can_be_root=False, ) ) return self._create_item_sample_result(items, json_data) diff --git a/addon_imps/tests/storage/test_bitbucket.py b/addon_imps/tests/storage/test_bitbucket.py index 8ed99a26..266f7a1c 100644 --- a/addon_imps/tests/storage/test_bitbucket.py +++ b/addon_imps/tests/storage/test_bitbucket.py @@ -104,11 +104,13 @@ async def test_list_root_items(self): item_id=f"workspace:{self.WORKSPACE}", item_name=self.WORKSPACE_NAME, item_type=ItemType.FOLDER, + can_be_root=False, ), ItemResult( item_id=f"workspace:{self.WORKSPACE2}", item_name=self.WORKSPACE2_NAME, item_type=ItemType.FOLDER, + can_be_root=False, ), ] @@ -131,6 +133,7 @@ async def test_get_item_info(self): item_id=f"workspace:{self.WORKSPACE}", item_name=self.WORKSPACE_NAME, item_type=ItemType.FOLDER, + can_be_root=False, ), }, { @@ -144,6 +147,7 @@ async def test_get_item_info(self): item_id=f"repository:{self.WORKSPACE}/{self.REPO}", item_name=self.REPO_NAME, item_type=ItemType.FOLDER, + can_be_root=True, ), }, { @@ -157,6 +161,7 @@ async def test_get_item_info(self): item_id=f"repository:{self.WORKSPACE}/{self.REPO}/{self.FILE_PATH}", item_name=self.FILE_NAME, item_type=ItemType.FILE, + can_be_root=False, ), }, ] @@ -204,11 +209,13 @@ async def test_list_child_items(self): item_id=f"repository:{self.WORKSPACE}/{self.REPO}", item_name=self.REPO_NAME, item_type=ItemType.FOLDER, + can_be_root=True, ), ItemResult( item_id=f"repository:{self.WORKSPACE}/{self.REPO2}", item_name=self.REPO2_NAME, item_type=ItemType.FOLDER, + can_be_root=True, ), ], }, @@ -234,11 +241,13 @@ async def test_list_child_items(self): item_id=f"repository:{self.WORKSPACE}/{self.REPO}/src", item_name="src", item_type=ItemType.FOLDER, + can_be_root=False, ), ItemResult( item_id=f"repository:{self.WORKSPACE}/{self.REPO}/README.md", item_name="README.md", item_type=ItemType.FILE, + can_be_root=False, ), ], }, @@ -264,11 +273,13 @@ async def test_list_child_items(self): item_id=f"repository:{self.WORKSPACE}/{self.REPO}/src/main.py", item_name="main.py", item_type=ItemType.FILE, + can_be_root=False, ), ItemResult( item_id=f"repository:{self.WORKSPACE}/{self.REPO}/src/utils.py", item_name="utils.py", item_type=ItemType.FILE, + can_be_root=False, ), ], }, @@ -325,13 +336,11 @@ async def test_build_wb_config_workspace(self): external_account_id="", ) - result = await self.imp.build_wb_config() - - expected_result = { - "owner": self.WORKSPACE, - "host": "api.bitbucket.org", - } - self.assertEqual(result, expected_result) + with self.assertRaises(ValueError) as context: + await self.imp.build_wb_config() + self.assertIn( + "Selecting only a workspace is not allowed", str(context.exception) + ) async def test_handle_response_success(self): mock_response = AsyncMock()