From 9c337e74b2dbd3ca886c0b669fac65cce713b8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20Gro=C3=9F?= Date: Wed, 15 Oct 2025 11:57:52 +0000 Subject: [PATCH 1/2] fix: get article details in new format --- src/python_picnic_api2/client.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/python_picnic_api2/client.py b/src/python_picnic_api2/client.py index 902fada..ea578a0 100644 --- a/src/python_picnic_api2/client.py +++ b/src/python_picnic_api2/client.py @@ -106,9 +106,13 @@ def get_article(self, article_id: str, add_category=False): "&show_category_action=true" data = self._get(path, add_picnic_headers=True) article_details = [] - for block in data["body"]["child"]["child"]["children"]: - if block["id"] == "product-details-page-root-main-container": - article_details = block["pml"]["component"]["children"] + + root_container = find_nodes_by_content( + data, {"id": "product-details-page-root-main-container"}, max_nodes=1) + if len(root_container) == 0: + return None + + article_details = root_container[0]["pml"]["component"]["children"] if len(article_details) == 0: return None From b2c6271233971aa2c0bb356881a5c7f62dc028eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20Gro=C3=9F?= Date: Wed, 15 Oct 2025 12:02:58 +0000 Subject: [PATCH 2/2] test: add test for unsupported return data --- tests/test_client.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test_client.py b/tests/test_client.py index f189133..f07dbd6 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -179,6 +179,35 @@ def test_get_article_with_category(self): article, {'name': 'Blue Band Goede start halvarine', 'id': 'p3f2qa', "category": {"l2_id": 2000, "l3_id": 3000, "name": "Test"}}) + def test_get_article_with_unsupported_structure(self): + self.session_mock().get.return_value = self.MockResponse( + {"body": {"child": {"child": {"children": [{ + "id": "unsupported-root-container", + "pml": { + "component": { + "children": [ + { + "markdown": "#(#333333)Goede start halvarine#(#333333)", + }, + { + "markdown": "Blue Band", + }, + + ] + } + } + }]}}}}, + 200 + ) + + article = self.client.get_article("p3f2qa") + self.session_mock().get.assert_called_with( + "https://storefront-prod.nl.picnicinternational.com/api/15/pages/product-details-page-root?id=p3f2qa&show_category_action=true", + headers=PICNIC_HEADERS, + ) + + assert article is None + def test_get_article_by_gtin(self): self.client.get_article_by_gtin("123456789") self.session_mock().get.assert_called_with(