Beispiel #1
0
 def jsonrpc_call(self, path="", method="", spider_name=None, host=None, port=None):
     url = self.get_wsurl(path=path, host=host, port=port)
     print(repr((url, method, spider_name)))
     if spider_name is None:
         return jsonrpc_client_call(url, method)
     else:
         return jsonrpc_client_call(url, method, spider_name)
    def test_jsonrpc_client_call_response(self):
        ul = urllib_mock()
        # must return result or error
        self.assertRaises(ValueError,
                          jsonrpc_client_call,
                          'url',
                          'test',
                          _urllib=ul)
        ul = urllib_mock(result={'one': 1})
        self.assertEquals(jsonrpc_client_call('url', 'test', _urllib=ul),
                          {'one': 1})
        ul = urllib_mock(error={
            'code': 123,
            'message': 'hello',
            'data': 'some data'
        })

        raised = False
        try:
            jsonrpc_client_call('url', 'test', _urllib=ul)
        except JsonRpcError as e:
            raised = True
            self.assertEqual(e.code, 123)
            self.assertEqual(e.message, 'hello')
            self.assertEqual(e.data, 'some data')
            assert '123' in str(e)
            assert 'hello' in str(e)
        assert raised, "JsonRpcError not raised"
 def test_jsonrpc_client_call_request(self):
     ul = urllib_mock(1)
     jsonrpc_client_call('url', 'test', 'one', 2, _urllib=ul)
     req = json.loads(ul.request)
     assert 'id' in req
     self.assertEqual(ul.url, 'url')
     self.assertEqual(req['jsonrpc'], '2.0')
     self.assertEqual(req['method'], 'test')
     self.assertEqual(req['params'], ['one', 2])
Beispiel #4
0
 def test_jsonrpc_client_call_request(self):
     ul = urllib_mock(1)
     jsonrpc_client_call('url', 'test', 'one', 2, _urllib=ul)
     req = json.loads(ul.request)
     assert 'id' in req
     self.assertEqual(ul.url, 'url')
     self.assertEqual(req['jsonrpc'], '2.0')
     self.assertEqual(req['method'], 'test')
     self.assertEqual(req['params'], ['one', 2])
Beispiel #5
0
 def jsonrpc_call(self,
                  path='',
                  method='',
                  spider_name=None,
                  host=None,
                  port=None):
     url = self.get_wsurl(path=path, host=host, port=port)
     print(repr((url, method, spider_name)))
     if spider_name is None:
         return jsonrpc_client_call(url, method)
     else:
         return jsonrpc_client_call(url, method, spider_name)
    def test_jsonrpc_client_call_response(self):
        ul = urllib_mock()
        # must return result or error
        self.assertRaises(ValueError, jsonrpc_client_call, 'url', 'test', _urllib=ul)
        ul = urllib_mock(result={'one': 1})
        self.assertEquals(jsonrpc_client_call('url', 'test', _urllib=ul), {'one': 1})
        ul = urllib_mock(error={'code': 123, 'message': 'hello', 'data': 'some data'})

        raised = False
        try:
            jsonrpc_client_call('url', 'test', _urllib=ul)
        except JsonRpcError, e:
            raised = True
            self.assertEqual(e.code, 123)
            self.assertEqual(e.message, 'hello')
            self.assertEqual(e.data, 'some data')
            assert '123' in str(e)
            assert 'hello' in str(e)
Beispiel #7
0
def jsonrpc_call(opts, path, method, *args, **kwargs):
    url = get_wsurl(opts, path)
    return jsonrpc_client_call(url, method, *args, **kwargs)
Beispiel #8
0
def jsonrpc_call(opts, path, method, *args, **kwargs):
    url = get_wsurl(opts, path)
    return jsonrpc_client_call(url, method, *args, **kwargs)
Beispiel #9
0
def jsonrpc_call(opts, path, method, *args, **kwargs):
    url = get_wsurl(opts, path)
    # print(repr((url, method, args, kwargs)))
    return jsonrpc_client_call(url, method, *args, **kwargs)
Beispiel #10
0
def jsonrpc_call_spider(path, method, *args, **kwargs):
    url = get_wsurl_spider(path)
    return jsonrpc_client_call(url, method, *args, **kwargs)
Beispiel #11
0
    def process_item(self, item, spider):
        jsonrpc_client_call(self.rpc_url, self.rpc_method, *args, **kwargs)

        return item
Beispiel #12
0
def jsonrpc_call(opts, path, method, *args, **kwargs):
    url = get_wsurl(opts, path)
    # print(repr((url, method, args, kwargs)))
    return jsonrpc_client_call(url, method, *args, **kwargs)