def test_updateAmount(self): cart = Cart(currency=self.currency) cart.save() self.factory.session = {'id_cart': cart.pk} # Just make sure the factory got a session object. addProduct(self.factory, self.product1.id) # Add a product to the cart. self.assertEqual(cart.cartitem_set.get(product=self.product1).amount, 1) # Default amount after added should be 1. updateAmount(self.factory, cart.cartitem_set.get(product=self.product1).pk, 5) # Update amount to 5. self.assertEqual(cart.cartitem_set.get(product=self.product1).amount, 5) # Amount should be 5 after change.
def test_removeProduct(self): from django.core.exceptions import ObjectDoesNotExist cart = Cart(currency=self.currency) cart.save() self.factory.session = {'id_cart': cart.pk} # Just make sure the factory got a session object. addProduct(self.factory, self.product1.id) # Add a product to the cart. self.assertEqual(cart.cartitem_set.get(product=self.product1).amount, 1) # Default amount after added should be 1. removeProduct(self.factory, cart.cartitem_set.get(product=self.product1).pk) # Remove the product that as just added. self.assertEqual(len(cart.cartitem_set.filter(product=self.product1)), 0) # After removing he product, it should not be found.
def test_AddProductToCart(self): cart = Cart(currency=self.currency) cart.save() self.factory.session = {'id_cart': cart.pk} # Just make sure the factory got a session object. # Add a product to the cart, with correct data. # Should return True. addProduct(self.factory, self.product1.id) self.assertEqual(len(cart.cartitem_set.all()), 1) # It should now exist 1 item in the cart. try: addProduct(self.factory, 53) # Add product with wrong ID. except: pass # After adding a product with wrong id (above), it should still only be 1 # item in the cart. self.assertEqual(len(cart.cartitem_set.all()), 1)