Esempio n. 1
0
def delete_inventory(inventory_id):
    """
    Delete an inventory
    This endpoint will delete an inventory based on 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)
def delete_inventory_item_by_id(inv_id):
    """
    Delete an Inventory Item

    This endpoint will delete and inventory item based the id specified in the path
    """
    app.logger.info("Request to delete inventory item with id: ", inv_id)
    inv = Inventory.find(inv_id)
    if inv:
        inv.delete()
    return make_response("", status.HTTP_204_NO_CONTENT)
Esempio n. 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 inventory_id '{}' was not found.".format(
                inventory_id))
    return make_response(jsonify(inventory.serialize()), status.HTTP_200_OK)
Esempio n. 4
0
 def get(self, 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:
         api.abort(
             status.HTTP_404_NOT_FOUND, "Inventory with id '{}' was not \
                   found.".format(inventory_id))
     return inventory.serialize(), status.HTTP_200_OK
def get_inventory_item_by_id(inv_id):
    """
    Retrieve a record for single Inventory row

    This endpoint will return an Inventory row based on its id
    """
    app.logger.info("Request for pet with id: %", inv_id)
    inv = Inventory.find(inv_id)
    if not inv:
        raise NotFound(
            "Inventory Item with id '{}' was not found.".format(inv_id))
    return make_response(jsonify(inv.serialize()), status.HTTP_200_OK)
Esempio n. 6
0
 def test_find_item(self):
     """ Find an item by ID """
     inv_items = InventoryFactory.create_batch(3)
     for inv_item in inv_items:
         inv_item.create()
     logging.debug(inv_items)
     # make sure they got saved
     self.assertEqual(len(Inventory.all()), 3)
     # find the 2nd inventory item in the list
     inv_item = Inventory.find(inv_items[1].id)
     self.assertIsNot(inv_item, None)
     self.assertEqual(inv_item.id, inv_items[1].id)
     self.assertEqual(inv_item.name, inv_items[1].name)
     self.assertEqual(inv_item.sku, inv_items[1].sku)
Esempio n. 7
0
def update_inventory(inventory_id):
    """
    Update an Inventory
    This endpoint will update an Inventory based the body that is posted
    """
    app.logger.info('Request to update 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))
    inventory.deserialize(request.get_json())
    inventory.id = inventory_id
    inventory.save()
    return make_response(jsonify(inventory.serialize()), status.HTTP_200_OK)
Esempio n. 8
0
 def put(self, inventory_id):
     """
     Update an Inventory
     This endpoint will update an Inventory based the body that is posted
     """
     app.logger.info('Request to update inventory with id: %s',
                     inventory_id)
     check_content_type('application/json')
     inventory = Inventory.find(inventory_id)
     if not inventory:
         api.abort(
             status.HTTP_404_NOT_FOUND, "Inventory with id '{}' was not \
                   found.".format(inventory_id))
     inventory.deserialize(request.get_json())
     inventory.id = inventory_id
     inventory.save()
     return inventory.serialize(), status.HTTP_200_OK
def update_inventory(inv_id):
    """
    Update an inventory item

    This endpoint will update an inventory item based on the body that is posted
    """
    app.logger.info("Request to update inventory with id: %s", inv_id)
    check_content_type("application/json")
    inventory = Inventory.find(inv_id)
    update_item = inventory.deserialize(request.get_json())

    if not inventory:
        raise NotFound("Inventory with id '{}' was not found.".format(inv_id))
    inventory.name = update_item.name
    inventory.sku = update_item.sku
    inventory.quantity = update_item.quantity
    inventory.restockLevel = update_item.restockLevel
    inventory.save()
    return make_response(jsonify(inventory.serialize()), status.HTTP_200_OK)
Esempio n. 10
0
    def test_find(self):
        """ Find a Inventory by ID """
        Inventory(product_id=1,
                  quantity=100,
                  restock_level=50,
                  condition="new",
                  available=False).save()
        inventory = Inventory(product_id=2,
                              quantity=21,
                              restock_level=20,
                              condition="used",
                              available=True)
        inventory.save()

        res = Inventory.find(inventory.id)
        self.assertIsNot(res, None)
        self.assertEqual(res.product_id, inventory.product_id)
        self.assertEqual(res.quantity, inventory.quantity)
        self.assertEqual(res.condition, inventory.condition)
        self.assertEqual(res.available, inventory.available)
        self.assertEqual(res.id, inventory.id)
Esempio n. 11
0
 def test_find_an_inventory(self):
     """ Find an inventory by id """
     new_inventory = Inventory(product_id=1,
                               quantity=100,
                               restock_level=50,
                               condition="new",
                               available=True)
     used_inventory = Inventory(product_id=2,
                                quantity=21,
                                restock_level=20,
                                condition="used",
                                available=True)
     new_inventory.save()
     used_inventory.save()
     inventory = Inventory.find(used_inventory.id)
     self.assertNotEqual(inventory, None)
     self.assertEqual(inventory.product_id, 2)
     self.assertEqual(inventory.quantity, 21)
     self.assertEqual(inventory.restock_level, 20)
     self.assertEqual(inventory.condition, "used")
     self.assertEqual(inventory.available, True)