Skip to content

Commit

Permalink
Initial cart_detail tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brylie committed Jul 7, 2023
1 parent 0dabacc commit eb29ef7
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion cart/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@ def test_cart_detail_view(self) -> None:

# add products to the cart
cart = Cart(request)

product_two_quantity = 2
cart.add(self.product1)
cart.add(self.product2, quantity=2)
cart.add(self.product2, quantity=product_two_quantity)

# get the response
response = cart_detail(request)
Expand All @@ -201,6 +203,51 @@ def test_cart_detail_view(self) -> None:
self.assertEqual(response.template_name, "cart/detail.html")
self.assertIn("cart", response.context_data)

cart_items = list(response.context_data["cart"])
expected_cart_length = 2
self.assertEqual(len(cart_items), expected_cart_length)

default_cart_quantity = 1
self.assertEqual(
cart_items[0]["product"],
self.product1,
)
self.assertEqual(
cart_items[0]["quantity"],
default_cart_quantity,
)
self.assertEqual(
cart_items[0]["price"],
self.product1.price,
)
expected_total_price_item_one = (
cart_items[0]["price"] * cart_items[0]["quantity"]
)
self.assertEqual(
cart_items[0]["total_price"],
expected_total_price_item_one,
)

self.assertEqual(
cart_items[1]["product"],
self.product2,
)
self.assertEqual(
cart_items[1]["quantity"],
product_two_quantity,
)
self.assertEqual(
cart_items[1]["price"],
self.product2.price,
)
expected_total_price_item_two = (
cart_items[1]["price"] * cart_items[1]["quantity"]
)
self.assertEqual(
cart_items[1]["total_price"],
expected_total_price_item_two,
)

def tearDown(self) -> None:
# delete all pages
Page.objects.all().delete()
Expand Down

0 comments on commit eb29ef7

Please sign in to comment.