def total_special_items(self): unique_products = {item for item in self.special_items} for item in unique_products: if item.special_details['specialType'] == 'basic unit discount': self.total += specials.basic_unit_discount(self, item.name) elif item.special_details['specialType'] == 'buy some get some': self.total += specials.buy_some_get_some(self, item.name) elif item.special_details['specialType'] == 'buy some for amount': self.total += specials.buy_some_for_amount(self, item.name)
def test_buy_some_for_amount__should_buy_three_for_five_with_one_extra( self, mock_special): item_name = 'soap' special_details = { 'specialType': 'buy some for amount', 'buyAmount': 3, 'dollarAmount': 5, 'limit': 2 } mock_special.return_value = special_details actual = specials.buy_some_for_amount(self.cart, item_name) assert actual == 7.49
def test_buy_some_for_amount__should_buy_three_for_five_twice_with_two_extra_due_to_limit_of_two( self, mock_special): self.cart.special_items += [self.soap, self.soap, self.soap, self.soap] item_name = 'soap' special_details = { 'specialType': 'buy some for amount', 'buyAmount': 3, 'dollarAmount': 5, 'limit': 2 } mock_special.return_value = special_details actual = specials.buy_some_for_amount(self.cart, item_name) assert actual == 14.98