当前位置: 首页>>代码示例>>Python>>正文


Python Cart.get_line方法代码示例

本文整理汇总了Python中cart.Cart.get_line方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.get_line方法的具体用法?Python Cart.get_line怎么用?Python Cart.get_line使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cart.Cart的用法示例。


在下文中一共展示了Cart.get_line方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AddToCartFormTest

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import get_line [as 别名]
class AddToCartFormTest(TestCase):

    def setUp(self):
        self.cart = Cart()
        self.post = {'quantity': 5}

    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')

    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,))

    def test_too_big_quantity(self):
        'Is AddToCartForm works with not correct quantity value'
        form = AddToCartForm({'quantity': 15}, cart=self.cart,
                             product=stock_product)
        self.assertFalse(form.is_valid())
        self.assertFalse(self.cart)

    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')
开发者ID:D0han,项目名称:saleor,代码行数:45,代码来源:tests.py

示例2: test_save

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import get_line [as 别名]
 def test_save(self):
     post = {
         'form-TOTAL_FORMS': 2,
         'form-INITIAL_FORMS': 2,
         'form-0-quantity': 5,
         'form-1-quantity': 5}
     cart = Cart()
     cart.add(stock_product, 10)
     cart.add(digital_product, 100)
     form = ReplaceCartLineFormSet(post, cart=cart)
     self.assertTrue(form.is_valid())
     form.save()
     product_quantity = cart.get_line(stock_product).quantity
     self.assertEqual(product_quantity, 5,
                      '%s is the bad quantity value' % (product_quantity,))
开发者ID:D0han,项目名称:saleor,代码行数:17,代码来源:tests.py

示例3: ReplaceCartLineFormTest

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import get_line [as 别名]
class ReplaceCartLineFormTest(TestCase):

    def setUp(self):
        self.cart = Cart()

    def test_quantity(self):
        'Is ReplaceCartLineForm works with correct quantity value'
        form = ReplaceCartLineForm({'quantity': 5}, cart=self.cart,
                                   product=stock_product)
        self.assertTrue(form.is_valid())
        form.save()
        form = ReplaceCartLineForm({'quantity': 5}, 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, 5,
                         '%s is the bad quantity value' % (product_quantity,))

    def test_too_big_quantity(self):
        'Is ReplaceCartLineForm works with to big quantity value'
        form = ReplaceCartLineForm({'quantity': 15}, cart=self.cart,
                                   product=stock_product)
        self.assertFalse(form.is_valid())
开发者ID:D0han,项目名称:saleor,代码行数:26,代码来源:tests.py


注:本文中的cart.Cart.get_line方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。