Changeset - 2f77f5bb23ee
[Not reviewed]
0 6 0
Christopher Neugebauer - 8 years ago 2016-04-06 07:24:25
chrisjrn@gmail.com
Replaces .active = False; .save() pattern in tests with a test controller method
6 files changed with 55 insertions and 51 deletions:
0 comments (0 inline, 0 general)
registrasion/tests/cart_controller_helper.py
Show inline comments
...
 
@@ -15,12 +15,16 @@ class TestingCartController(CartController):
 
    def add_to_cart(self, product, quantity):
 
        ''' Adds _quantity_ of the given _product_ to the cart. Raises
 
        ValidationError if constraints are violated.'''
 

	
 
        try:
 
            product_item = rego.ProductItem.objects.get(
 
                cart=self.cart,
 
                product=product)
 
            old_quantity = product_item.quantity
 
        except ObjectDoesNotExist:
 
            old_quantity = 0
 
        self.set_quantity(product, old_quantity + quantity)
 

	
 
    def next_cart(self):
 
        self.cart.active = False
 
        self.cart.save()
registrasion/tests/test_cart.py
Show inline comments
...
 
@@ -65,30 +65,30 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase):
 
            cls.products.append(prod)
 

	
 
        cls.PROD_1 = cls.products[0]
 
        cls.PROD_2 = cls.products[1]
 
        cls.PROD_3 = cls.products[2]
 
        cls.PROD_4 = cls.products[3]
 

	
 
        cls.PROD_4.price = Decimal("5.00")
 
        cls.PROD_4.save()
 

	
 
        # Burn through some carts -- this made some past EC tests fail
 
        current_cart = TestingCartController.for_user(cls.USER_1)
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
 
        current_cart = TestingCartController.for_user(cls.USER_2)
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
 
    @classmethod
 
    def make_ceiling(cls, name, limit=None, start_time=None, end_time=None):
 
        limit_ceiling = rego.TimeOrStockLimitEnablingCondition.objects.create(
 
            description=name,
 
            mandatory=True,
 
            limit=limit,
 
            start_time=start_time,
 
            end_time=end_time
 
        )
 
        limit_ceiling.save()
 
        limit_ceiling.products.add(cls.PROD_1, cls.PROD_2)
...
 
@@ -133,26 +133,26 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase):
 
            code=code,
 
            limit=limit,
 
        )
 
        voucher.save()
 
        return voucher
 

	
 

	
 
class BasicCartTests(RegistrationCartTestCase):
 

	
 
    def test_get_cart(self):
 
        current_cart = TestingCartController.for_user(self.USER_1)
 

	
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
 
        old_cart = current_cart
 

	
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        self.assertNotEqual(old_cart.cart, current_cart.cart)
 

	
 
        current_cart2 = TestingCartController.for_user(self.USER_1)
 
        self.assertEqual(current_cart.cart, current_cart2.cart)
 

	
 
    def test_add_to_cart_collapses_product_items(self):
 
        current_cart = TestingCartController.for_user(self.USER_1)
 

	
...
 
@@ -205,26 +205,26 @@ class BasicCartTests(RegistrationCartTestCase):
 

	
 
        # User should be able to add 1 of PROD_1 to the current cart.
 
        current_cart.add_to_cart(self.PROD_1, 1)
 

	
 
        # User should be able to add 1 of PROD_1 to the current cart.
 
        current_cart.add_to_cart(self.PROD_1, 1)
 

	
 
        # User should not be able to add 10 of PROD_1 to the current cart now,
 
        # because they have a limit of 10.
 
        with self.assertRaises(ValidationError):
 
            current_cart.add_to_cart(self.PROD_1, 10)
 

	
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        # User should not be able to add 10 of PROD_1 to the current cart now,
 
        # even though it's a new cart.
 
        with self.assertRaises(ValidationError):
 
            current_cart.add_to_cart(self.PROD_1, 10)
 

	
 
        # Second user should not be affected by first user's limits
 
        second_user_cart = TestingCartController.for_user(self.USER_2)
 
        second_user_cart.add_to_cart(self.PROD_1, 10)
 

	
 
    def set_limits(self):
...
 
