Add tests

This commit is contained in:
Eugenio Lacuesta 2022-10-30 18:28:16 -03:00
parent 3259a42525
commit b18560315b
No known key found for this signature in database
GPG Key ID: DA3EF2D0913E9810
2 changed files with 22 additions and 0 deletions

View File

@ -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

View File

@ -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)