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


Python Product.save方法代码示例

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


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

示例1: CategoryDetailViewTestCase

# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import save [as 别名]
class CategoryDetailViewTestCase(TestCase):
    def setUp(self):
        self.cat = Category()
        self.cat.name = 'Test Category'
        self.cat.save()
        
        self.product = Product()
        self.product.name = 'test'
        self.product.short_description = 'test'
        self.product.long_description = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.save()
        self.product.categories.add(self.cat)
    
    def test_01_get_context_works(self):
        #self.create_fixtures()
        view = CategoryDetailView(kwargs={'pk':self.cat.id})
        setattr(view, 'object', view.get_object())
        ret = view.get_context_data()
        self.assertEqual(len(ret), 1)
        
    def test_02_get_context_works_with_list_of_products(self):
        #self.create_fixtures()
        self.product.active = True
        self.product.save()
        view = CategoryDetailView(kwargs={'pk':self.cat.id})
        setattr(view, 'object', view.get_object())
        ret = view.get_context_data()
        self.assertEqual(len(ret), 2)
开发者ID:agalitsyn,项目名称:django-shop-simplecategories,代码行数:31,代码来源:views.py

示例2: ProductTestCase

# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import save [as 别名]
class ProductTestCase(TestCase):

    def create_fixtures(self):
        
        self.product = Product()
        self.product.name = 'test'
        self.product.short_description = 'test'
        self.product.long_description = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.save()
    
    def test_unicode_returns_proper_stuff(self):
        self.create_fixtures()
        ret = self.product.__unicode__()
        self.assertEqual(ret, self.product.name)
        
    def test_active_filter_returns_only_active_products(self):
        self.create_fixtures()
        ret1 = len(Product.objects.active())
        # Set self.product to be active
        self.product.active = True
        self.product.save()
        ret2 = len(Product.objects.active())
        self.assertNotEqual(ret1, ret2)
        self.assertEqual(ret1, 0)
        self.assertEqual(ret2, 1)
开发者ID:MechanisM,项目名称:django-shop,代码行数:28,代码来源:product.py

示例3: ProductTestCase

# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import save [as 别名]
class ProductTestCase(TestCase):

    def setUp(self):
        self.product = Product()
        self.product.name = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.save()

    def test_unicode_returns_proper_stuff(self):
        ret = self.product.__unicode__()
        self.assertEqual(ret, self.product.name)

    def test_active_filter_returns_only_active_products(self):
        ret1 = len(Product.objects.active())
        # Set self.product to be active
        self.product.active = True
        self.product.save()
        ret2 = len(Product.objects.active())
        self.assertNotEqual(ret1, ret2)
        self.assertEqual(ret1, 0)
        self.assertEqual(ret2, 1)

    def test_get_name_works_properly_by_default(self):
        res = self.product.get_name()
        self.assertEqual(res, self.product.name)
开发者ID:alainwolf,项目名称:openbroadcast.org,代码行数:27,代码来源:product.py

示例4: ProductDetailViewTestCase

# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import save [as 别名]
class ProductDetailViewTestCase(TestCase):
    def create_fixtures(self):
        
        self.product = Product()
        self.product.name = 'test'
        self.product.short_description = 'test'
        self.product.long_description = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.save()
        
        self.view = ProductDetailView(kwargs={'pk':self.product.id})
    
    def test_01_get_product_returns_correctly(self):
        self.create_fixtures()
        setattr(self.view, 'object', None)
        obj = self.view.get_object()
        inst = isinstance(obj,Product)
        self.assertEqual(inst, True)
        
    def test_02_get_templates_return_expected_values(self):
        self.create_fixtures()
        self.view = ProductDetailView()
        setattr(self.view, 'object', None)
        tmp = self.view.get_template_names()
        self.assertEqual(len(tmp), 1)
开发者ID:MechanisM,项目名称:django-shop,代码行数:27,代码来源:views.py

示例5: ProductListViewTestCase

# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import save [as 别名]
class ProductListViewTestCase(TestCase):
    def setUp(self):
        self.product1 = Product()
        self.product1.name = 'test1'
        self.product1.slug = 'test1'
        self.product1.short_description = 'test1'
        self.product1.long_description = 'test1'
        self.product1.unit_price = Decimal('1.0')
        self.product1.active = True
        self.product1.save()

        self.product2 = Product()
        self.product2.name = 'test2'
        self.product2.slug = 'test2'
        self.product2.short_description = 'test2'
        self.product2.long_description = 'test2'
        self.product2.unit_price = Decimal('1.0')
        self.product2.active = False
        self.product2.save()

    def test_get_queryset(self):
        """
        Test that ProductListView.get_queryset() returns
        only active products, filtering inactive ones.
        """
        view = ProductListView()
        active_products = view.get_queryset()
        self.assertEqual(len(active_products), 1)

        for product in active_products:
            self.assertEqual(product.active, True)
开发者ID:sarva,项目名称:django-shop,代码行数:33,代码来源:views.py

示例6: CategoriesTestCase

# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import save [as 别名]
class CategoriesTestCase(TestCase):
    def setUp(self):
        self.category = Category()
        self.category.name = "test_category"
        self.category.save()
        
        self.product = Product()
        self.product.name = 'test'
        self.product.short_description = 'test'
        self.product.long_description = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.save()
        self.product.categories.add(self.category)
        
    def test_01_category_unicode_returns_name(self):
        #self.create_fixtures()
        ret = self.category.__unicode__()
        self.assertEqual(ret, self.category.name)
        
    def test_02_category_get_products_works(self):
        #self.create_fixtures()
        ret = self.category.get_products()
        self.assertEqual(len(ret),1)
        cat_product = ret[0]
        self.assertEqual(cat_product,self.product)
开发者ID:agalitsyn,项目名称:django-shop-simplecategories,代码行数:27,代码来源:categories.py

示例7: test_product_adds_additional_categories

# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import save [as 别名]
 def test_product_adds_additional_categories(self):
     p = Product(
         name='Product 4',
         slug=slugify('Product 4'),
         active=True,
         unit_price=Decimal(random.randint(50, 1000)),
         main_category=Category.objects.get(slug='level1-second')
     )
     
     p.save()
     self.assertEqual(p.additional_categories.all()[0].slug, 'level1-second')
开发者ID:armonge,项目名称:django-shop-categories,代码行数:13,代码来源:__init__.py

示例8: create_fixtures

# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import save [as 别名]
def create_fixtures(options=False):
    product = Product( name='product 1', slug='product-1', active=True,
                       unit_price=43)
    product.save()
    if not options:
        return
    option_group = OptionGroup(name='option group 1', slug='option-group-1')
    option_group.save()
    option_group.products.add(product)

    Option.objects.create(name='option 1', price='42', group=option_group)
    Option.objects.create(name='option 2', price='84', group=option_group)
开发者ID:alainwolf,项目名称:openbroadcast.org,代码行数:14,代码来源:test_utils.py

示例9: ProductTestCase

# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import save [as 别名]
class ProductTestCase(TestCase):

    def create_fixtures(self):
        self.category = Category()
        self.category.name = "test_category"
        self.category.save()
        
        self.product = Product()
        self.product.name = 'test'
        self.product.short_description = 'test'
        self.product.long_description = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.category = self.category
        self.product.save()
    
    def test_01_unicode_returns_proper_stuff(self):
        self.create_fixtures()
        ret = self.product.__unicode__()
        self.assertEqual(ret, self.product.name)
        
    def test_02_specify_returns_self_when_not_a_subclass(self):
        self.create_fixtures()
        ret = self.product.get_specific()
        self.assertEqual(ret, self.product)
        
    def test_03_active_filter_returns_only_active_products(self):
        self.create_fixtures()
        ret1 = len(Product.objects.active())
        # Set self.product to be active
        self.product.active = True
        self.product.save()
        ret2 = len(Product.objects.active())
        self.assertNotEqual(ret1, ret2)
        self.assertEqual(ret1, 0)
        self.assertEqual(ret2, 1)
    
    def test_04_category_unicode_returns_name(self):
        self.create_fixtures()
        ret = self.category.__unicode__()
        self.assertEqual(ret, self.category.name)
        
    def test_05_category_get_products_works(self):
        self.create_fixtures()
        ret = self.category.get_products()
        self.assertEqual(len(ret),1)
        cat_product = ret[0]
        self.assertEqual(cat_product,self.product)
开发者ID:audreyr,项目名称:django-shop,代码行数:49,代码来源:product.py

示例10: ProductStatisticsTestCase

# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import save [as 别名]
class ProductStatisticsTestCase(TestCase):

    def setUp(self):
        self.product = Product()
        self.product.name = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.save()
        
        self.product2 = Product()
        self.product2.name = 'test2'
        self.product2.unit_price = Decimal('1.0')
        self.product2.save()
        
        self.product3 = Product()
        self.product3.name = 'test3'
        self.product3.unit_price = Decimal('1.0')
        self.product3.save()

        self.order = Order()
        self.order.order_subtotal = Decimal('10')
        self.order.order_total = Decimal('10')
        self.order.shipping_cost = Decimal('0')
        
        self.order.shipping_name = 'toto'
        self.order.shipping_address = 'address'
        self.order.shipping_address2 = 'address2'
        self.order.shipping_city = 'city'
        self.order.shipping_zip_code = 'zip'
        self.order.shipping_state = 'state'
        self.order.shipping_country = 'country'
        
        self.order.billing_name = 'toto'
        self.order.billing_address = 'address'
        self.order.billing_address2 = 'address2'
        self.order.billing_city = 'city'
        self.order.billing_zip_code = 'zip'
        self.order.billing_state = 'state'
        self.order.billing_country = 'country'
        self.order.save()
        
        self.orderitem1 = OrderItem()
        self.orderitem1.order = self.order
        self.orderitem1.product = self.product
        self.orderitem1.quantity = 5 # this will be the most bought
        self.orderitem1.save()
        
        self.orderitem2 = OrderItem()
        self.orderitem2.order = self.order
        self.orderitem2.product = self.product2
        self.orderitem2.quantity = 1 # this will be the second most
        self.orderitem2.save()

    def test_top_selling_works(self):
        res = Product.statistics.top_selling_products(10)
        self.assertNotEqual(res, None)
        self.assertEqual(len(res), 2)
        self.assertTrue(self.product3 not in res)
开发者ID:ojii,项目名称:django-shop,代码行数:59,代码来源:product.py

示例11: ProductDetailViewTestCase

# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import save [as 别名]
class ProductDetailViewTestCase(TestCase):
    def setUp(self):

        self.product = Product()
        self.product.name = "test"
        self.product.short_description = "test"
        self.product.long_description = "test"
        self.product.unit_price = Decimal("1.0")
        self.product.active = True
        self.product.save()

        self.view = ProductDetailView(kwargs={"pk": self.product.pk})

    def test_get_product_returns_correctly(self):
        setattr(self.view, "object", None)
        obj = self.view.get_object()
        inst = isinstance(obj, Product)
        self.assertEqual(inst, True)

    def test_get_templates_return_expected_values(self):
        self.view = ProductDetailView()
        setattr(self.view, "object", None)
        tmp = self.view.get_template_names()
        self.assertEqual(len(tmp), 1)
开发者ID:berrym72,项目名称:django-shop,代码行数:26,代码来源:views.py

示例12: ProductOptionsTestCase

# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import save [as 别名]
class ProductOptionsTestCase(TestCase):

    PRODUCT_PRICE = Decimal("100")
    AWESOME_OPTION_PRICE = Decimal("50")  # The price of awesome?
    TEN_PERCENT = Decimal(10) / Decimal(100)

    def create_fixtures(self):
        cart_modifiers_pool.USE_CACHE = False

        self.user = User.objects.create(username="test", email="[email protected]", first_name="Test", last_name="Toto")

        self.product = Product()
        self.product.name = "TestPrduct"
        self.product.slug = "TestPrduct"
        self.product.short_description = "TestPrduct"
        self.product.long_description = "TestPrduct"
        self.product.active = True
        self.product.unit_price = self.PRODUCT_PRICE
        self.product.save()

        self.ogroup = OptionGroup()
        self.ogroup.product = self.product
        self.ogroup.name = "Test group"
        self.ogroup.save()

        self.option = Option()
        self.option.group = self.ogroup
        self.option.name = "Awesome"
        self.option.price = self.AWESOME_OPTION_PRICE
        self.option.save()

        self.cart = Cart()
        self.cart.user = self.user
        self.cart.save()

        self.cartitem = CartItem()
        self.cartitem.cart = self.cart
        self.cartitem.quantity = 1
        self.cartitem.product = self.product
        self.cartitem.save()

    def test_01_no_options_yield_normal_price(self):
        self.create_fixtures()
        MODIFIERS = ["shop.cart.modifiers.product_options.ProductOptionsModifier"]
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
            # No need to add a product there is already on in the fixtures
            self.cart.update()
            self.cart.save()
            sub_should_be = 1 * self.PRODUCT_PRICE
            total_should_be = sub_should_be

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

    def test_02_awesome_option_increases_price_by_its_value(self):
        self.create_fixtures()

        c_item_option = CartItemOption()
        c_item_option.option = self.option
        c_item_option.cartitem = self.cartitem
        c_item_option.save()

        MODIFIERS = ["shop.cart.modifiers.product_options.ProductOptionsModifier"]
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
            self.cart.update()
            self.cart.save()
            sub_should_be = (1 * self.PRODUCT_PRICE) + (1 * self.AWESOME_OPTION_PRICE)
            total_should_be = sub_should_be

            self.assertEqual(self.cart.subtotal_price, sub_should_be)
            self.assertEqual(self.cart.total_price, total_should_be)
