summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFlavio Percoco <flaper87@gmail.com>2015-01-27 14:20:27 +0100
committerFlavio Percoco <fpercoco@redhat.com>2015-01-29 10:37:55 +0000
commit93c9bc1fe0ae3f5c95395e7a883fdffcc79d7151 (patch)
tree144bd39ac84421b72484f204baeef6b3be45d64b /tests
parent363b17085195e6f38c8b7cf3ac3398f5f3806305 (diff)
downloadpython-glanceclient-93c9bc1fe0ae3f5c95395e7a883fdffcc79d7151.tar.gz
Add a `--limit` parameter to list operations
In v2, we use the link header during paginations to know when there are more images available in the server that could be returned in the same request. This way, it's possible to iterate over the generator returned by list and consume the images in the server. However, it's currently not possible to tell glanceclient the exact number of images we want, which basically means that it'll *always* go through the whole list of images in the server unless the limit is implemented by the consumer. DocImpact Change-Id: I9f65a40d4eafda6320e5c7d94d03fcd1bbc93e33 Closes-bug: #1415035
Diffstat (limited to 'tests')
-rw-r--r--tests/v2/test_images.py41
-rw-r--r--tests/v2/test_shell_v2.py2
2 files changed, 43 insertions, 0 deletions
diff --git a/tests/v2/test_images.py b/tests/v2/test_images.py
index ed6e75f..2f3efeb 100644
--- a/tests/v2/test_images.py
+++ b/tests/v2/test_images.py
@@ -78,6 +78,25 @@ data_fixtures = {
]},
),
},
+ '/v2/images?limit=2': {
+ 'GET': (
+ {},
+ {
+ 'images': [
+ {
+ 'id': '3a4560a1-e585-443e-9b39-553b46ec92d1',
+ 'name': 'image-1',
+ },
+ {
+ 'id': '6f99bf80-2ee6-47cf-acfe-1f1fabb7e810',
+ 'name': 'image-2',
+ },
+ ],
+ 'next': ('/v2/images?limit=2&'
+ 'marker=6f99bf80-2ee6-47cf-acfe-1f1fabb7e810'),
+ },
+ ),
+ },
'/v2/images?limit=1': {
'GET': (
{},
@@ -104,6 +123,17 @@ data_fixtures = {
]},
),
},
+ ('/v2/images?limit=1&marker=6f99bf80-2ee6-47cf-acfe-1f1fabb7e810'): {
+ 'GET': (
+ {},
+ {'images': [
+ {
+ 'id': '3f99bf80-2ee6-47cf-acfe-1f1fabb7e811',
+ 'name': 'image-3',
+ },
+ ]},
+ ),
+ },
'/v2/images/3a4560a1-e585-443e-9b39-553b46ec92d1': {
'GET': (
{},
@@ -420,6 +450,17 @@ class TestController(testtools.TestCase):
self.assertEqual('6f99bf80-2ee6-47cf-acfe-1f1fabb7e810', images[1].id)
self.assertEqual('image-2', images[1].name)
+ def test_list_images_paginated_with_limit(self):
+ # NOTE(bcwaldon):cast to list since the controller returns a generator
+ images = list(self.controller.list(limit=3, page_size=2))
+ self.assertEqual('3a4560a1-e585-443e-9b39-553b46ec92d1', images[0].id)
+ self.assertEqual('image-1', images[0].name)
+ self.assertEqual('6f99bf80-2ee6-47cf-acfe-1f1fabb7e810', images[1].id)
+ self.assertEqual('image-2', images[1].name)
+ self.assertEqual('3f99bf80-2ee6-47cf-acfe-1f1fabb7e811', images[2].id)
+ self.assertEqual('image-3', images[2].name)
+ self.assertEqual(3, len(images))
+
def test_list_images_visibility_public(self):
filters = {'filters': {'visibility': 'public'}}
images = list(self.controller.list(**filters))
diff --git a/tests/v2/test_shell_v2.py b/tests/v2/test_shell_v2.py
index 3480e5c..fd781c0 100644
--- a/tests/v2/test_shell_v2.py
+++ b/tests/v2/test_shell_v2.py
@@ -61,6 +61,7 @@ class ShellV2Test(testtools.TestCase):
def test_do_image_list(self):
input = {
+ 'limit': None,
'page_size': 18,
'visibility': True,
'member_status': 'Fake',
@@ -88,6 +89,7 @@ class ShellV2Test(testtools.TestCase):
def test_do_image_list_with_property_filter(self):
input = {
+ 'limit': None,
'page_size': 1,
'visibility': True,
'member_status': 'Fake',