def test_more_files__no_available_params__breaks(self): """ Tests that the method breaks if the paratemers for the next request are empty. """ bucket = Bucket(self.mock_api, {}) bucket._next_files = False bucket._next_params = (1, 2, 3) self.assertEqual([], list(bucket.more_files())) bucket._next_files = True bucket._next_params = False self.assertEqual([], list(bucket.more_files()))
def test_more_files__no_more_files__breaks(self): """ Tests that the method breaks if the request returns empty results. """ bucket = Bucket(self.mock_api, {}) bucket.files = MagicMock() bucket.files.return_value = [] bucket._next_files = True bucket._next_params = (1, 2, 3) self.assertEqual([], list(bucket.more_files())) bucket.files.assert_called_with(*bucket._next_params, bucket._next_files)
def test_more_files__files_available__yields_files(self): """ Tests that more files are listed if available. """ bucket = Bucket(self.mock_api, {}) bucket.files = MagicMock() names = ('f1', 'f2') bucket.files.side_effect = [ [File(self.mock_api, bucket, {'fileName': names[0]})], [File(self.mock_api, bucket, {'fileName': names[1]})], ] bucket._next_files = True bucket._next_params = (1, 2, 3) more_files_generator = bucket.more_files() for name in names: files = next(more_files_generator) self.assertTrue(isinstance(files, list)) self.assertTrue(isinstance(files[0], File)) self.assertEqual(files[0].name, name) self.assertRaises(RuntimeError, next, more_files_generator)