When setting quantities on products, only raise errors if they’re due to changes made during the current call to set_quantities.
Fixes #54
This commit is contained in:
		
							parent
							
								
									3517bdd281
								
							
						
					
					
						commit
						fc81f107ed
					
				
					 2 changed files with 23 additions and 1 deletions
				
			
		| 
						 | 
					@ -132,6 +132,7 @@ class CartController(object):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        product_quantities = list(product_quantities)
 | 
					        product_quantities = list(product_quantities)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # n.b need to add have the existing items first so that the new
 | 
					        # n.b need to add have the existing items first so that the new
 | 
				
			||||||
        # items override the old ones.
 | 
					        # items override the old ones.
 | 
				
			||||||
        all_product_quantities = dict(itertools.chain(
 | 
					        all_product_quantities = dict(itertools.chain(
 | 
				
			||||||
| 
						 | 
					@ -140,7 +141,16 @@ class CartController(object):
 | 
				
			||||||
        )).items()
 | 
					        )).items()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Validate that the limits we're adding are OK
 | 
					        # Validate that the limits we're adding are OK
 | 
				
			||||||
 | 
					        products = set(product for product, q in product_quantities)
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
            self._test_limits(all_product_quantities)
 | 
					            self._test_limits(all_product_quantities)
 | 
				
			||||||
 | 
					        except CartValidationError as ve:
 | 
				
			||||||
 | 
					            # Only raise errors for products that we're explicitly
 | 
				
			||||||
 | 
					            # Manipulating here.
 | 
				
			||||||
 | 
					            for ve_field in ve.error_list:
 | 
				
			||||||
 | 
					                product, message = ve_field.message
 | 
				
			||||||
 | 
					                if product in products:
 | 
				
			||||||
 | 
					                    raise ve
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        new_items = []
 | 
					        new_items = []
 | 
				
			||||||
        products = []
 | 
					        products = []
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -382,3 +382,15 @@ class FlagTestCases(RegistrationCartTestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        with self.assertRaises(ValidationError):
 | 
					        with self.assertRaises(ValidationError):
 | 
				
			||||||
            cart2.add_to_cart(self.PROD_1, 1)
 | 
					            cart2.add_to_cart(self.PROD_1, 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_flag_failures_only_break_affected_products(self):
 | 
				
			||||||
 | 
					        ''' If a flag fails, it should only affect its own products. '''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.add_product_flag()
 | 
				
			||||||
 | 
					        cart1 = TestingCartController.for_user(self.USER_1)
 | 
				
			||||||
 | 
					        cart1.add_to_cart(self.PROD_2, 1)
 | 
				
			||||||
 | 
					        cart1.add_to_cart(self.PROD_1, 1)
 | 
				
			||||||
 | 
					        cart1.set_quantity(self.PROD_2, 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # The following should not fail, as PROD_3 is not affected by flag.
 | 
				
			||||||
 | 
					        cart1.add_to_cart(self.PROD_3, 1)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue