def test_list_inventories_with_filters(self): provider = utils.create_test_resource_provider( context=self.context) inventory1 = utils.create_test_inventory( total=10, resource_provider_id=provider.id, resource_class_id=1, context=self.context) inventory2 = utils.create_test_inventory( total=20, resource_provider_id=provider.id, resource_class_id=2, context=self.context) res = dbapi.list_inventories( self.context, filters={'total': 10}) self.assertEqual([inventory1.id], [r.id for r in res]) res = dbapi.list_inventories( self.context, filters={'total': 20}) self.assertEqual([inventory2.id], [r.id for r in res]) res = dbapi.list_inventories( self.context, filters={'total': 11111}) self.assertEqual([], [r.id for r in res]) res = dbapi.list_inventories( self.context, filters={'total': inventory1.total}) self.assertEqual([inventory1.id], [r.id for r in res])
def test_list_inventories(self): totals = [] for i in range(1, 6): provider = utils.create_test_resource_provider( id=i, uuid=uuidutils.generate_uuid(), context=self.context) inventory = utils.create_test_inventory( id=i, resource_provider_id=provider.id, total=i, context=self.context) totals.append(inventory['total']) res = dbapi.list_inventories(self.context) res_totals = [r.total for r in res] self.assertEqual(sorted(totals), sorted(res_totals))
def test_list_inventories_sorted(self): totals = [] for i in range(5): provider = utils.create_test_resource_provider( id=i, uuid=uuidutils.generate_uuid(), context=self.context) inventory = utils.create_test_inventory( id=i, resource_provider_id=provider.id, total=10 - i, context=self.context) totals.append(inventory['total']) res = dbapi.list_inventories(self.context, sort_key='total') res_totals = [r.total for r in res] self.assertEqual(sorted(totals), res_totals) self.assertRaises(exception.InvalidParameterValue, dbapi.list_inventories, self.context, sort_key='foo')