def setUp(self): self.factory = JSONRPCServerFactory() self.factory.addHandler(TestHandler(), 'foo') self.proto = self.factory.buildProtocol(('127.0.0.1', 0)) self.tr = proto_helpers.StringTransport() self.proto.makeConnection(self.tr) self.client = client.JSONRPCClient()
class ServerTestCase(TXJasonTestCase): def setUp(self): self.factory = JSONRPCServerFactory() self.factory.addHandler(TestHandler(), 'foo') self.proto = self.factory.buildProtocol(('127.0.0.1', 0)) self.tr = proto_helpers.StringTransport() self.proto.makeConnection(self.tr) self.client = client.JSONRPCClient() def _test(self, request, expected): request = makeNetstring(request) self.proto.dataReceived(request) self.assertEqual(self.tr.value(), expected) def test_request(self): request = self.client._getPayload('foo.add', 'X', 1, 2) self._test(request, '42:{"jsonrpc": "2.0", "result": 3, "id": "X"},') def test_notification(self): request = self.client._getPayload('foo.add', None, 1, 2) self._test(request, '') def test_error(self): request = self.client._getPayload('add', 'X', 1, 2) self._test(request, '87:{"jsonrpc": "2.0", "id": "X", "error": {"message": "Method not found", "code": -32601}},')
class ServerTestCase(TXJasonTestCase): def setUp(self): self.factory = JSONRPCServerFactory() self.factory.addHandler(TestHandler(), 'foo') self.proto = self.factory.buildProtocol(('127.0.0.1', 0)) self.tr = proto_helpers.StringTransport() self.proto.makeConnection(self.tr) self.client = client.JSONRPCClient() def _test(self, request, expected): request = makeNetstring(request) self.proto.dataReceived(request) self.assertEqual(self.tr.value(), expected) def test_request(self): request = self.client._getPayload('foo.add', 'X', 1, 2) self._test(request, '42:{"jsonrpc": "2.0", "result": 3, "id": "X"},') def test_notification(self): request = self.client._getPayload('foo.add', None, 1, 2) self._test(request, '') def test_error(self): request = self.client._getPayload('add', 'X', 1, 2) self._test( request, '87:{"jsonrpc": "2.0", "id": "X", "error": {"message": "Method not found", "code": -32601}},' )