-
Notifications
You must be signed in to change notification settings - Fork 10.8k
[MRG+1] Add ability to use FormRequest in contracts #3383
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3383 +/- ##
==========================================
+ Coverage 84.46% 84.48% +0.01%
==========================================
Files 167 167
Lines 9362 9369 +7
Branches 1390 1392 +2
==========================================
+ Hits 7908 7915 +7
Misses 1199 1199
Partials 255 255
|
Hey @StasDeep! What do you think about adding request_cls attribute to Contract instead, so that one can define a contract which uses FormRequest, SplashRequest or any other Request class? I don't quite like hardcoding |
Hi @kmike! Thanks for the idea, that sounds much better indeed. I've implemented |
tests/test_contracts.py
Outdated
name = 'custom_form' | ||
|
||
def adjust_request_args(self, args): | ||
args['request_cls'] = FormRequest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about doing it in a different way:
class CustomFormContract(Contract):
name = 'custom_form'
request_cls = FormRequest
def adjust_request_args(self, args):
args['formdata'] = {'name': 'scrapy'}
return args
Not passing request_cls in args
looks cleaner to me, because request_cls
is not really a keyword argument passed to a request initializer.
That said, if it is not an request arg, we'd need some rule to determine which class to use if there are several contracts in a chain. Something like "take last explicitly defined request_cls".
@kmike could you please review the PR? |
Looks good, thanks @StasDeep! |
With current implementation of contracts, it is basically not possible to create a generic
@form
contract, but I think we should at least allow to addformdata
in custom contracts.Closes #3382.