def test_deserialize_an_order(self): """ Deserialize an order """ product = self._create_product() order = self._create_order(products=[product]) serial_order = order.serialize() new_order = Order() new_order.deserialize(serial_order) self.assertEqual(new_order.id, order.id) self.assertEqual(new_order.name, order.name) self.assertEqual(new_order.status, order.status)
def post(self): """ Creates an Order This endpoint will create an Order based the data in the body that is posted """ app.logger.info('Request to create an order') check_content_type('application/json') order = Order() order.deserialize(request.get_json()) order.save() message = order.serialize() location_url = api.url_for(OrderCollection, order_id=order.id, _external=True) return order.serialize(), status.HTTP_201_CREATED, {'Location': location_url }
def order_post(): """ Creates an order This endpoint will create an order based the data in the body that is posted """ app.logger.info('Request to create an order') check_content_type('application/json') order = Order() order.deserialize(request.get_json()) order.save() message = order.serialize() location_url = url_for('get_orders', order_id=order.id, _external=True) return make_response(jsonify(message), status.HTTP_201_CREATED, {'Location': location_url})
def create_orders(): """ Creates an Order This endpoint will create an Order based the data in the body that is posted """ app.logger.info("Request to create an Order") # pylint: disable=maybe-no-member app.logger.info(request.get_json()) # pylint: disable=maybe-no-member check_content_type("application/json") order = Order() order.deserialize(request.get_json()) order.create() message = order.serialize() location_url = url_for("get_orders", order_id=order.id, _external=True) return make_response(jsonify(message), status.HTTP_201_CREATED, {"Location": location_url})
def test_deserialize_an_order(self): """ Deserialization of an Order """ data = {"customer_id": 123, "order_items": [ {"product_id": 1, "quantity": 1, "price": 5, "status": "PLACED"} ]} order = Order() order.deserialize(data) self.assertNotEqual(order, None) self.assertEqual(order.id, None) self.assertEqual(order.customer_id, 123) self.assertEqual(order.created_date, None) self.assertEqual(len(order.order_items), 1) self.assertEqual(order.order_items[0].item_id, None) self.assertEqual(order.order_items[0].product_id, 1)
def test_deserialize_a_order(self): """ Test deserialization of an Order """ data = { "uuid": "2edf8761-0c1f-4039-9f5c-907a5a03f39c", "product_id": 1, "customer_id": 1, "price": 10, "quantity": 1, "status": "In Progress" } order = Order() order.deserialize(data) self.assertNotEqual(order, None) self.assertEqual(order.id, None) self.assertEqual(order.uuid, "2edf8761-0c1f-4039-9f5c-907a5a03f39c"), self.assertEqual(order.product_id, 1), self.assertEqual(order.customer_id, 1), self.assertEqual(order.price, 10), self.assertEqual(order.quantity, 1)