• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python cartmodel.Cart类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: CheckoutCartToOrderTestCase

class CheckoutCartToOrderTestCase(TestCase):
    def setUp(self):
        self.user = User.objects.create(username="test", email="[email protected]", first_name="Test", last_name="Toto")
        self.request = Mock()
        setattr(self.request, "user", self.user)
        setattr(self.request, "session", {})
        setattr(self.request, "method", "GET")
        self.cart = Cart()
        self.cart.user = self.user
        self.cart.save()

    def test_order_created(self):
        view = CheckoutSelectionView(request=self.request)
        res = view.create_order_object_from_cart()
        self.assertEqual(res.order_total, Decimal("0"))

    def test_processing_signal(self):
        view = CheckoutSelectionView(request=self.request)

        order_from_signal = []

        def receiver(sender, order=None, **kwargs):
            order_from_signal.append(order)

        processing.connect(receiver)
        res = view.create_order_object_from_cart()

        self.assertIs(res, order_from_signal[0])
开发者ID:ronkhan,项目名称:django-shop,代码行数:28,代码来源:views_checkout.py


示例2: get_or_create_cart

def get_or_create_cart(request, save=False):
    """
    Return cart for current visitor.

    For a logged in user, try to get the cart from the database. If it's not there or it's empty,
    use the cart from the session.
    If the user is not logged in use the cart from the session.
    If there is no cart object in the database or session, create one.

    If ``save`` is True, cart object will be explicitly saved.
    """
    cart = None
    if not hasattr(request, '_cart'):
        is_logged_in = request.user and not isinstance(request.user, AnonymousUser)

        if is_logged_in:
            # if we are authenticated
            session_cart = get_cart_from_session(request)
            if session_cart and session_cart.user == request.user:
                # and the session cart already belongs to us, we are done
                cart = session_cart
            elif session_cart and session_cart.total_quantity > 0 and session_cart.user != request.user:
                # if it does not belong to us yet
                database_cart = get_cart_from_database(request)
                if database_cart:
                    # and there already is a cart that belongs to us in the database
                    # delete the old database cart
                    database_cart.delete()
                    database_cart = None
                # save the user to the new one from the session
                session_cart.user = request.user
                session_cart.save()
                cart = session_cart
            else:
                # if there is no session_cart, or it's empty, use the database cart
                cart = get_cart_from_database(request)
                if cart:
                    # and save it to the session
                    request.session['cart_id'] = cart.id
        else:
            # not authenticated? cart might be in session
            cart = get_cart_from_session(request)

        if not cart:
            # in case it's our first visit and no cart was created yet
            if is_logged_in:
                cart = Cart(user=request.user)
            elif getattr(request, 'session', None) is not None:
                cart = Cart()

        if save and not cart.pk:
            cart.save()
            request.session['cart_id'] = cart.id

        setattr(request, '_cart', cart)

    cart = getattr(request, '_cart')  # There we *must* have a cart
    return cart
开发者ID:commoncode,项目名称:django-shop,代码行数:58,代码来源:cart.py


示例3: create_fixtures

    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()
开发者ID:ojii,项目名称:django-shop-simplevariations,代码行数:34,代码来源:product_options.py


示例4: CheckoutCartToOrderTestCase

class CheckoutCartToOrderTestCase(TestCase):

    def setUp(self):
        self.user = User.objects.create(username="test",
                                        email="[email protected]",
                                        first_name="Test",
                                        last_name="Toto")
        self.request = Mock()
        setattr(self.request, 'user', self.user)
        setattr(self.request, 'session', {})
        setattr(self.request, 'method', 'GET')
        self.product = Product(name='pizza', slug='pizza', unit_price='1.45')
        self.product.save()
        self.cart = Cart()
        self.cart.user = self.user
        self.cart.save()

    def test_order_created(self):
        view = CheckoutSelectionView(request=self.request)
        res = view.create_order_object_from_cart()
        self.assertEqual(res.order_total, Decimal('0'))

    def test_orders_are_created_and_cleaned_up(self):
        view = CheckoutSelectionView(request=self.request)
        # create a new order with pk 1
        old_order = view.create_order_object_from_cart()
        # create order with pk 2 so sqlite doesn't reuse pk 1
        Order.objects.create()
        # then create a different new order, from a different cart with pk 3
        # order pk 1 should be deleted here
        self.cart.add_product(self.product)
        new_order = view.create_order_object_from_cart()
        self.assertFalse(Order.objects.filter(pk=old_order.pk).exists()) # check it was deleted
        self.assertNotEqual(old_order.order_total, new_order.order_total)

    def test_processing_signal(self):
        view = CheckoutSelectionView(request=self.request)

        order_from_signal = []
        def receiver(sender, order=None, **kwargs):
            order_from_signal.append(order)

        processing.connect(receiver)
        res = view.create_order_object_from_cart()

        self.assertIs(res, order_from_signal[0])
