コード例 #1
0
    def test_socket_client(self):
        controller = Controller(config_file=self.config_file.name)

        with mock.patch('socket.socket') as MockSocket:
            sock = controller.socket_client()

        assert sock == MockSocket.return_value
        assert MockSocket.call_args[0] == (socket.AF_UNIX, socket.SOCK_STREAM)
コード例 #2
0
    def test_handle_mcrunnerd_action(self):
        controller = Controller(config_file=self.config_file.name)
        controller.send_mcrunnerd_package = mock.MagicMock()

        controller.handle_mcrunnerd_action('package')

        assert controller.send_mcrunnerd_package.call_count == 1
        assert controller.send_mcrunnerd_package.call_args[0] == ('package', )
コード例 #3
0
ファイル: test_mcrunner.py プロジェクト: vicngtor/mcrunner
    def test_socket_client(self):
        controller = Controller(config_file=self.config_file.name)

        with mock.patch('socket.socket') as MockSocket:
            sock = controller.socket_client()

        assert sock == MockSocket.return_value
        assert MockSocket.call_args[0] == (socket.AF_UNIX, socket.SOCK_STREAM)
コード例 #4
0
ファイル: test_mcrunner.py プロジェクト: vicngtor/mcrunner
    def test_handle_mcrunnerd_action(self):
        controller = Controller(config_file=self.config_file.name)
        controller.send_mcrunnerd_package = mock.MagicMock()

        controller.handle_mcrunnerd_action('package')

        assert controller.send_mcrunnerd_package.call_count == 1
        assert controller.send_mcrunnerd_package.call_args[0] == ('package',)
コード例 #5
0
    def test_handle_server_action(self):
        controller = Controller(config_file=self.config_file.name)
        controller.send_mcrunnerd_package = mock.MagicMock()

        controller.handle_server_action('action', 'server_1')

        assert controller.send_mcrunnerd_package.call_count == 1
        assert controller.send_mcrunnerd_package.call_args[0] == (
            'action{delim}server_1'.format(
                delim=MCRUNNERD_COMMAND_DELIMITER), )
コード例 #6
0
ファイル: test_mcrunner.py プロジェクト: vicngtor/mcrunner
    def test_send_mcrunnerd_package_with_socket_error(self):
        controller = Controller(config_file=self.config_file.name)

        controller.socket_client = mock.MagicMock(side_effect=socket.error)

        with mock.patch('mcrunner.mcrunner._output') as mock_print:
            controller.send_mcrunnerd_package('some_package')

        assert mock_print.call_count == 1
        assert mock_print.call_args[0] == ('Could not connect to socket - is mcrunnerd running?',)
コード例 #7
0
ファイル: test_mcrunner.py プロジェクト: vicngtor/mcrunner
    def test_handle_server_action_with_command(self):
        controller = Controller(config_file=self.config_file.name)
        controller.send_mcrunnerd_package = mock.MagicMock()

        controller.handle_server_action('action', 'server_1', command='some command')

        assert controller.send_mcrunnerd_package.call_count == 1
        assert controller.send_mcrunnerd_package.call_args[0] == (
            'action{delim}server_1{delim}some command'.format(delim=MCRUNNERD_COMMAND_DELIMITER),
        )
コード例 #8
0
    def test_send_mcrunnerd_package_with_socket_error(self):
        controller = Controller(config_file=self.config_file.name)

        controller.socket_client = mock.MagicMock(side_effect=socket.error)

        with mock.patch('mcrunner.mcrunner._output') as mock_print:
            controller.send_mcrunnerd_package('some_package')

        assert mock_print.call_count == 1
        assert mock_print.call_args[0] == (
            'Could not connect to socket - is mcrunnerd running?', )
コード例 #9
0
    def test_load_empty_config(self):
        self.config_file.close()
        self.config_file = tempfile.NamedTemporaryFile()

        controller = Controller(config_file=self.config_file.name)

        assert controller.sock_file == None
