Skip to content
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

fix: total filtered download #187

Merged
merged 4 commits into from
May 6, 2024
Merged
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
10 changes: 9 additions & 1 deletion deepset_cloud_sdk/_service/files_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,15 @@ async def download(

pbar: Optional[tqdm] = None
if show_progress:
total = (await self._files.list_paginated(workspace_name, limit=1)).total
total = (
await self._files.list_paginated(
workspace_name,
name=name,
content=content,
odata_filter=odata_filter,
limit=1,
)
).total
pbar = tqdm(total=total, desc="Download Progress")

after_value = None
Expand Down
53 changes: 53 additions & 0 deletions tests/unit/service/test_files_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,59 @@ async def test_download_files_with_filter(self, file_service: FilesService, monk
after_value=None,
)

async def test_download_files_with_filter_and_progress_bar(
self, file_service: FilesService, monkeypatch: MonkeyPatch
) -> None:
mocked_list_paginated = AsyncMock(
return_value=FileList(
total=1,
data=[
File(
file_id=UUID("cd16435f-f6eb-423f-bf6f-994dc8a36a10"),
url="/api/v1/workspaces/search tests/files/cd16435f-f6eb-423f-bf6f-994dc8a36a10",
name="silly_things_2.txt",
size=611,
created_at=datetime.datetime.fromisoformat("2022-06-21T16:40:00.634653+00:00"),
meta={},
)
],
has_more=False,
),
)

monkeypatch.setattr(file_service._files, "list_paginated", mocked_list_paginated)

mocked_download = AsyncMock(return_value=None)
monkeypatch.setattr(file_service._files, "download", mocked_download)

await file_service.download(
workspace_name="test_workspace",
show_progress=True, # This requires a previous cal that checks the total number of files
odata_filter="category eq 'news'",
name="asdf",
content="bsdf",
batch_size=54,
)

mocked_list_paginated.mock_calls == [
call(
workspace_name="test_workspace",
name="asdf",
content="bsdf",
odata_filter="category eq 'news'",
limit=54,
),
call(
workspace_name="test_workspace",
name="asdf",
content="bsdf",
odata_filter="category eq 'news'",
limit=54,
after_file_id=None,
after_value=None,
),
]

async def test_download_all_files_with_file_not_found(
self, file_service: FilesService, monkeypatch: MonkeyPatch
) -> None:
Expand Down
Loading