Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Merge branch 'master' into feature/issue-3364

Daniel Grañad7b98a37146e
diff --cc tests/test_contracts.py
index 21be54c76,fc5c94771..cf62581e4
--- a/tests/test_contracts.py
+++ b/tests/test_contracts.py
@@@ -24,21 -25,15 +25,30 @@@ class ResponseMock(object)
url = 'http://scrapy.org'
+class CustomSuccessContract(Contract):
+ name = 'custom_success_contract'
+
+ def adjust_request_args(self, args):
+ args['url'] = 'http://scrapy.org'
+ return args
+
+
+class CustomFailContract(Contract):
+ name = 'custom_fail_contract'
+
+ def adjust_request_args(self, args):
+ raise TypeError('Error in adjust_request_args')
+
+
+ class CustomFormContract(Contract):
+ name = 'custom_form'
+ request_cls = FormRequest
+
+ def adjust_request_args(self, args):
+ args['formdata'] = {'name': 'scrapy'}
+ return args
+
+
class TestSpider(Spider):
name = 'demo_spider'
@@@ -115,39 -110,20 +125,47 @@@
"""
pass
+ def custom_form(self, response):
+ """
+ @url http://scrapy.org
+ @custom_form
+ """
+ pass
+
+class CustomContractSuccessSpider(Spider):
+ name = 'custom_contract_success_spider'
+
+ def parse(self, response):
+ """
+ @custom_success_contract
+ """
+ pass
+
+
+class CustomContractFailSpider(Spider):
+ name = 'custom_contract_fail_spider'
+
+ def parse(self, response):
+ """
+ @custom_fail_contract
+ """
+ pass
+
+
class InheritsTestSpider(TestSpider):
name = 'inherits_demo_spider'
class ContractsManagerTest(unittest.TestCase):
- contracts = [UrlContract, ReturnsContract, ScrapesContract, CustomFormContract]
+ contracts = [
+ UrlContract,
+ ReturnsContract,
+ ScrapesContract,
++ CustomFormContract,
+ CustomSuccessContract,
- CustomFailContract
++ CustomFailContract,
+ ]
def setUp(self):
self.conman = ContractsManager(self.contracts)