开发者ID:albeirochoa,项目名称:django-shop,代码行数:46,代码来源:views_checkout.py


示例5: setUp

 def setUp(self):
     self.user = User.objects.create(username="test", email="[email protected]", first_name="Test", last_name="Toto")
     self.request = Mock()
     setattr(self.request, "user", self.user)
     setattr(self.request, "session", {})
     setattr(self.request, "method", "GET")
     self.cart = Cart()
     self.cart.user = self.user
     self.cart.save()
开发者ID:ronkhan,项目名称:django-shop,代码行数:9,代码来源:views_checkout.py


示例6: CheckoutCartToOrderTestCase

class CheckoutCartToOrderTestCase(TestCase):

    def setUp(self):
        self.user = User.objects.create(username="test",
                                        email="[email protected]",
                                        first_name="Test",
                                        last_name="Toto")
        self.request = Mock()
        setattr(self.request, 'user', self.user)
        setattr(self.request, 'session', {})
        setattr(self.request, 'method', 'GET')
        self.cart = Cart()
        self.cart.user = self.user
        self.cart.save()

    def test_order_created(self):
        view = CheckoutSelectionView(request=self.request)
        res = view.create_order_object_from_cart()
        self.assertEqual(res.order_total, Decimal('0'))
开发者ID:ZloiGremlin,项目名称:django-shop,代码行数:19,代码来源:views_checkout.py


示例7: setUp

 def setUp(self):
     self.user = User.objects.create(username="test",
                                     email="[email protected]",
                                     first_name="Test",
                                     last_name="Toto")
     self.request = Mock()
     setattr(self.request, 'user', self.user)
     setattr(self.request, 'session', {})
     setattr(self.request, 'method', 'GET')
     self.cart = Cart()
     self.cart.user = self.user
     self.cart.save()
开发者ID:ZloiGremlin,项目名称:django-shop,代码行数:12,代码来源:views_checkout.py


示例8: setUp

 def setUp(self):
     self.user = User.objects.create(username="test",
                                     email="[email protected]",
                                     first_name="Test",
                                     last_name="Toto")
     self.request = Mock()
     setattr(self.request, 'user', self.user)
     setattr(self.request, 'session', {})
     setattr(self.request, 'method', 'GET')
     self.product = Product(name='pizza', slug='pizza', unit_price='1.45')
     self.product.save()
     self.cart = Cart()
     self.cart.user = self.user
     self.cart.save()
开发者ID:albeirochoa,项目名称:django-shop,代码行数:14,代码来源:views_checkout.py


示例9: create_fixtures

 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.cart = Cart()
     self.cart.user = self.user
     self.cart.save()
     
     self.client = Client()
     self.client.user = self.user
     self.client.save()
     
     self.country = Country.objects.create(name='CH')
     
     self.address = Address()
     self.address.client = self.client
     self.address.address = 'address'
     self.address.address2 = 'address2'
     self.address.zip_code = '1234'
     self.address.state = 'ZH'
     self.address.country = self.country
     self.address.is_billing = True
     self.address.is_shipping = True
     self.address.save()
     
     self.address2 = Address()
     self.address2.client = self.client
     self.address2.address = '2address'
     self.address2.address2 = '2address2'
     self.address2.zip_code = '21234'
     self.address2.state = '2ZH'
     self.address2.country = self.country
     self.address2.is_billing = True
     self.address2.is_shipping = False
     self.address2.save()
