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)
def test_get_first_valid_shipping_method(self): """Test utils.get_first_valid_shipping_method """ # Prepare request user = User.objects.get(username="******") request = DummyRequest(user=user) # Create a weigth criterion and add it to the shipping method 1. WeightCriterion.objects.create(content=self.sm1, value=10.0, operator=LESS_THAN) # Create a weigth criterion and add it to the shipping method 2. WeightCriterion.objects.create(content=self.sm2, value=10.0, operator=GREATER_THAN) # For product 1 (weight: 6.0) the sm1 is the first valid (weight: 5.0 - 10.0) result = utils.get_first_valid_shipping_method(request, product=self.p1) self.assertEqual(result, self.sm1) # For product 1 (weight: 12.0) the sm1 is the first valid (weigth: > 10.0) result = utils.get_first_valid_shipping_method(request, product=self.p2) self.assertEqual(result, self.sm2)
def setUp(self): """ """ self.client.login(username="******", password="******") self.user = User.objects.get(username="******") self.request = DummyRequest(user=self.user) self.page = Page.objects.create(title="Page Title", slug="page-title", body="<p>This is a body</p>")
def setUp(self): """ """ self.user = User.objects.get(username="******") self.request = DummyRequest(user=self.user) self.d = Discount.objects.create(name="Summer", value=10.0, type=0) self.p = Product.objects.create(name="Product", slug="p", price=11, weight=12.0) # Delete the cart for every test method. cart = lfs.cart.utils.get_cart(self.request) if cart: cart.delete()
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)
def setUp(self): """ """ self.client.login(username="******", password="******") self.user = User.objects.get(username="******") self.request = DummyRequest(user=self.user) # Create delivery times self.dt1 = DeliveryTime.objects.create(min=3, max=4, unit=DELIVERY_TIME_UNIT_DAYS) self.dt2 = DeliveryTime.objects.create(min=1, max=2, unit=DELIVERY_TIME_UNIT_DAYS) self.dt3 = DeliveryTime.objects.create(min=5, max=6, unit=DELIVERY_TIME_UNIT_DAYS) self.sm1 = ShippingMethod.objects.create(name="Standard", active=True, price=1, delivery_time=self.dt1, priority=1) self.sm2 = ShippingMethod.objects.create(name="Express", active=True, delivery_time=self.dt2, priority=2) self.p1 = Product.objects.create(name="Product 1", slug="p1", price=9, weight=6.0, active=True) self.p2 = Product.objects.create(name="Product 2", slug="p2", price=11, weight=12.0, active=True) # Delete the cart for every test method. cart = cart_utils.get_cart(self.request) if cart: cart.delete()
def test_valid_shipping_methods_3(self): """Test with a given product. """ # Prepare request user = User.objects.get(username="******") request = DummyRequest(user=user) # Create a weigth criterion and add it to the shipping method 1. c = WeightCriterion.objects.create(weight=10.0, operator=GREATER_THAN) co = CriteriaObjects(criterion=c, content=self.sm1) co.save() # As the product has a weigth of 6.0 the shipping method is not valid result = c.is_valid(request, product=self.p1) self.assertEqual(result, False) # As product 2 has a weigth of 12.0 the shipping method is valid result = c.is_valid(request, product=self.p1) self.assertEqual(result, False)
def test_valid_shipping_methods_3(self): """Test with a given product. """ # Prepare request user = User.objects.get(username="******") request = DummyRequest(user=user) # Create a weigth criterion and add it to the shipping method 1. c = WeightCriterion.objects.create(content=self.sm1, value=10.0, operator=GREATER_THAN) # As the product has a weigth of 6.0 the shipping method is not valid c.product = self.p1 c.request = request result = c.is_valid() self.assertEqual(result, False) # As product 2 has a weigth of 11.0 the shipping method is valid c.product = self.p2 result = c.is_valid() self.assertEqual(result, True)
def setUp(self): """ """ self.client.login(username="******", password="******") self.user = User.objects.get(username="******") self.request = DummyRequest(user=self.user) self.root = Page.objects.create( id=1, title="Root", slug="", exclude_from_navigation=False, ) self.page = Page.objects.create(id=2, title="Page Title", slug="page-title", body="<p>This is a body</p>", short_text="This is a short text")
def test_get_category_nodes(self): """ """ category_nodes = get_category_nodes(DummyRequest())