Merge "Object: pass filter to bay list"
This commit is contained in:
commit
53b48b8f7b
|
@ -125,7 +125,7 @@ class Bay(base.MagnumPersistentObject, base.MagnumObject,
|
|||
|
||||
@base.remotable_classmethod
|
||||
def list(cls, context, limit=None, marker=None,
|
||||
sort_key=None, sort_dir=None):
|
||||
sort_key=None, sort_dir=None, filters=None):
|
||||
"""Return a list of Bay objects.
|
||||
|
||||
:param context: Security context.
|
||||
|
@ -133,13 +133,17 @@ class Bay(base.MagnumPersistentObject, base.MagnumObject,
|
|||
:param marker: pagination marker for large data sets.
|
||||
:param sort_key: column to sort results by.
|
||||
:param sort_dir: direction to sort. "asc" or "desc".
|
||||
:param filters: filter dict, can includes 'baymodel_id', 'name',
|
||||
'node_count', 'stack_id', 'api_address',
|
||||
'node_addresses', 'project_id', 'user_id'.
|
||||
:returns: a list of :class:`Bay` object.
|
||||
|
||||
"""
|
||||
db_bays = cls.dbapi.get_bay_list(context, limit=limit,
|
||||
marker=marker,
|
||||
sort_key=sort_key,
|
||||
sort_dir=sort_dir)
|
||||
sort_dir=sort_dir,
|
||||
filters=filters)
|
||||
return Bay._from_db_object_list(db_bays, cls, context)
|
||||
|
||||
@base.remotable
|
||||
|
|
|
@ -70,6 +70,22 @@ class TestBayObject(base.DbTestCase):
|
|||
self.assertIsInstance(bays[0], objects.Bay)
|
||||
self.assertEqual(self.context, bays[0]._context)
|
||||
|
||||
def test_list_with_filters(self):
|
||||
with mock.patch.object(self.dbapi, 'get_bay_list',
|
||||
autospec=True) as mock_get_list:
|
||||
mock_get_list.return_value = [self.fake_bay]
|
||||
filters = {'name': 'bay1'}
|
||||
bays = objects.Bay.list(self.context, filters=filters)
|
||||
|
||||
mock_get_list.assert_called_once_with(self.context, sort_key=None,
|
||||
sort_dir=None,
|
||||
filters=filters, limit=None,
|
||||
marker=None)
|
||||
self.assertEqual(mock_get_list.call_count, 1)
|
||||
self.assertThat(bays, HasLength(1))
|
||||
self.assertIsInstance(bays[0], objects.Bay)
|
||||
self.assertEqual(self.context, bays[0]._context)
|
||||
|
||||
def test_create(self):
|
||||
with mock.patch.object(self.dbapi, 'create_bay',
|
||||
autospec=True) as mock_create_bay:
|
||||
|
|
Loading…
Reference in New Issue