def test_discounts_are_released_by_refunds(self): self.add_discount_prod_1_includes_prod_2(quantity=2) cart = TestingCartController.for_user(self.USER_1) cart.add_to_cart(self.PROD_1, 1) # Enable the discount discounts = DiscountController.available_discounts( self.USER_1, [], [self.PROD_2], ) self.assertEqual(1, len(discounts)) cart.next_cart() cart = TestingCartController.for_user(self.USER_1) cart.add_to_cart(self.PROD_2, 2) # The discount will be exhausted cart.next_cart() discounts = DiscountController.available_discounts( self.USER_1, [], [self.PROD_2], ) self.assertEqual(0, len(discounts)) cart.cart.status = commerce.Cart.STATUS_RELEASED cart.cart.save() discounts = DiscountController.available_discounts( self.USER_1, [], [self.PROD_2], ) self.assertEqual(1, len(discounts))
def test_enumerate_no_discounts_if_condition_not_met(self): self.add_discount_prod_1_includes_cat_2(quantity=1) discounts = DiscountController.available_discounts( self.USER_1, [], [self.PROD_3], ) self.assertEqual(0, len(discounts)) discounts = DiscountController.available_discounts( self.USER_1, [self.CAT_2], [], ) self.assertEqual(0, len(discounts))
def test_enumerate_no_discounts_for_no_input(self): discounts = DiscountController.available_discounts( self.USER_1, [], [], ) self.assertEqual(0, len(discounts))
def test_discount_is_gone_after_quantity_exhausted(self): self.test_discount_quantity_is_correct_after_first_purchase() discounts = DiscountController.available_discounts( self.USER_1, [self.CAT_2], [], ) self.assertEqual(0, len(discounts))
def test_category_discount_appears_once_with_two_valid_product(self): self.add_discount_prod_1_includes_cat_2(quantity=1) cart = TestingCartController.for_user(self.USER_1) cart.add_to_cart(self.PROD_1, 1) # Enable the discount discounts = DiscountController.available_discounts( self.USER_1, [], [self.PROD_3, self.PROD_4]) self.assertEqual(1, len(discounts))
def test_product_discount_enabled_twice_appears_twice(self): self.add_discount_prod_1_includes_prod_3_and_prod_4(quantity=2) cart = TestingCartController.for_user(self.USER_1) cart.add_to_cart(self.PROD_1, 1) # Enable the discount discounts = DiscountController.available_discounts( self.USER_1, [], [self.PROD_3, self.PROD_4], ) self.assertEqual(2, len(discounts))
def test_product_discount_does_not_appear_with_category(self): self.add_discount_prod_1_includes_prod_2(quantity=1) cart = TestingCartController.for_user(self.USER_1) cart.add_to_cart(self.PROD_1, 1) # Enable the discount discounts = DiscountController.available_discounts( self.USER_1, [self.CAT_1], [], ) self.assertEqual(0, len(discounts))
def test_category_discount_appears_once_if_met_twice(self): self.add_discount_prod_1_includes_cat_2(quantity=1) cart = TestingCartController.for_user(self.USER_1) cart.add_to_cart(self.PROD_1, 1) # Enable the discount discounts = DiscountController.available_discounts( self.USER_1, [self.CAT_2], [self.PROD_3], ) self.assertEqual(1, len(discounts))
def test_product_discount_applied_on_different_invoices(self): # quantity=1 means "quantity per product" self.add_discount_prod_1_includes_prod_3_and_prod_4(quantity=1) cart = TestingCartController.for_user(self.USER_1) cart.add_to_cart(self.PROD_1, 1) # Enable the discount discounts = DiscountController.available_discounts( self.USER_1, [], [self.PROD_3, self.PROD_4], ) self.assertEqual(2, len(discounts)) # adding one of PROD_3 should make it no longer an available discount. cart.add_to_cart(self.PROD_3, 1) cart.next_cart() # should still have (and only have) the discount for prod_4 discounts = DiscountController.available_discounts( self.USER_1, [], [self.PROD_3, self.PROD_4], ) self.assertEqual(1, len(discounts))
def test_discount_quantity_is_correct_after_first_purchase(self): self.test_discount_quantity_is_correct_before_first_purchase() cart = TestingCartController.for_user(self.USER_1) cart.add_to_cart(self.PROD_3, 1) # Exhaust the quantity discounts = DiscountController.available_discounts( self.USER_1, [self.CAT_2], [], ) self.assertEqual(1, discounts[0].quantity) cart.next_cart()
def test_discount_quantity_is_correct_before_first_purchase(self): self.add_discount_prod_1_includes_cat_2(quantity=2) cart = TestingCartController.for_user(self.USER_1) cart.add_to_cart(self.PROD_1, 1) # Enable the discount cart.add_to_cart(self.PROD_3, 1) # Exhaust the quantity discounts = DiscountController.available_discounts( self.USER_1, [self.CAT_2], [], ) self.assertEqual(2, discounts[0].quantity) cart.next_cart()
def test_discount_ceiling_aggregates_products(self): # Create two carts, add 1xprod_1 to each. Ceiling should disappear # after second. self.make_discount_ceiling( "Multi-product limit discount ceiling", limit=2, ) for i in xrange(2): cart = TestingCartController.for_user(self.USER_1) cart.add_to_cart(self.PROD_1, 1) cart.next_cart() discounts = DiscountController.available_discounts( self.USER_1, [], [self.PROD_1], ) self.assertEqual(0, len(discounts))