def test_SaveAs(self, mock_save_study, mock_version):
        project_dir = Path("controller_save_project_as.ksp")

        self.addCleanup(lambda: DeleteDirectoryIfExisting(project_dir))
        DeleteDirectoryIfExisting(project_dir) # remove potential leftovers

        controller = PluginController()

        self.assertIsNone(controller._previous_save_path)

        with patch.object(controller._main_window, 'StatusBarInfo') as patch_fct_status_bar:
            with patch.object(controller._project_path_handler, 'GetSavePath', return_value=project_dir) as patch_fct:
                with self.assertLogs('kratos_salome_plugin.gui.plugin_controller', level='INFO') as cm:
                    controller._SaveAs()
                    self.assertEqual(len(cm.output), 2)
                    self.assertEqual(cm.output[0], 'INFO:kratos_salome_plugin.gui.plugin_controller:Saving project as ...')
                    self.assertEqual(cm.output[1], 'INFO:kratos_salome_plugin.gui.plugin_controller:Saved project under "{}"'.format(project_dir))

                self.assertEqual(patch_fct_status_bar.call_count, 1)
                self.assertEqual(patch_fct.call_count, 1)
                self.assertTrue(project_dir.is_dir())
                num_files_after_first_save = len(listdir(project_dir))
                self.assertGreater(num_files_after_first_save, 0)

                self.assertEqual(controller._previous_save_path, project_dir)

                # calling it a second time should ask again for the save-path
                controller._SaveAs()
                self.assertEqual(patch_fct_status_bar.call_count, 2)
                self.assertEqual(patch_fct.call_count, 2)
                self.assertTrue(project_dir.is_dir())
                self.assertEqual(num_files_after_first_save, len(listdir(project_dir))) # make sure not more files are created

                self.assertEqual(controller._previous_save_path, project_dir)
    def test_SaveAs_failed(self, mock_save_study, mock_version):
        project_dir = Path("controller_save_project_as_failed.ksp")

        controller = PluginController()

        self.assertIsNone(controller._previous_save_path)

        with patch.object(controller._project_path_handler, 'GetSavePath', return_value=project_dir) as patch_fct_get_save_path:
            with patch.object(controller._project_manager, 'SaveProject', return_value=False) as patch_fct_save_proj:
                with self.assertLogs('kratos_salome_plugin.gui.plugin_controller', level='INFO') as cm:
                    controller._SaveAs()
                    self.assertEqual(len(cm.output), 2)
                    self.assertEqual(cm.output[0], 'INFO:kratos_salome_plugin.gui.plugin_controller:Saving project as ...')
                    self.assertEqual(cm.output[1], 'CRITICAL:kratos_salome_plugin.gui.plugin_controller:Failed to save project under "{}"!'.format(project_dir))

                self.assertEqual(patch_fct_get_save_path.call_count, 1)
                self.assertEqual(patch_fct_save_proj.call_count, 1)
                self.assertFalse(project_dir.is_dir())
                self.assertIsNone(controller._previous_save_path)
    def test_SaveAs_aborted(self, mock_save_study, mock_version):
        project_dir = Path("controller_save_project_as_aborted.ksp")

        controller = PluginController()

        self.assertIsNone(controller._previous_save_path)

        with patch.object(controller._project_manager, 'SaveProject') as patch_fct_save_project:
            with patch.object(controller._main_window, 'StatusBarWarning') as patch_fct_status_bar:
                with patch(_QFileDialog_patch+'getSaveFileName', return_value=("",0)) as patch_fct:
                    with self.assertLogs('kratos_salome_plugin.gui.plugin_controller', level='INFO') as cm:
                        controller._SaveAs()
                        self.assertEqual(len(cm.output), 2)
                        self.assertEqual(cm.output[0], 'INFO:kratos_salome_plugin.gui.plugin_controller:Saving project as ...')
                        self.assertEqual(cm.output[1], 'INFO:kratos_salome_plugin.gui.plugin_controller:Saving was aborted')

                    self.assertEqual(patch_fct_save_project.call_count, 0)
                    self.assertEqual(patch_fct_status_bar.call_count, 1)
                    self.assertEqual(patch_fct.call_count, 1)
                    self.assertFalse(project_dir.is_dir())
                    self.assertIsNone(controller._previous_save_path)