コード例 #1
0
 def send_response(self, params):
     """
     Sends a successful response to this request
     :param params: Data to send back with the response
     """
     message = JSONRPCMessage.create_response(self._message.message_id,
                                              params)
     self._queue.put(message)
コード例 #2
0
    def test_create_response(self):
        # If: I create a response
        message = JSONRPCMessage.create_response(10, {})

        # Then:
        # ... The message should have all the properties I defined
        self.assertIsNotNone(message)
        self.assertEqual(message.message_id, 10)
        self.assertIsNone(message.message_method)
        self.assertIsNone(message.message_params)
        self.assertIsNotNone(message.message_result)
        self.assertDictEqual(message.message_result, {})
        self.assertIsNone(message.message_error)
        self.assertEqual(message.message_type,
                         JSONRPCMessageType.ResponseSuccess)

        # ... The dictionary should have the same values stored
        dictionary = message.dictionary
        self.assertIsNotNone(dictionary)
        self.assertDictEqual(dictionary, {
            'jsonrpc': '2.0',
            'result': {},
            'id': 10
        })
コード例 #3
0
 def _received_response_callback(self, params: any):
     rpc_message = JSONRPCMessage.create_response(0, params)
     received_message = ReceivedMessage(JSONRPCMessageType.ResponseSuccess, None, params, type(params), rpc_message)
     self._received_messages.append(received_message)
コード例 #4
0
 def test_dispatch_response_success():
     # TODO: Replace with robust logic once response routing is implemented
     # If: I dispatch a response message
     message = JSONRPCMessage.create_response('123', {})
     server = JSONRPCServer(None, None, logger=utils.get_mock_logger())
     server._dispatch_message(message)