Exemplo n.º 1
0
 def test_find_by_cartId(self):
     """ Find all items for a particular CartId """
     ShoppingCartItems(productID=1234, price=12.99, quantity=1,
                       cartId=5).add()
     ShoppingCartItems(productID=4321, price=18.99, quantity=2,
                       cartId=8).add()
     items = ShoppingCartItems.allItems(8)
     self.assertEqual(items[0].productID, 4321)
     self.assertEqual(items[0].price, 18.99)
     self.assertEqual(items[0].quantity, 2)
     self.assertEqual(items[0].cartId, 8)
Exemplo n.º 2
0
def get_items(cart_id):
    """ Returns all the items in a cart """
    app.logger.info('Getting items of Cart with id: {}'.format(cart_id))
    cart = ShoppingCart.find(cart_id)
    if not cart:
        raise NotFound('Cart with id: {} was not found'.format(cart_id))
    results = ShoppingCartItems.allItems(cart_id)
    if not results:
        raise NotFound(
            'Cart with id: {} does not have any item'.format(cart_id))
    return jsonify([item.serialize() for item in results]), status.HTTP_200_OK