Skip to content
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
8 changes: 7 additions & 1 deletion google/cloud/storage/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def _query_params(self):
def reload(
self,
client=None,
projection="noAcl",
timeout=_DEFAULT_TIMEOUT,
if_generation_match=None,
if_generation_not_match=None,
Expand All @@ -151,6 +152,11 @@ def reload(
:param client: the client to use. If not passed, falls back to the
``client`` stored on the current object.

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

:type timeout: float or tuple
:param timeout: (Optional) The amount of time, in seconds, to wait
for the server response.
Expand Down Expand Up @@ -183,7 +189,7 @@ def reload(
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
_add_generation_match_parameters(
query_params,
if_generation_match=if_generation_match,
Expand Down
12 changes: 12 additions & 0 deletions tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,18 @@ def test_resumable_upload_with_generation_match(self):
with open(file_data["path"], "rb") as file_obj:
blob.upload_from_file(file_obj, if_metageneration_match=3)

def test_upload_blob_owner(self):
blob = self.bucket.blob("MyBuffer")
file_contents = b"Hello World"
blob.upload_from_string(file_contents)
self.case_blobs_to_delete.append(blob)

same_blob = self.bucket.blob("MyBuffer")
same_blob.reload(projection="full") # Initialize properties.
user_email = Config.CLIENT._credentials.service_account_email
owner = same_blob.owner
self.assertIn(user_email, owner["entity"])


class TestUnicode(unittest.TestCase):
@vpcsc_config.skip_if_inside_vpcsc
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,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