Skip to content

Commit f8fb2fb

Browse files
committed
Improve test coverage for the splash spider attribute
1 parent 03aaab9 commit f8fb2fb

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

tests/test_middleware.py

+35-2
Original file line numberDiff line numberDiff line change
@@ -769,9 +769,10 @@ def test_adjust_timeout():
769769

770770
def test_spider_attribute():
771771
req_url = "http://scrapy.org"
772-
req1 = scrapy.Request(req_url)
773-
774772
spider = scrapy.Spider("example")
773+
mw = _get_mw()
774+
775+
req1 = scrapy.Request(req_url)
775776
spider.splash = {"args": {"images": 0}}
776777

777778
mw = _get_mw()
@@ -785,5 +786,37 @@ def test_spider_attribute():
785786

786787
# spider attribute blank middleware disabled
787788
spider.splash = {}
789+
req3 = mw.process_request(req1, spider)
790+
assert req3 is None
791+
792+
793+
def test_spider_attribute_dont_splash():
794+
req_url = "http://scrapy.org"
795+
spider = scrapy.Spider("example")
796+
mw = _get_mw()
797+
798+
req1 = scrapy.Request(req_url, meta={'dont_splash': True})
799+
spider.splash = {"args": {"images": 0}}
800+
801+
req2 = mw.process_request(req1, spider)
802+
assert req2 is None
803+
804+
response = Response("http://example.com", request=req1)
805+
response2 = mw.process_response(req1, response, None)
806+
assert response2 is response
807+
808+
809+
def test_spider_attribute_blank():
810+
req_url = "http://scrapy.org"
811+
spider = scrapy.Spider("example")
812+
mw = _get_mw()
813+
814+
req1 = scrapy.Request(req_url)
815+
spider.splash = {}
816+
788817
req2 = mw.process_request(req1, spider)
789818
assert req2 is None
819+
820+
response = Response("http://example.com", request=req1)
821+
response2 = mw.process_response(req1, response, None)
822+
assert response2 is response

0 commit comments

Comments
 (0)