Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/python_picnic_api2/client.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -176,7 +176,7 @@ def search(self, term: str) -> SearchResult:
return SearchResult.from_page(raw_results)

def get_cart(self) -> Cart:
return Cart.from_api(self._get("/cart"))
return Cart.from_api(self._get("/cart", add_picnic_headers=True))

def get_article(self, article_id: str, add_category=False) -> Article | None:
path = f"/pages/product-details-page-root?id={article_id}" + \
Expand DownExpand Up@@ -212,14 +212,16 @@ def get_article_category(self, article_id: str):

def add_product(self, product_id: str, count: int = 1) -> Cart:
data = {"product_id": product_id, "count": count}
return Cart.from_api(self._post("/cart/add_product", data))
return Cart.from_api(self._post("/cart/add_product", data,
add_picnic_headers=True))

def remove_product(self, product_id: str, count: int = 1) -> Cart:
data = {"product_id": product_id, "count": count}
return Cart.from_api(self._post("/cart/remove_product", data))
return Cart.from_api(self._post("/cart/remove_product", data,
add_picnic_headers=True))

def clear_cart(self) -> Cart:
return Cart.from_api(self._post("/cart/clear"))
return Cart.from_api(self._post("/cart/clear", add_picnic_headers=True))

def get_delivery_slots(self) -> DeliverySlots:
return DeliverySlots.from_api(self._get("/cart/delivery_slots"))
Expand Down
10 changes: 8 additions & 2 deletions tests/test_client.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -254,7 +254,8 @@ def test_get_cart(self):
)
cart = self.client.get_cart()
self.session_mock().get.assert_called_with(
self.expected_base_url + "/cart", headers=None
self.expected_base_url + "/cart",
headers=PICNIC_HEADERS,
)
self.assertEqual(cart.type, "ORDER")
self.assertEqual(cart.total_count, 3)
Expand All@@ -267,6 +268,7 @@ def test_add_product(self):
self.session_mock().post.assert_called_with(
self.expected_base_url + "/cart/add_product",
json={"product_id": "p3f2qa", "count": 1},
headers=PICNIC_HEADERS,
)
self.assertEqual(cart.type, "ORDER")

Expand All@@ -278,6 +280,7 @@ def test_add_multiple_products(self):
self.session_mock().post.assert_called_with(
self.expected_base_url + "/cart/add_product",
json={"product_id": "gs4puhf3a", "count": 5},
headers=PICNIC_HEADERS,
)

def test_remove_product(self):
Expand All@@ -288,6 +291,7 @@ def test_remove_product(self):
self.session_mock().post.assert_called_with(
self.expected_base_url + "/cart/remove_product",
json={"product_id": "gs4puhf3a", "count": 5},
headers=PICNIC_HEADERS,
)

def test_clear_cart(self):
Expand All@@ -296,7 +300,9 @@ def test_clear_cart(self):
)
cart = self.client.clear_cart()
self.session_mock().post.assert_called_with(
self.expected_base_url + "/cart/clear", json=None
self.expected_base_url + "/cart/clear",
json=None,
headers=PICNIC_HEADERS,
)
self.assertEqual(cart.type, "ORDER")

Expand Down