test_request.py (1054B)
1 # standard imports 2 import unittest 3 4 # local imports 5 from jsonrpc_std.base import JSONRPCBase 6 from jsonrpc_std.interface import ( 7 jsonrpc_request, 8 jsonrpc_response, 9 jsonrpc_result, 10 jsonrpc_is_response_to, 11 ) 12 13 14 class TestRequest(unittest.TestCase): 15 16 def test_request(self): 17 req = jsonrpc_request('foo_barBaz') 18 self.assertEqual(req['jsonrpc'], JSONRPCBase.version_string) 19 self.assertEqual(type(req['id']).__name__, 'str') 20 self.assertEqual(req['method'], 'foo_barBaz') 21 self.assertEqual(len(req['params']), 0) 22 23 24 def test_response(self): 25 res = jsonrpc_response('foo', 42) 26 self.assertEqual(res['id'], 'foo') 27 self.assertEqual(res['result'], 42) 28 r = jsonrpc_result(res, None) 29 self.assertEqual(r, 42) 30 31 32 def test_response_compare(self): 33 req = jsonrpc_request('foo_barBaz') 34 res = jsonrpc_response(req['id'], 42) 35 self.assertTrue(jsonrpc_is_response_to(req, res)) 36 37 38 if __name__ == '__main__': 39 unittest.main()