Skip to content

Commit

Permalink
Add tests for allow_offsite in the downloader mw.
Browse files Browse the repository at this point in the history
  • Loading branch information
wRAR committed May 17, 2024
1 parent 0c44e98 commit ad5eff1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_downloadermiddleware_offsite.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,37 @@ def test_process_request_dont_filter(value, filtered):
assert mw.process_request(request, spider) is None


@pytest.mark.parametrize(
("allow_offsite", "dont_filter", "filtered"),
(
(True, UNSET, False),
(True, None, False),
(True, False, False),
(True, True, False),
(False, UNSET, True),
(False, None, True),
(False, False, True),
(False, True, False),
),
)
def test_process_request_allow_offsite(allow_offsite, dont_filter, filtered):
crawler = get_crawler(Spider)
spider = crawler._create_spider(name="a", allowed_domains=["a.example"])
mw = OffsiteMiddleware.from_crawler(crawler)
mw.spider_opened(spider)
kwargs = {"meta": {}}
if allow_offsite is not UNSET:
kwargs["meta"]["allow_offsite"] = allow_offsite
if dont_filter is not UNSET:
kwargs["dont_filter"] = dont_filter
request = Request("https://b.example", **kwargs)
if filtered:
with pytest.raises(IgnoreRequest):
mw.process_request(request, spider)
else:
assert mw.process_request(request, spider) is None


@pytest.mark.parametrize(
"value",
(
Expand Down

0 comments on commit ad5eff1

Please sign in to comment.