diff options
-rw-r--r-- | glanceclient/tests/unit/test_shell.py | 4 | ||||
-rw-r--r-- | glanceclient/tests/unit/v1/test_images.py | 31 | ||||
-rw-r--r-- | glanceclient/tests/unit/v2/test_client_requests.py | 6 | ||||
-rw-r--r-- | glanceclient/tests/unit/v2/test_metadefs_namespaces.py | 16 |
4 files changed, 34 insertions, 23 deletions
diff --git a/glanceclient/tests/unit/test_shell.py b/glanceclient/tests/unit/test_shell.py index fce8ce0..4a123ab 100644 --- a/glanceclient/tests/unit/test_shell.py +++ b/glanceclient/tests/unit/test_shell.py @@ -45,6 +45,7 @@ import json DEFAULT_IMAGE_URL = 'http://127.0.0.1:9292/' DEFAULT_IMAGE_URL_INTERNAL = 'http://127.0.0.1:9191/' DEFAULT_USERNAME = 'username' +DEFAULT_PAGE_SIZE = 200 DEFAULT_PASSWORD = 'password' DEFAULT_TENANT_ID = 'tenant_id' DEFAULT_TENANT_NAME = 'tenant_name' @@ -711,7 +712,8 @@ class ShellTestWithNoOSImageURLPublic(ShellTestWithKeystoneV3Auth): glance_shell = openstack_shell.OpenStackImagesShell() glance_shell.main(args.split()) self.assertEqual(self.requests.request_history[2].url, - self.image_url + "v2/images?limit=200&" + self.image_url + "v2/images?" + f"limit={DEFAULT_PAGE_SIZE}&" "sort_key=name&sort_dir=asc") diff --git a/glanceclient/tests/unit/v1/test_images.py b/glanceclient/tests/unit/v1/test_images.py index 1af7412..ef8256c 100644 --- a/glanceclient/tests/unit/v1/test_images.py +++ b/glanceclient/tests/unit/v1/test_images.py @@ -25,6 +25,9 @@ from glanceclient.v1 import images from glanceclient.v1 import shell +DEFAULT_PAGE_SIZE = 20 + + fixtures = { '/v1/images': { 'POST': ( @@ -67,7 +70,7 @@ fixtures = { ]}, ), }, - '/v1/images/detail?is_public=None&limit=20': { + f'/v1/images/detail?is_public=None&limit={DEFAULT_PAGE_SIZE}': { 'GET': ( {'x-openstack-request-id': 'req-1234'}, {'images': [ @@ -157,7 +160,7 @@ fixtures = { ]}, ), }, - '/v1/images/detail?limit=20&marker=a': { + f'/v1/images/detail?limit={DEFAULT_PAGE_SIZE}&marker=a': { 'GET': ( {}, {'images': [ @@ -227,7 +230,7 @@ fixtures = { ]}, ), }, - '/v1/images/detail?limit=20&name=foo': { + f'/v1/images/detail?limit={DEFAULT_PAGE_SIZE}&name=foo': { 'GET': ( {}, {'images': [ @@ -244,7 +247,7 @@ fixtures = { ]}, ), }, - '/v1/images/detail?limit=20&property-ping=pong': + f'/v1/images/detail?limit={DEFAULT_PAGE_SIZE}&property-ping=pong': { 'GET': ( {}, @@ -257,7 +260,7 @@ fixtures = { ]}, ), }, - '/v1/images/detail?limit=20&sort_dir=desc': { + f'/v1/images/detail?limit={DEFAULT_PAGE_SIZE}&sort_dir=desc': { 'GET': ( {}, {'images': [ @@ -274,7 +277,7 @@ fixtures = { ]}, ), }, - '/v1/images/detail?limit=20&sort_key=name': { + f'/v1/images/detail?limit={DEFAULT_PAGE_SIZE}&sort_key=name': { 'GET': ( {}, {'images': [ @@ -467,31 +470,31 @@ class ImageManagerTest(testtools.TestCase): def test_list_with_marker(self): list(self.mgr.list(marker='a')) - url = '/v1/images/detail?limit=20&marker=a' + url = f'/v1/images/detail?limit={DEFAULT_PAGE_SIZE}&marker=a' expect = [('GET', url, {}, None)] self.assertEqual(expect, self.api.calls) def test_list_with_filter(self): list(self.mgr.list(filters={'name': "foo"})) - url = '/v1/images/detail?limit=20&name=foo' + url = f'/v1/images/detail?limit={DEFAULT_PAGE_SIZE}&name=foo' expect = [('GET', url, {}, None)] self.assertEqual(expect, self.api.calls) def test_list_with_property_filters(self): list(self.mgr.list(filters={'properties': {'ping': 'pong'}})) - url = '/v1/images/detail?limit=20&property-ping=pong' + url = f'/v1/images/detail?limit={DEFAULT_PAGE_SIZE}&property-ping=pong' expect = [('GET', url, {}, None)] self.assertEqual(expect, self.api.calls) def test_list_with_sort_dir(self): list(self.mgr.list(sort_dir='desc')) - url = '/v1/images/detail?limit=20&sort_dir=desc' + url = f'/v1/images/detail?limit={DEFAULT_PAGE_SIZE}&sort_dir=desc' expect = [('GET', url, {}, None)] self.assertEqual(expect, self.api.calls) def test_list_with_sort_key(self): list(self.mgr.list(sort_key='name')) - url = '/v1/images/detail?limit=20&sort_key=name' + url = f'/v1/images/detail?limit={DEFAULT_PAGE_SIZE}&sort_key=name' expect = [('GET', url, {}, None)] self.assertEqual(expect, self.api.calls) @@ -748,7 +751,7 @@ class ImageManagerTest(testtools.TestCase): self.assertEqual(value, headers["name"]) def test_image_list_with_owner(self): - images = self.mgr.list(owner='A', page_size=20) + images = self.mgr.list(owner='A', page_size=DEFAULT_PAGE_SIZE) image_list = list(images) self.assertEqual('A', image_list[0].owner) self.assertEqual('a', image_list[0].id) @@ -764,11 +767,11 @@ class ImageManagerTest(testtools.TestCase): self.assertEqual(['req-1234'], fields['return_req_id']) def test_image_list_with_notfound_owner(self): - images = self.mgr.list(owner='X', page_size=20) + images = self.mgr.list(owner='X', page_size=DEFAULT_PAGE_SIZE) self.assertEqual(0, len(list(images))) def test_image_list_with_empty_string_owner(self): - images = self.mgr.list(owner='', page_size=20) + images = self.mgr.list(owner='', page_size=DEFAULT_PAGE_SIZE) image_list = list(images) self.assertRaises(AttributeError, lambda: image_list[0].owner) self.assertEqual('c', image_list[0].id) diff --git a/glanceclient/tests/unit/v2/test_client_requests.py b/glanceclient/tests/unit/v2/test_client_requests.py index b1c32f2..287a201 100644 --- a/glanceclient/tests/unit/v2/test_client_requests.py +++ b/glanceclient/tests/unit/v2/test_client_requests.py @@ -25,6 +25,9 @@ from glanceclient.tests import utils as testutils from glanceclient.v2.image_schema import _BASE_SCHEMA +DEFAULT_PAGE_SIZE = 200 + + class ClientTestRequests(testutils.TestCase): """Client tests using the requests mock library.""" @@ -35,7 +38,8 @@ class ClientTestRequests(testutils.TestCase): self.requests = self.useFixture(rm_fixture.Fixture()) self.requests.get('http://example.com/v2/schemas/image', json=schema_fixture) - self.requests.get('http://example.com/v2/images?limit=200', + self.requests.get('http://example.com/v2/images?' + f'limit={DEFAULT_PAGE_SIZE}', json=image_list_fixture) gc = client.Client(2.2, "http://example.com/v2.1") images = gc.images.list() diff --git a/glanceclient/tests/unit/v2/test_metadefs_namespaces.py b/glanceclient/tests/unit/v2/test_metadefs_namespaces.py index 35d7198..6ef74fb 100644 --- a/glanceclient/tests/unit/v2/test_metadefs_namespaces.py +++ b/glanceclient/tests/unit/v2/test_metadefs_namespaces.py @@ -19,6 +19,7 @@ from glanceclient.tests.unit.v2 import base from glanceclient.tests import utils from glanceclient.v2 import metadefs +DEFAULT_PAGE_SIZE = 20 NAMESPACE1 = 'Namespace1' NAMESPACE2 = 'Namespace2' NAMESPACE3 = 'Namespace3' @@ -60,7 +61,7 @@ def _get_namespace_fixture(ns_name, rt_name=RESOURCE_TYPE1, **kwargs): data_fixtures = { - "/v2/metadefs/namespaces?limit=20": { + f"/v2/metadefs/namespaces?limit={DEFAULT_PAGE_SIZE}": { "GET": ( {}, { @@ -112,7 +113,7 @@ data_fixtures = { } ) }, - "/v2/metadefs/namespaces?limit=20&sort_dir=asc": { + f"/v2/metadefs/namespaces?limit={DEFAULT_PAGE_SIZE}&sort_dir=asc": { "GET": ( {}, { @@ -124,7 +125,7 @@ data_fixtures = { } ) }, - "/v2/metadefs/namespaces?limit=20&sort_key=created_at": { + f"/v2/metadefs/namespaces?limit={DEFAULT_PAGE_SIZE}&sort_key=created_at": { "GET": ( {}, { @@ -136,7 +137,8 @@ data_fixtures = { } ) }, - "/v2/metadefs/namespaces?limit=20&resource_types=%s" % RESOURCE_TYPE1: { + "/v2/metadefs/namespaces?limit=%d&resource_types=%s" % ( + DEFAULT_PAGE_SIZE, RESOURCE_TYPE1): { "GET": ( {}, { @@ -148,8 +150,8 @@ data_fixtures = { } ) }, - "/v2/metadefs/namespaces?limit=20&resource_types=" - "%s%%2C%s" % (RESOURCE_TYPE1, RESOURCE_TYPE2): { + "/v2/metadefs/namespaces?limit=%d&resource_types=" + "%s%%2C%s" % (DEFAULT_PAGE_SIZE, RESOURCE_TYPE1, RESOURCE_TYPE2): { "GET": ( {}, { @@ -161,7 +163,7 @@ data_fixtures = { } ) }, - "/v2/metadefs/namespaces?limit=20&visibility=private": { + f"/v2/metadefs/namespaces?limit={DEFAULT_PAGE_SIZE}&visibility=private": { "GET": ( {}, { |