Skip to content

Commit 6a82190

Browse files
pawelmhmGallaecio
authored andcommitted
[#15/spider_attribute] adds proper tests
1 parent 9e362e5 commit 6a82190

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/test_middleware.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,3 +783,25 @@ def test_adjust_timeout():
783783
})
784784
req2 = mw.process_request(req2, None)
785785
assert req2.meta['download_timeout'] == 30
786+
787+
788+
def test_spider_attribute():
789+
req_url = "http://scrapy.org"
790+
req1 = scrapy.Request(req_url)
791+
792+
spider = scrapy.Spider("example")
793+
spider.splash = {"args": {"images": 0}}
794+
795+
mw = _get_mw()
796+
req1 = mw.process_request(req1, spider)
797+
assert "_splash_processed" in req1.meta
798+
assert "render.json" in req1.url
799+
assert "url" in json.loads(req1.body)
800+
assert json.loads(req1.body).get("url") == req_url
801+
assert "images" in json.loads(req1.body)
802+
assert req1.method == 'POST'
803+
804+
# spider attribute blank middleware disabled
805+
spider.splash = {}
806+
req2 = mw.process_request(req1, spider)
807+
assert req2 is None

0 commit comments

Comments
 (0)