Skip to content

Commit

Permalink
Merge pull request #855 from tseaver/825-storage_blob_make_public-exp…
Browse files Browse the repository at this point in the history
…licit_connection

#825:  Allow passing explicit connection to 'Blob.make_public'
  • Loading branch information
tseaver committed May 7, 2015
2 parents aafcd2a + ad0557d commit d134452
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
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

0 comments on commit d134452

Please sign in to comment.