Example #1
0
    def test_jsonrpc_decode_invalid(self):
        req = '123'

        rpc_req, rpc_resp, rpc_err = jsonrpc.decode(req)

        self.assertEqual(len(rpc_req), 0)
        self.assertEqual(len(rpc_resp), 0)
        self.assertEqual(len(rpc_err), 1)

        self.assertEqual(type(rpc_err[0]), jsonrpc.JsonRpc_ParseError)
Example #2
0
    def test_request_error_batch_invalid_nonempty(self):
        req = '[1]'
        
        resp = requests.post('http://localhost:6780/', data=req)
        self.assertEqual(resp.status_code, 200)

        rpc_req, rpc_resp, rpc_err = jsonrpc.decode(resp.content)

        self.assertEqual(len(rpc_req), 0)
        self.assertEqual(len(rpc_resp), 0)
        self.assertEqual(len(rpc_err), 1)

        rpc_err = rpc_err[0]
        self.assertEqual(type(rpc_err), jsonrpc.JsonRpc_InvalidRequest)
Example #3
0
    def test_request_error_invalid_request(self):
        req = '{"jsonrpc": "2.0", "method": 1, "params": "bar"}'
        
        resp = requests.post('http://localhost:6780/', data=req)
        self.assertEqual(resp.status_code, 200)

        rpc_req, rpc_resp, rpc_err = jsonrpc.decode(resp.content)

        self.assertEqual(len(rpc_req), 0)
        self.assertEqual(len(rpc_resp), 0)
        self.assertEqual(len(rpc_err), 1)

        rpc_err = rpc_err[0]
        self.assertEqual(type(rpc_err), jsonrpc.JsonRpc_InvalidRequest)
Example #4
0
    def test_request_call_exception(self):
        req = '{"jsonrpc": "2.0", "method": "raise_exception", "id": 4}'

        resp = requests.post('http://localhost:6780/', data=req)
        self.assertEqual(resp.status_code, 200)

        rpc_req, rpc_resp, rpc_err = jsonrpc.decode(resp.content)

        self.assertEqual(len(rpc_req), 0)
        self.assertEqual(len(rpc_resp), 0)
        self.assertEqual(len(rpc_err), 1)

        rpc_err = rpc_err[0]
        self.assertEqual(type(rpc_err), jsonrpc.JsonRpc_ServerException)
Example #5
0
    def test_request_call_multi_combo_param(self):
        req = '{"jsonrpc": "2.0", "method": "subtract", "params": [42], "kwargs": {"minuend": 23}, "id": 3}'

        resp = requests.post('http://localhost:6780/', data=req)
        self.assertEqual(resp.status_code, 200)

        rpc_req, rpc_resp, rpc_err = jsonrpc.decode(resp.content)

        self.assertEqual(len(rpc_req), 0)
        self.assertEqual(len(rpc_resp), 1)
        self.assertEqual(len(rpc_err), 0)

        rpc_resp = rpc_resp[0]
        self.assertEqual(rpc_resp.result, 19)
        self.assertEqual(rpc_resp.id, 3)
Example #6
0
    def test_request_call_no_params(self):
        req = '{"jsonrpc": "2.0", "method": "foobar", "id": 2}'

        resp = requests.post('http://localhost:6780/', data=req)
        self.assertEqual(resp.status_code, 200)

        rpc_req, rpc_resp, rpc_err = jsonrpc.decode(resp.content)

        self.assertEqual(len(rpc_req), 0)
        self.assertEqual(len(rpc_resp), 1)
        self.assertEqual(len(rpc_err), 0)

        rpc_resp = rpc_resp[0]
        self.assertEqual(rpc_resp.result, None)
        self.assertEqual(rpc_resp.id, 2)
Example #7
0
    def test_request_batch(self):
        req = '[{"jsonrpc": "2.0", "method": "subtract", "params": [100, 10], "id": 1}, \
                {"jsonrpc": "2.0", "method": "subtract", "params": [99, 11], "id": 2}]'

        resp = requests.post('http://localhost:6780/', data=req)
        self.assertEqual(resp.status_code, 200)

        rpc_req, rpc_resp, rpc_err = jsonrpc.decode(resp.content)

        self.assertEqual(len(rpc_req), 0)
        self.assertEqual(len(rpc_resp), 2)
        self.assertEqual(len(rpc_err), 0)

        self.assertEqual(rpc_resp[0].result, 90)
        self.assertEqual(rpc_resp[0].id, 1)
        self.assertEqual(rpc_resp[1].result, 88)
        self.assertEqual(rpc_resp[1].id, 2)
Example #8
0
    def test_request_error_batch_invalid_json(self):
        req = '[\
                        {"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"},\
                        {"jsonrpc": "2.0", "method"\
                    ]'
        
        resp = requests.post('http://localhost:6780/', data=req)
        self.assertEqual(resp.status_code, 200)

        rpc_req, rpc_resp, rpc_err = jsonrpc.decode(resp.content)

        self.assertEqual(len(rpc_req), 0)
        self.assertEqual(len(rpc_resp), 0)
        self.assertEqual(len(rpc_err), 1)

        rpc_err = rpc_err[0]
        self.assertEqual(type(rpc_err), jsonrpc.JsonRpc_ParseError)