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


Python Cart.update_quantity方法代码示例

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


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

示例1: CartTestCase

# 需要导入模块: from shop.models.cartmodel import Cart [as 别名]
# 或者: from shop.models.cartmodel.Cart import update_quantity [as 别名]

#.........这里部分代码省略.........
            self.cart.save()

            self.assertEqual(self.cart.subtotal_price, self.PRODUCT_PRICE)
            self.assertEqual(self.cart.total_price, (self.TEN_PERCENT*self.PRODUCT_PRICE)+self.PRODUCT_PRICE)

    def test_one_object_two_modifiers_no_rebate(self):
        MODIFIERS = ['shop.cart.modifiers.tax_modifiers.TenPercentGlobalTaxModifier',
                     'shop.cart.modifiers.rebate_modifiers.BulkRebateModifier']
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
            self.cart.add_product(self.product)

            self.cart.update()
            self.cart.save()

            self.assertEqual(self.cart.subtotal_price, self.PRODUCT_PRICE)
            self.assertEqual(self.cart.total_price, (self.TEN_PERCENT*self.PRODUCT_PRICE)+self.PRODUCT_PRICE)

    def test_one_object_two_modifiers_with_rebate(self):
        MODIFIERS = ['shop.cart.modifiers.tax_modifiers.TenPercentGlobalTaxModifier',
                     'shop.cart.modifiers.rebate_modifiers.BulkRebateModifier']
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
            # We add 6 objects now :)
            self.cart.add_product(self.product,6)
            self.cart.update()
            self.cart.save()

            #subtotal is 600 - 10% = 540
            sub_should_be = (6*self.PRODUCT_PRICE) - (self.TEN_PERCENT*(6*self.PRODUCT_PRICE))

            total_should_be = sub_should_be + (self.TEN_PERCENT*sub_should_be)

            self.assertEqual(self.cart.subtotal_price, sub_should_be)
            self.assertEqual(self.cart.total_price, total_should_be)

    def test_add_same_object_twice(self):
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):
            self.assertEqual(self.cart.total_quantity, 0)
            self.cart.add_product(self.product)
            self.cart.add_product(self.product)
            self.cart.update()
            self.cart.save()

            self.assertEqual(len(self.cart.items.all()),1)
            self.assertEqual(self.cart.items.all()[0].quantity, 2)
            self.assertEqual(self.cart.total_quantity, 2)

    def test_add_same_object_twice_no_merge(self):
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):
            self.assertEqual(self.cart.total_quantity, 0)
            self.cart.add_product(self.product, merge=False)
            self.cart.add_product(self.product, merge=False)
            self.cart.update()
            self.cart.save()

            self.assertEqual(len(self.cart.items.all()),2)
            self.assertEqual(self.cart.items.all()[0].quantity, 1)
            self.assertEqual(self.cart.items.all()[1].quantity, 1)

    def test_add_product_updates_last_updated(self):
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):
            initial = self.cart.last_updated
            self.cart.add_product(self.product)
            self.assertNotEqual(initial, self.cart.last_updated)

    def test_cart_item_should_use_specific_type_to_get_price(self):
        base_product = BaseProduct.objects.create(unit_price=self.PRODUCT_PRICE)
        variation = base_product.productvariation_set.create(
                name="Variation 1"
                )
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):
            self.cart.add_product(variation)
            self.cart.update()
            self.cart.save()
            self.assertEqual(self.cart.subtotal_price, self.PRODUCT_PRICE)

    def test_update_quantity_deletes(self):
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):
            self.assertEqual(self.cart.total_quantity, 0)
            self.cart.add_product(self.product)
            self.cart.add_product(self.product)
            self.cart.update()
            self.cart.save()

            self.assertEqual(len(self.cart.items.all()),1)
            self.cart.update_quantity(self.cart.items.all()[0].id, 0)
            self.assertEqual(len(self.cart.items.all()),0)

    def test_custom_queryset_is_used_when_passed_to_method(self):
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):
            # first we add any product
            self.cart.add_product(self.product)

            # now we try to select a CartItem that does not exist yet. This
            # could be an item with a yet unused combination of variations.
            qs = CartItem.objects.filter(cart=self.cart, product=self.product,
                                         quantity=42)
            # although we add the same product and have merge=True, there should
            # be a new CartItem being created now.
            self.cart.add_product(self.product, queryset=qs)
            self.assertEqual(len(self.cart.items.all()),2)
开发者ID:KristianOellegaard,项目名称:django-shop,代码行数:104,代码来源:cart.py

