示例#1
0
 def test_quantity(self):
     'Is AddToCartForm works with correct quantity value on empty cart'
     form = AddToCartForm(self.post, cart=self.cart, product=stock_product)
     self.assertTrue(form.is_valid())
     self.assertFalse(self.cart)
     form.save()
     product_quantity = self.cart.get_line(stock_product).quantity
     self.assertEqual(product_quantity, 5, 'Bad quantity')
示例#2
0
文件: tests.py 项目: D0han/saleor
 def test_quantity(self):
     'Is AddToCartForm works with correct quantity value on empty cart'
     form = AddToCartForm(self.post, cart=self.cart, product=stock_product)
     self.assertTrue(form.is_valid())
     self.assertFalse(self.cart)
     form.save()
     product_quantity = self.cart.get_line(stock_product).quantity
     self.assertEqual(product_quantity, 5, 'Bad quantity')
示例#3
0
 def test_clean_quantity_product(self):
     'Is AddToCartForm works with not stocked product'
     cart = Cart()
     self.post['quantity'] = 10000
     form = AddToCartForm(self.post, cart=cart, product=digital_product)
     self.assertTrue(form.is_valid(), 'Form doesn\'t valitate')
     self.assertFalse(cart, 'Cart isn\'t empty')
     form.save()
     self.assertTrue(cart, 'Cart is empty')
示例#4
0
文件: tests.py 项目: D0han/saleor
 def test_clean_quantity_product(self):
     'Is AddToCartForm works with not stocked product'
     cart = Cart()
     self.post['quantity'] = 10000
     form = AddToCartForm(self.post, cart=cart, product=digital_product)
     self.assertTrue(form.is_valid(), 'Form doesn\'t valitate')
     self.assertFalse(cart, 'Cart isn\'t empty')
     form.save()
     self.assertTrue(cart, 'Cart is empty')
示例#5
0
 def test_max_quantity(self):
     'Is AddToCartForm works with correct product stock value'
     form = AddToCartForm(self.post, cart=self.cart, product=stock_product)
     self.assertTrue(form.is_valid())
     form.save()
     form = AddToCartForm(self.post, cart=self.cart, product=stock_product)
     self.assertTrue(form.is_valid())
     form.save()
     product_quantity = self.cart.get_line(stock_product).quantity
     self.assertEqual(product_quantity, 10,
                      '%s is the bad quantity value' % (product_quantity, ))
示例#6
0
文件: tests.py 项目: D0han/saleor
 def test_max_quantity(self):
     'Is AddToCartForm works with correct product stock value'
     form = AddToCartForm(self.post, cart=self.cart, product=stock_product)
     self.assertTrue(form.is_valid())
     form.save()
     form = AddToCartForm(self.post, cart=self.cart, product=stock_product)
     self.assertTrue(form.is_valid())
     form.save()
     product_quantity = self.cart.get_line(stock_product).quantity
     self.assertEqual(product_quantity, 10,
                      '%s is the bad quantity value' % (product_quantity,))
示例#7
0
def add_to_cart():
    if request.form:
        try:
            product = get_or_404(Product, request.form['product_id'])
        except KeyError:
            return redirect(request.referrer)
        shoppingcart = ShoppingCart.for_session_cart(request.cart)
        form = AddToCartForm(request.form, product=product, cart=shoppingcart)
        if form.validate():
            flash('Added {0} {1} to the cart'.format(
                form.quantity.data, product.name))
            form.save()
        return redirect(url_for('.index'))
    return redirect(request.referrer)