Example #1
0
 def test_one_without_dependent(self):
     """
     One target product in the absence of its dependent product doesn't trigger discount.
     """
     product_store = self._create_product_store()
     twix_20_discount = DependentDiscountOffer("twix", "pasta", Decimal("0.2"))
     basket = Basket(product_store)
     twix_basketitem = basket.add("twix")
     self.assertEqual(twix_20_discount.calculate_line_total(twix_basketitem, product_store, basket), Decimal("0.80"))
Example #2
0
 def test_one_without_dependent(self):
     '''One target product in the absence of its dependent product doesn't
     trigger discount.'''
     product_store = self._create_product_store()
     mars_snickers_20_discount = DependentDiscountOffer(
         'mars bar', 'snickers bar', Decimal('0.2'))
     cart = Cart(product_store)
     mars_cartitem = cart.add('mars bar')
     self.assertEqual(mars_snickers_20_discount.calculate_line_total(
         mars_cartitem, product_store, cart), Decimal('0.65'))
Example #3
0
 def test_two_with_one_dependent(self):
     '''Two target product in the presence of one dependent product
     triggers discount.'''
     product_store = self._create_product_store()
     mars_snickers_20_discount = DependentDiscountOffer(
         'mars bar', 'snickers bar', Decimal('0.2'))
     cart = Cart(product_store)
     mars_cartitem = cart.add('mars bar', 2)
     cart.add('snickers bar')
     self.assertEqual(mars_snickers_20_discount.calculate_line_total(
         mars_cartitem, product_store, cart), Decimal('1.17'))
Example #4
0
 def test_one_without_dependent(self):
     '''One target product in the absence of its dependent product doesn't
     trigger discount.'''
     product_store = self._create_product_store()
     mars_snickers_20_discount = DependentDiscountOffer(
         'mars bar', 'snickers bar', Decimal('0.2'))
     cart = Cart(product_store)
     mars_cartitem = cart.add('mars bar')
     self.assertEqual(
         mars_snickers_20_discount.calculate_line_total(
             mars_cartitem, product_store, cart), Decimal('0.65'))
Example #5
0
 def test_one_without_dependent(self):
     '''One target product in the absence of its dependent product doesn't
     trigger discount.'''
     product_store = self._create_product_store()
     mars_snickers_20_discount = DependentDiscountOffer(
         'ice cream', 'dairy milk', float('0.2'))
     cart = Cart(product_store)
     mars_cartitem = cart.add('ice cream')
     self.assertEqual(
         round(
             mars_snickers_20_discount.calculate_line_total(
                 mars_cartitem, product_store, cart), 2), float('3.49'))
Example #6
0
 def test_two_with_one_dependent(self):
     '''Two target product in the presence of one dependent product
     triggers discount.'''
     product_store = self._create_product_store()
     mars_snickers_20_discount = DependentDiscountOffer(
         'mars bar', 'snickers bar', Decimal('0.2'))
     cart = Cart(product_store)
     mars_cartitem = cart.add('mars bar', 2)
     cart.add('snickers bar')
     self.assertEqual(
         mars_snickers_20_discount.calculate_line_total(
             mars_cartitem, product_store, cart), Decimal('1.17'))
Example #7
0
 def test_two_with_one_dependent(self):
     '''Two target product in the presence of one dependent product
     triggers discount.'''
     product_store = self._create_product_store()
     mars_snickers_20_discount = DependentDiscountOffer(
         'ice cream', 'dairy milk', float('0.2'))
     cart = Cart(product_store)
     mars_cartitem = cart.add('ice cream', 2)
     cart.add('dairy milk')
     self.assertEqual(
         round(
             mars_snickers_20_discount.calculate_line_total(
                 mars_cartitem, product_store, cart), 2), float('6.28'))
Example #8
0
 def test_get_total_with_dependent_discount_offer(self):
     """
     Basket get_total returns correct value with dependent discount offer applied.
     """
     product_store = self._create_product_store()
     twix_pasta_20_discount = DependentDiscountOffer("twix", "pasta", Decimal("0.2"))
     basket = Basket(product_store)
     basket.add("twix", 2)
     basket.add("pasta")
     self.assertEqual(basket.get_total(offers=[twix_pasta_20_discount]), Decimal('2.94'))
Example #9
0
 def test_get_total_with_dependent_discount_offer(self):
     '''Cart get_total returns correct value with a dependent discount
     offer applied.'''
     product_store = self._create_product_store()
     kitkat_apple_20_discount = DependentDiscountOffer(
         'kitkat', 'apple', float('0.2'))
     cart = Cart(product_store)
     cart.add('kitkat', 2)
     cart.add('apple')
     self.assertEqual(
         round(cart.get_total(offers=[kitkat_apple_20_discount]), 2),
         float('1.41'))
Example #10
0
 def test_get_total_with_dependent_discount_offer(self):
     '''Cart get_total returns correct value with a dependent discount
     offer applied.'''
     product_store = self._create_product_store()
     strawberries_apple_20_discount = DependentDiscountOffer(
         'strawberries', 'apple', Decimal('0.2'))
     cart = Cart(product_store)
     cart.add('strawberries', 2)
     cart.add('apple')
     self.assertEqual(
         cart.get_total(offers=[strawberries_apple_20_discount]),
         Decimal('3.75'))
Example #11
0
 def test_get_total_with_two_offers_on_same_target(self):
     '''Cart get_total returns cheapest total when two offers are
     applicable for the same target.'''
     product_store = self._create_product_store()
     bogof_kitkat = MultiBuyOffer('kitkat', 1, 1)
     kitkat_apple_20_discount = DependentDiscountOffer(
         'kitkat', 'apple', float('0.2'))
     cart = Cart(product_store)
     cart.add('kitkat', 2)
     cart.add('apple')
     self.assertEqual(
         cart.get_total(offers=[bogof_kitkat, kitkat_apple_20_discount]),
         float('0.85'))
Example #12
0
 def test_get_total_with_two_offers_on_same_target(self):
     '''Cart get_total returns cheapest total when two offers are
     applicable for the same target.'''
     product_store = self._create_product_store()
     bogof_strawberries = MultiBuyOffer('strawberries', 1, 1)
     strawberries_apple_20_discount = DependentDiscountOffer(
         'strawberries', 'apple', Decimal('0.2'))
     cart = Cart(product_store)
     cart.add('strawberries', 2)
     cart.add('apple')
     self.assertEqual(
         cart.get_total(
             offers=[bogof_strawberries, strawberries_apple_20_discount]),
         Decimal('2.15'))