@@ -159,55 +159,55 @@ class DiscountTestCase(RegistrationCartTestCase):
self.assertEqual(1, discount_items[0].quantity)
self.assertEqual(discount_half.pk, discount_items[0].discount.pk)
# The full discount should be applied twice
self.assertEqual(2, discount_items[1].quantity)
self.assertEqual(discount_full.pk, discount_items[1].discount.pk)
def test_discount_applies_across_carts(self):
self.add_discount_prod_1_includes_prod_2()
# Enable the discount during the first cart.
cart = TestingCartController.for_user(self.USER_1)
cart.add_to_cart(self.PROD_1, 1)
cart.cart.active = False
cart.cart.save()
cart.next_cart()
# Use the discount in the second cart
cart.add_to_cart(self.PROD_2, 1)
# The discount should be applied.
self.assertEqual(1, len(cart.cart.discountitem_set.all()))
# The discount should respect the total quantity across all
# of the user's carts.
cart.add_to_cart(self.PROD_2, 2)
# Having one item in the second cart leaves one more item where
# the discount is applicable. The discount should apply, but only for
# quantity=1
discount_items = list(cart.cart.discountitem_set.all())
def test_discount_applies_only_once_enabled(self):
# This would exhaust discount if present
self.assertEqual(2, discount_items[0].quantity)
def test_category_discount_applies_once_per_category(self):
self.add_discount_prod_1_includes_cat_2(quantity=1)
@@ -337,39 +337,37 @@ class DiscountTestCase(RegistrationCartTestCase):
discounts = discount.available_discounts(self.USER_1, [self.CAT_1], [])
self.assertEqual(0, len(discounts))
def test_discount_quantity_is_correct_before_first_purchase(self):
self.add_discount_prod_1_includes_cat_2(quantity=2)
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
cart.add_to_cart(self.PROD_3, 1) # Exhaust the quantity
discounts = discount.available_discounts(self.USER_1, [self.CAT_2], [])
self.assertEqual(2, discounts[0].quantity)
inv = InvoiceController.for_cart(cart.cart)
inv.pay("Dummy reference", inv.invoice.value)
self.assertTrue(inv.invoice.paid)
def test_discount_quantity_is_correct_after_first_purchase(self):
self.test_discount_quantity_is_correct_before_first_purchase()
self.assertEqual(1, discounts[0].quantity)
def test_discount_is_gone_after_quantity_exhausted(self):
self.test_discount_quantity_is_correct_after_first_purchase()
def test_product_discount_enabled_twice_appears_twice(self):
self.add_discount_prod_1_includes_prod_3_and_prod_4(quantity=2)
discounts = discount.available_discounts(
self.USER_1,
@@ -381,35 +379,35 @@ class DiscountTestCase(RegistrationCartTestCase):
def test_discounts_are_released_by_refunds(self):
self.add_discount_prod_1_includes_prod_2(quantity=2)
[],
[self.PROD_2],
)
self.assertEqual(1, len(discounts))
cart.cart.active = False # Keep discount enabled
cart.add_to_cart(self.PROD_2, 2) # The discount will be exhausted
cart.cart.released = True