Skip to content

Commit

Permalink
add tests for remove_all method(test_shopping_cart)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliana-str committed Dec 28, 2023
1 parent 7a0e217 commit d4f87e6
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions backend/tests/api_tests/test_shopping_cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def test_get_shopping_cart_by_anonimous_user(self, client):
response = client.get("/api/shopping_cart/")
assert response.status_code == status.HTTP_200_OK

def test_delete_shopping_cart_by_anonimous_user(self, client, products):
def test_remove_product_from_shopping_cart_by_anonimous_user(
self, client, products):
shopping_cart_data = {
"products": [
{"id": products[0].id, "quantity": 1},
Expand All @@ -85,13 +86,14 @@ def test_delete_shopping_cart_by_anonimous_user(self, client, products):
assert response.status_code == status.HTTP_201_CREATED
product_remove = products[0].id
endpoint = f"/api/shopping_cart/{product_remove}"
response = client.delete(endpoint, product_remove, format="json")
client.delete(endpoint, product_remove, format="json")
response = client.get("/api/shopping_cart/")
assert response.status_code == status.HTTP_200_OK
data = response.json()
assert product_remove not in data

def test_delete_shopping_cart_by_authorized_user(self, auth_client, products):
def test_remove_product_from_shopping_cart_by_authorized_user(
self, auth_client, products):
shopping_cart_data = {
"products": [
{"id": products[0].id, "quantity": 1},
Expand All @@ -107,8 +109,40 @@ def test_delete_shopping_cart_by_authorized_user(self, auth_client, products):
assert response.status_code == status.HTTP_201_CREATED
product_remove = products[0].id
endpoint = f"/api/shopping_cart/{product_remove}"
response = auth_client.delete(endpoint, product_remove, format="json")
auth_client.delete(endpoint, product_remove, format="json")
response = auth_client.get("/api/shopping_cart/")
assert response.status_code == status.HTTP_200_OK
data = response.json()
assert product_remove not in data

def test_remove_all_shopping_cart_by_anonimous_user(self, client, products):
shopping_cart_data = {
"products": [
{"id": products[0].id, "quantity": 1},
{"id": products[1].id, "quantity": 3},
]
}
response = client.post("/api/shopping_cart/", shopping_cart_data, format="json")
data = response.json()
assert "products" in data
assert len(data["products"]) == 2
assert response.status_code == status.HTTP_201_CREATED
endpoint = "/api/shopping_cart/remove_all"
client.delete(endpoint, format="json")

def test_remove_all_shopping_cart_by_authorized_user(self, auth_client, products):
shopping_cart_data = {
"products": [
{"id": products[0].id, "quantity": 1},
{"id": products[1].id, "quantity": 3},
]
}
response = auth_client.post(
"/api/shopping_cart/", shopping_cart_data, format="json"
)
data = response.json()
assert "products" in data
assert len(data["products"]) == 2
assert response.status_code == status.HTTP_201_CREATED
endpoint = "/api/shopping_cart/remove_all"
auth_client.delete(endpoint, format="json")

0 comments on commit d4f87e6

Please sign in to comment.