Beispiel #1
0
    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))
Beispiel #2
0
    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))
Beispiel #3
0
 def test_enumerate_no_discounts_for_no_input(self):
     discounts = DiscountController.available_discounts(
         self.USER_1,
         [],
         [],
     )
     self.assertEqual(0, len(discounts))
Beispiel #4
0
 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))
Beispiel #5
0
    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))
Beispiel #6
0
 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))
Beispiel #7
0
    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))
Beispiel #8
0
    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))
Beispiel #9
0
    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))
Beispiel #10
0
    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()
Beispiel #11
0
    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()
Beispiel #12
0
    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))
Beispiel #13
0
    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))