Add limit and marker to QueryParameters class
After moving to resource2, we've sort of lost the ability to set limits and markers on list calls while adding query mappings to Resource subclasses via the QueryParameters class. Every accepted query parameter must be listed there, so because we didn't have limit and marker in there, we were only supporting unbounded list requests even though Resource.list is capable of accepting limit and marker arguments. This change adds limit and marker into the default mapping since they're so widely used. Change-Id: I31901b03974b198af3d7231003d985a1ae54062f
This commit is contained in:
parent
431c20269b
commit
88f27bf520
@ -190,8 +190,12 @@ class QueryParameters(object):
|
||||
:param mappings: Key-value pairs where the key is the client-side
|
||||
name we'll accept here and the value is the name
|
||||
the server expects, e.g, changes_since=changes-since
|
||||
|
||||
By default, both limit and marker are included in the initial mapping
|
||||
as they're the most common query parameters used for listing resources.
|
||||
"""
|
||||
self._mapping = dict({name: name for name in names}, **mappings)
|
||||
self._mapping = {"limit": "limit", "marker": "marker"}
|
||||
self._mapping.update(dict({name: name for name in names}, **mappings))
|
||||
|
||||
def _transpose(self, query):
|
||||
"""Transpose the keys in query based on the mapping
|
||||
|
@ -47,7 +47,9 @@ class TestFlavor(testtools.TestCase):
|
||||
self.assertDictEqual({"sort_key": "sort_key",
|
||||
"sort_dir": "sort_dir",
|
||||
"min_disk": "minDisk",
|
||||
"min_ram": "minRam"},
|
||||
"min_ram": "minRam",
|
||||
"limit": "limit",
|
||||
"marker": "marker"},
|
||||
sot._query_mapping._mapping)
|
||||
|
||||
def test_make_basic(self):
|
||||
|
@ -56,7 +56,9 @@ class TestImage(testtools.TestCase):
|
||||
"type": "type",
|
||||
"min_disk": "minDisk",
|
||||
"min_ram": "minRam",
|
||||
"changes_since": "changes-since"},
|
||||
"changes_since": "changes-since",
|
||||
"limit": "limit",
|
||||
"marker": "marker"},
|
||||
sot._query_mapping._mapping)
|
||||
|
||||
def test_make_basic(self):
|
||||
|
@ -83,7 +83,9 @@ class TestServer(testtools.TestCase):
|
||||
"status": "status",
|
||||
"host": "host",
|
||||
"all_tenants": "all_tenants",
|
||||
"changes_since": "changes-since"},
|
||||
"changes_since": "changes-since",
|
||||
"limit": "limit",
|
||||
"marker": "marker"},
|
||||
sot._query_mapping._mapping)
|
||||
|
||||
def test_make_it(self):
|
||||
|
@ -37,7 +37,8 @@ class TestServerGroup(testtools.TestCase):
|
||||
self.assertTrue(sot.allow_delete)
|
||||
self.assertTrue(sot.allow_list)
|
||||
|
||||
self.assertDictEqual({"all_projects": "all_projects"},
|
||||
self.assertDictEqual({"all_projects": "all_projects",
|
||||
"limit": "limit", "marker": "marker"},
|
||||
sot._query_mapping._mapping)
|
||||
|
||||
def test_make_it(self):
|
||||
|
@ -58,7 +58,9 @@ class TestSecret(testtools.TestCase):
|
||||
"updated": "updated",
|
||||
"expiration": "expiration",
|
||||
"sort": "sort",
|
||||
"algorithm": "alg"},
|
||||
"algorithm": "alg",
|
||||
"limit": "limit",
|
||||
"marker": "marker"},
|
||||
sot._query_mapping._mapping)
|
||||
|
||||
def test_make_it(self):
|
||||
|
@ -350,7 +350,10 @@ class TestQueryParameters(base.TestCase):
|
||||
|
||||
sot = resource2.QueryParameters(location, **mapping)
|
||||
|
||||
self.assertEqual({"location": "location", "first_name": "first-name"},
|
||||
self.assertEqual({"location": "location",
|
||||
"first_name": "first-name",
|
||||
"limit": "limit",
|
||||
"marker": "marker"},
|
||||
sot._mapping)
|
||||
|
||||
def test_transpose_unmapped(self):
|
||||
|
Loading…
Reference in New Issue
Block a user