Ejemplo n.º 1
0
class FixedPriceBenefitTest(OfferTest):
    
    def setUp(self):
        super(FixedPriceBenefitTest, self).setUp()
        self.benefit = FixedPriceBenefit(range=self.range, type="FixedPrice", value=Decimal('10.00'))
        
    def test_correct_discount_is_returned(self):
        products = [create_product(Decimal('8.00')), create_product(Decimal('4.00'))]
        range = Range.objects.create(name="Dummy range")
        for product in products:
            range.included_products.add(product)
            range.included_products.add(product)
            
        basket = Basket.objects.create()
        [basket.add_product(p) for p in products]
        
        condition = CoverageCondition(range=range, type="Coverage", value=2)
        discount = self.benefit.apply(basket, condition)
        self.assertEquals(Decimal('2.00'), discount)   
        
    def test_no_discount_is_returned_when_value_is_greater_than_product_total(self):
        products = [create_product(Decimal('4.00')), create_product(Decimal('4.00'))]
        range = Range.objects.create(name="Dummy range")
        for product in products:
            range.included_products.add(product)
            range.included_products.add(product)
            
        basket = Basket.objects.create()
        [basket.add_product(p) for p in products]
        
        condition = CoverageCondition(range=range, type="Coverage", value=2)
        discount = self.benefit.apply(basket, condition)
        self.assertEquals(Decimal('0.00'), discount) 
Ejemplo n.º 2
0
 def test_correct_discount_for_count_condition(self):
     products = [create_product(Decimal('7.00')), 
                 create_product(Decimal('8.00')),
                 create_product(Decimal('12.00'))]
     
     # Create range that includes the products
     range = Range.objects.create(name="Dummy range")
     for product in products:
         range.included_products.add(product)
     condition = CountCondition(range=range, type="Count", value=3)
         
     # Create basket that satisfies condition but with one extra product    
     basket = Basket.objects.create()
     [basket.add_product(p, 2) for p in products]
     
     benefit = FixedPriceBenefit(range=range, type="FixedPrice", value=Decimal('20.00'))
     self.assertEquals(Decimal('2.00'), benefit.apply(basket, condition))
     self.assertEquals(Decimal('12.00'), benefit.apply(basket, condition)) 
     self.assertEquals(Decimal('0.00'), benefit.apply(basket, condition))
Ejemplo n.º 3
0
class FixedPriceBenefitTest(OfferTest):
    def setUp(self):
        super(FixedPriceBenefitTest, self).setUp()
        self.benefit = FixedPriceBenefit(range=self.range,
                                         type="FixedPrice",
                                         value=Decimal('10.00'))

    def test_correct_discount_is_returned(self):
        products = [
            create_product(Decimal('8.00')),
            create_product(Decimal('4.00'))
        ]
        range = Range.objects.create(name="Dummy range")
        for product in products:
            range.included_products.add(product)
            range.included_products.add(product)

        basket = Basket.objects.create()
        [basket.add_product(p) for p in products]

        condition = CoverageCondition(range=range, type="Coverage", value=2)
        discount = self.benefit.apply(basket, condition)
        self.assertEquals(Decimal('2.00'), discount)

    def test_no_discount_is_returned_when_value_is_greater_than_product_total(
            self):
        products = [
            create_product(Decimal('4.00')),
            create_product(Decimal('4.00'))
        ]
        range = Range.objects.create(name="Dummy range")
        for product in products:
            range.included_products.add(product)
            range.included_products.add(product)

        basket = Basket.objects.create()
        [basket.add_product(p) for p in products]

        condition = CoverageCondition(range=range, type="Coverage", value=2)
        discount = self.benefit.apply(basket, condition)
        self.assertEquals(Decimal('0.00'), discount)
Ejemplo n.º 4
0
    def test_correct_discount_for_count_condition(self):
        products = [
            create_product(Decimal('7.00')),
            create_product(Decimal('8.00')),
            create_product(Decimal('12.00'))
        ]

        # Create range that includes the products
        range = Range.objects.create(name="Dummy range")
        for product in products:
            range.included_products.add(product)
        condition = CountCondition(range=range, type="Count", value=3)

        # Create basket that satisfies condition but with one extra product
        basket = Basket.objects.create()
        [basket.add_product(p, 2) for p in products]

        benefit = FixedPriceBenefit(range=range,
                                    type="FixedPrice",
                                    value=Decimal('20.00'))
        self.assertEquals(Decimal('2.00'), benefit.apply(basket, condition))
        self.assertEquals(Decimal('12.00'), benefit.apply(basket, condition))
        self.assertEquals(Decimal('0.00'), benefit.apply(basket, condition))
