Example #1
0
 def setUp(self):
     super(ValueConditionTest, self).setUp()
     self.cond = ValueCondition(range=self.range,
                                type="Value",
                                value=Decimal('10.00'))
     self.item = create_product(price=Decimal('5.00'))
     self.expensive_item = create_product(price=Decimal('15.00'))
Example #2
0
 def test_absolute_does_not_consume_twice(self):
     product = create_product(Decimal('25000'))
     rng = Range.objects.create(name='Dummy')
     rng.included_products.add(product)
     condition = ValueCondition(range=rng, type='Value', value=Decimal('5000'))
     basket = Basket.objects.create()
     basket.add_product(product, 5)
     benefit = AbsoluteDiscountBenefit(range=rng, type='Absolute', value=Decimal('100'))
     self.assertTrue(condition.is_satisfied(basket))
     self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
     self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
     self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
     self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
     self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
     self.assertEquals(Decimal('0'), benefit.apply(basket, condition))
Example #3
0
class ValueConditionTest(OfferTest):
    def setUp(self):
        super(ValueConditionTest, self).setUp()
        self.cond = ValueCondition(range=self.range, type="Count", value=Decimal('10.00'))
        self.item = create_product(price=Decimal('5.00'))
    
    def test_empty_basket_fails_condition(self):
        self.assertFalse(self.cond.is_satisfied(self.basket))
        
    def test_less_value_basket_fails_condition(self):
        self.basket.add_product(self.item, 1)
        self.assertFalse(self.cond.is_satisfied(self.basket))    
        
    def test_matching_basket_passes_condition(self):
        self.basket.add_product(self.item, 2)
        self.assertTrue(self.cond.is_satisfied(self.basket))   
        
    def test_greater_than_basket_passes_condition(self):
        self.basket.add_product(self.item, 3)
        self.assertTrue(self.cond.is_satisfied(self.basket)) 
        
    def test_consumption(self):
        self.basket.add_product(self.item, 3)
        self.cond.consume_items(self.basket)
        self.assertEquals(1, self.basket.all_lines()[0].quantity_without_discount)
Example #4
0
class ValueConditionTest(OfferTest):
    def setUp(self):
        super(ValueConditionTest, self).setUp()
        self.cond = ValueCondition(range=self.range,
                                   type="Count",
                                   value=Decimal('10.00'))
        self.item = create_product(price=Decimal('5.00'))

    def test_empty_basket_fails_condition(self):
        self.assertFalse(self.cond.is_satisfied(self.basket))

    def test_less_value_basket_fails_condition(self):
        self.basket.add_product(self.item, 1)
        self.assertFalse(self.cond.is_satisfied(self.basket))

    def test_matching_basket_passes_condition(self):
        self.basket.add_product(self.item, 2)
        self.assertTrue(self.cond.is_satisfied(self.basket))

    def test_greater_than_basket_passes_condition(self):
        self.basket.add_product(self.item, 3)
        self.assertTrue(self.cond.is_satisfied(self.basket))

    def test_consumption(self):
        self.basket.add_product(self.item, 3)
        self.cond.consume_items(self.basket)
        self.assertEquals(1,
                          self.basket.all_lines()[0].quantity_without_discount)
Example #5
0
    def test_product_does_consume_item_if_not_in_condition_range(self):
        # Set up condition using a different range from benefit
        range = Range.objects.create(name="Small range")
        other_product = create_product(price=Decimal('15.00'))
        range.included_products.add(other_product)
        cond = ValueCondition(range=range,
                              type="Value",
                              value=Decimal('10.00'))

        self.basket.add_product(self.item, 1)
        self.benefit.apply(self.basket, cond)
        line = self.basket.all_lines()[0]
        self.assertEqual(line.quantity_without_discount, 0)
Example #6
0
 def setUp(self):
     super(ValueConditionTest, self).setUp()
     self.cond = ValueCondition(range=self.range, type="Value", value=Decimal('10.00'))
     self.item = create_product(price=Decimal('5.00'))
     self.expensive_item = create_product(price=Decimal('15.00'))