コード例 #10
0
ファイル: test_mcrunner.py プロジェクト: vicngtor/mcrunner
    def test_send_mcrunnerd_package_with_sendall_error(self):
        controller = Controller(config_file=self.config_file.name)

        socket_error = socket.error('bad send')

        mock_sock = mock.MagicMock()
        controller.socket_client = mock.MagicMock(return_value=mock_sock)
        mock_sock.sendall = mock.MagicMock(side_effect=socket_error)

        with mock.patch('mcrunner.mcrunner._output') as mock_print:
            controller.send_mcrunnerd_package('some_package')

        assert mock_sock.sendall.call_count == 1
        assert mock_sock.sendall.call_args[0] == ('some_package',)

        assert mock_print.call_count == 1
        assert mock_print.call_args[0] == ('Error sending mcrunnerd package: %s' % str(socket_error),)

        assert mock_sock.close.call_count == 1
コード例 #11
0
ファイル: test_mcrunner.py プロジェクト: vicngtor/mcrunner
    def test_send_mcrunnerd_package_with_no_message(self):
        controller = Controller(config_file=self.config_file.name)

        mock_sock = mock.MagicMock()
        controller.socket_client = mock.MagicMock(return_value=mock_sock)
        mock_sock.recv = mock.MagicMock(side_effect=[
            COMMAND_RESPONSE_STATUSES['DONE']
        ])

        with mock.patch('mcrunner.mcrunner._output') as mock_print:
            controller.send_mcrunnerd_package('some_package')

        assert mock_sock.sendall.call_count == 1
        assert mock_sock.sendall.call_args[0] == ('some_package',)

        assert mock_sock.recv.call_count == 1
        assert mock_sock.recv.call_args[0] == (1,)

        assert mock_print.call_count == 0

        assert mock_sock.close.call_count == 1
コード例 #12
0
ファイル: test_mcrunner.py プロジェクト: sbezboro/mcrunner
    def test_send_mcrunnerd_package(self):
        controller = Controller(config_file=self.config_file.name)

        controller.socket_client = mock.MagicMock()

        mock_connection = mock.MagicMock()
        mock_connection.receive_message = mock.MagicMock(side_effect=[
            'some sample response message',
            None  # socket closed
        ])

        with mock.patch('mcrunner.mcrunner._output') as mock_print:
            with mock.patch('mcrunner.mcrunner.ClientSocketConnection', return_value=mock_connection):
                controller.send_mcrunnerd_package('some_package')

        assert mock_connection.send_message.call_count == 1
        assert mock_connection.send_message.call_args[0] == ('some_package',)

        assert mock_print.call_count == 1
        assert mock_print.call_args[0] == ('some sample response message',)

        assert mock_connection.close.call_count == 1
コード例 #13
0
    def test_send_mcrunnerd_package_with_sendall_error(self):
        controller = Controller(config_file=self.config_file.name)

        controller.socket_client = mock.MagicMock()

        socket_error = socket.error('bad send')

        mock_connection = mock.MagicMock()
        mock_connection.send_message = mock.MagicMock(side_effect=socket_error)

        with mock.patch('mcrunner.mcrunner._output') as mock_print:
            with mock.patch('mcrunner.mcrunner.ClientSocketConnection',
                            return_value=mock_connection):
                controller.send_mcrunnerd_package('some_package')

        assert mock_connection.send_message.call_count == 1
        assert mock_connection.send_message.call_args[0] == ('some_package', )

        assert mock_print.call_count == 1
        assert mock_print.call_args[0] == (
            'Error sending mcrunnerd package: %s' % str(socket_error), )

        assert mock_connection.close.call_count == 1
コード例 #14
0
    def test_send_mcrunnerd_package(self):
        controller = Controller(config_file=self.config_file.name)

        controller.socket_client = mock.MagicMock()

        mock_connection = mock.MagicMock()
        mock_connection.receive_message = mock.MagicMock(side_effect=[
            'some sample response message',
            None  # socket closed
        ])

        with mock.patch('mcrunner.mcrunner._output') as mock_print:
            with mock.patch('mcrunner.mcrunner.ClientSocketConnection',
                            return_value=mock_connection):
                controller.send_mcrunnerd_package('some_package')

        assert mock_connection.send_message.call_count == 1
        assert mock_connection.send_message.call_args[0] == ('some_package', )

        assert mock_print.call_count == 1
        assert mock_print.call_args[0] == ('some sample response message', )

        assert mock_connection.close.call_count == 1
コード例 #15
0
    def test_load_config(self):
        controller = Controller(config_file=self.config_file.name)

        assert controller.sock_file == '/tmp/mcrunner.sock'