Пример #1
0
    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_delete_an_order(self):
     """ Delete an Order """
     order_items1 = [OrderItem(product_id=1, quantity=1, price=5.0, status="PLACED")]
     order = Order(customer_id=111, order_items=order_items1)
     order.create()
     self.assertEqual(len(Order.all()), 1)
     # delete the order and make sure it isn't in the database
     order.delete()
     self.assertEqual(len(Order.all()), 0)
Пример #3
0
 def test_add_a_order(self):
     """ Create an order and add it to the database """
     orders = Order.all()
     self.assertEqual(orders, [])
     order = self._create_order()
     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)
Пример #4
0
 def test_delete_a_order(self):
     """ Delete an Order """
     uuid_str = str(uuid.uuid4())
     order = Order(uuid=uuid_str,
                   product_id=1,
                   customer_id=1,
                   price=10,
                   quantity=1)
     order.save()
     self.assertEqual(len(Order.all()), 1)
     # delete the order and make sure it isn't in the database
     order.delete()
     self.assertEqual(len(Order.all()), 0)
Пример #5
0
 def test_delete_an_order(self):
     """ Delete an order from the database """
     orders = Order.all()
     self.assertEqual(orders, [])
     order = self._create_order()
     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)
     order = orders[0]
     order.delete()
     orders = Order.all()
     self.assertEqual(len(orders), 0)
Пример #6
0
def list_all_orders():
    """ Returns all of the Orders """
    app.logger.info('Request for order list')
    orders = Order.all()

    results = [order.serialize() for order in orders]
    return make_response(jsonify(results), status.HTTP_200_OK)
Пример #7
0
 def test_add_a_order(self):
     """ Create a order and add it to the database """
     orders = Order.all()
     self.assertEqual(orders, [])
     uuid_str = str(uuid.uuid4())
     order = Order(uuid=uuid_str,
                   product_id=1,
                   customer_id=1,
                   price=10,
                   quantity=1)
     self.assertTrue(order != None)
     self.assertEqual(order.id, None)
     order.save()
     # Asert 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)
Пример #8
0
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)
Пример #9
0
def list_orders():
    """ Returns all of the Orders """
    app.logger.info("Request for orders list")  # pylint: disable=maybe-no-member
    orders = []
    name = request.args.get("name")
    if name:
        orders = Order.find_by_name(name)
    else:
        orders = Order.all()

    results = [order.serialize() for order in orders]
    return make_response(jsonify(results), status.HTTP_200_OK)
Пример #10
0
    def test_add_order_product(self):
        """ Create an order with an product and add it to the database """
        orders = Order.all()
        self.assertEqual(orders, [])
        order = self._create_order()
        product = self._create_product()
        order.products.append(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)

        #new_order = Order.find(order.id)
        self.assertEqual(order.products[0].name, product.name)

        product2 = self._create_product()
        order.products.append(product2)
        order.save()

        #new_order = Order.find(order.id)
        self.assertEqual(len(order.products), 2)
        self.assertEqual(order.products[1].name, product2.name)
Пример #11
0
 def test_update_a_order(self):
     """ Update an Order """
     uuid_str = str(uuid.uuid4())
     order = Order(uuid=uuid_str,
                   product_id=1,
                   customer_id=1,
                   price=10,
                   quantity=1)
     order.save()
     self.assertEqual(order.id, 1)
     # Change it an save it
     order.product_id = 2
     order.save()
     self.assertEqual(order.id, 1)
     # Fetch it back and make sure the id hasn't changed
     # but the data did change
     orders = Order.all()
     self.assertEqual(len(orders), 1)
     self.assertEqual(orders[0].product_id, 2)