From f97c62c19d2c7b693da1280308d871db0f1a0520 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 1 May 2015 16:30:24 -0400 Subject: [PATCH] #825: Allow passing explicit connection to '_BlobIterator.__init__'. --- gcloud/storage/bucket.py | 10 ++++++++-- gcloud/storage/test_bucket.py | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/gcloud/storage/bucket.py b/gcloud/storage/bucket.py index 4589d4ee3f62..fe533ba34e55 100644 --- a/gcloud/storage/bucket.py +++ b/gcloud/storage/bucket.py @@ -63,12 +63,18 @@ class _BlobIterator(Iterator): :type extra_params: dict or None :param extra_params: Extra query string parameters for the API call. + + :type connection: :class:`gcloud.storage.connection.Connection` + :param connection: The connection to use when sending requests. Defaults + to the bucket's connection """ - def __init__(self, bucket, extra_params=None): + def __init__(self, bucket, extra_params=None, connection=None): + if connection is None: + connection = bucket.connection self.bucket = bucket self.prefixes = () super(_BlobIterator, self).__init__( - connection=bucket.connection, path=bucket.path + '/o', + connection=connection, path=bucket.path + '/o', extra_params=extra_params) def get_items_from_response(self, response): diff --git a/gcloud/storage/test_bucket.py b/gcloud/storage/test_bucket.py index 8274b2e6e16e..6a74fbccd8f2 100644 --- a/gcloud/storage/test_bucket.py +++ b/gcloud/storage/test_bucket.py @@ -37,6 +37,17 @@ def test_ctor(self): self.assertEqual(iterator.next_page_token, None) self.assertEqual(iterator.prefixes, ()) + def test_ctor_w_explicit_connection(self): + connection = _Connection() + bucket = _Bucket(None) + iterator = self._makeOne(bucket, connection=connection) + self.assertTrue(iterator.bucket is bucket) + self.assertTrue(iterator.connection is connection) + self.assertEqual(iterator.path, '%s/o' % bucket.path) + self.assertEqual(iterator.page_number, 0) + self.assertEqual(iterator.next_page_token, None) + self.assertEqual(iterator.prefixes, ()) + def test_get_items_from_response_empty(self): connection = _Connection() bucket = _Bucket(connection)