Ejemplo n.º 5
0
 def test_discount_when_more_products_than_required(self):
     products = [create_product(Decimal('4.00')), 
                 create_product(Decimal('8.00')),
                 create_product(Decimal('12.00'))]
     
     # Create range that includes the products
     range = Range.objects.create(name="Dummy range")
     for product in products:
         range.included_products.add(product)
     condition = CoverageCondition(range=range, type="Coverage", value=3)
         
     # Create basket that satisfies condition but with one extra product    
     basket = Basket.objects.create()
     [basket.add_product(p) for p in products]
     basket.add_product(products[0])
     
     benefit = FixedPriceBenefit(range=range, type="FixedPrice", value=Decimal('20.00'))
     discount = benefit.apply(basket, condition)
     self.assertEquals(Decimal('4.00'), discount) 
Ejemplo n.º 6
0
    def test_discount_when_more_products_than_required(self):
        products = [
            create_product(Decimal('4.00')),
            create_product(Decimal('8.00')),
            create_product(Decimal('12.00'))
        ]

        # Create range that includes the products
        range = Range.objects.create(name="Dummy range")
        for product in products:
            range.included_products.add(product)
        condition = CoverageCondition(range=range, type="Coverage", value=3)

        # Create basket that satisfies condition but with one extra product
        basket = Basket.objects.create()
        [basket.add_product(p) for p in products]
        basket.add_product(products[0])

        benefit = FixedPriceBenefit(range=range,
                                    type="FixedPrice",
                                    value=Decimal('20.00'))
        discount = benefit.apply(basket, condition)
        self.assertEquals(Decimal('4.00'), discount)
Ejemplo n.º 7
0
class FixedPriceBenefitTest(OfferTest):
    
    def setUp(self):
        super(FixedPriceBenefitTest, self).setUp()
        self.benefit = FixedPriceBenefit(range=self.range, type="FixedPrice", value=Decimal('10.00'))
        
    def test_correct_discount_for_count_condition(self):
        products = [create_product(Decimal('7.00')), 
                    create_product(Decimal('8.00')),
                    create_product(Decimal('12.00'))]
        
        # Create range that includes the products
        range = Range.objects.create(name="Dummy range")
        for product in products:
            range.included_products.add(product)
        condition = CountCondition(range=range, type="Count", value=3)
            
        # Create basket that satisfies condition but with one extra product    
        basket = Basket.objects.create()
        [basket.add_product(p, 2) for p in products]
        
        benefit = FixedPriceBenefit(range=range, type="FixedPrice", value=Decimal('20.00'))
        self.assertEquals(Decimal('2.00'), benefit.apply(basket, condition))
        self.assertEquals(Decimal('12.00'), benefit.apply(basket, condition)) 
        self.assertEquals(Decimal('0.00'), benefit.apply(basket, condition))

    def test_correct_discount_is_returned(self):
        products = [create_product(Decimal('8.00')), create_product(Decimal('4.00'))]
        range = Range.objects.create(name="Dummy range")
        for product in products:
            range.included_products.add(product)
            range.included_products.add(product)
            
        basket = Basket.objects.create()
        [basket.add_product(p) for p in products]
        
        condition = CoverageCondition(range=range, type="Coverage", value=2)
        discount = self.benefit.apply(basket, condition)
        self.assertEquals(Decimal('2.00'), discount)

    def test_no_discount_when_product_not_discountable(self):
        product = create_product(Decimal('18.00'))
        product.is_discountable = False
        product.save()

        product_range = Range.objects.create(name="Dummy range")
        product_range.included_products.add(product)
            
        basket = Basket.objects.create()
        basket.add_product(product)
        
        condition = CoverageCondition(range=product_range, type="Coverage", value=1)
        discount = self.benefit.apply(basket, condition)
        self.assertEquals(Decimal('0.00'), discount)   
        
    def test_no_discount_is_returned_when_value_is_greater_than_product_total(self):
        products = [create_product(Decimal('4.00')), create_product(Decimal('4.00'))]
        range = Range.objects.create(name="Dummy range")
        for product in products:
            range.included_products.add(product)
            range.included_products.add(product)
            
        basket = Basket.objects.create()
        [basket.add_product(p) for p in products]
        
        condition = CoverageCondition(range=range, type="Coverage", value=2)
        discount = self.benefit.apply(basket, condition)
        self.assertEquals(Decimal('0.00'), discount) 
        
    def test_discount_when_more_products_than_required(self):
        products = [create_product(Decimal('4.00')), 
                    create_product(Decimal('8.00')),
                    create_product(Decimal('12.00'))]
        
        # Create range that includes the products
        range = Range.objects.create(name="Dummy range")
        for product in products:
            range.included_products.add(product)
        condition = CoverageCondition(range=range, type="Coverage", value=3)
            
        # Create basket that satisfies condition but with one extra product    
        basket = Basket.objects.create()
        [basket.add_product(p) for p in products]
        basket.add_product(products[0])
        
        benefit = FixedPriceBenefit(range=range, type="FixedPrice", value=Decimal('20.00'))
        discount = benefit.apply(basket, condition)
        self.assertEquals(Decimal('4.00'), discount) 
        
    def test_discount_when_applied_twice(self):
        products = [create_product(Decimal('4.00')), 
                    create_product(Decimal('8.00')),
                    create_product(Decimal('12.00'))]
        
        # Create range that includes the products
        range = Range.objects.create(name="Dummy range")
        for product in products:
            range.included_products.add(product)
        condition = CoverageCondition(range=range, type="Coverage", value=3)
            
        # Create basket that satisfies condition but with one extra product    
        basket = Basket.objects.create()
        [basket.add_product(p, 2) for p in products]
        
        benefit = FixedPriceBenefit(range=range, type="FixedPrice", value=Decimal('20.00'))
        first_discount = benefit.apply(basket, condition)
        self.assertEquals(Decimal('4.00'), first_discount) 
        second_discount = benefit.apply(basket, condition)
        self.assertEquals(Decimal('4.00'), second_discount) 
