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: 7 additions & 3 deletions src/python_picnic_api2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down