def test_multibuy_must_not_have_value(self): benefit = models.Benefit(range=self.range, type=models.Benefit.MULTIBUY, value=1) with self.assertRaises(ValidationError): benefit.clean()
def test_multibuy_range_required(self): benefit = models.Benefit(range=None, type=models.Benefit.MULTIBUY, value=1) with self.assertRaises(ValidationError): benefit.clean()
def test_multibuy_must_not_have_max_affected_items(self): benefit = models.Benefit(range=self.range, type=models.Benefit.MULTIBUY, max_affected_items=2) with self.assertRaises(ValidationError): benefit.clean()
def test_requires_a_benefit_value(self): rng = models.Range.objects.create( name="", includes_all_products=True) benefit = models.Benefit( type=models.Benefit.FIXED, range=rng ) with self.assertRaises(ValidationError): benefit.clean()
def test_shipping_percentage_validation(self): benefit = models.Benefit( type=models.Benefit.SHIPPING_PERCENTAGE, value=105, # Invalid value ) with self.assertRaises(ValidationError): benefit.clean()
def test_shipping_percentage_required(self): benefit = models.Benefit( type=models.Benefit.SHIPPING_PERCENTAGE, value=None, # This should be required ) with self.assertRaises(ValidationError): benefit.clean()
def test_shipping_max_affected_items_must_not_be_set(self): benefit = models.Benefit( type=models.Benefit.SHIPPING_PERCENTAGE, value=50, max_affected_items=5, ) with self.assertRaises(ValidationError): benefit.clean()
def test_absolute_range_must_not_be_set(self): benefit = models.Benefit( type=models.Benefit.SHIPPING_ABSOLUTE, value=10, range=self.range, ) with self.assertRaises(ValidationError): benefit.clean()
def test_fixed_max_affected_items_must_not_be_set(self): benefit = models.Benefit( type=models.Benefit.SHIPPING_FIXED_PRICE, value=10, max_affected_items=5, ) with self.assertRaises(ValidationError): benefit.clean()
def test_fixed_range_must_not_be_set(self): benefit = models.Benefit( type=models.Benefit.SHIPPING_FIXED_PRICE, value=10, range=self.range, ) with self.assertRaises(ValidationError): benefit.clean()
def test_absolute_max_affected_items_must_not_be_set(self): benefit = models.Benefit( type=models.Benefit.SHIPPING_ABSOLUTE, value=10, max_affected_items=5, ) with self.assertRaises(ValidationError): benefit.clean()
def test_shipping_range_must_not_be_set(self): product_range = models.Range.objects.create(name="Foo", includes_all_products=True) benefit = models.Benefit( type=models.Benefit.SHIPPING_PERCENTAGE, value=50, range=product_range, # Range shouldn't be allowed ) with self.assertRaises(ValidationError): benefit.clean()
def test_available_with_offer(self): basket = BasketFactory() product1 = ProductFactory() product2 = ProductFactory() basket.add_product(product1, quantity=1) basket.add_product(product2, quantity=10) benefit = models.Benefit( type=models.Benefit.PERCENTAGE, value=10, max_affected_items=5, ) benefit.save() offer1 = ConditionalOfferFactory(name='offer1', benefit=benefit) lines = basket.all_lines() assert lines[0].consumer.available(offer1) == 1 assert lines[1].consumer.available(offer1) == 5
def test_requires_a_range(self): benefit = models.Benefit(type=models.Benefit.FIXED, value=10) with self.assertRaises(ValidationError): benefit.clean()
def test_absolute_requires_value(self): benefit = models.Benefit(type=models.Benefit.SHIPPING_ABSOLUTE) with self.assertRaises(ValidationError): benefit.clean()