Skip to content

Commit d134452

Browse files
committed
Merge pull request #855 from tseaver/825-storage_blob_make_public-explicit_connection
#825: Allow passing explicit connection to 'Blob.make_public'
2 parents aafcd2a + ad0557d commit d134452

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

gcloud/storage/blob.py

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

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

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

gcloud/storage/test_blob.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ def test_upload_from_string_w_text(self):
729729
self.assertEqual(headers['Content-Type'], 'text/plain')
730730
self.assertEqual(rq[0]['body'], ENCODED)
731731

732-
def test_make_public(self):
732+
def test_make_public_w_implicit_ocnnection(self):
733733
from gcloud.storage.acl import _ACLEntity
734734
from gcloud.storage._testing import _monkey_defaults
735735
BLOB_NAME = 'blob-name'
@@ -749,6 +749,24 @@ def test_make_public(self):
749749
self.assertEqual(kw[0]['data'], {'acl': permissive})
750750
self.assertEqual(kw[0]['query_params'], {'projection': 'full'})
751751

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

0 commit comments

Comments
 (0)