开发者ID:FinalAngel,项目名称:django-shop,代码行数:49,代码来源:order.py


示例10: setUp

    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()
开发者ID:AlexHill,项目名称:django-shop,代码行数:15,代码来源:cart_modifiers.py


示例11: get_or_create_cart

def get_or_create_cart(request, save=False):
    """
    Return cart for current visitor.

    Let's inspect the request for user or session, then either find a
    matching cart and return it or build a new one.

    If ``save`` is True, cart object will be explicitely saved.
    """
    cart = None
    if not hasattr(request, '_cart'):
        if request.user and not isinstance(request.user, AnonymousUser):
            # There is a logged in user
            cart = Cart.objects.filter(user=request.user)  # a list
            if not cart:  # if list is empty
                cart = Cart(user=request.user)
            else:
                cart = cart[0]  # Get the first one from the list
        else:
            session = getattr(request, 'session', None)
            if session != None:
                # There is a session
                cart_id = session.get('cart_id')
                if cart_id:
                    try:
                        cart = Cart.objects.get(pk=cart_id)
                    except Cart.DoesNotExist:
                        cart = None
                if not cart:
                    cart = Cart()
        if save and not cart.pk:
            cart.save()
            request.session['cart_id'] = cart.id
        setattr(request, '_cart', cart)
    cart = getattr(request, '_cart')  # There we *must* have a cart
    return cart
开发者ID:bakanov,项目名称:django-shop,代码行数:36,代码来源:cart.py


