Skip to content

Commit

Permalink
Fixing use of Iterator in storage system tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Oct 25, 2016
1 parent a6890c5 commit 9a504c6
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions system_tests/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,20 @@ def test_paginate_files(self):
truncation_size = 1
count = len(self.FILENAMES) - truncation_size
iterator = self.bucket.list_blobs(max_results=count)
iterator.update_page()
blobs = list(iterator.page)
page_iter = iterator.pages

page1 = six.next(page_iter)
blobs = list(page1)
self.assertEqual(len(blobs), count)
self.assertIsNotNone(iterator.next_page_token)

iterator.update_page()
last_blobs = list(iterator.page)
# Technically the iterator is exhausted.
self.assertEqual(iterator.num_results, iterator.max_results)
# But we modify the iterator to continue paging after
# articially stopping after ``count`` items.
iterator.max_results = None

page2 = six.next(page_iter)
last_blobs = list(page2)
self.assertEqual(len(last_blobs), truncation_size)


Expand Down Expand Up @@ -301,17 +308,17 @@ def tearDownClass(cls):
@RetryErrors(unittest.TestCase.failureException)
def test_root_level_w_delimiter(self):
iterator = self.bucket.list_blobs(delimiter='/')
iterator.update_page()
blobs = list(iterator.page)
page = six.next(iterator.pages)
blobs = list(page)
self.assertEqual([blob.name for blob in blobs], ['file01.txt'])
self.assertIsNone(iterator.next_page_token)
self.assertEqual(iterator.prefixes, set(['parent/']))

@RetryErrors(unittest.TestCase.failureException)
def test_first_level(self):
iterator = self.bucket.list_blobs(delimiter='/', prefix='parent/')
iterator.update_page()
blobs = list(iterator.page)
page = six.next(iterator.pages)
blobs = list(page)
self.assertEqual([blob.name for blob in blobs], ['parent/file11.txt'])
self.assertIsNone(iterator.next_page_token)
self.assertEqual(iterator.prefixes, set(['parent/child/']))
Expand All @@ -325,8 +332,8 @@ def test_second_level(self):

iterator = self.bucket.list_blobs(delimiter='/',
prefix='parent/child/')
iterator.update_page()
blobs = list(iterator.page)
page = six.next(iterator.pages)
blobs = list(page)
self.assertEqual([blob.name for blob in blobs],
expected_names)
self.assertIsNone(iterator.next_page_token)
Expand All @@ -341,8 +348,8 @@ def test_third_level(self):
# Exercise a layer deeper to illustrate this.
iterator = self.bucket.list_blobs(delimiter='/',
prefix='parent/child/grand/')
iterator.update_page()
blobs = list(iterator.page)
page = six.next(iterator.pages)
blobs = list(page)
self.assertEqual([blob.name for blob in blobs],
['parent/child/grand/file31.txt'])
self.assertIsNone(iterator.next_page_token)
Expand Down

0 comments on commit 9a504c6

Please sign in to comment.