diff --git a/src/python_picnic_api2/client.py b/src/python_picnic_api2/client.py index 9ecf4d9..4d45668 100644 --- a/src/python_picnic_api2/client.py +++ b/src/python_picnic_api2/client.py @@ -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}" + \ @@ -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")) diff --git a/tests/test_client.py b/tests/test_client.py index 53ffdf5..6b73f24 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -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) @@ -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") @@ -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): @@ -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): @@ -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")