Пример #1
0
    def test_shipping_methods_criterion_for_empty_cart(self):
        """Test with a given product.
        """
        # Prepare request
        user = User.objects.get(username="******")

        # Create a width criterion and add it to the shipping method price
        smp = ShippingMethodPrice.objects.create(shipping_method=self.sm1, price=10.0, active=True)
        WidthCriterion.objects.create(content=smp, value=10.0, operator=GREATER_THAN)

        # there is no product in the cart so criterion is not valid
        self.client.post(
            reverse('lfs_login'),
            dict(
                username='******',
                password='******',
                action='login'
            ),
            follow=True
        )

        response = self.client.get(
            reverse('lfs_cart')
        )

        request = response.context['request']

        cart_utils.create_cart(request)
        result = smp.is_valid(request)
        self.assertEqual(result, False)
Пример #2
0
    def test_shipping_methods_criterion_for_empty_cart(self):
        """Test with a given product.
        """
        # Prepare request
        user = User.objects.get(username="******")
        request = DummyRequest(user=user)

        # Create a width criterion and add it to the shipping method price
        smp = ShippingMethodPrice.objects.create(shipping_method=self.sm1, price=10.0, active=True)
        WidthCriterion.objects.create(content=smp, value=10.0, operator=GREATER_THAN)

        # there is no product in the cart so criterion is not valid
        cart_utils.create_cart(request)
        result = smp.is_valid(request)
        self.assertEqual(result, False)
Пример #3
0
    def test_shipping_methods_criterion_for_empty_cart(self):
        """Test with a given product.
        """
        # Prepare request
        user = User.objects.get(username="******")
        request = DummyRequest(user=user)

        # Create a width criterion and add it to the shipping method price
        smp = ShippingMethodPrice.objects.create(shipping_method=self.sm1, price=10.0, active=True)
        c = WidthCriterion.objects.create(content=smp, value=10.0, operator=GREATER_THAN)

        # there is no product in the cart so criterion is not valid
        cart_utils.create_cart(request)
        result = smp.is_valid(request)
        self.assertEqual(result, False)
Пример #4
0
    def test_valid_shipping_methods_2(self):
        """Tests valid shipping methods. Test with a cart price criterion.
        """
        user = User.objects.get(username="******")
        request = DummyRequest(user=user)

        # Create a cart price criterion and add it to the shipping method 1
        CartPriceCriterion.objects.create(content=self.sm1,
                                          value=10.0,
                                          operator=GREATER_THAN)

        # Cart price is 0.0 sms1 is not valid
        sms = utils.get_valid_shipping_methods(request)
        self.assertEqual(len(sms), 1)

        # Add some products to the cart
        cart = cart_utils.create_cart(request)

        # Cart price is still under 10 - sms1 is not valid
        CartItem.objects.create(cart=cart, product=self.p1, amount=1)
        update_cart_cache(cart)

        sms = utils.get_valid_shipping_methods(request)
        self.assertEqual(len(sms), 1)

        # Cart price is greater than 10.0 now - sms1 is valid
        CartItem.objects.create(cart=cart, product=self.p2, amount=1)
        update_cart_cache(cart)

        sms = utils.get_valid_shipping_methods(request)
        self.assertEqual(len(sms), 2)
Пример #5
0
    def test_valid_shipping_methods_2(self):
        """Tests valid shipping methods. Test with a cart price criterion.
        """
        user = User.objects.get(username="******")
        request = DummyRequest(user=user)

        # Create a cart price criterion and add it to the shipping method 1
        c = CartPriceCriterion.objects.create(price=10.0, operator=GREATER_THAN)
        co = CriteriaObjects(criterion=c, content=self.sm1)
        co.save()

        # Cart price is 0.0 sms1 is not valid
        sms = utils.get_valid_shipping_methods(request)
        self.assertEqual(len(sms), 1)

        # Add some products to the cart
        cart = cart_utils.create_cart(request)

        # Cart price is still under 10 - sms1 is not valid
        CartItem.objects.create(cart=cart, product=self.p1, amount=1)
        update_cart_cache(cart)

        sms = utils.get_valid_shipping_methods(request)
        self.assertEqual(len(sms), 1)

        # Cart price is greater than 10.0 now - sms1 is valid
        CartItem.objects.create(cart=cart, product=self.p2, amount=1)
        update_cart_cache(cart)

        sms = utils.get_valid_shipping_methods(request)
        self.assertEqual(len(sms), 2)
Пример #6
0
    def test_valid_shipping_methods_2(self):
        """Tests valid shipping methods. Test with a cart price criterion.
        """
        self.client.post(
            reverse('lfs_login'),
            dict(
                username='******',
                password='******',
                action='login'
            ),
            follow=True
        )

        response = self.client.get(
            reverse('lfs_cart')
        )
        request = response.context['request']

        # Create a cart price criterion and add it to the shipping method 1
        CartPriceCriterion.objects.create(content=self.sm1, value=10.0, operator=GREATER_THAN)

        # Cart price is 0.0 sms1 is not valid
        sms = utils.get_valid_shipping_methods(request)
        self.assertEqual(len(sms), 1)

        # Add some products to the cart
        cart = cart_utils.create_cart(request)

        # Cart price is still under 10 - sms1 is not valid
        CartItem.objects.create(cart=cart, product=self.p1, amount=1)
        update_cart_cache(cart)

        sms = utils.get_valid_shipping_methods(request)
        self.assertEqual(len(sms), 1)

        # Cart price is greater than 10.0 now - sms1 is valid
        CartItem.objects.create(cart=cart, product=self.p2, amount=1)
        update_cart_cache(cart)

        sms = utils.get_valid_shipping_methods(request)
        self.assertEqual(len(sms), 2)