From 6dc5c568db9ef8318cf148b78a17f6ccef9bcbf2 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 1 May 2015 16:11:33 -0400 Subject: [PATCH 1/2] Allow passing explicit connection to 'Blob.make_public'. See #825. --- gcloud/storage/blob.py | 14 +++++++++++--- gcloud/storage/test_blob.py | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/gcloud/storage/blob.py b/gcloud/storage/blob.py index dd55525a6e25..2ca9fe08c6bd 100644 --- a/gcloud/storage/blob.py +++ b/gcloud/storage/blob.py @@ -513,10 +513,18 @@ def upload_from_string(self, data, content_type='text/plain', size=len(data), content_type=content_type, connection=connection) - def make_public(self): - """Make this blob public giving all users read access.""" + def make_public(self, connection=None): + """Make this blob public giving all users read access. + + :type connection: :class:`gcloud.storage.connection.Connection` or + ``NoneType`` + :param connection: Optional. The connection to use when sending + requests. If not provided, falls back to default. + """ + if connection is None: + connection = self.connection self.acl.all().grant_read() - self.acl.save() + self.acl.save(connection=connection) cache_control = _scalar_property('cacheControl') """HTTP 'Cache-Control' header for this object. diff --git a/gcloud/storage/test_blob.py b/gcloud/storage/test_blob.py index eb57bc6b82d0..d8127cf45a73 100644 --- a/gcloud/storage/test_blob.py +++ b/gcloud/storage/test_blob.py @@ -749,6 +749,24 @@ def test_make_public(self): self.assertEqual(kw[0]['data'], {'acl': permissive}) self.assertEqual(kw[0]['query_params'], {'projection': 'full'}) + def test_make_public_w_explicit_connection(self): + from gcloud.storage.acl import _ACLEntity + BLOB_NAME = 'blob-name' + permissive = [{'entity': 'allUsers', 'role': _ACLEntity.READER_ROLE}] + after = {'acl': permissive} + connection = _Connection(after) + bucket = _Bucket(None) + blob = self._makeOne(BLOB_NAME, bucket=bucket) + blob.acl.loaded = True + blob.make_public(connection=connection) + self.assertEqual(list(blob.acl), permissive) + kw = connection._requested + self.assertEqual(len(kw), 1) + self.assertEqual(kw[0]['method'], 'PATCH') + self.assertEqual(kw[0]['path'], '/b/name/o/%s' % BLOB_NAME) + self.assertEqual(kw[0]['data'], {'acl': permissive}) + self.assertEqual(kw[0]['query_params'], {'projection': 'full'}) + def test_cache_control_getter(self): BLOB_NAME = 'blob-name' connection = _Connection() From ad0557d5dff512e56b46bb8ccf7f743e809d3d99 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Mon, 4 May 2015 17:31:15 -0400 Subject: [PATCH 2/2] Forward connection w/o interception to 'ACL.save'. --- gcloud/storage/blob.py | 2 -- gcloud/storage/test_blob.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/gcloud/storage/blob.py b/gcloud/storage/blob.py index 2ca9fe08c6bd..2776b71153a5 100644 --- a/gcloud/storage/blob.py +++ b/gcloud/storage/blob.py @@ -521,8 +521,6 @@ def make_public(self, connection=None): :param connection: Optional. The connection to use when sending requests. If not provided, falls back to default. """ - if connection is None: - connection = self.connection self.acl.all().grant_read() self.acl.save(connection=connection) diff --git a/gcloud/storage/test_blob.py b/gcloud/storage/test_blob.py index d8127cf45a73..5e5c0c1c9870 100644 --- a/gcloud/storage/test_blob.py +++ b/gcloud/storage/test_blob.py @@ -729,7 +729,7 @@ def test_upload_from_string_w_text(self): self.assertEqual(headers['Content-Type'], 'text/plain') self.assertEqual(rq[0]['body'], ENCODED) - def test_make_public(self): + def test_make_public_w_implicit_ocnnection(self): from gcloud.storage.acl import _ACLEntity from gcloud.storage._testing import _monkey_defaults BLOB_NAME = 'blob-name'