mirror of https://github.com/scrapy/scrapy.git
Add tests
This commit is contained in:
parent
3259a42525
commit
b18560315b
|
|
@ -419,6 +419,17 @@ class CrawlSpiderWithErrback(CrawlSpiderWithParseMethod):
|
|||
self.logger.info('[errback] status %i', failure.value.response.status)
|
||||
|
||||
|
||||
class CrawlSpiderWithProcessRequestCallbackKeywordArguments(CrawlSpiderWithParseMethod):
|
||||
name = 'crawl_spider_with_process_request_cb_kwargs'
|
||||
rules = (
|
||||
Rule(LinkExtractor(), callback='parse', follow=True, process_request="process_request"),
|
||||
)
|
||||
|
||||
def process_request(self, request, response):
|
||||
request.cb_kwargs["foo"] = "process_request"
|
||||
return request
|
||||
|
||||
|
||||
class BytesReceivedCallbackSpider(MetaSpider):
|
||||
|
||||
full_response_length = 2**18
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ from tests.spiders import (
|
|||
CrawlSpiderWithAsyncGeneratorCallback,
|
||||
CrawlSpiderWithErrback,
|
||||
CrawlSpiderWithParseMethod,
|
||||
CrawlSpiderWithProcessRequestCallbackKeywordArguments,
|
||||
DelaySpider,
|
||||
DuplicateStartRequestsSpider,
|
||||
FollowAllSpider,
|
||||
|
|
@ -426,6 +427,16 @@ class CrawlSpiderTestCase(TestCase):
|
|||
self.assertIn("[errback] status 500", str(log))
|
||||
self.assertIn("[errback] status 501", str(log))
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_crawlspider_process_request_cb_kwargs(self):
|
||||
crawler = get_crawler(CrawlSpiderWithProcessRequestCallbackKeywordArguments)
|
||||
with LogCapture() as log:
|
||||
yield crawler.crawl(mockserver=self.mockserver)
|
||||
|
||||
self.assertIn("[parse] status 200 (foo: process_request)", str(log))
|
||||
self.assertIn("[parse] status 201 (foo: process_request)", str(log))
|
||||
self.assertIn("[parse] status 202 (foo: bar)", str(log))
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_async_def_parse(self):
|
||||
crawler = get_crawler(AsyncDefSpider)
|
||||
|
|
|
|||
Loading…
Reference in New Issue