Example #7
0
class ValueConditionTest(OfferTest):
    def setUp(self):
        super(ValueConditionTest, self).setUp()
        self.cond = ValueCondition(range=self.range, type="Value", value=Decimal('10.00'))
        self.item = create_product(price=Decimal('5.00'))
        self.expensive_item = create_product(price=Decimal('15.00'))
    
    def test_empty_basket_fails_condition(self):
        self.assertFalse(self.cond.is_satisfied(self.basket))

    def test_empty_basket_fails_partial_condition(self):
        self.assertFalse(self.cond.is_partially_satisfied(self.basket))
        
    def test_less_value_basket_fails_condition(self):
        self.basket.add_product(self.item, 1)
        self.assertFalse(self.cond.is_satisfied(self.basket))    

    def test_not_discountable_item_fails_condition(self):
        self.expensive_item.is_discountable = False
        self.expensive_item.save()
        self.basket.add_product(self.expensive_item, 1)
        self.assertFalse(self.cond.is_satisfied(self.basket))

    def test_upsell_message(self):
        self.basket.add_product(self.item, 1)
        self.assertTrue('Spend' in self.cond.get_upsell_message(self.basket))

    def test_matching_basket_fails_partial_condition(self):
        self.basket.add_product(self.item, 2)
        self.assertFalse(self.cond.is_partially_satisfied(self.basket))   

    def test_less_value_basket_passes_partial_condition(self):
        self.basket.add_product(self.item, 1)
        self.assertTrue(self.cond.is_partially_satisfied(self.basket))    
        
    def test_matching_basket_passes_condition(self):
        self.basket.add_product(self.item, 2)
        self.assertTrue(self.cond.is_satisfied(self.basket))   
        
    def test_greater_than_basket_passes_condition(self):
        self.basket.add_product(self.item, 3)
        self.assertTrue(self.cond.is_satisfied(self.basket)) 
        
    def test_consumption(self):
        self.basket.add_product(self.item, 3)
        self.cond.consume_items(self.basket)
        self.assertEquals(1, self.basket.all_lines()[0].quantity_without_discount)

    def test_consumption_with_high_value_product(self):
        self.basket.add_product(self.expensive_item, 1)
        self.cond.consume_items(self.basket)
        self.assertEquals(0, self.basket.all_lines()[0].quantity_without_discount)
        
    def test_is_consumed_respects_quantity_consumed(self):
        self.basket.add_product(self.expensive_item, 1)
        self.assertTrue(self.cond.is_satisfied(self.basket))
        self.cond.consume_items(self.basket)
        self.assertFalse(self.cond.is_satisfied(self.basket))
Example #8
0
class ValueConditionTest(OfferTest):
    def setUp(self):
        super(ValueConditionTest, self).setUp()
        self.cond = ValueCondition(range=self.range,
                                   type="Value",
                                   value=Decimal('10.00'))
        self.item = create_product(price=Decimal('5.00'))
        self.expensive_item = create_product(price=Decimal('15.00'))

    def test_empty_basket_fails_condition(self):
        self.assertFalse(self.cond.is_satisfied(self.basket))

    def test_empty_basket_fails_partial_condition(self):
        self.assertFalse(self.cond.is_partially_satisfied(self.basket))

    def test_less_value_basket_fails_condition(self):
        self.basket.add_product(self.item, 1)
        self.assertFalse(self.cond.is_satisfied(self.basket))

    def test_upsell_message(self):
        self.basket.add_product(self.item, 1)
        self.assertTrue('Spend' in self.cond.get_upsell_message(self.basket))

    def test_matching_basket_fails_partial_condition(self):
        self.basket.add_product(self.item, 2)
        self.assertFalse(self.cond.is_partially_satisfied(self.basket))

    def test_less_value_basket_passes_partial_condition(self):
        self.basket.add_product(self.item, 1)
        self.assertTrue(self.cond.is_partially_satisfied(self.basket))

    def test_matching_basket_passes_condition(self):
        self.basket.add_product(self.item, 2)
        self.assertTrue(self.cond.is_satisfied(self.basket))

    def test_greater_than_basket_passes_condition(self):
        self.basket.add_product(self.item, 3)
        self.assertTrue(self.cond.is_satisfied(self.basket))

    def test_consumption(self):
        self.basket.add_product(self.item, 3)
        self.cond.consume_items(self.basket)
        self.assertEquals(1,
                          self.basket.all_lines()[0].quantity_without_discount)

    def test_consumption_with_high_value_product(self):
        self.basket.add_product(self.expensive_item, 1)
        self.cond.consume_items(self.basket)
        self.assertEquals(0,
                          self.basket.all_lines()[0].quantity_without_discount)

    def test_is_consumed_respects_quantity_consumed(self):
        self.basket.add_product(self.expensive_item, 1)
        self.assertTrue(self.cond.is_satisfied(self.basket))
        self.cond.consume_items(self.basket)
        self.assertFalse(self.cond.is_satisfied(self.basket))