@@ -234,24 +234,47 @@ class DiscountTestCase(RegistrationCartTestCase):
# Both users should be able to apply the same discount
# in the same way
for user in (self.USER_1, self.USER_2):
cart = TestingCartController.for_user(user)
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
cart.add_to_cart(self.PROD_3, 1)
discount_items = list(cart.cart.discountitem_set.all())
# The discount is applied.
self.assertEqual(1, len(discount_items))
def test_discount_applies_to_most_expensive_item(self):
self.add_discount_prod_1_includes_cat_2(quantity=1)
cart = TestingCartController.for_user(self.USER_1)
import itertools
prods = (self.PROD_3, self.PROD_4)
for first, second in itertools.permutations(prods, 2):
cart.set_quantity(first, 1)
cart.set_quantity(second, 1)
# There should only be one discount
# It should always apply to PROD_3, as it costs more.
self.assertEqual(discount_items[0].product, self.PROD_3)
cart.set_quantity(first, 0)
cart.set_quantity(second, 0)
# Tests for the DiscountController.available_discounts enumerator
def test_enumerate_no_discounts_for_no_input(self):
discounts = DiscountController.available_discounts(
self.USER_1,
[],
)
self.assertEqual(0, len(discounts))
def test_enumerate_no_discounts_if_condition_not_met(self):