def test_update_order_product(self): """" Update an orders product """ orders = Order.all() self.assertEqual(orders, []) product = self._create_product() order = self._create_order(products=[product]) order.create() # Assert that it was assigned an id and shows up in the database self.assertEqual(order.id, 1) orders = Order.all() self.assertEqual(len(orders), 1) # Fetch it back order = Order.find(order.id) old_product = order.products[0] self.assertEqual(old_product.price, product.price) old_product.price = 1 order.save() # Fetch it back again order = Order.find(order.id) product = order.products[0] self.assertEqual(product.price, 1)
def test_update_order(self): """ Update an order """ order = self._create_order() order.create() # Assert that it was assigned an id and shows up in the database self.assertEqual(order.id, 1) # Fetch it back order = Order.find(order.id) order.status = "Cancelled" order.save() # Fetch it back again order = Order.find(order.id) self.assertEqual(order.status, "Cancelled")
def delete_orders(order_id): """ Delete an Order This endpoint will delete an Order based the id specified in the path """ app.logger.info("Request to delete order with id: %s", order_id) # pylint: disable=maybe-no-member order = Order.find(order_id) if order: order.delete() return make_response("", status.HTTP_204_NO_CONTENT)
def delete(self, order_id): """ Delete an Order This endpoint will delete an Order based the body that is posted """ app.logger.info('Request to delete an order with id: %s', order_id) order = Order.find(order_id) if order: order.delete() return make_response('', status.HTTP_204_NO_CONTENT)
def delete_orders(order_id): """ Delete an Order This endpoint will delete an Order based the id specified in the path """ app.logger.info('Request to delete an order with id: %s', order_id) order = Order.find(order_id) if order: order.delete() return make_response('', status.HTTP_204_NO_CONTENT)
def get_orders(order_id): """ Retrieve an order This endpoint will return an order based on it's id """ app.logger.info('Request for an order with id: %s', order_id) order = Order.find(order_id) if not order: raise NotFound("Order with id '{}' was not found.".format(order_id)) return make_response(jsonify(order.serialize()), status.HTTP_200_OK)
def test_find_order(self): """ Find an Order by ID """ order_items1 = [OrderItem(product_id=1, quantity=1, price=5, status="PLACED")] order1 = Order(customer_id=111, order_items=order_items1) order1.create() order = Order.find(order1.id) self.assertIsNot(order, None) self.assertEqual(order.id, order1.id) self.assertEqual(order.customer_id, 111) self.assertEqual(len(order.order_items), 1) self.assertEqual(order.order_items[0].product_id, 1)
def delete_all_orders(): """ Returns IDs of the Orders """ app.logger.info("Request for Order list") orders = [] id = request.args.get("id") if id: orders = Order.find(id) else: orders = Order.all() results = [order.delete() for order in orders] return make_response("", status.HTTP_204_NO_CONTENT)
def get_orders(order_id): """ Retrieve a single Order This endpoint will return an Order based on it's id """ # app.logger.info("Request for Order with id: %s", order_id)# pylint: disable=maybe-no-member # order = Order.find_or_404(order_id) # return make_response(jsonify(order.serialize()), status.HTTP_200_OK) app.logger.info("Request to read an order with id: %s") order = Order.find(order_id) if not order: raise NotFound("order with id '{}' was not found.".format(order_id)) return make_response(jsonify(order.serialize()), status.HTTP_200_OK)
def test_update_an_order(self): """ Update an existing Order """ order_item1 = OrderItem(product_id=1, quantity=1, price=5, status="PLACED") order_items = [order_item1] order = Order(customer_id=111, order_items=order_items) order.create() self.assertTrue(order.id is not None) order.customer_id = 234 order.update() new_order = Order.find(order.id) self.assertEqual(new_order.id, order.id) self.assertEqual(new_order.customer_id, 234)
def update_orders(order_id): """ Update an Order This endpoint will update an Order based the body that is posted """ app.logger.info("Request to update order with id: %s", order_id) check_content_type("application/json") order = Order.find(order_id) if not order: raise NotFound("Order with id '{}' was not found.".format(order_id)) order.deserialize(request.get_json()) order.id = order_id order.save() return make_response(jsonify(order.serialize()), status.HTTP_200_OK)
def put(self, order_id): """ Cancel an Order This endpoint will cancel an Order based the id specified in the path """ app.logger.info('Request to cancel an order with id: %s', order_id) check_content_type('application/json') order = Order.find(order_id) if not order: raise NotFound("Order with id '{}' was not found.".format(order_id)) order.deserialize(request.get_json()) order.status = 'Cancelled' order.save() return make_response(jsonify(order.serialize()), status.HTTP_200_OK)
def cancel_orders(order_id): """ Cancel the order This endpoint will cancel the order and tell other squads """ app.logger.info('Request to cancel the order with id: %s', order_id) # pylint: disable=maybe-no-member order = Order.find(order_id) if not order: raise NotFound( "Order with the id '{}' was not found.".format(order_id)) # TODO should probably check to make sure this order hasn't been shipped or delivered first order.id = order_id order.status = OrderStatus.Canceled order.save() # Notify other systems like shipping/billing of cancellation... return make_response(jsonify(order.serialize()), status.HTTP_200_OK)
def test_find_order(self): """ Find an Order by ID """ uuid_str = str(uuid.uuid4()) Order(uuid=uuid_str, product_id=1, customer_id=1, price=10, quantity=1).save() next_order = Order(uuid="2edf8761-0c1f-4039-9f5c-907a5a03f39c", product_id=1, customer_id=1, price=10, quantity=1) next_order.save() order = Order.find(next_order.id) self.assertIsNot(order, None) self.assertEqual(order.id, next_order.id) 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)
def test_find_invalid_order(self): """ Find an Order by an invalid ID """ order = Order.find(0) self.assertEqual(order, None)