Skip to content

Commit

Permalink
SerpOrganicResult: inherit Item
Browse files Browse the repository at this point in the history
  • Loading branch information
Gallaecio committed Nov 12, 2024
1 parent 36558cf commit 8a06197
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions tests/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,3 +949,27 @@ def test_get_probability_request(cls, has_proba):
def test_deprecated_request_list_caster():
with pytest.deprecated_call():
RequestListCaster(ProbabilityRequest)


def test_organic_result_from_dict():
serp_dict = {
"organicResults": [
{
"description": "…",
"name": "…",
"url": f"https://example.com/{rank}",
"rank": rank,
}
for rank in range(1, 11)
],
"metadata": {
"dateDownloaded": "2024-10-25T08:59:45Z",
"displayedQuery": "foo bar",
"searchedQuery": "foo bar",
"totalOrganicResults": 99999,
},
"pageNumber": 1,
"url": "https://example.com",
}
serp = Serp.from_dict(serp_dict)
assert isinstance(serp.organicResults[0], SerpOrganicResult)
2 changes: 1 addition & 1 deletion zyte_common_items/items/serp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


@attrs.define(kw_only=True)
class SerpOrganicResult:
class SerpOrganicResult(Item):
"""Data from a non-paid result of a search engine results page."""

#: Result excerpt.
Expand Down

0 comments on commit 8a06197

Please sign in to comment.