def test_delete_a_inventory(self): """ Delete an inventory """ inventory = Inventory(name="tools", category="widget1", available=True,condition="new") inventory.save() self.assertEqual(len(Inventory.all()), 1) # delete the inventory and make sure it isn't in the database inventory.delete() self.assertEqual(len(Inventory.all()), 0)
def test_add_a_inventory(self): """ Create an inventory and add it to the database """ inventorys = Inventory.all() self.assertEqual(inventorys, []) inventory = Inventory(name="tools", category="widget1", available=True, condition="new") self.assertTrue(inventory != None) self.assertEqual(inventory.id, None) inventory.save() # Asert that it was assigned an id and shows up in the database self.assertNotEqual(inventory.id, None) inventorys = Inventory.all() self.assertEqual(len(inventorys), 1) self.assertEqual(inventorys[0].name, "tools") self.assertEqual(inventorys[0].category, "widget1") self.assertEqual(inventorys[0].available, True) self.assertEqual(inventorys[0].condition, "new")
def test_update_a_inventory(self): """ Update an Inventory """ inventory = Inventory(name="tools", category="widget1", available=True,condition="new") inventory.save() self.assertNotEqual(inventory.id, None) # Change it an save it inventory.category = "jkwidget2" inventory.save() # Fetch it back and make sure the id hasn't changed # but the data did change inventory = Inventory.all() self.assertEqual(len(inventory), 1) self.assertEqual(inventory[0].category, "jkwidget2") self.assertEqual(inventory[0].name, "tools")
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)