@@ -263,52 +263,52 @@ class BasicCartTests(RegistrationCartTestCase):
 
        # Cannot add to cart if category limit is filled by one product.
 
        current_cart.set_quantity(self.PROD_3, 10)
 
        with self.assertRaises(ValidationError):
 
            current_cart.set_quantity(self.PROD_4, 1)
 

	
 
        # Can add to cart if category limit is not filled by one product
 
        current_cart.set_quantity(self.PROD_3, 5)
 
        current_cart.set_quantity(self.PROD_4, 5)
 
        # Cannot add to cart if category limit is filled by two products
 
        with self.assertRaises(ValidationError):
 
            current_cart.add_to_cart(self.PROD_3, 1)
 

	
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        # The category limit should extend across carts
 
        with self.assertRaises(ValidationError):
 
            current_cart.add_to_cart(self.PROD_3, 10)
 

	
 
    def test_per_user_category_and_product_limits(self):
 
        self.set_limits()
 

	
 
        current_cart = TestingCartController.for_user(self.USER_1)
 

	
 
        # Hit both the product and category edges:
 
        current_cart.set_quantity(self.PROD_3, 4)
 
        current_cart.set_quantity(self.PROD_4, 6)
 
        with self.assertRaises(ValidationError):
 
            # There's unlimited PROD_3, but limited in the category
 
            current_cart.add_to_cart(self.PROD_3, 1)
 

	
 
        current_cart.set_quantity(self.PROD_3, 0)
 
        with self.assertRaises(ValidationError):
 
            # There's only 6 allowed of PROD_4
 
            current_cart.add_to_cart(self.PROD_4, 1)
 

	
 
        # The limits should extend across carts...
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        current_cart.set_quantity(self.PROD_3, 4)
 

	
 
        with self.assertRaises(ValidationError):
 
            current_cart.set_quantity(self.PROD_3, 5)
 

	
 
        with self.assertRaises(ValidationError):
 
            current_cart.set_quantity(self.PROD_4, 1)
 

	
 
    def __available_products_test(self, item, quantity):
 
        self.set_limits()
...
 
@@ -316,25 +316,25 @@ class BasicCartTests(RegistrationCartTestCase):
 
        def get_prods():
 
            return ProductController.available_products(
 
                self.USER_1,
 
                products=[self.PROD_2, self.PROD_3, self.PROD_4],
 
            )
 

	
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        prods = get_prods()
 
        self.assertTrue(item in prods)
 
        current_cart.add_to_cart(item, quantity)
 
        self.assertTrue(item in prods)
 

	
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
 
        current_cart = TestingCartController.for_user(self.USER_1)
 

	
 
        prods = get_prods()
 
        self.assertTrue(item not in prods)
 

	
 
    def test_available_products_respects_category_limits(self):
 
        self.__available_products_test(self.PROD_3, 10)
 

	
 
    def test_available_products_respects_product_limits(self):
 
        self.__available_products_test(self.PROD_4, 6)
registrasion/tests/test_ceilings.py
Show inline comments
...
 
@@ -82,26 +82,26 @@ class CeilingsTestCases(RegistrationCartTestCase):
 

	
 
        # User 2 should not be able to add item to their cart
 
        # because user 1 has item reserved, exhausting the ceiling
 
        with self.assertRaises(ValidationError):
 
            second_cart.add_to_cart(self.PROD_1, 1)
 

	
 
        # User 2 should be able to add item to their cart once the
 
        # reservation duration is elapsed
 
        self.add_timedelta(self.RESERVATION + datetime.timedelta(seconds=1))
 
        second_cart.add_to_cart(self.PROD_1, 1)
 

	
 
        # User 2 pays for their cart
 
        second_cart.cart.active = False
 
        second_cart.cart.save()
 

	
 
        second_cart.next_cart()
 

	
 
        # User 1 should not be able to add item to their cart
 
        # because user 2 has paid for their reserved item, exhausting
 
        # the ceiling, regardless of the reservation time.
 
        self.add_timedelta(self.RESERVATION * 20)
 
        with self.assertRaises(ValidationError):
 
            first_cart.add_to_cart(self.PROD_1, 1)
 

	
 
    def test_validate_cart_fails_product_ceilings(self):
 
        self.make_ceiling("Limit ceiling", limit=1)
 
        self.__validation_test()
 

	
...
 
