def test_shipping_price_3(self): """Tests an additional shipping method price with a criterion. """ # Add a shipping method price smp = ShippingMethodPrice.objects.create(shipping_method=self.sm1, price=5) # Add a criterion the to the price c = CartPriceCriterion.objects.create(price=10.0, operator=GREATER_THAN) co = CriteriaObjects.objects.create(criterion=c, content=smp) # The cart price is less than 10, hence the price is not valid and the # shipping price is the default price of the shipping method , which is # 1, see above. costs = utils.get_shipping_costs(self.request, self.sm1) self.assertEqual(costs["price"], 1) # No we add some items to the cart cart = cart_utils.get_or_create_cart(self.request) CartItem.objects.create(cart=cart, product=self.p1, amount=2) update_cart_cache(cart) # The cart price is now greater than 10, hence the price valid and the # shipping price is the price of the yet valid additional price. costs = utils.get_shipping_costs(self.request, self.sm1) self.assertEqual(costs["price"], 5)
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)