Skip to content
Permalink
Browse files
fix(storage): add projection parameter to blob.reload method (#146)
* fix(storage): add projection parameter to blob.reload method

* fix(storage): add system test

* fix(storage): nit
  • Loading branch information
HemangChothani committed May 15, 2020
1 parent 0944442 commit ddad20b3c3d2e6bf482e34dad85fa4b0ff90e1b1
Showing with 43 additions and 1 deletion.
  1. +7 −1 google/cloud/storage/_helpers.py
  2. +12 −0 tests/system/test_system.py
  3. +24 −0 tests/unit/test__helpers.py
@@ -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,
@@ -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.
@@ -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,
@@ -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
@@ -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, {})

0 comments on commit ddad20b

Please sign in to comment.