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
12 changes: 9 additions & 3 deletions gcloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,16 @@ 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.
"""
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.
Expand Down
20 changes: 19 additions & 1 deletion gcloud/storage/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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()
Expand Down