Ejemplo n.º 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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def test_jsonrpc_request_error_batch_invalid_nonempty(self):
        req = '[1]'

        resp = requests.post(self.TEST_URI, 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)
Ejemplo n.º 4
0
    def test_jsonrpc_request_call_exception(self):
        req = '{"jsonrpc": "2.0", "method": "raise_exception", "id": 4}'

        resp = requests.post(self.TEST_URI, 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)
Ejemplo n.º 5
0
    def test_jsonrpc_request_call_exception(self):
        req = '{"jsonrpc": "2.0", "method": "raise_exception", "id": 4}'

        resp = requests.post(self.TEST_URI, 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)
Ejemplo n.º 6
0
    def test_jsonrpc_request_error_batch_invalid_nonempty(self):
        req = '[1]'

        resp = requests.post(self.TEST_URI, 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)
Ejemplo n.º 7
0
    def test_jsonrpc_request_error_invalid_request(self):
        req = '{"jsonrpc": "2.0", "method": 1, "params": "bar"}'

        resp = requests.post(self.TEST_URI, 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)
Ejemplo n.º 8
0
    def test_jsonrpc_request_error_invalid_request(self):
        req = '{"jsonrpc": "2.0", "method": 1, "params": "bar"}'

        resp = requests.post(self.TEST_URI, 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)
Ejemplo n.º 9
0
    def test_jsonrpc_request_call_multi_combo_param(self):
        req = '{"jsonrpc": "2.0", "method": "subtract", "params": [42], "kwargs": {"minuend": 23}, "id": 3}'

        resp = requests.post(self.TEST_URI, 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)
Ejemplo n.º 10
0
    def test_jsonrpc_request_call_no_params(self):
        req = '{"jsonrpc": "2.0", "method": "foobar", "id": 2}'

        resp = requests.post(self.TEST_URI, 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)
Ejemplo n.º 11
0
    def test_jsonrpc_request_error_parse_invalid_batch(self):
        req = '[1,2,3]'

        resp = requests.post(self.TEST_URI, 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), 3)

        self.assertEqual(type(rpc_err[0]), jsonrpc.JsonRpc_InvalidRequest)
        self.assertEqual(type(rpc_err[1]), jsonrpc.JsonRpc_InvalidRequest)
        self.assertEqual(type(rpc_err[2]), jsonrpc.JsonRpc_InvalidRequest)
Ejemplo n.º 12
0
    def test_jsonrpc_request_call_multi_combo_param(self):
        req = '{"jsonrpc": "2.0", "method": "subtract", "params": [42], "kwargs": {"minuend": 23}, "id": 3}'

        resp = requests.post(self.TEST_URI, 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)
Ejemplo n.º 13
0
    def test_jsonrpc_request_call_no_params(self):
        req = '{"jsonrpc": "2.0", "method": "foobar", "id": 2}'

        resp = requests.post(self.TEST_URI, 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)
Ejemplo n.º 14
0
    def test_jsonrpc_request_error_parse_invalid_batch(self):
        req = '[1,2,3]'

        resp = requests.post(self.TEST_URI, 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), 3)

        self.assertEqual(type(rpc_err[0]), jsonrpc.JsonRpc_InvalidRequest)
        self.assertEqual(type(rpc_err[1]), jsonrpc.JsonRpc_InvalidRequest)
        self.assertEqual(type(rpc_err[2]), jsonrpc.JsonRpc_InvalidRequest)
Ejemplo n.º 15
0
    def test_jsonrpc_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(self.TEST_URI, 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)
Ejemplo n.º 16
0
    def test_jsonrpc_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(self.TEST_URI, 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)
Ejemplo n.º 17
0
    def test_jsonrpc_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(self.TEST_URI, 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)
Ejemplo n.º 18
0
    def test_jsonrpc_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(self.TEST_URI, 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)