[test] Handle keyword args in CrawlSpider.parse

This commit is contained in:
Eugenio Lacuesta 2019-12-26 15:12:19 -03:00
parent 8d4948f6ca
commit c54df8253a
No known key found for this signature in database
GPG Key ID: DA3EF2D0913E9810
2 changed files with 9 additions and 6 deletions

View File

@ -211,8 +211,9 @@ class CrawlSpiderWithParseMethod(MockServerSpider, CrawlSpider):
url = self.mockserver.url("/alpayload")
yield Request(url, method="POST", body=test_body)
def parse(self, response):
self.logger.info('[parse] status %i', response.status)
def parse(self, response, foo=None):
self.logger.info('[parse] status %i (foo: %s)', response.status, foo)
yield Request(self.mockserver.url("/status?n=202"), self.parse, cb_kwargs={"foo": "bar"})
class CrawlSpiderWithErrback(CrawlSpiderWithParseMethod):

View File

@ -316,8 +316,9 @@ class CrawlSpiderTestCase(TestCase):
with LogCapture() as log:
yield self.runner.join()
self.assertIn("[parse] status 200", str(log))
self.assertIn("[parse] status 201", str(log))
self.assertIn("[parse] status 200 (foo: None)", str(log))
self.assertIn("[parse] status 201 (foo: None)", str(log))
self.assertIn("[parse] status 202 (foo: bar)", str(log))
@defer.inlineCallbacks
def test_crawlspider_with_errback(self):
@ -326,8 +327,9 @@ class CrawlSpiderTestCase(TestCase):
with LogCapture() as log:
yield self.runner.join()
self.assertIn("[parse] status 200", str(log))
self.assertIn("[parse] status 201", str(log))
self.assertIn("[parse] status 200 (foo: None)", str(log))
self.assertIn("[parse] status 201 (foo: None)", str(log))
self.assertIn("[parse] status 202 (foo: bar)", str(log))
self.assertIn("[errback] status 404", str(log))
self.assertIn("[errback] status 500", str(log))
self.assertIn("[errback] status 501", str(log))