Replaces .active = False; .save() pattern in tests with a test controller method
This commit is contained in:
		
							parent
							
								
									8ad265a65a
								
							
						
					
					
						commit
						2f77f5bb23
					
				
					 6 changed files with 55 additions and 51 deletions
				
			
		|  | @ -24,3 +24,7 @@ class TestingCartController(CartController): | |||
|         except ObjectDoesNotExist: | ||||
|             old_quantity = 0 | ||||
|         self.set_quantity(product, old_quantity + quantity) | ||||
| 
 | ||||
|     def next_cart(self): | ||||
|         self.cart.active = False | ||||
|         self.cart.save() | ||||
|  |  | |||
|  | @ -74,12 +74,12 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase): | |||
| 
 | ||||
|         # 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): | ||||
|  | @ -142,8 +142,8 @@ 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 | ||||
| 
 | ||||
|  | @ -214,8 +214,8 @@ class BasicCartTests(RegistrationCartTestCase): | |||
|         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, | ||||
|  | @ -272,8 +272,8 @@ class BasicCartTests(RegistrationCartTestCase): | |||
|         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 | ||||
|  | @ -298,8 +298,8 @@ class BasicCartTests(RegistrationCartTestCase): | |||
|             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) | ||||
|  | @ -325,8 +325,8 @@ class BasicCartTests(RegistrationCartTestCase): | |||
|         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) | ||||
| 
 | ||||
|  |  | |||
|  | @ -91,8 +91,8 @@ class CeilingsTestCases(RegistrationCartTestCase): | |||
|         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 | ||||
|  | @ -128,8 +128,8 @@ class CeilingsTestCases(RegistrationCartTestCase): | |||
|             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() | ||||
|  | @ -140,15 +140,15 @@ class CeilingsTestCases(RegistrationCartTestCase): | |||
|         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) | ||||
| 
 | ||||
|  | @ -176,8 +176,8 @@ class CeilingsTestCases(RegistrationCartTestCase): | |||
|         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 | ||||
|  |  | |||
|  | @ -168,8 +168,8 @@ class DiscountTestCase(RegistrationCartTestCase): | |||
|         # 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) | ||||
|  | @ -177,8 +177,8 @@ class DiscountTestCase(RegistrationCartTestCase): | |||
| 
 | ||||
|         # 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. | ||||
|  | @ -197,8 +197,8 @@ class DiscountTestCase(RegistrationCartTestCase): | |||
|         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) | ||||
|  | @ -346,8 +346,8 @@ class DiscountTestCase(RegistrationCartTestCase): | |||
| 
 | ||||
|         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() | ||||
|  | @ -357,8 +357,8 @@ class DiscountTestCase(RegistrationCartTestCase): | |||
| 
 | ||||
|         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() | ||||
|  | @ -388,12 +388,12 @@ class DiscountTestCase(RegistrationCartTestCase): | |||
|         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, | ||||
|  | @ -403,7 +403,7 @@ class DiscountTestCase(RegistrationCartTestCase): | |||
|         self.assertEqual(0, len(discounts)) | ||||
| 
 | ||||
|         cart.cart.released = True | ||||
|         cart.cart.save() | ||||
|         cart.next_cart() | ||||
| 
 | ||||
|         discounts = discount.available_discounts( | ||||
|             self.USER_1, | ||||
|  |  | |||
|  | @ -68,8 +68,8 @@ class EnablingConditionTestCases(RegistrationCartTestCase): | |||
| 
 | ||||
|         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) | ||||
|  | @ -103,8 +103,8 @@ class EnablingConditionTestCases(RegistrationCartTestCase): | |||
| 
 | ||||
|         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) | ||||
|  | @ -241,15 +241,15 @@ class EnablingConditionTestCases(RegistrationCartTestCase): | |||
|         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) | ||||
|  | @ -260,15 +260,15 @@ class EnablingConditionTestCases(RegistrationCartTestCase): | |||
|         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) | ||||
|  |  | |||
|  | @ -34,8 +34,8 @@ class VoucherTestCases(RegistrationCartTestCase): | |||
|         # 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. | ||||
|  | @ -125,8 +125,8 @@ class VoucherTestCases(RegistrationCartTestCase): | |||
|         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) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Christopher Neugebauer
						Christopher Neugebauer