def test_find_by_category(self): """ Find an Inventory by Category """ Inventory(name="tools", category="widget1", available=True,condition="new").save() Inventory(name="materials", category="widget2", available=False,condition="old").save() inventory = Inventory.find_by_category("widget1") self.assertEqual(inventory[0].category, "widget1") self.assertEqual(inventory[0].name, "tools") self.assertEqual(inventory[0].available, True) self.assertEqual(inventory[0].condition, "new")
def list_inventory(): """ Returns all of the Inventory """ app.logger.info('Request for inventory list') inventory = [] category = request.args.get('category') name = request.args.get('name') condition = request.args.get('condition') count = request.args.get('count') available = request.args.get('available') if category: inventory = Inventory.find_by_category(category) elif name: inventory = Inventory.find_by_name(name) else: inventory = Inventory.all() results = [inventory.serialize() for inventory in inventory] return make_response(jsonify(results), status.HTTP_200_OK)