예제 #1
0
 def test_find_by_restock_level(self):
     """ Find inventories by restock_level"""
     Inventory(product_id=1,
               quantity=100,
               restock_level=20,
               condition="new",
               available=True).save()
     Inventory(product_id=2,
               quantity=20,
               restock_level=30,
               condition="new",
               available=True).save()
     Inventory(product_id=3,
               quantity=30,
               restock_level=50,
               condition="new",
               available=True).save()
     Inventory(product_id=4,
               quantity=120,
               restock_level=50,
               condition="new",
               available=True).save()
     Inventory(product_id=5,
               quantity=49,
               restock_level=50,
               condition="new",
               available=True).save()
     inventory = Inventory.find_by_restock_level(20)
     self.assertEqual(len(inventory), 1)
     inventory = Inventory.find_by_restock_level(50)
     self.assertEqual(len(inventory), 3)
예제 #2
0
def list_inventory():
    """ Returns all of the inventory """
    app.logger.info('Request for inventory list')
    inventories = []
    restock = request.args.get('restock')
    restock_level = request.args.get('restock-level')
    condition = request.args.get('condition')
    product_id = request.args.get('product-id')
    available = request.args.get('available')
    if restock:
        if restock == "true":
            inventories = Inventory.find_by_restock(True)
        elif restock == "false":
            inventories = Inventory.find_by_restock(False)
    elif restock_level:
        inventories = Inventory.find_by_restock_level(restock_level)
    elif condition:
        if product_id:
            inventories = Inventory.find_by_condition_with_pid(
                condition, product_id)
        elif not product_id:
            inventories = Inventory.find_by_condition(condition)
    elif product_id:
        inventories = Inventory.find_by_product_id(product_id)
    elif available:
        if available == 'true':
            inventories = Inventory.find_by_availability(True)
        elif available == 'false':
            inventories = Inventory.find_by_availability(False)
    else:
        inventories = Inventory.all()
    results = [e.serialize() for e in inventories]
    return make_response(jsonify(results), status.HTTP_200_OK)