Esempio n. 1
0
    def test_save_file_raises_permission_error(self, mocked_os,
                                               mocked_save_file_as,
                                               mocked_zipfile):
        """
        Test that when a PermissionError is raised when trying to save a file, it is handled correctly
        """
        # GIVEN: A service manager, a service to save
        mocked_main_window = MagicMock()
        mocked_main_window.service_manager_settings_section = 'servicemanager'
        Registry().register('main_window', mocked_main_window)
        Registry().register('application', MagicMock())
        service_manager = ServiceManager(None)
        service_manager._service_path = MagicMock()
        service_manager._save_lite = False
        service_manager.service_items = []
        service_manager.service_theme = 'Default'
        service_manager.service_manager_list = MagicMock()
        mocked_save_file_as.return_value = True
        mocked_zipfile.ZipFile.return_value = MagicMock()
        mocked_os.link.side_effect = PermissionError

        # WHEN: The service is saved and a PermissionError is raised
        result = service_manager.save_file()

        # THEN: The "save_as" method is called to save the service
        assert result is True
        mocked_save_file_as.assert_called_with()
Esempio n. 2
0
    def test_save_file_raises_permission_error(self, mocked_save_file_as, mocked_zipfile, mocked_shutil_copy):
        """
        Test that when a PermissionError is raised when trying to save a file, it is handled correctly
        """
        # GIVEN: A service manager, a service to save
        mocked_main_window = MagicMock()
        mocked_main_window.service_manager_settings_section = 'servicemanager'
        Registry().register('main_window', mocked_main_window)
        Registry().register('application', MagicMock())
        service_manager = ServiceManager(None)
        service_manager._file_name = os.path.join('temp', 'filename.osz')
        service_manager._save_lite = False
        service_manager.service_items = []
        service_manager.service_theme = 'Default'
        service_manager.service_manager_list = MagicMock()
        mocked_save_file_as.return_value = True
        mocked_zipfile.ZipFile.return_value = MagicMock()
        mocked_shutil_copy.side_effect = PermissionError

        # WHEN: The service is saved and a PermissionError is thrown
        result = service_manager.save_file()

        # THEN: The "save_as" method is called to save the service
        self.assertTrue(result)
        mocked_save_file_as.assert_called_with()
Esempio n. 3
0
    def test_save_local_file_raises_permission_error(self, mocked_save_file_as,
                                                     mocked_zipfile,
                                                     mocked_shutil_copy):
        """
        Test that when a PermissionError is raised when trying to save a local file, it is handled correctly
        """
        # GIVEN: A service manager, a service to save
        mocked_main_window = MagicMock()
        mocked_main_window.service_manager_settings_section = 'servicemanager'
        Registry().register('main_window', mocked_main_window)
        Registry().register('application', MagicMock())
        service_manager = ServiceManager(None)
        service_manager._file_name = os.path.join('temp', 'filename.osz')
        service_manager._save_lite = False
        service_manager.service_items = []
        service_manager.service_theme = 'Default'
        mocked_save_file_as.return_value = True
        mocked_zipfile.ZipFile.return_value = MagicMock()
        mocked_shutil_copy.side_effect = PermissionError

        # WHEN: The service is saved and a PermissionError is thrown
        result = service_manager.save_local_file()

        # THEN: The "save_as" method is called to save the service
        self.assertTrue(result)
        mocked_save_file_as.assert_called_with()
Esempio n. 4
0
 def create_basic_service_test(self):
     """
     Test the create basic service array
     """
     # GIVEN: A new service manager instance.
     service_manager = ServiceManager(None)
     # WHEN: when the basic service array is created.
     service_manager._save_lite = False
     service_manager.service_theme = 'test_theme'
     service = service_manager.create_basic_service()[0]
     # THEN: The controller should be registered in the registry.
     self.assertNotEqual(service, None, 'The base service should be created')
     self.assertEqual(service['openlp_core']['service-theme'], 'test_theme', 'The test theme should be saved')
     self.assertEqual(service['openlp_core']['lite-service'], False, 'The lite service should be saved')