Merge "Unhardcode the value of DEFAULT_PAGE_SIZE from the tests"

This commit is contained in:
Zuul 2023-02-09 15:33:18 +00:00 committed by Gerrit Code Review
commit 2d893b12dd
4 changed files with 34 additions and 23 deletions

View File

@ -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")

View File

@ -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)

View File

@ -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()

View File

@ -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": (
{},
{