Example #1
0
    def test_jsonrpc_client_call_request(self):
        sentcall = {}
        def _urlopen(url, data):
            sentcall['url'] = url
            sentcall['data'] = data
            return _umock(1)

        with patch.object(urllib.request, 'urlopen', _urlopen):
            jsonrpc_client_call('url', 'test', 'one', 2)
            req = json.loads(str_to_unicode(sentcall['data']))
            assert 'id' in req
            self.assertEqual(sentcall['url'], 'url')
            self.assertEqual(req['jsonrpc'], '2.0')
            self.assertEqual(req['method'], 'test')
            self.assertEqual(req['params'], ['one', 2])
Example #2
0
    def test_jsonrpc_client_call_request(self):
        sentcall = {}

        def _urlopen(url, data):
            sentcall['url'] = url
            sentcall['data'] = data
            return _umock(1)

        with patch.object(urllib.request, 'urlopen', _urlopen):
            jsonrpc_client_call('url', 'test', 'one', 2)
            req = json.loads(str_to_unicode(sentcall['data']))
            assert 'id' in req
            self.assertEqual(sentcall['url'], 'url')
            self.assertEqual(req['jsonrpc'], '2.0')
            self.assertEqual(req['method'], 'test')
            self.assertEqual(req['params'], ['one', 2])
Example #3
0
    def test_jsonrpc_client_call_response(self, urlopen_mock):
        urlopen_mock.return_value = _umock()
        # must return result or error
        self.assertRaises(ValueError, jsonrpc_client_call, 'url', 'test')
        urlopen_mock.return_value = _umock(result={'one': 1})
        self.assertEquals(jsonrpc_client_call('url', 'test'), {'one': 1})
        urlopen_mock.return_value = _umock(error={'code': 123,
                                                  'message': 'hello',
                                                  'data': 'some data'})

        raised = False
        try:
            jsonrpc_client_call('url', 'test')
        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"
Example #4
0
    def test_jsonrpc_client_call_response(self, urlopen_mock):
        urlopen_mock.return_value = _umock()
        # must return result or error
        self.assertRaises(ValueError, jsonrpc_client_call, 'url', 'test')
        urlopen_mock.return_value = _umock(result={'one': 1})
        self.assertEquals(jsonrpc_client_call('url', 'test'), {'one': 1})
        urlopen_mock.return_value = _umock(error={'code': 123,
                                                  'message': 'hello',
                                                  'data': 'some data'})

        raised = False
        try:
            jsonrpc_client_call('url', 'test')
        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"
Example #5
0
def jsonrpc_call(opts, path, method, *args, **kwargs):
    url = get_wsurl(opts, path)
    return jsonrpc_client_call(url, method, *args, **kwargs)
def jsonrpc_call(opts, path, method, *args, **kwargs):
    url = get_wsurl(opts, path)
    return jsonrpc_client_call(url, method, *args, **kwargs)