Skip to content

Commit

Permalink
Allow passing explicit connection to 'Blob.make_public'.
Browse files Browse the repository at this point in the history
See #825.
  • Loading branch information
tseaver committed May 2, 2015
1 parent ef28081 commit 02ce8e1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
14 changes: 11 additions & 3 deletions gcloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,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.
Expand Down
18 changes: 18 additions & 0 deletions gcloud/storage/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,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

0 comments on commit 02ce8e1

Please sign in to comment.