mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-25 20:23:56 +00:00
Check that arguments and keyword arguments are not passed simultaneously in jsonrpc_client_call()
This commit is contained in:
parent
ffad8e08e7
commit
88c99e0b83
@ -36,6 +36,9 @@ class JsonRpcUtilsTestCase(unittest.TestCase):
|
||||
crawler = CrawlerMock([])
|
||||
self.json_decoder = ScrapyJSONDecoder(crawler=crawler)
|
||||
|
||||
def test_jsonrpc_client_call_args_kwargs_raises(self):
|
||||
self.assertRaises(ValueError, jsonrpc_client_call, 'url', 'test', 'one', kw=123)
|
||||
|
||||
def test_jsonrpc_client_call_request(self):
|
||||
ul = urllib_mock(1)
|
||||
jsonrpc_client_call('url', 'test', 'one', 2, _urllib=ul)
|
||||
|
@ -31,6 +31,8 @@ class JsonRpcError(Exception):
|
||||
def jsonrpc_client_call(url, method, *args, **kwargs):
|
||||
"""Execute a JSON-RPC call on the given url"""
|
||||
_urllib = kwargs.pop('_urllib', urllib)
|
||||
if args and kwargs:
|
||||
raise ValueError("Pass *args or **kwargs but not both to jsonrpc_client_call")
|
||||
req = {'jsonrpc': '2.0', 'method': method, 'params': args or kwargs, 'id': 1}
|
||||
res = json.loads(_urllib.urlopen(url, json.dumps(req)).read())
|
||||
if 'result' in res:
|
||||
|
Loading…
x
Reference in New Issue
Block a user