diff --git a/gcloud/storage/acl.py b/gcloud/storage/acl.py index 673aa05d744d..1be3a0a7d966 100644 --- a/gcloud/storage/acl.py +++ b/gcloud/storage/acl.py @@ -351,15 +351,33 @@ def get_entities(self): self._ensure_loaded() return list(self.entities.values()) - def reload(self, connection=None): + @staticmethod + def _client_or_connection(client): + """Temporary method to get a connection from a client. + + If the client is null, gets the connection from the environment. + + :type client: :class:`gcloud.storage.client.Client` or ``NoneType`` + :param client: Optional. The client to use. If not passed, falls back + to default connection. + + :rtype: :class:`gcloud.storage.connection.Connection` + :returns: The connection determined from the ``client`` or environment. + """ + if client is None: + return _require_connection() + else: + return client.connection + + def reload(self, client=None): """Reload the ACL data from Cloud Storage. - :type connection: :class:`gcloud.storage.connection.Connection` or None - :param connection: explicit connection to use for API request; - defaults to instance property. + :type client: :class:`gcloud.storage.client.Client` or ``NoneType`` + :param client: Optional. The client to use. If not passed, falls back + to default connection. """ path = self.reload_path - connection = _require_connection(connection) + connection = self._client_or_connection(client) self.entities.clear() diff --git a/gcloud/storage/bucket.py b/gcloud/storage/bucket.py index ccd59f65d87f..50c7d607a5fa 100644 --- a/gcloud/storage/bucket.py +++ b/gcloud/storage/bucket.py @@ -830,7 +830,7 @@ def disable_website(self): """ return self.configure_website(None, None) - def make_public(self, recursive=False, future=False, connection=None): + def make_public(self, recursive=False, future=False, client=None): """Make a bucket public. If ``recursive=True`` and the bucket contains more than 256 @@ -845,12 +845,11 @@ def make_public(self, recursive=False, future=False, connection=None): :param future: If True, this will make all objects created in the future public as well. - :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. + :type client: :class:`gcloud.storage.client.Client` or ``NoneType`` + :param client: Optional. The client to use. If not passed, falls back + to default connection. """ - connection = _require_connection(connection) + connection = self._client_or_connection(client) self.acl.all().grant_read() self.acl.save(connection=connection) @@ -858,7 +857,7 @@ def make_public(self, recursive=False, future=False, connection=None): if future: doa = self.default_object_acl if not doa.loaded: - doa.reload(connection=connection) + doa.reload(client=client) doa.all().grant_read() doa.save(connection=connection) diff --git a/gcloud/storage/test_acl.py b/gcloud/storage/test_acl.py index 7c0b9fb197e1..4919062984e5 100644 --- a/gcloud/storage/test_acl.py +++ b/gcloud/storage/test_acl.py @@ -526,11 +526,12 @@ def test_reload_missing_w_explicit_connection(self): # https://github.com/GoogleCloudPlatform/gcloud-python/issues/652 ROLE = 'role' connection = _Connection({}) + client = _Client(connection) acl = self._makeOne() acl.reload_path = '/testing/acl' acl.loaded = True acl.entity('allUsers', ROLE) - acl.reload(connection=connection) + acl.reload(client=client) self.assertEqual(list(acl), []) kw = connection._requested self.assertEqual(len(kw), 1) @@ -557,11 +558,12 @@ def test_reload_empty_result_clears_local_w_implicit_connection(self): def test_reload_empty_result_clears_local_w_explicit_connection(self): ROLE = 'role' connection = _Connection({'items': []}) + client = _Client(connection) acl = self._makeOne() acl.reload_path = '/testing/acl' acl.loaded = True acl.entity('allUsers', ROLE) - acl.reload(connection=connection) + acl.reload(client=client) self.assertTrue(acl.loaded) self.assertEqual(list(acl), []) kw = connection._requested @@ -590,10 +592,11 @@ def test_reload_nonempty_result_w_explicit_connection(self): ROLE = 'role' connection = _Connection( {'items': [{'entity': 'allUsers', 'role': ROLE}]}) + client = _Client(connection) acl = self._makeOne() acl.reload_path = '/testing/acl' acl.loaded = True - acl.reload(connection=connection) + acl.reload(client=client) self.assertTrue(acl.loaded) self.assertEqual(list(acl), [{'entity': 'allUsers', 'role': ROLE}]) kw = connection._requested @@ -870,3 +873,9 @@ def api_request(self, **kw): raise NotFound('miss') else: return response + + +class _Client(object): + + def __init__(self, connection): + self.connection = connection diff --git a/gcloud/storage/test_bucket.py b/gcloud/storage/test_bucket.py index f05b498c12e1..23943ec6c629 100644 --- a/gcloud/storage/test_bucket.py +++ b/gcloud/storage/test_bucket.py @@ -1026,6 +1026,7 @@ def test_make_public_recursive_too_many(self): ], } connection = _Connection(AFTER, GET_BLOBS_RESP) + client = _Client(connection) bucket = self._makeOne(NAME) bucket.acl.loaded = True bucket.default_object_acl.loaded = True @@ -1033,7 +1034,7 @@ def test_make_public_recursive_too_many(self): # Make the Bucket refuse to make_public with 2 objects. bucket._MAX_OBJECTS_FOR_ITERATION = 1 self.assertRaises(ValueError, bucket.make_public, recursive=True, - connection=connection) + client=client) class _Connection(object):