Skip to content

Commit

Permalink
feat: add 'page_size' parameter to 'Bucket.list_blobs, list_buckets (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanyuan authored Jul 22, 2021
1 parent 1f1b138 commit c5f4ad8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions google/cloud/storage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ def _list_resource(
max_results=None,
extra_params=None,
page_start=page_iterator._do_nothing_page_start,
page_size=None,
timeout=_DEFAULT_TIMEOUT,
retry=DEFAULT_RETRY,
):
Expand All @@ -399,6 +400,7 @@ def _list_resource(
max_results=max_results,
extra_params=extra_params,
page_start=page_start,
page_size=page_size,
)

def _patch_resource(
Expand Down Expand Up @@ -1134,6 +1136,7 @@ def list_blobs(
versions=None,
projection="noAcl",
fields=None,
page_size=None,
timeout=_DEFAULT_TIMEOUT,
retry=DEFAULT_RETRY,
):
Expand Down Expand Up @@ -1200,6 +1203,10 @@ def list_blobs(
``'items(name,contentLanguage),nextPageToken'``.
See: https://cloud.google.com/storage/docs/json_api/v1/parameters#fields
page_size (int):
(Optional) Maximum number of blobs to return in each page.
Defaults to a value set by the API.
timeout (Optional[Union[float, Tuple[float, float]]]):
The amount of time, in seconds, to wait for the server response.
Expand Down Expand Up @@ -1269,6 +1276,7 @@ def list_blobs(
max_results=max_results,
extra_params=extra_params,
page_start=_blobs_page_start,
page_size=page_size,
timeout=timeout,
retry=retry,
)
Expand All @@ -1284,6 +1292,7 @@ def list_buckets(
projection="noAcl",
fields=None,
project=None,
page_size=None,
timeout=_DEFAULT_TIMEOUT,
retry=DEFAULT_RETRY,
):
Expand Down Expand Up @@ -1330,6 +1339,10 @@ def list_buckets(
:param project: (Optional) The project whose buckets are to be listed.
If not passed, uses the project set on the client.
:type page_size: int
:param page_size: (Optional) Maximum number of buckets to return in each page.
Defaults to a value set by the API.
:type timeout: float or tuple
:param timeout:
(Optional) The amount of time, in seconds, to wait
Expand Down Expand Up @@ -1367,6 +1380,7 @@ def list_buckets(
page_token=page_token,
max_results=max_results,
extra_params=extra_params,
page_size=page_size,
timeout=timeout,
retry=retry,
)
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1589,13 +1589,15 @@ def test_list_blobs_w_defaults_w_bucket_obj(self):
expected_max_results = None
expected_extra_params = {"projection": "noAcl"}
expected_page_start = _blobs_page_start
expected_page_size = None
client._list_resource.assert_called_once_with(
expected_path,
expected_item_to_value,
page_token=expected_page_token,
max_results=expected_max_results,
extra_params=expected_extra_params,
page_start=expected_page_start,
page_size=expected_page_size,
timeout=self._get_default_timeout(),
retry=DEFAULT_RETRY,
)
Expand All @@ -1616,6 +1618,7 @@ def test_list_blobs_w_explicit_w_user_project(self):
include_trailing_delimiter = True
versions = True
projection = "full"
page_size = 2
fields = "items/contentLanguage,nextPageToken"
credentials = _make_credentials()
client = self._make_one(project=project, credentials=credentials)
Expand All @@ -1641,6 +1644,7 @@ def test_list_blobs_w_explicit_w_user_project(self):
versions=versions,
projection=projection,
fields=fields,
page_size=page_size,
timeout=timeout,
retry=retry,
)
Expand All @@ -1665,13 +1669,15 @@ def test_list_blobs_w_explicit_w_user_project(self):
"userProject": user_project,
}
expected_page_start = _blobs_page_start
expected_page_size = 2
client._list_resource.assert_called_once_with(
expected_path,
expected_item_to_value,
page_token=expected_page_token,
max_results=expected_max_results,
extra_params=expected_extra_params,
page_start=expected_page_start,
page_size=expected_page_size,
timeout=timeout,
retry=retry,
)
Expand Down Expand Up @@ -1699,6 +1705,7 @@ def test_list_buckets_w_defaults(self):
expected_item_to_value = _item_to_bucket
expected_page_token = None
expected_max_results = None
expected_page_size = None
expected_extra_params = {
"project": project,
"projection": "noAcl",
Expand All @@ -1709,6 +1716,7 @@ def test_list_buckets_w_defaults(self):
page_token=expected_page_token,
max_results=expected_max_results,
extra_params=expected_extra_params,
page_size=expected_page_size,
timeout=self._get_default_timeout(),
retry=DEFAULT_RETRY,
)
Expand All @@ -1726,6 +1734,7 @@ def test_list_buckets_w_explicit(self):
credentials = _make_credentials()
client = self._make_one(project=project, credentials=credentials)
client._list_resource = mock.Mock(spec=[])
page_size = 2
timeout = 42
retry = mock.Mock(spec=[])

Expand All @@ -1736,6 +1745,7 @@ def test_list_buckets_w_explicit(self):
prefix=prefix,
projection=projection,
fields=fields,
page_size=page_size,
timeout=timeout,
retry=retry,
)
Expand All @@ -1752,12 +1762,14 @@ def test_list_buckets_w_explicit(self):
"projection": projection,
"fields": fields,
}
expected_page_size = 2
client._list_resource.assert_called_once_with(
expected_path,
expected_item_to_value,
page_token=expected_page_token,
max_results=expected_max_results,
extra_params=expected_extra_params,
page_size=expected_page_size,
timeout=timeout,
retry=retry,
)
Expand Down

0 comments on commit c5f4ad8

Please sign in to comment.