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(storage): add projection parameter to blob.reload method #146

Merged
merged 4 commits into from May 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions google/cloud/storage/_helpers.py
Expand Up @@ -121,11 +121,16 @@ def _query_params(self):
params["userProject"] = self.user_project
return params

def reload(self, client=None, timeout=_DEFAULT_TIMEOUT):
def reload(self, projection="noAcl", client=None, timeout=_DEFAULT_TIMEOUT):
"""Reload properties from Cloud Storage.

If :attr:`user_project` is set, bills the API request to that project.

:type projection: str
:param projection: (Optional) If used, must be 'full' or 'noAcl'.
Defaults to ``'noAcl'``. Specifies the set of
properties to return.

:type client: :class:`~google.cloud.storage.client.Client` or
``NoneType``
:param client: the client to use. If not passed, falls back to the
Expand All @@ -139,9 +144,7 @@ def reload(self, client=None, timeout=_DEFAULT_TIMEOUT):
"""
client = self._require_client(client)
query_params = self._query_params
# Pass only '?projection=noAcl' here because 'acl' and related
# are handled via custom endpoints.
query_params["projection"] = "noAcl"
query_params["projection"] = projection
api_response = client._connection.api_request(
method="GET",
path=self.path,
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test__helpers.py
Expand Up @@ -151,6 +151,30 @@ def test_reload_w_user_project(self):
)
self.assertEqual(derived._changes, set())

def test_reload_w_projection(self):
connection = _Connection({"foo": "Foo"})
client = _Client(connection)
derived = self._derivedClass("/path")()
# Make sure changes is not a set instance before calling reload
# (which will clear / replace it with an empty set), checked below.
derived._changes = object()
derived.reload(projection="full", client=client, timeout=42)
self.assertEqual(derived._properties, {"foo": "Foo"})
kw = connection._requested
self.assertEqual(len(kw), 1)
self.assertEqual(
kw[0],
{
"method": "GET",
"path": "/path",
"query_params": {"projection": "full"},
"headers": {},
"_target_object": derived,
"timeout": 42,
},
)
self.assertEqual(derived._changes, set())

def test__set_properties(self):
mixin = self._make_one()
self.assertEqual(mixin._properties, {})
Expand Down