예제 #1
0
 def test_add_an_inventory_item(self):
     """ Create an inventory item and add it to the database """
     inventory = Inventory.all()
     self.assertEqual(inventory, [])
     inv_item = Inventory(name="Rolex Watch",
                          sku="R1232020",
                          quantity=10,
                          restockLevel=12)
     self.assertTrue(inv_item != None)
     self.assertEqual(inv_item.id, None)
     inv_item.create()
     self.assertEqual(inv_item.id, 1)
     inventory = Inventory.all()
     self.assertEqual(len(inventory), 1)
def create_inventory():
    """
    Creates an Inventory Item
    This endpoint will create an Inventory Item based the data in the body that is posted
    """
    app.logger.info("Request to create inventory")
    check_content_type("application/json")
    inv = Inventory()
    inv.deserialize(request.get_json())
    inv.create()
    message = inv.serialize()
    location_url = url_for("get_inventory_item_by_id",
                           inv_id=inv.id,
                           _external=True)
    return make_response(jsonify(message), status.HTTP_201_CREATED,
                         {"Location": location_url})