开发者ID:ojii,项目名称:django-shop-simplevariations,代码行数:73,代码来源:product_options.py

示例13: CartTestCase

# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import save [as 别名]
class CartTestCase(TestCase):
    PRODUCT_PRICE = Decimal('100')
    TEN_PERCENT = Decimal(10) / Decimal(100)
    
    def create_fixtures(self):
        
        cart_modifiers_pool.USE_CACHE=False
        
        self.user = User.objects.create(username="test", email="[email protected]")
        self.product = Product()
        self.product.name = "TestPrduct"
        self.product.slug = "TestPrduct"
        self.product.short_description = "TestPrduct"
        self.product.long_description = "TestPrduct"
        self.product.active = True
        self.product.unit_price = self.PRODUCT_PRICE
        self.product.save()
        
        self.cart = Cart()
        self.cart.user = self.user
        self.cart.save()
    
    def test_01_empty_cart_costs_0(self):
        self.create_fixtures()
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):
            
            self.cart.update()
            
            self.assertEqual(self.cart.subtotal_price, Decimal('0.0'))
            self.assertEqual(self.cart.total_price, Decimal('0.0'))
            
    def test_02_one_object_no_modifiers(self):
        self.create_fixtures()
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):
            self.cart.add_product(self.product)
            self.cart.save()
            self.cart.update()
            self.cart.save()
            
            self.assertEqual(self.cart.subtotal_price, self.PRODUCT_PRICE)
            self.assertEqual(self.cart.total_price, self.PRODUCT_PRICE)
    
    def test_03_two_objects_no_modifier(self):
        self.create_fixtures()
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):
            
            # We add two objects now :)
            self.cart.add_product(self.product,2)
            self.cart.update()
            self.cart.save()
            
            self.assertEqual(self.cart.subtotal_price, self.PRODUCT_PRICE*2)
            self.assertEqual(self.cart.total_price, self.PRODUCT_PRICE*2)
            
    def test_04_one_object_simple_modifier(self):
        self.create_fixtures()
        MODIFIERS = ['shop.cart.modifiers.tax_modifiers.TenPercentTaxModifier']
        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_05_one_object_two_modifiers_no_rebate(self):
        self.create_fixtures()
        MODIFIERS = ['shop.cart.modifiers.tax_modifiers.TenPercentTaxModifier',
                     '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_06_one_object_two_modifiers_with_rebate(self):
        self.create_fixtures()
        MODIFIERS = ['shop.cart.modifiers.tax_modifiers.TenPercentTaxModifier',
                     '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_07_add_same_object_twice(self):
        self.create_fixtures()
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):
            self.cart.add_product(self.product)
            self.cart.add_product(self.product)
#.........这里部分代码省略.........
开发者ID:audreyr,项目名称:django-shop,代码行数:103,代码来源:cart.py

示例14: CartModifiersTestCase

# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import save [as 别名]
class CartModifiersTestCase(TestCase):

    PRODUCT_PRICE = Decimal('100')

    def setUp(self):
        cart_modifiers_pool.USE_CACHE = False
        self.user = User.objects.create(username="test",
            email="[email protected]")
        self.product = Product()
        self.product.name = "TestPrduct"
        self.product.slug = "TestPrduct"
        self.product.short_description = "TestPrduct"
        self.product.long_description = "TestPrduct"
        self.product.active = True
        self.product.unit_price = self.PRODUCT_PRICE
        self.product.save()

        self.cart = Cart()
        self.cart.user = self.user
        self.cart.save()

    def test_01_cart_modifier_pool_loads_modifiers_properly(self):
        """
        Let's add a price modifier to the settings, then load it,
        then call a method on it to make sure it works.
        """
        MODIFIERS = [
            'shop.cart.modifiers.tax_modifiers.TenPercentGlobalTaxModifier']
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
            thelist = modifiers_pool.cart_modifiers_pool.get_modifiers_list()
            self.assertEqual(len(thelist), 1)
            instance = thelist[0]
            self.assertTrue(hasattr(instance, 'TAX_PERCENTAGE'))

    def test_02_cart_modifiers_pool_handles_wrong_path(self):
        MODIFIERS = ['shop2.cart.modifiers.tax_modifiers']  # wrong path
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
            raised = False
            try:
                modifiers_pool.cart_modifiers_pool.get_modifiers_list()
            except:
                raised = True
            self.assertTrue(raised)

    def test_03_cart_modifiers_pool_handles_wrong_module(self):
        MODIFIERS = ['shop.cart.modifiers.tax_modifiers.IdontExist']
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
            raised = False
            try:
                modifiers_pool.cart_modifiers_pool.get_modifiers_list()
            except ImproperlyConfigured:
                raised = True
            self.assertTrue(raised)

    def test_03_cart_modifiers_pool_handles_not_a_path(self):
        MODIFIERS = ['shop']
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
            raised = False
            try:
                modifiers_pool.cart_modifiers_pool.get_modifiers_list()
            except ImproperlyConfigured:
                raised = True
            self.assertTrue(raised)

    def test_state_is_passed_around_properly(self):
        MODIFIERS = ['shop.tests.cart_modifiers.CarModifierUsingStatePassing']
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
            self.cart.add_product(self.product)
            self.cart.save()
            self.cart.update()  # This should raise if the state isn't passed
开发者ID:Fandekasp,项目名称:django-shop,代码行数:72,代码来源:cart_modifiers.py

示例15: CartTestCase

# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import save [as 别名]
class CartTestCase(TestCase):
    PRODUCT_PRICE = Decimal('100')
    TEN_PERCENT = Decimal(10) / Decimal(100)

    def setUp(self):

        cart_modifiers_pool.USE_CACHE=False

        self.user = User.objects.create(username="test", email="[email protected]")
        self.product = Product()
        self.product.name = "TestPrduct"
        self.product.slug = "TestPrduct"
        self.product.short_description = "TestPrduct"
        self.product.long_description = "TestPrduct"
        self.product.active = True
        self.product.unit_price = self.PRODUCT_PRICE
        self.product.save()

        self.cart = Cart()
        self.cart.user = self.user
        self.cart.save()

    def test_empty_cart_costs_0_quantity_0(self):
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):

            self.cart.update()

            self.assertEqual(self.cart.subtotal_price, Decimal('0.0'))
            self.assertEqual(self.cart.total_price, Decimal('0.0'))
            self.assertEqual(self.cart.total_quantity, 0)

    def test_one_object_no_modifiers(self):
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):
            self.cart.add_product(self.product)
            self.cart.save()
            self.cart.update()
            self.cart.save()

            self.assertEqual(self.cart.subtotal_price, self.PRODUCT_PRICE)
            self.assertEqual(self.cart.total_price, self.PRODUCT_PRICE)
            self.assertEqual(self.cart.total_quantity, 1)

    def test_two_objects_no_modifier(self):
        with SettingsOverride(SHOP_CART_MODIFIERS=[]):

            # We add two objects now :)
            self.cart.add_product(self.product,2)
            self.cart.update()
            self.cart.save()

            self.assertEqual(self.cart.subtotal_price, self.PRODUCT_PRICE*2)
            self.assertEqual(self.cart.total_price, self.PRODUCT_PRICE*2)
            self.assertEqual(self.cart.total_quantity, 2)

    def test_one_object_simple_modifier(self):
        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):
        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()
#.........这里部分代码省略.........
开发者ID:KristianOellegaard,项目名称:django-shop,代码行数:103,代码来源:cart.py


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