Skip to content

Commit

Permalink
Add a validation test for serp.
Browse files Browse the repository at this point in the history
  • Loading branch information
wRAR committed Dec 25, 2024
1 parent 318eb83 commit 405fecc
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/test_serp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from urllib.parse import quote_plus

import pytest
from pydantic import ValidationError
from scrapy import Request
from scrapy_spider_metadata import get_spider_metadata
from scrapy_zyte_api.responses import ZyteAPITextResponse
Expand Down Expand Up @@ -765,3 +766,29 @@ def test_item_type_mappings():

# Also ensure that no dict value is repeated.
assert len(actual_keys) == len(set(ITEM_TYPE_CLASSES.values()))


@pytest.mark.parametrize(
"input_data,raises",
[
({"search_queries": "foo"}, False),
({"search_queries": "foo "}, False),
({"search_queries": " foo "}, False),
({"search_queries": " fo o "}, False),
({"search_queries": "fo o"}, False),
({"search_queries": "fo\n o "}, False),
({"search_queries": ["fo", " o "]}, False),
({"search_queries": ["fo", " "]}, False),
({"search_queries": " "}, True),
({"search_queries": ""}, True),
({"search_queries": " "}, True),
({"search_queries": " \n "}, True),
({"search_queries": [" ", " "]}, True),
],
)
def test_query_validation(input_data, raises):
if raises:
with pytest.raises(ValidationError):
GoogleSearchSpider(**input_data)
else:
GoogleSearchSpider(**input_data)

0 comments on commit 405fecc

Please sign in to comment.