def test_find_by_available(self): inventory = Inventory(product_id=333, condition="new", quantity=1, restock_level=10, available=0) if not Inventory.find_by_product_id_condition(inventory.product_id, inventory.condition): inventory.create() inventory = Inventory(product_id=444, condition="new", quantity=1, restock_level=10, available=1) if not Inventory.find_by_product_id_condition(inventory.product_id, inventory.condition): inventory.create() inventories = Inventory.find_by_available(1) self.assertEqual(len(list(inventories)), 1)
def get(self): """ Returns a collection of the inventory records """ msg = "A GET request for ALL inventories." inventories = [] params = inventory_args.parse_args() if params[keys.KEY_PID]: pid = params[keys.KEY_PID] query = 'Filtering by category: {}'.format(params[keys.KEY_PID]) app.logger.info(query) msg = "{} {}".format(msg, query) inventories = Inventory.find_by_product_id(pid) elif params[keys.KEY_CND]: cnd = params[keys.KEY_CND] query = 'Filtering by category: {}'.format(params[keys.KEY_CND]) app.logger.info(query) msg = "{} {}".format(msg, query) inventories = Inventory.find_by_condition(cnd) elif params[keys.KEY_QTY] and params[keys.KEY_QTY] >= 0: qty = params[keys.KEY_QTY] query = 'Filtering by category: {}'.format(params[keys.KEY_QTY]) app.logger.info(query) msg = "{} {}".format(msg, query) inventories = Inventory.find_by_quantity(qty) elif params[keys.KEY_AVL] in [ keys.AVAILABLE_TRUE, keys.AVAILABLE_FALSE ]: avl = params[keys.KEY_AVL] query = 'Filtering by category: {}'.format(params[keys.KEY_AVL]) app.logger.info(query) msg = "{} {}".format(msg, query) inventories = Inventory.find_by_available(avl) else: inventories = Inventory.find_all() app.logger.info(msg) results = [inv.serialize() for inv in inventories] app.logger.info("Returning {} inventories".format(len(results))) return results, status.HTTP_200_OK