Пример #1
0
 def post(self):
     """
     Creates a Product
     This endpoint will create a Product based the data in the body that is posted
     """
     try:
         check_content_type('application/json')
         product = Product(1, "", "", "", 0, "", 0, "", 0)
         # product = Product()
         # app.logger.info((api.payload))
         product.deserialize(api.payload)
         product.save()
         message = product.serialize()
         location_url = api.url_for(ProductCollection,
                                    item_id=product.id,
                                    _external=True)
         # return make_response(jsonify(message), status.HTTP_201_CREATED,
         #                      {
         #                          'Location': location_url
         #                      })
         return product.serialize(), status.HTTP_201_CREATED, {
             'Location': location_url
         }
     except ValidationError:
         return request_validation_error('Invalid Data')
Пример #2
0
def create_products():
    """
    Creates a Pet
    This endpoint will create a Pet based the data in the body that is posted
    """
    check_content_type('application/json')
    product = Product(1, "", "", "", 0, "", 0, "", 0)
    product.deserialize(request.get_json())
    product.save()
    message = product.serialize()
    location_url = url_for('list_products_by_id',
                           item_id=product.id,
                           _external=True)
    return make_response(jsonify(message), status.HTTP_201_CREATED,
                         {'Location': location_url})
Пример #3
0
 def test_deserialize_a_product(self):
     """ Test deserialization of a Product """
     data = {
         "id": 1,
         "name": "Couch",
         "description": "White couch",
         "category": "Furniture",
         "price": 200,
         "condition": "Boxed",
         "inventory": 50,
         "rating": 8,
         "review": " "
     }
     product = Product(1, "", "", "", 0, "", 0, "", 0)
     product.deserialize(data)
     self.assertIsNot(product, None)
     self.assertEqual(product.id, 1)
     self.assertEqual(product.name, "Couch")
     self.assertEqual(product.category, "Furniture")
     self.assertEqual(product.description, "White couch")
     self.assertEqual(product.price, 200)
     self.assertEqual(product.condition, "Boxed")
     self.assertEqual(product.inventory, 50)
     self.assertEqual(product.rating, 8)