@@ -119,45 +119,45 @@ class CeilingsTestCases(RegistrationCartTestCase):
 
        first_cart.add_to_cart(self.PROD_1, 1)
 
        first_cart.validate_cart()
 

	
 
        # Cart should become invalid if lapsed carts are claimed.
 
        self.add_timedelta(self.RESERVATION + datetime.timedelta(seconds=1))
 

	
 
        # Unpaid cart within reservation window
 
        second_cart.add_to_cart(self.PROD_1, 1)
 
        with self.assertRaises(ValidationError):
 
            first_cart.validate_cart()
 

	
 
        # Paid cart outside the reservation window
 
        second_cart.cart.active = False
 
        second_cart.cart.save()
 

	
 
        second_cart.next_cart()
 
        self.add_timedelta(self.RESERVATION + datetime.timedelta(seconds=1))
 
        with self.assertRaises(ValidationError):
 
            first_cart.validate_cart()
 

	
 
    def test_items_released_from_ceiling_by_refund(self):
 
        self.make_ceiling("Limit ceiling", limit=1)
 

	
 
        first_cart = TestingCartController.for_user(self.USER_1)
 
        first_cart.add_to_cart(self.PROD_1, 1)
 

	
 
        first_cart.cart.active = False
 
        first_cart.cart.save()
 

	
 
        first_cart.next_cart()
 

	
 
        second_cart = TestingCartController.for_user(self.USER_2)
 
        with self.assertRaises(ValidationError):
 
            second_cart.add_to_cart(self.PROD_1, 1)
 

	
 
        first_cart.cart.released = True
 
        first_cart.cart.save()
 
        first_cart.next_cart()
 

	
 
        second_cart.add_to_cart(self.PROD_1, 1)
 

	
 
    def test_discount_ceiling_only_counts_items_covered_by_ceiling(self):
 
        self.make_discount_ceiling("Limit ceiling", limit=1, percentage=50)
 
        voucher = self.new_voucher(code="VOUCHER")
 

	
 
        discount = rego.VoucherDiscount.objects.create(
 
            description="VOUCHER RECIPIENT",
 
            voucher=voucher,
 
        )
 
        discount.save()
...
 
@@ -167,20 +167,20 @@ class CeilingsTestCases(RegistrationCartTestCase):
 
            percentage=100,
 
            quantity=1
 
        ).save()
 

	
 
        # Buy two of PROD_1, in separate carts:
 
        cart = TestingCartController.for_user(self.USER_1)
 
        # the 100% discount from the voucher should apply to the first item
 
        # and not the ceiling discount.
 
        cart.apply_voucher("VOUCHER")
 
        cart.add_to_cart(self.PROD_1, 1)
 
        self.assertEqual(1, len(cart.cart.discountitem_set.all()))
 

	
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
 
        cart.next_cart()
 

	
 
        # The second cart has no voucher attached, so should apply the
 
        # ceiling discount
 
        cart = TestingCartController.for_user(self.USER_1)
 
        cart.add_to_cart(self.PROD_1, 1)
 
        self.assertEqual(1, len(cart.cart.discountitem_set.all()))
registrasion/tests/test_discount.py
Show inline comments
...
 
@@ -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 = TestingCartController.for_user(self.USER_1)
 
        cart.add_to_cart(self.PROD_2, 1)
 

	
 
        # The discount should be applied.
 
        self.assertEqual(1, len(cart.cart.discountitem_set.all()))
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
 
        cart.next_cart()
 

	
 
        # The discount should respect the total quantity across all
 
        # of the user's carts.
 
        cart = TestingCartController.for_user(self.USER_1)
 
        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())
 
        self.assertEqual(1, discount_items[0].quantity)
 

	
 
    def test_discount_applies_only_once_enabled(self):
 
        # Enable the discount during the first cart.
 
        cart = TestingCartController.for_user(self.USER_1)
 
        cart.add_to_cart(self.PROD_1, 1)
 
        # This would exhaust discount if present
 
        cart.add_to_cart(self.PROD_2, 2)
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
 
        cart.next_cart()
 

	
 
        self.add_discount_prod_1_includes_prod_2()
 
        cart = TestingCartController.for_user(self.USER_1)
 
        cart.add_to_cart(self.PROD_2, 2)
 

	
 
        discount_items = list(cart.cart.discountitem_set.all())
 
        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)
 
        cart = TestingCartController.for_user(self.USER_1)
 
        cart.add_to_cart(self.PROD_1, 1)
