コード例 #1
0
ファイル: test_server.py プロジェクト: jaunis/xivo-bus
    def test_server_sends_marshaled_exception_when_callback_raises_exception(self, mock_command_response):
        request = '{"name": "foobar", "arg": {"arg1": "value"}}'

        expected = '{"error": "raise me!", "value": null}'

        command_response = Mock(CommandResponse)
        command_response.error = "raise me!"
        command_response.value = None
        mock_command_response.return_value = command_response
        callback = Mock(side_effect=BusCtlServerError())

        marshaler = Mock(Marshaler)
        server = BusCtlServer()
        server._marshaler = marshaler

        command = Mock()
        command.name = "foobar"
        marshaler.unmarshal_command.return_value = command
        marshaler.marshal_response.return_value = expected

        command_class = Mock()
        command_class.name = "foobar"

        server.add_command(command_class, callback)

        response = server._process_next_command(request)

        self.assertEqual(response, expected)
        marshaler.marshal_response.assert_called_once_with(command_response)
コード例 #2
0
ファイル: test_server.py プロジェクト: jaunis/xivo-bus
    def test_server_sends_marshaled_exception_when_callback_raises_exception(
            self, mock_command_response):
        request = '{"name": "foobar", "arg": {"arg1": "value"}}'

        expected = '{"error": "raise me!", "value": null}'

        command_response = Mock(CommandResponse)
        command_response.error = "raise me!"
        command_response.value = None
        mock_command_response.return_value = command_response
        callback = Mock(side_effect=BusCtlServerError())

        marshaler = Mock(Marshaler)
        server = BusCtlServer()
        server._marshaler = marshaler

        command = Mock()
        command.name = "foobar"
        marshaler.unmarshal_command.return_value = command
        marshaler.marshal_response.return_value = expected

        command_class = Mock()
        command_class.name = "foobar"

        server.add_command(command_class, callback)

        response = server._process_next_command(request)

        self.assertEqual(response, expected)
        marshaler.marshal_response.assert_called_once_with(command_response)
コード例 #3
0
ファイル: test_server.py プロジェクト: jaunis/xivo-bus
    def test_command_callback_is_called_by_process_next_command(self):
        callback = Mock()
        marshaler = Mock()

        server = BusCtlServer()
        server._marshaler = marshaler

        command = Mock()
        command.name = "foobar"
        marshaler.unmarshal_command.return_value = command

        command_class = Mock()
        command_class.name = "foobar"

        server.add_command(command_class, callback)

        server._process_next_command(
            '{"name": "foobar", "arg": {"arg1": "value"}}')

        callback.assert_called_once_with(command)
コード例 #4
0
ファイル: test_server.py プロジェクト: jaunis/xivo-bus
    def test_command_callback_is_called_by_process_next_command(self):
        callback = Mock()
        marshaler = Mock()

        server = BusCtlServer()
        server._marshaler = marshaler

        command = Mock()
        command.name = "foobar"
        marshaler.unmarshal_command.return_value = command

        command_class = Mock()
        command_class.name = "foobar"

        server.add_command(command_class, callback)

        server._process_next_command('{"name": "foobar", "arg": {"arg1": "value"}}')

        callback.assert_called_once_with(command)