Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow spider attr #15

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[#15/spider_attribute] adds proper tests
  • Loading branch information
pawelmhm committed Jun 19, 2015
commit 586ab58f2424e693781eebc017bfd6b5e78d93ff
1 change: 0 additions & 1 deletion scrapyjs/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from scrapy.exceptions import NotConfigured

from scrapy import log
from scrapy.http.response.html import HtmlResponse
from scrapy.http.headers import Headers


Expand Down
22 changes: 22 additions & 0 deletions tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,25 @@ def test_adjust_timeout():
})
req2 = mw.process_request(req2, None)
assert req2.meta['download_timeout'] == 30


def test_spider_attribute():
req_url = "http:https://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