Пример #1
0
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)
    order = Order.find_or_404(order_id)
    return make_response(jsonify(order.serialize()), status.HTTP_200_OK)
Пример #2
0
    def test_find_or_404(self):
        """ Find or throw 404 error """
        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_or_404(order.id)
        self.assertEqual(order.id, 1)
Пример #3
0
def create_products(order_id):
    """
    Create an Product on an Order
    This endpoint will add an product to an order
    """
    app.logger.info("Request to add an product to an order")  # pylint: disable=maybe-no-member
    check_content_type("application/json")
    order = Order.find_or_404(order_id)
    product = Product()
    product.deserialize(request.get_json())
    order.products.append(product)
    order.save()
    message = product.serialize()
    return make_response(jsonify(message), status.HTTP_201_CREATED)
Пример #4
0
 def test_find_or_404_found(self):
     """ Find or return 404 found """
     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_or_404(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)
Пример #5
0
def list_products(order_id):
    """ Returns all of the Products for an Order """
    app.logger.info("Request for Order Products...")  # pylint: disable=maybe-no-member
    order = Order.find_or_404(order_id)
    results = [product.serialize() for product in order.products]
    return make_response(jsonify(results), status.HTTP_200_OK)