...
 
@@ -337,37 +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 = 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 = discount.available_discounts(self.USER_1, [self.CAT_2], [])
 
        self.assertEqual(2, discounts[0].quantity)
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
 
        cart.next_cart()
 

	
 
    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 = discount.available_discounts(self.USER_1, [self.CAT_2], [])
 
        self.assertEqual(1, discounts[0].quantity)
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
 
        cart.next_cart()
 

	
 
    def test_discount_is_gone_after_quantity_exhausted(self):
 
        self.test_discount_quantity_is_correct_after_first_purchase()
 
        discounts = discount.available_discounts(self.USER_1, [self.CAT_2], [])
 
        self.assertEqual(0, 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 = discount.available_discounts(
 
            self.USER_1,
...
 
@@ -379,35 +379,35 @@ class DiscountTestCase(RegistrationCartTestCase):
 
    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 = discount.available_discounts(
 
            self.USER_1,
 
            [],
 
            [self.PROD_2],
 
        )
 
        self.assertEqual(1, len(discounts))
 

	
 
        cart.cart.active = False  # Keep discount enabled
 
        cart.cart.save()
 
        cart.next_cart()
 

	
 
        cart = TestingCartController.for_user(self.USER_1)
 
        cart.add_to_cart(self.PROD_2, 2)  # The discount will be exhausted
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
 
        cart.next_cart()
 

	
 
        discounts = discount.available_discounts(
 
            self.USER_1,
 
            [],
 
            [self.PROD_2],
 
        )
 
        self.assertEqual(0, len(discounts))
 

	
 
        cart.cart.released = True
 
        cart.cart.save()
 
        cart.next_cart()
 

	
 
        discounts = discount.available_discounts(
 
            self.USER_1,
 
            [],
 
            [self.PROD_2],
 
        )
 
        self.assertEqual(1, len(discounts))
registrasion/tests/test_enabling_condition.py
Show inline comments
...
 
@@ -59,26 +59,26 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        with self.assertRaises(ValidationError):
 
            current_cart.add_to_cart(self.PROD_1, 1)
 

	
 
        current_cart.add_to_cart(self.PROD_2, 1)
 
        current_cart.add_to_cart(self.PROD_1, 1)
 

	
 
    def test_product_enabled_by_product_in_previous_cart(self):
 
        self.add_product_enabling_condition()
 

	
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        current_cart.add_to_cart(self.PROD_2, 1)
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
 
        # Create new cart and try to add PROD_1
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        current_cart.add_to_cart(self.PROD_1, 1)
 

	
 
    def test_product_enabling_condition_enables_category(self):
 
        self.add_product_enabling_condition_on_category()
 

	
 
        # Cannot buy PROD_1 without buying item from CAT_2
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        with self.assertRaises(ValidationError):
 
            current_cart.add_to_cart(self.PROD_1, 1)
...
 
@@ -94,26 +94,26 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 
        with self.assertRaises(ValidationError):
 
            current_cart.add_to_cart(self.PROD_1, 1)
 

	
 
        # PROD_3 is in CAT_2
 
        current_cart.add_to_cart(self.PROD_3, 1)
 
        current_cart.add_to_cart(self.PROD_1, 1)
 

	
 
    def test_product_enabled_by_category_in_previous_cart(self):
 
        self.add_category_enabling_condition()
 

	
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        current_cart.add_to_cart(self.PROD_3, 1)
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
 
        # Create new cart and try to add PROD_1
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        current_cart.add_to_cart(self.PROD_1, 1)
 

	
 
    def test_multiple_non_mandatory_conditions(self):
 
        self.add_product_enabling_condition()
 
        self.add_category_enabling_condition()
 

	
 
        # User 1 is testing the product enabling condition
 
        cart_1 = TestingCartController.for_user(self.USER_1)
 
        # Cannot add PROD_1 until a condition is met
...
 
@@ -232,52 +232,52 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
 
            products=[self.PROD_1, self.PROD_2],
 
        )
 

	
 
        self.assertTrue(self.PROD_1 in prods)
 
        self.assertTrue(self.PROD_2 in prods)
 

	
 
    def test_category_enabling_condition_fails_if_cart_refunded(self):
 
        self.add_category_enabling_condition(mandatory=False)
 

	
 
        cart = TestingCartController.for_user(self.USER_1)
 
        cart.add_to_cart(self.PROD_3, 1)
 

	
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
 
        cart.next_cart()
 

	
 
        cart_2 = TestingCartController.for_user(self.USER_1)
 
        cart_2.add_to_cart(self.PROD_1, 1)
 
        cart_2.set_quantity(self.PROD_1, 0)
 

	
 
        cart.cart.released = True
 
        cart.cart.save()
 
        cart.next_cart()
 

	
 
        with self.assertRaises(ValidationError):
 
            cart_2.set_quantity(self.PROD_1, 1)
 

	
 
    def test_product_enabling_condition_fails_if_cart_refunded(self):
 
        self.add_product_enabling_condition(mandatory=False)
 

	
 
        cart = TestingCartController.for_user(self.USER_1)
 
        cart.add_to_cart(self.PROD_2, 1)
 

	
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
 
        cart.next_cart()
 

	
 
        cart_2 = TestingCartController.for_user(self.USER_1)
 
        cart_2.add_to_cart(self.PROD_1, 1)
 
        cart_2.set_quantity(self.PROD_1, 0)
 

	
 
        cart.cart.released = True
 
        cart.cart.save()
 
        cart.next_cart()
 

	
 
        with self.assertRaises(ValidationError):
 
            cart_2.set_quantity(self.PROD_1, 1)
 

	
 
    def test_available_categories(self):
 
        self.add_product_enabling_condition_on_category(mandatory=False)
 

	
 
        cart_1 = TestingCartController.for_user(self.USER_1)
 

	
 
        cats = CategoryController.available_categories(
 
            self.USER_1,
 
        )
registrasion/tests/test_voucher.py
Show inline comments
...
 
@@ -25,26 +25,26 @@ class VoucherTestCases(RegistrationCartTestCase):
 
        cart_1.apply_voucher(voucher.code)
 
        self.assertIn(voucher, cart_1.cart.vouchers.all())
 

	
 
        # Second user should not be able to apply this voucher (it's exhausted)
 
        cart_2 = TestingCartController.for_user(self.USER_2)
 
        with self.assertRaises(ValidationError):
 
            cart_2.apply_voucher(voucher.code)
 

	
 
        # After the reservation duration
 
        # user 2 should be able to apply voucher
 
        self.add_timedelta(rego.Voucher.RESERVATION_DURATION * 2)
 
        cart_2.apply_voucher(voucher.code)
 
        cart_2.cart.active = False
 
        cart_2.cart.save()
 

	
 
        cart_2.next_cart()
 

	
 
        # After the reservation duration, even though the voucher has applied,
 
        # it exceeds the number of vouchers available.
 
        self.add_timedelta(rego.Voucher.RESERVATION_DURATION * 2)
 
        with self.assertRaises(ValidationError):
 
            cart_1.validate_cart()
 

	
 
    def test_fix_simple_errors_resolves_unavailable_voucher(self):
 
        self.test_apply_voucher()
 

	
 
        # User has an exhausted voucher leftover from test_apply_voucher
 
        cart_1 = TestingCartController.for_user(self.USER_1)
...
 
@@ -116,26 +116,26 @@ class VoucherTestCases(RegistrationCartTestCase):
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        current_cart.apply_voucher(voucher.code)
 
        current_cart.apply_voucher(voucher.code)
 

	
 
        # You can apply the code twice, but it will only add to the cart once.
 
        self.assertEqual(1, current_cart.cart.vouchers.count())
 

	
 
    def test_voucher_can_only_be_applied_once_across_multiple_carts(self):
 
        voucher = self.new_voucher(limit=2)
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        current_cart.apply_voucher(voucher.code)
 

	
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
 
        current_cart.next_cart()
 

	
 
        current_cart = TestingCartController.for_user(self.USER_1)
 

	
 
        with self.assertRaises(ValidationError):
 
            current_cart.apply_voucher(voucher.code)
 

	
 
        return current_cart
 

	
 
    def test_refund_releases_used_vouchers(self):
 
        voucher = self.new_voucher(limit=2)
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        current_cart.apply_voucher(voucher.code)
0 comments (0 inline, 0 general)