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

feat: support page_size in bucket.list_blobs #1275

Merged
merged 2 commits into from
May 17, 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
7 changes: 7 additions & 0 deletions google/cloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,7 @@ def list_blobs(
match_glob=None,
include_folders_as_prefixes=None,
soft_deleted=None,
page_size=None,
):
"""Return an iterator used to find blobs in the bucket.
Expand Down Expand Up @@ -1401,6 +1402,11 @@ def list_blobs(
Note ``soft_deleted`` and ``versions`` cannot be set to True simultaneously. See:
https://cloud.google.com/storage/docs/soft-delete
:type page_size: int
:param page_size:
(Optional) Maximum number of blobs to return in each page.
Defaults to a value set by the API.
:rtype: :class:`~google.api_core.page_iterator.Iterator`
:returns: Iterator of all :class:`~google.cloud.storage.blob.Blob`
in this bucket matching the arguments.
Expand All @@ -1418,6 +1424,7 @@ def list_blobs(
versions=versions,
projection=projection,
fields=fields,
page_size=page_size,
timeout=timeout,
retry=retry,
match_glob=match_glob,
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,7 @@ def test_list_blobs_w_defaults(self):
expected_fields = None
expected_include_folders_as_prefixes = None
soft_deleted = None
page_size = None
client.list_blobs.assert_called_once_with(
bucket,
max_results=expected_max_results,
Expand All @@ -1196,6 +1197,7 @@ def test_list_blobs_w_defaults(self):
match_glob=expected_match_glob,
include_folders_as_prefixes=expected_include_folders_as_prefixes,
soft_deleted=soft_deleted,
page_size=page_size,
)

def test_list_blobs_w_explicit(self):
Expand All @@ -1211,6 +1213,7 @@ def test_list_blobs_w_explicit(self):
include_folders_as_prefixes = True
versions = True
soft_deleted = True
page_size = 2
projection = "full"
fields = "items/contentLanguage,nextPageToken"
bucket = self._make_one(client=None, name=name)
Expand All @@ -1236,6 +1239,7 @@ def test_list_blobs_w_explicit(self):
match_glob=match_glob,
include_folders_as_prefixes=include_folders_as_prefixes,
soft_deleted=soft_deleted,
page_size=page_size,
)

self.assertIs(iterator, other_client.list_blobs.return_value)
Expand All @@ -1253,6 +1257,7 @@ def test_list_blobs_w_explicit(self):
expected_fields = fields
expected_include_folders_as_prefixes = include_folders_as_prefixes
expected_soft_deleted = soft_deleted
expected_page_size = page_size
other_client.list_blobs.assert_called_once_with(
bucket,
max_results=expected_max_results,
Expand All @@ -1270,6 +1275,7 @@ def test_list_blobs_w_explicit(self):
match_glob=expected_match_glob,
include_folders_as_prefixes=expected_include_folders_as_prefixes,
soft_deleted=expected_soft_deleted,
page_size=expected_page_size,
)

def test_list_notifications_w_defaults(self):
Expand Down