Skip to content

[ENG-7316] Off-AddOns-Release: Google Drive Integration Error (500 Internal Server Error) #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions addon_imps/storage/google_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
)


ROOT_ITEM_ID = "root"

ROOT_ITEM = ItemResult(
item_name="Root",
item_type=ItemType.FOLDER,
item_id=ROOT_ITEM_ID,
)


class GoogleDriveStorageImp(storage.StorageAddonHttpRequestorImp):
"""storage on google drive

Expand All @@ -25,13 +34,15 @@ async def get_external_account_id(self, _: dict[str, str]) -> str:
return ""

async def list_root_items(self, page_cursor: str = "") -> storage.ItemSampleResult:
return ItemSampleResult(items=[await self.get_item_info("root")], total_count=1)
return ItemSampleResult(items=[ROOT_ITEM], total_count=1)

async def build_wb_config(self) -> dict:
return {"folder": {"id": self.config.connected_root_id}}

async def get_item_info(self, item_id: str) -> storage.ItemResult:
item_id = item_id or "root"
if item_id == ROOT_ITEM_ID:
return ROOT_ITEM

async with self.network.GET(f"drive/v3/files/{item_id}") as response:
if response.http_status == 200:
json = await response.json_content()
Expand Down
33 changes: 22 additions & 11 deletions addon_imps/tests/storage/test_google_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)

from addon_imps.storage.google_drive import (
ROOT_ITEM,
File,
GoogleDriveStorageImp,
)
Expand Down Expand Up @@ -58,12 +59,12 @@ async def test_list_root_items(self):
result = await self.imp.list_root_items()

expected_result = ItemSampleResult(
items=[mock_response],
items=[ROOT_ITEM],
total_count=1,
)

self.assertEqual(expected_result, result)
self.imp.get_item_info.assert_awaited_once_with("root")
self.imp.get_item_info.assert_not_called()

async def test_list_child_items(self):
args = namedtuple(
Expand Down Expand Up @@ -157,14 +158,24 @@ async def _test_list_collection_items_ordinary(
],
)

async def test_get_item_info(self):
cases = [("", "root"), ("foo", "foo")]
for item_id in cases:
self.network.reset_mock()
with self.subTest(case=f"case: {item_id=}"):
await self._test_item_info(*item_id)
async def test_get_item_info_root(self):
self.network.reset_mock()
self._patch_get(
{
"kind": "drive#file",
"driveId": "123",
"extra_attribute": "dasdasd",
"mimeType": "application/vnd.google-apps.folder",
"name": "foobar",
"id": "1023",
}
)
result = await self.imp.get_item_info("root")
self.network.GET.assert_not_called()
assert result == ROOT_ITEM

async def _test_item_info(self, item_id: str, url_segment: str):
async def test_get_item_info(self):
self.network.reset_mock()
self._patch_get(
{
"kind": "drive#file",
Expand All @@ -175,8 +186,8 @@ async def _test_item_info(self, item_id: str, url_segment: str):
"id": "1023",
}
)
result = await self.imp.get_item_info(item_id)
self._assert_get(f"drive/v3/files/{url_segment}")
result = await self.imp.get_item_info("foo")
self._assert_get("drive/v3/files/foo")
assert result == ItemResult(
item_id="1023", item_name="foobar", item_type=ItemType.FOLDER
)
Expand Down