Skip to content

Commit

Permalink
#825: Allow passing explicit connection to '_BlobIterator.__init__'.
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed May 6, 2015
1 parent 245a090 commit f97c62c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 11 additions & 0 deletions gcloud/storage/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f97c62c

Please sign in to comment.