Exemplo n.º 1
0
 def send_notification(self, method, params):
     """
     Sends a notification, independent to this request
     :param method: String name of the method for the notification
     :param params: Data to send with the notification
     """
     message = JSONRPCMessage.create_notification(method, params)
     self._queue.put(message)
Exemplo n.º 2
0
 def send_notification(self, method, params):
     """
     Sends a new notification over the JSON RPC channel
     :param method: String name of the method of the notification being send
     :param params: Any data to send along with the notification
     """
     message = JSONRPCMessage.create_notification(method, params)
     self._queue.put(message)
Exemplo n.º 3
0
    def send_notification(self, method, params):
        """
        Sends a notification, independent of any request
        :param method: String name of the method for the notification
        :param params: Data to send with the notification
        """
        # Create the message
        message = JSONRPCMessage.create_notification(method, params)

        # TODO: Add support for handlers for the responses
        # Add the message to the output queue
        self._output_queue.put(message)
Exemplo n.º 4
0
    def test_dispatch_notification_no_handler():
        # If: I dispatch a message that has no handler
        logger = utils.get_mock_logger()
        message = JSONRPCMessage.create_notification('non_existent', {})
        server = JSONRPCServer(None, None, logger=logger)
        server._dispatch_message(message)

        # Then:
        # ... Nothing should have happened
        # TODO: Capture that an error was sent
        # ... A warning should have been logged
        logger.warn.assert_called_once()
Exemplo n.º 5
0
    def test_dispatch_notification_normal(self):
        # Setup: Create a server with a single handler that has none for the deserialization class
        config = IncomingMessageConfiguration('test/test', _TestParams)
        handler = mock.MagicMock()
        server = JSONRPCServer(None, None, logger=utils.get_mock_logger())
        server.set_notification_handler(config, handler)

        # If: I dispatch a message that has none set for the deserialization class
        params = {}
        message = JSONRPCMessage.create_notification('test/test', params)
        server._dispatch_message(message)

        # Then:
        # ... The handler should have been called
        handler.assert_called_once()

        # ... The parameters to the handler should have been a request context and params
        self.assertIsInstance(handler.mock_calls[0][1][0], NotificationContext)
        self.assertIs(handler.mock_calls[0][1][0]._queue, server._output_queue)
        self.assertIsInstance(handler.mock_calls[0][1][1], _TestParams)
Exemplo n.º 6
0
    def test_create_notification(self):
        # If: I create a notification
        message = JSONRPCMessage.create_notification("test/test", {})

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

        # ... The dictionary should have the same values stored
        dictionary = message.dictionary
        self.assertIsNotNone(dictionary)
        self.assertDictEqual(dictionary, {
            'jsonrpc': '2.0',
            'method': 'test/test',
            'params': {}
        })
 def _received_notification_callback(self, method: str, params: any):
     rpc_message = JSONRPCMessage.create_notification(method, params)
     received_message = ReceivedMessage(JSONRPCMessageType.Notification, method, params, type(params), rpc_message)
     self._received_messages.append(received_message)