Skip to content

Commit

Permalink
[scrapy-plugins#15/spider_attribute] adds proper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelmhm authored and Gallaecio committed Aug 12, 2019
1 parent 9e362e5 commit 6a82190
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,3 +783,25 @@ def test_adjust_timeout():
})
req2 = mw.process_request(req2, None)
assert req2.meta['download_timeout'] == 30


def test_spider_attribute():
req_url = "http://scrapy.org"
req1 = scrapy.Request(req_url)

spider = scrapy.Spider("example")
spider.splash = {"args": {"images": 0}}

mw = _get_mw()
req1 = mw.process_request(req1, spider)
assert "_splash_processed" in req1.meta
assert "render.json" in req1.url
assert "url" in json.loads(req1.body)
assert json.loads(req1.body).get("url") == req_url
assert "images" in json.loads(req1.body)
assert req1.method == 'POST'

# spider attribute blank middleware disabled
spider.splash = {}
req2 = mw.process_request(req1, spider)
assert req2 is None

0 comments on commit 6a82190

Please sign in to comment.