示例12: setUp

    def setUp(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.cart = Cart()
        self.cart.user = self.user
        self.cart.save()

        # self.client.user = self.user
        # self.client.save()

        self.country = Country.objects.create(name="CH")

        self.address = Address()
        self.address.name = "Test Toto"
        self.address.address = "address"
        self.address.address2 = "address2"
        self.address.zip_code = "1234"
        self.address.state = "ZH"
        self.address.country = self.country
        self.address.is_billing = True
        self.address.is_shipping = True
        self.address.save()

        self.address2 = Address()
        self.address2.name = "Test Toto"
        self.address2.address = "2address"
        self.address2.address2 = "2address2"
        self.address2.zip_code = "21234"
        self.address2.state = "2ZH"
        self.address2.country = self.country
        self.address2.is_billing = True
        self.address2.is_shipping = False
        self.address2.save()
开发者ID:wmsmith,项目名称:django-shop,代码行数:45,代码来源:order.py


示例13: setUp

    def setUp(self):
        cart_modifiers_pool.USE_CACHE = False
        user = User.objects.create(username="test", email="[email protected]")
        self.request = Mock()
        setattr(self.request, 'user', user)
        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.inactive_product = Product(name='InactiveProduct', slug='InactiveProduct', active=False)
        self.inactive_product.save()

        self.cart = Cart()
        self.cart.user = user
        self.cart.save()
开发者ID:Julila,项目名称:django-shop,代码行数:19,代码来源:cart.py


示例14: CartTestCase

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:RuuPiE,项目名称:django-shop,代码行数:101,代码来源:cart.py


示例15: OrderConversionTestCase

class OrderConversionTestCase(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]",
                                        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.cart = Cart()
        self.cart.user = self.user
        self.cart.save()
        
        self.client = Client()
        self.client.user = self.user
        self.client.save()
        
        self.country = Country.objects.create(name='CH')
        
        self.address = Address()
        self.address.client = self.client
        self.address.address = 'address'
        self.address.address2 = 'address2'
        self.address.zip_code = '1234'
        self.address.state = 'ZH'
        self.address.country = self.country
        self.address.is_billing = True
        self.address.is_shipping = True
        self.address.save()
        
        self.address2 = Address()
        self.address2.client = self.client
        self.address2.address = '2address'
        self.address2.address2 = '2address2'
        self.address2.zip_code = '21234'
        self.address2.state = '2ZH'
        self.address2.country = self.country
        self.address2.is_billing = True
        self.address2.is_shipping = False
        self.address2.save()
    
    def test_01_create_order_from_simple_cart(self):
        '''
        Let's make sure that all the info is copied over properly when using
        Order.objects.create_from_cart()
        '''
        self.create_fixtures()
        self.cart.add_product(self.product)
        self.cart.update()
        self.cart.save()
        
        o = Order.objects.create_from_cart(self.cart)
        
        self.assertNotEqual(o, None)
        
        ois = OrderItem.objects.filter(order=o)
        cis = CartItem.objects.filter(cart=self.cart)
        self.assertEqual(len(ois), len(cis))
        
        self.assertEqual(o.order_subtotal, self.cart.subtotal_price)
        self.assertEqual(o.order_total, self.cart.total_price)

    def test_02_create_order_from_taxed_cart(self):
        '''
        This time assert that everything is consistent with a tax cart modifier
        '''
        self.create_fixtures()
        MODIFIERS = ['shop.cart.modifiers.tax_modifiers.TenPercentTaxModifier']
        
        with SettingsOverride(SHOP_PRICE_MODIFIERS=MODIFIERS):

            self.cart.add_product(self.product)
            self.cart.update()
            self.cart.save()
            
            o = Order.objects.create_from_cart(self.cart,)
            
            # Must not return None, obviously
            self.assertNotEqual(o, None)
            
            # Compare all the OrderItems to all CartItems (length)
            ois = OrderItem.objects.filter(order=o)
            cis = CartItem.objects.filter(cart=self.cart)
            self.assertEqual(len(ois), len(cis))
            
            # Assert that there are as many extra_cart_price_fields than there
#.........这里部分代码省略.........
开发者ID:FinalAngel,项目名称:django-shop,代码行数:101,代码来源:order.py


示例16: CartTestCase

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,代码行数:101,代码来源:cart.py


示例17: CartModifiersTestCase

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,代码行数:70,代码来源:cart_modifiers.py


示例18: CartTestCase

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,代码行数:101,代码来源:cart.py


示例19: OrderConversionTestCase

class OrderConversionTestCase(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]", 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.cart = Cart()
        self.cart.user = self.user
        self.cart.save()

        # self.client.user = self.user
        # self.client.save()

        self.country = Country.objects.create(name="CH")

        self.address = Address()
        self.address.name = "Test Toto"
        self.address.address = "address"
        self.address.address2 = "address2"
        self.address.zip_code = "1234"
        self.address.state = "ZH"
        self.address.country = self.country
        self.address.is_billing = True
        self.address.is_shipping = True
        self.address.save()

        self.address2 = Address()
        self.address2.name = "Test Toto"
        self.address2.address = "2address"
        self.address2.address2 = "2address2"
        self.address2.zip_code = "21234"
        self.address2.state = "2ZH"
        self.address2.country = self.country
        self.address2.is_billing = True
        self.address2.is_shipping = False
        self.address2.save()

    def test_create_order_from_simple_cart(self):
        """
        Let's make sure that all the info is copied over properly when using
        Order.objects.create_from_cart()
        """
        self.cart.add_product(self.product)
        self.cart.update()
        self.cart.save()

        o = Order.objects.create_from_cart(self.cart)

        self.assertNotEqual(o, None)

        ois = OrderItem.objects.filter(order=o)
        cis = CartItem.objects.filter(cart=self.cart)
        self.assertEqual(len(ois), len(cis))

        self.assertEqual(ois[0].line_subtotal, self.PRODUCT_PRICE)
        self.assertEqual(ois[0].line_total, self.PRODUCT_PRICE)

        self.assertEqual(o.order_subtotal, self.cart.subtotal_price)
        self.assertEqual(o.order_total, self.cart.total_price)

    def test_create_order_from_taxed_cart(self):
        """
        This time assert that everything is consistent with a tax cart modifier
        """
        MODIFIERS = ["shop.cart.modifiers.tax_modifiers.TenPercentGlobalTaxModifier"]

        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):

            sel 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ordermodel.Order类代码示例发布时间:2022-05-27
下一篇:
Python cart_modifiers_pool.get_modifiers_list函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap