Пример #1
0
 def test_valid_two_requestz(self):
     request = '{ "jsonrpc": "2.0", "id": "123456", "method": "ping" }'
     json = loads(request)
     self.assertTrue(validate_request(json))
     request = '{ "jsonrpc": "2.0", "method": "ping" }'
     json = loads(request)
     self.assertTrue(validate_request(json))
     request = '{ "id": 123, "method": "ping" }'
     json = loads(request)
     self.assertTrue(validate_request(json))
     request = '{ "id": 123, "method": "ping", "params": "foo" }'
     json = loads(request)
     self.assertTrue(validate_request(json))
     request = '{ "id": 123, "method": "ping", "params": { "x": 5 } }'
     json = loads(request)
     self.assertTrue(validate_request(json))
Пример #2
0
 def test_invalid_request(self):
     # version is wrong
     request = '{ "jsonrpc": "3.0", "id": "123456", "method": "ping" }'
     json = loads(request)
     self.assertIsInstance(validate_request(json), Fault)
     request = '{ "jsonrpc": 2.0, "id": "123456", "method": "ping" }'
     json = loads(request)
     # no id nor jsonrpc
     self.assertIsInstance(validate_request(json), Fault)
     request = '{ "method": "ping" }'
     json = loads(request)
     self.assertIsInstance(validate_request(json), Fault)
     # no id nor jsonrpc
     self.assertIsInstance(validate_request(json), Fault)
     request = '{ "jsonrpc": "3.0", "id": "123456", "foo": 42 }'
     json = loads(request)
     self.assertIsInstance(validate_request(json), Fault)