Skip to content

Commit

Permalink
[ENG-6672] | fixed bug when workspace item_type selected for Bitbucket (
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-andriy authored Dec 17, 2024
1 parent 9764d59 commit 7b7ba60
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
15 changes: 8 additions & 7 deletions addon_imps/storage/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 16 additions & 7 deletions addon_imps/tests/storage/test_bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
]

Expand All @@ -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,
),
},
{
Expand All @@ -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,
),
},
{
Expand All @@ -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,
),
},
]
Expand Down Expand Up @@ -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,
),
],
},
Expand All @@ -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,
),
],
},
Expand All @@ -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,
),
],
},
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 7b7ba60

Please sign in to comment.