Ejemplo n.º 8
0
class FixedPriceBenefitTest(OfferTest):
    def setUp(self):
        super(FixedPriceBenefitTest, self).setUp()
        self.benefit = FixedPriceBenefit(range=self.range,
                                         type="FixedPrice",
                                         value=Decimal('10.00'))

    def test_correct_discount_for_count_condition(self):
        products = [
            create_product(Decimal('7.00')),
            create_product(Decimal('8.00')),
            create_product(Decimal('12.00'))
        ]

        # Create range that includes the products
        range = Range.objects.create(name="Dummy range")
        for product in products:
            range.included_products.add(product)
        condition = CountCondition(range=range, type="Count", value=3)

        # Create basket that satisfies condition but with one extra product
        basket = Basket.objects.create()
        [basket.add_product(p, 2) for p in products]

        benefit = FixedPriceBenefit(range=range,
                                    type="FixedPrice",
                                    value=Decimal('20.00'))
        self.assertEquals(Decimal('2.00'), benefit.apply(basket, condition))
        self.assertEquals(Decimal('12.00'), benefit.apply(basket, condition))
        self.assertEquals(Decimal('0.00'), benefit.apply(basket, condition))

    def test_correct_discount_is_returned(self):
        products = [
            create_product(Decimal('8.00')),
            create_product(Decimal('4.00'))
        ]
        range = Range.objects.create(name="Dummy range")
        for product in products:
            range.included_products.add(product)
            range.included_products.add(product)

        basket = Basket.objects.create()
        [basket.add_product(p) for p in products]

        condition = CoverageCondition(range=range, type="Coverage", value=2)
        discount = self.benefit.apply(basket, condition)
        self.assertEquals(Decimal('2.00'), discount)

    def test_no_discount_is_returned_when_value_is_greater_than_product_total(
            self):
        products = [
            create_product(Decimal('4.00')),
            create_product(Decimal('4.00'))
        ]
        range = Range.objects.create(name="Dummy range")
        for product in products:
            range.included_products.add(product)
            range.included_products.add(product)

        basket = Basket.objects.create()
        [basket.add_product(p) for p in products]

        condition = CoverageCondition(range=range, type="Coverage", value=2)
        discount = self.benefit.apply(basket, condition)
        self.assertEquals(Decimal('0.00'), discount)

    def test_discount_when_more_products_than_required(self):
        products = [
            create_product(Decimal('4.00')),
            create_product(Decimal('8.00')),
            create_product(Decimal('12.00'))
        ]

        # Create range that includes the products
        range = Range.objects.create(name="Dummy range")
        for product in products:
            range.included_products.add(product)
        condition = CoverageCondition(range=range, type="Coverage", value=3)

        # Create basket that satisfies condition but with one extra product
        basket = Basket.objects.create()
        [basket.add_product(p) for p in products]
        basket.add_product(products[0])

        benefit = FixedPriceBenefit(range=range,
                                    type="FixedPrice",
                                    value=Decimal('20.00'))
        discount = benefit.apply(basket, condition)
        self.assertEquals(Decimal('4.00'), discount)

    def test_discount_when_applied_twice(self):
        products = [
            create_product(Decimal('4.00')),
            create_product(Decimal('8.00')),
            create_product(Decimal('12.00'))
        ]

        # Create range that includes the products
        range = Range.objects.create(name="Dummy range")
        for product in products:
            range.included_products.add(product)
        condition = CoverageCondition(range=range, type="Coverage", value=3)

        # Create basket that satisfies condition but with one extra product
        basket = Basket.objects.create()
        [basket.add_product(p, 2) for p in products]

        benefit = FixedPriceBenefit(range=range,
                                    type="FixedPrice",
                                    value=Decimal('20.00'))
        first_discount = benefit.apply(basket, condition)
        self.assertEquals(Decimal('4.00'), first_discount)
        second_discount = benefit.apply(basket, condition)
        self.assertEquals(Decimal('4.00'), second_discount)