Ejemplo n.º 1
0
 def test_batch_invalid(self):
     request = '[1,2,3]'
     response = '[' \
         '{"jsonrpc": "2.0", "error": {"code": -32600, ' \
         '"message": "Invalid Request"}, "id": null},' \
         '{"jsonrpc": "2.0", "error": {"code": -32600, ' \
         '"message": "Invalid Request"}, "id": null},' \
         '{"jsonrpc": "2.0", "error": {"code": -32600, ' \
         '"message": "Invalid Request"}, "id": null}]'
     self.assertEqual(dealer.process_request(request), jsonok(response))
Ejemplo n.º 2
0
 def test_call_batch(self):
     request = '[' \
         '{"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"},' \
         '{"jsonrpc": "2.0", "method": "notify_hello", "params": [7]},' \
         '{"jsonrpc": "2.0", "method": "subtract", "params": [42,23], "id": "2"},' \
         '{"foo": "boo"},' \
         '{"jsonrpc": "2.0", "method": "foo.get", "params": {"name": "myself"}, "id": "5"},' \
         '{"jsonrpc": "2.0", "method": "get_data", "id": "9"}]'
     response = '[' \
         '{"jsonrpc": "2.0", "result": 7, "id": "1"},' \
         '{"jsonrpc": "2.0", "result": 19, "id": "2"},' \
         '{"jsonrpc": "2.0", "error":{"code": -32600, "message": "Invalid Request"}, ' \
         '"id": null},' \
         '{"jsonrpc": "2.0", "error":{"code": -32601, "message": "Method not found"}, ' \
         '"id": "5"},' \
         '{"jsonrpc": "2.0", "result": ["hello", 5], "id": "9"}]'
     self.assertEqual(dealer.process_request(request), jsonok(response))
Ejemplo n.º 3
0
 def test_internal_error(self):
     request = '{"jsonrpc": "2.0", "method": "error_div", "id": 1}'
     response = '{"jsonrpc": "2.0", "error": { "message": "Internal error", ' \
                '"code": -32603, "data": "integer division or modulo by zero"}, "id": 1}'
     self.assertEqual(dealer.process_request(request), jsonok(response))
Ejemplo n.º 4
0
 def test_non_existent_method(self):
     request = '{"jsonrpc": "2.0", "method": "bar", "id": "1"}'
     response = '{"jsonrpc": "2.0", "error": {"code": -32601, ' \
                '"message": "Method not found"}, "id": "1"}'
     self.assertEqual(dealer.process_request(request), jsonok(response))
Ejemplo n.º 5
0
 def test_notification_foobar(self):
     request = '{"jsonrpc": "2.0", "method": "foobar"}'
     response = None
     self.assertEqual(dealer.process_request(request), response)
Ejemplo n.º 6
0
 def test_notification_update(self):
     request = '{"jsonrpc": "2.0", "method": "update", "params": [1,2,3,4,5]}'
     response = None
     self.assertEqual(dealer.process_request(request), response)
Ejemplo n.º 7
0
 def test_foobar(self):
     request = '{"jsonrpc": "2.0", "method": "foobar", "id": 1}'
     response = '{"jsonrpc": "2.0", "result": null, "id": 1}'
     self.assertEqual(dealer.process_request(request), jsonok(response))
Ejemplo n.º 8
0
 def test_invalid_params_subtract(self):
     request = '{"jsonrpc": "2.0","method": "subtract","params": [42,"2"],"id": 1}'
     response = '{"jsonrpc": "2.0", "error": {"code": -32602, ' \
                '"message": "Invalid params"}, "id": 1}'
     self.assertEqual(dealer.process_request(request), jsonok(response))
Ejemplo n.º 9
0
 def test_subtract_named_params(self):
     request = '{"jsonrpc": "2.0", "method": "subtract", ' \
               '"params": {"subtrahend": 23, "minuend": 42}, "id": 3}'
     response = '{"jsonrpc": "2.0", "result": 19, "id": 3}'
     self.assertEqual(dealer.process_request(request), jsonok(response))
Ejemplo n.º 10
0
 def test_subtract_pos_params(self):
     request = '{"jsonrpc": "2.0","method": "subtract","params": [42, 23],"id": 1}'
     response = '{"jsonrpc": "2.0", "result": 19, "id": 1}'
     self.assertEqual(dealer.process_request(request), jsonok(response))
Ejemplo n.º 11
0
 def test_call_batch_notification(self):
     request = '[{"jsonrpc": "2.0", "method": "notify_sum", "params": [1,2,4]},' \
               '{"jsonrpc": "2.0", "method": "notify_hello", "params": [7]}]'
     response = None
     self.assertEqual(dealer.process_request(request), response)
Ejemplo n.º 12
0
 def test_batch_invalid_json(self):
     request = '[{"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"},' \
               '{"jsonrpc": "2.0", "method"]'
     response = '{"jsonrpc": "2.0", "error": {"code": -32700, ' \
                '"message": "Parse error"}, "id": null}'
     self.assertEqual(dealer.process_request(request), jsonok(response))
Ejemplo n.º 13
0
 def test_invalid_request(self):
     request = '{"jsonrpc": "2.0", "method": 1, "params": "bar"}'
     response = '{"jsonrpc": "2.0", "error": {"code": -32600, ' \
                '"message": "Invalid Request"}, "id": null}'
     self.assertEqual(dealer.process_request(request), jsonok(response))
Ejemplo n.º 14
0
 def test_invalid_json(self):
     request = '{"jsonrpc": "2.0", "method": "foobar, "params": "bar", "baz]'
     response = '{"jsonrpc": "2.0", "error": {"code": -32700, ' \
                '"message": "Parse error"}, "id": null}'
     self.assertEqual(dealer.process_request(request), jsonok(response))