Beispiel #1
0
 def test_find_inventory(self):
     """ Find an Inventory by ID """
     Inventory("tools", "widget1").save()
     # saved_pet = Pet("kitty", "cat").save()
     saved_inventory = Inventory("materials", "widget2")
     saved_inventory.save()
     inventory = Inventory.find(saved_inventory.id)
     self.assertIsNot(inventory, None)
     self.assertEqual(inventory.id, saved_inventory.id)
     self.assertEqual(inventory.name, "materials")
Beispiel #2
0
def delete_inventory(inventory_id):
    """
    Delete an Inventory

    This endpoint will delete an inventory based the id specified in the path
    """
    app.logger.info('Request to delete inventory with id: %s', inventory_id)
    inventory = Inventory.find(inventory_id)
    if inventory:
        inventory.delete()
    return make_response('', status.HTTP_204_NO_CONTENT)
Beispiel #3
0
def get_inventory(inventory_id):
    """
    Retrieve a single Inventory

    This endpoint will return an Inventory based on it's id
    """
    app.logger.info('Request for Inventory with id: %s', inventory_id)
    inventory = Inventory.find(inventory_id)
    if not inventory:
        raise NotFound(
            "Inventory with id '{}' was not found.".format(inventory_id))
    return make_response(jsonify(inventory.serialize()), status.HTTP_200_OK)
Beispiel #4
0
def void_inventory(inventory_id):
    """Void an inventory item"""
    app.logger.info('Request to void inventory with id: %s', inventory_id)
    check_content_type('application/json')
    inventory = Inventory.find(inventory_id)
    if not inventory:
        raise NotFound(
            "Inventory with id '{}' was not found.".format(inventory_id))
    data = request.get_json()
    app.logger.info(data)
    inventory.deserialize(data)
    inventory.id = inventory_id
    inventory.available = False
    inventory.save()
    return make_response(jsonify(inventory.serialize()), status.HTTP_200_OK)
Beispiel #5
0
def update_inventory(inventory_id):
    """
    Update a Inventory

    This endpoint will update an Inventory based the body that is posted
    """
    app.logger.info('Request to Update a inventory with id [%s]', inventory_id)
    check_content_type('application/json')
    inventory = Inventory.find(inventory_id)
    if not inventory:
        raise NotFound(
            "inventory with id '{}' was not found.".format(inventory_id))
    data = request.get_json()
    app.logger.info(data)
    inventory.deserialize(data)
    inventory.id = inventory_id
    inventory.save()
    return make_response(jsonify(inventory.serialize()), status.HTTP_200_OK)