示例2: CartTestCase

# 需要导入模块: from shop.models.cartmodel import Cart [as 别名]
# 或者: from shop.models.cartmodel.Cart import update_quantity [as 别名]

#.........这里部分代码省略.........
            
    def test_one_object_simple_modifier(self):
        self.create_fixtures()
        MODIFIERS = ['shop.cart.modifiers.tax_modifiers.TenPercentGlobalTaxModifier']
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
            self.cart.add_product(self.product)
            self.cart.update()
            self.cart.save()
            
            self.assertEqual(self.cart.subtotal_price, self.PRODUCT_PRICE)
            self.assertEqual(self.cart.total_price, (self.TEN_PERCENT*self.PRODUCT_PRICE)+self.PRODUCT_PRICE)
            
    def test_one_object_two_modifiers_no_rebate(self):
        self.create_fixtures()
        MODIFIERS = ['shop.cart.modifiers.tax_modifiers.TenPercentGlobalTaxModifier',
                     'shop.cart.modifiers.rebate_modifiers.BulkRebateModifier']
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
            self.cart.add_product(self.product)
            
            self.cart.update()
            self.cart.save()
            
            self.assertEqual(self.cart.subtotal_price, self.PRODUCT_PRICE)
            self.assertEqual(self.cart.total_price, (self.TEN_PERCENT*self.PRODUCT_PRICE)+self.PRODUCT_PRICE)
            
    def test_one_object_two_modifiers_with_rebate(self):
        self.create_fixtures()
        MODIFIERS = ['shop.cart.modifiers.tax_modifiers.TenPercentGlobalTaxModifier',
                     'shop.cart.modifiers.rebate_modifiers.BulkRebateModifier']
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
            # We add 6 objects now :)
            self.cart.add_product(self.product,6)
            self.cart.update()
            self.cart.save()
            
            #subtotal is 600 - 10% = 540
            sub_should_be = (6*self.PRODUCT_PRICE) - (self.TEN_PERCENT*(6*self.PRODUCT_PRICE)) 
            
            total_should_be = sub_should_be + (self.TEN_PERCENT*sub_should_be) 
            
            self.assertEqual(self.cart.subtotal_price, sub_should_be)
            self.assertEqual(self.cart.total_price, total_should_be)
            
    def test_add_same_object_twice(self):
        self.create_fixtures()
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):
            self.assertEqual(self.cart.total_quantity, 0)
            self.cart.add_product(self.product)
            self.cart.add_product(self.product)
            self.cart.update()
            self.cart.save()
            
            self.assertEqual(len(self.cart.items.all()),1)
            self.assertEqual(self.cart.items.all()[0].quantity, 2)
            self.assertEqual(self.cart.total_quantity, 2)
    
    def test_add_same_object_twice_no_merge(self):
        self.create_fixtures()
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):
            self.assertEqual(self.cart.total_quantity, 0)
            self.cart.add_product(self.product, merge=False)
            self.cart.add_product(self.product, merge=False)
            self.cart.update()
            self.cart.save()
            
            self.assertEqual(len(self.cart.items.all()),2)
            self.assertEqual(self.cart.items.all()[0].quantity, 1)
            self.assertEqual(self.cart.items.all()[1].quantity, 1)
            
    def test_add_product_updates_last_updated(self):
        self.create_fixtures()
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):
            initial = self.cart.last_updated
            self.cart.add_product(self.product)
            self.assertNotEqual(initial, self.cart.last_updated)

    def test_cart_item_should_use_specific_type_to_get_price(self):
        self.create_fixtures()
        base_product = BaseProduct.objects.create(unit_price=self.PRODUCT_PRICE)
        variation = base_product.productvariation_set.create(
                name="Variation 1"
                )
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):
            self.cart.add_product(variation)
            self.cart.update()
            self.cart.save()
            self.assertEqual(self.cart.subtotal_price, self.PRODUCT_PRICE)
    
    def test_update_quantity_deletes(self):
        self.create_fixtures()
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):
            self.assertEqual(self.cart.total_quantity, 0)
            self.cart.add_product(self.product)
            self.cart.add_product(self.product)
            self.cart.update()
            self.cart.save()

            self.assertEqual(len(self.cart.items.all()),1)
            self.cart.update_quantity(self.cart.items.all()[0].id, 0)
            self.assertEqual(len(self.cart.items.all()),0)
开发者ID:matthiasnuesch,项目名称:django-shop,代码行数:104,代码来源:cart.py


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