Ejemplo n.º 1
0
    def test_jsonrpc_server_call(self):
        t = TestTarget()
        r = jsonrpc_server_call(t, u'invalid json data', self.json_decoder)
        assert 'error' in r
        assert r['jsonrpc'] == '2.0'
        assert r['id'] is None
        self.assertEqual(r['error']['code'], jsonrpc_errors.PARSE_ERROR)
        assert 'Traceback' in r['error']['data']

        r = jsonrpc_server_call(t, u'{"test": "test"}', self.json_decoder)
        assert 'error' in r
        assert r['jsonrpc'] == '2.0'
        assert r['id'] is None
        self.assertEqual(r['error']['code'], jsonrpc_errors.INVALID_REQUEST)

        r = jsonrpc_server_call(t, u'{"method": "notfound", "id": 1}',
                                self.json_decoder)
        assert 'error' in r
        assert r['jsonrpc'] == '2.0'
        assert r['id'] == 1
        self.assertEqual(r['error']['code'], jsonrpc_errors.METHOD_NOT_FOUND)

        r = jsonrpc_server_call(t, u'{"method": "exception", "id": 1}',
                                self.json_decoder)
        assert 'error' in r
        assert r['jsonrpc'] == '2.0'
        assert r['id'] == 1
        self.assertEqual(r['error']['code'], jsonrpc_errors.INTERNAL_ERROR)
        assert 'testing-errors' in r['error']['message']
        assert 'Traceback' in r['error']['data']

        r = jsonrpc_server_call(t, u'{"method": "call", "id": 2}',
                                self.json_decoder)
        assert 'result' in r
        assert r['jsonrpc'] == '2.0'
        assert r['id'] == 2
        self.assertEqual(r['result'], ([], {}))

        r = jsonrpc_server_call(
            t, u'{"method": "call", "params": [456, 123], "id": 3}',
            self.json_decoder)
        assert 'result' in r
        assert r['jsonrpc'] == '2.0'
        assert r['id'] == 3
        self.assertEqual(r['result'], ([456, 123], {}))

        r = jsonrpc_server_call(
            t, u'{"method": "call", "params": {"data": 789}, "id": 3}',
            self.json_decoder)
        assert 'result' in r
        assert r['jsonrpc'] == '2.0'
        assert r['id'] == 3
        self.assertEqual(r['result'], ([], {'data': 789}))
Ejemplo n.º 2
0
    def test_jsonrpc_server_call(self):
        t = TestTarget()
        r = jsonrpc_server_call(t, u'invalid json data', self.json_decoder)
        assert 'error' in r
        assert r['jsonrpc'] == '2.0'
        assert r['id'] is None
        self.assertEqual(r['error']['code'], jsonrpc_errors.PARSE_ERROR)
        assert 'Traceback' in r['error']['data']

        r = jsonrpc_server_call(t, u'{"test": "test"}', self.json_decoder)
        assert 'error' in r
        assert r['jsonrpc'] == '2.0'
        assert r['id'] is None
        self.assertEqual(r['error']['code'], jsonrpc_errors.INVALID_REQUEST)

        r = jsonrpc_server_call(t, u'{"method": "notfound", "id": 1}', self.json_decoder)
        assert 'error' in r
        assert r['jsonrpc'] == '2.0'
        assert r['id'] == 1
        self.assertEqual(r['error']['code'], jsonrpc_errors.METHOD_NOT_FOUND)

        r = jsonrpc_server_call(t, u'{"method": "exception", "id": 1}', self.json_decoder)
        assert 'error' in r
        assert r['jsonrpc'] == '2.0'
        assert r['id'] == 1
        self.assertEqual(r['error']['code'], jsonrpc_errors.INTERNAL_ERROR)
        assert 'testing-errors' in r['error']['message']
        assert 'Traceback' in r['error']['data']

        r = jsonrpc_server_call(t, u'{"method": "call", "id": 2}', self.json_decoder)
        assert 'result' in r
        assert r['jsonrpc'] == '2.0'
        assert r['id'] == 2
        self.assertEqual(r['result'], ([], {}))

        r = jsonrpc_server_call(t, u'{"method": "call", "params": [456, 123], "id": 3}',
                                self.json_decoder)
        assert 'result' in r
        assert r['jsonrpc'] == '2.0'
        assert r['id'] == 3
        self.assertEqual(r['result'], ([456, 123], {}))

        r = jsonrpc_server_call(t, u'{"method": "call", "params": {"data": 789}, "id": 3}',
                                self.json_decoder)
        assert 'result' in r
        assert r['jsonrpc'] == '2.0'
        assert r['id'] == 3
        self.assertEqual(r['result'], ([], {'data': 789}))
Ejemplo n.º 3
0
 def render_POST(self, txrequest):
     reqstr = txrequest.content.getvalue()
     target = self.get_target()
     return jsonrpc_server_call(target, reqstr, self.json_decoder)
Ejemplo n.º 4
0
 def render_POST(self, txrequest):
     reqstr = txrequest.content.getvalue()
     target = self.get_target()
     return jsonrpc_server_call(target, reqstr, self.json_decoder)