Example #1
0
 def test_cart_increase(self):
     current_quantity = self.cart_item.quantity if self.cart_item else 0
     CartView.update_item(
         pk=self.cart_item.item.id if self.cart_item else 4,
         action='increase',
         user=self.user)
     self.cart_item = CartItem.objects.get(user=self.user)
     self.assertEqual(self.cart_item.quantity, current_quantity + 1)
Example #2
0
    def test_cart_full_update(self):
        # Increase 1 time, (add the item)
        CartView.update_item(pk=4, user=self.user, action='increase')
        self.assertEqual(len(CartItem.objects.filter(user=self.user)), 1)

        c = CartItem.objects.get(user=self.user)

        # Increase to 2
        CartView.update_item(pk=4, user=self.user, action='increase')
        c.refresh_from_db()
        self.assertEqual(c.quantity, 2)

        # Decrease back to 1
        CartView.update_item(pk=4, user=self.user, action='decrease')
        c.refresh_from_db()
        self.assertEqual(c.quantity, 1)

        # Delete the instance, as quantity is 0
        CartView.update_item(pk=4, user=self.user, action='decrease')
        self.assertEqual(len(CartItem.objects.filter(user=self.user)), 0)
Example #3
0
 def test_add_new_to_cart(self):
     CartView.update_item(pk=4, user=self.user, action='increase')
     self.assertEqual(len(CartItem.objects.filter(user=self.user)), 1)