def test_prepare_ssh_command_ssh_exception(self, mock_exec, mock_rsa, mock_os, mock_g): current_path = None mock_os.path.dirname.return_value = current_path key_path = '/id_rsa' mock_os.path.join.return_value = key_path mock_rsa.from_private_key_file.side_effect = Exception("ex") config_name = "japac" server = "bdds01" hostname = "192.168.88.88" client_id = "123" tool = "ping" param = "192.168.88.54" with self.assertRaises(Exception): common.prepare_ssh_command(config_name, server, hostname, client_id, tool, param) mock_exec.assert_not_called() mock_g.user.logger.error.asert_called_once()
def test_prepare_ssh_command_fail(self, mock_ssh_open_connection, mock_sshclient, mock_exec, mock_rsa, mock_os): current_path = '/' mock_os.path.dirname.return_value = current_path key_path = '/id_rsa' mock_os.path.join.return_value = key_path key = mock.Mock() mock_rsa.from_private_key_file.return_value = key ssh = mock.Mock() mock_sshclient.return_value = ssh mock_ssh_open_connection.return_value = False config_name = "japac" server = "bdds01" hostname = "192.168.88.88" client_id = "123" tool = "ping" param = "192.168.88.54" with self.assertRaises(Exception): common.prepare_ssh_command(config_name, server, hostname, client_id, tool, param) mock_exec.assert_not_called()
def test_prepare_ssh_command(self, mock_ssh_open_connection, mock_sshclient, mock_exec, mock_rsa, mock_os, mock_update_result_global_stream_result, mock_thread): current_path = '/' mock_os.path.dirname.return_value = current_path key_path = '/id_rsa' mock_os.path.join.return_value = key_path key = mock.Mock() mock_rsa.from_private_key_file.return_value = key ssh = mock.Mock() mock_sshclient.return_value = ssh mock_ssh_open_connection.return_value = True config_name = "japac" server = "bdds01" hostname = "192.168.88.88" client_id = "123" tool = "ping" param = "192.168.88.54" t = mock.MagicMock() mock_thread.return_value = t common.prepare_ssh_command(config_name, server, hostname, client_id, tool, param) mock_exec.assert_not_called()