Exemplo n.º 1
0
 def test_create_inventory_with_bad_data(self):
     """ Create with wrong type"""
     test_inventory = Inventory(product_id=1,
                                quantity=30,
                                restock_level=20,
                                condition='new',
                                available="True")
     resp = self.app.post('/inventory',
                          json=test_inventory.serialize(),
                          content_type='application/json')
     self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
Exemplo n.º 2
0
 def test_serialize_an_inventory_item(self):
     """ Test serialization of an inventory item """
     inv_item = Inventory()
     data = inv_item.serialize()
     self.assertNotEqual(data, None)
     self.assertIn("id", data)
     self.assertEqual(data["id"], inv_item.id)
     self.assertIn("name", data)
     self.assertEqual(data["name"], inv_item.name)
     self.assertIn("sku", data)
     self.assertEqual(data["sku"], inv_item.sku)
     self.assertIn("quantity", data)
     self.assertEqual(data["quantity"], inv_item.quantity)
     self.assertIn("restockLevel", data)
     self.assertEqual(data["restockLevel"], inv_item.restockLevel)
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})
Exemplo n.º 4
0
def create_inventory():
    """
    Creates an Inventory
    This endpoint will create an Inventory based
    the data in the body that is posted
    """
    app.logger.info('Request to create an inventory')
    check_content_type('application/json')
    inventory = Inventory()
    inventory.deserialize(request.get_json())
    inventory.save()
    message = inventory.serialize()
    location_url = url_for('get_inventory',
                           inventory_id=inventory.inventory_id,
                           _external=True)
    return make_response(jsonify(message), status.HTTP_201_CREATED,
                         {'Location': location_url})
Exemplo n.º 5
0
 def post(self):
     """
     Creates an Inventory
     This endpoint will create an Inventory based
     the data in the body that is posted
     """
     app.logger.info('Request to create an inventory')
     check_content_type('application/json')
     inventory = Inventory()
     app.logger.debug('Payload = %s', api.payload)
     inventory.deserialize(api.payload)
     inventory.save()
     location_url = api.url_for(InventoryResource,
                                inventory_id=inventory.id,
                                _external=True)
     return inventory.serialize(), status.HTTP_201_CREATED, \
     {'Location': location_url}
Exemplo n.º 6
0
 def test_serialize_an_inventory(self):
     """ Test serialization of an inventory """
     inventory = Inventory(product_id=1, quantity=100,\
                           restock_level=50, condition="new",\
                           available=True)
     data = inventory.serialize()
     self.assertNotEqual(inventory, None)
     self.assertIn('product_id', data)
     self.assertEqual(data['product_id'], 1)
     self.assertIn('quantity', data)
     self.assertEqual(data['quantity'], 100)
     self.assertIn('restock_level', data)
     self.assertEqual(data['restock_level'], 50)
     self.assertIn('condition', data)
     self.assertEqual(data['condition'], "new")
     self.assertIn('available', data)
     self.assertEqual(data['available'], True)