Skip to content

Commit 02ce8e1

Browse files
committed
Allow passing explicit connection to 'Blob.make_public'.
See #825.
1 parent ef28081 commit 02ce8e1

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

gcloud/storage/blob.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,18 @@ def upload_from_string(self, data, content_type='text/plain',
512512
size=len(data), content_type=content_type,
513513
connection=connection)
514514

515-
def make_public(self):
516-
"""Make this blob public giving all users read access."""
515+
def make_public(self, connection=None):
516+
"""Make this blob public giving all users read access.
517+
518+
:type connection: :class:`gcloud.storage.connection.Connection` or
519+
``NoneType``
520+
:param connection: Optional. The connection to use when sending
521+
requests. If not provided, falls back to default.
522+
"""
523+
if connection is None:
524+
connection = self.connection
517525
self.acl.all().grant_read()
518-
self.acl.save()
526+
self.acl.save(connection=connection)
519527

520528
cache_control = _scalar_property('cacheControl')
521529
"""HTTP 'Cache-Control' header for this object.

gcloud/storage/test_blob.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,24 @@ def test_make_public(self):
747747
self.assertEqual(kw[0]['data'], {'acl': permissive})
748748
self.assertEqual(kw[0]['query_params'], {'projection': 'full'})
749749

750+
def test_make_public_w_explicit_connection(self):
751+
from gcloud.storage.acl import _ACLEntity
752+
BLOB_NAME = 'blob-name'
753+
permissive = [{'entity': 'allUsers', 'role': _ACLEntity.READER_ROLE}]
754+
after = {'acl': permissive}
755+
connection = _Connection(after)
756+
bucket = _Bucket(None)
757+
blob = self._makeOne(BLOB_NAME, bucket=bucket)
758+
blob.acl.loaded = True
759+
blob.make_public(connection=connection)
760+
self.assertEqual(list(blob.acl), permissive)
761+
kw = connection._requested
762+
self.assertEqual(len(kw), 1)
763+
self.assertEqual(kw[0]['method'], 'PATCH')
764+
self.assertEqual(kw[0]['path'], '/b/name/o/%s' % BLOB_NAME)
765+
self.assertEqual(kw[0]['data'], {'acl': permissive})
766+
self.assertEqual(kw[0]['query_params'], {'projection': 'full'})
767+
750768
def test_cache_control_getter(self):
751769
BLOB_NAME = 'blob-name'
752770
connection = _Connection()

0 commit comments

Comments
 (0)