def test_remove_item_from_cart(self): add_to_cart(self.manage_cart_items(self.prod1, 'add')) cart = self.get_cart() self.assertEqual(cart.items_number, 1) request = self.manage_cart_items(self.prod1, 'remove') response = add_to_cart(request) self.assertEqual(response.status_code, 200) self.assertEqual(cart.items_number, 0)
def test_delete_item_from_cart(self): add_to_cart(self.manage_cart_items(self.prod1, 'add')) add_to_cart(self.manage_cart_items(self.prod2, 'add')) cart = self.get_cart() self.assertEqual(cart.items_number, 2) request = self.manage_cart_items(self.prod1, 'delete') response = add_to_cart(request) self.assertEqual(response.status_code, 200) self.assertEqual(cart.items_number, 1) self.assertEqual(float(cart.cart_total), self.prod2.total_price)
def test_cart_data_1_item(self): add_to_cart(self.manage_cart_items(self.prod1, 'add')) request = self.factory.get( GET_CART_DATA, **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'}) request.user = self.user response = get_cart_data(request) content = { 'cart_total': str(self.prod1.total_price), 'cart_items': 1, } self.assertEqual(response.status_code, 200) self.assertJSONEqual(str(response.content, encoding='utf8'), content)
def test_json_response_after_delete_item(self): add_to_cart(self.manage_cart_items(self.prod1, 'add')) add_to_cart(self.manage_cart_items(self.prod2, 'add')) cart = self.get_cart() self.assertEqual(cart.items_number, 2) request = self.manage_cart_items(self.prod1, 'delete') response = add_to_cart(request) content = { 'product_qty': 0, 'product_total': '0.00', 'cart_items': 1, } self.assertJSONEqual(str(response.content, encoding='utf8'), content)
def test_add_item_to_cart(self): request = self.manage_cart_items(self.prod1, 'add') response = add_to_cart(request) cart = self.get_cart() self.assertEqual(response.status_code, 200) self.assertEqual(cart.items_number, 1)
def test_json_response_after_add_item(self): request = self.manage_cart_items(self.prod1, 'add') response = add_to_cart(request) content = { 'product_qty': 1, 'product_total': str(self.prod1.total_price), 'cart_items': 1, } self.assertJSONEqual(str(response.content, encoding='utf8'), content)
def get_success_url(self): add_to_cart(self.request, self.object.pk) return reverse('carts:view_cart')