File diff eb5dd5903697 → 5debbb2ac82e
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()))