예제 #1
0
    def unzip_theme_test(self):
        """
        Test that unzipping of themes works
        """
        # GIVEN: A theme file, a output folder and some mocked out internal functions
        with patch('openlp.core.ui.thememanager.critical_error_message_box') \
                as mocked_critical_error_message_box:
            theme_manager = ThemeManager(None)
            theme_manager._create_theme_from_xml = MagicMock()
            theme_manager.generate_and_save_image = MagicMock()
            theme_manager.path = ''
            folder = mkdtemp()
            theme_file = os.path.join(TEST_RESOURCES_PATH, 'themes',
                                      'Moss_on_tree.otz')

            # WHEN: We try to unzip it
            theme_manager.unzip_theme(theme_file, folder)

            # THEN: Files should be unpacked
            self.assertTrue(
                os.path.exists(
                    os.path.join(folder, 'Moss on tree', 'Moss on tree.xml')))
            self.assertEqual(mocked_critical_error_message_box.call_count, 0,
                             'No errors should have happened')
            shutil.rmtree(folder)
예제 #2
0
    def test_unzip_theme_invalid_version(self):
        """
        Test that themes with invalid (< 2.0) or with no version attributes are rejected
        """
        # GIVEN: An instance of ThemeManager whilst mocking a theme that returns a theme with no version attribute
        with patch('openlp.core.ui.thememanager.zipfile.ZipFile') as mocked_zip_file,\
                patch('openlp.core.ui.thememanager.ElementTree.getroot') as mocked_getroot,\
                patch('openlp.core.ui.thememanager.XML'),\
                patch('openlp.core.ui.thememanager.critical_error_message_box') as mocked_critical_error_message_box:

            mocked_zip_file.return_value = MagicMock(**{'namelist.return_value': [os.path.join('theme', 'theme.xml')]})
            mocked_getroot.return_value = MagicMock(**{'get.return_value': None})
            theme_manager = ThemeManager(None)

            # WHEN: unzip_theme is called
            theme_manager.unzip_theme('theme.file', 'folder')

            # THEN: The critical_error_message_box should have been called
            self.assertEqual(mocked_critical_error_message_box.call_count, 1, 'Should have been called once')
예제 #3
0
    def test_unzip_theme(self):
        """
        Test that unzipping of themes works
        """
        # GIVEN: A theme file, a output folder and some mocked out internal functions
        with patch('openlp.core.ui.thememanager.critical_error_message_box') \
                as mocked_critical_error_message_box:
            theme_manager = ThemeManager(None)
            theme_manager._create_theme_from_xml = MagicMock()
            theme_manager.generate_and_save_image = MagicMock()
            theme_manager.path = ''
            folder = mkdtemp()
            theme_file = os.path.join(TEST_RESOURCES_PATH, 'themes', 'Moss_on_tree.otz')

            # WHEN: We try to unzip it
            theme_manager.unzip_theme(theme_file, folder)

            # THEN: Files should be unpacked
            self.assertTrue(os.path.exists(os.path.join(folder, 'Moss on tree', 'Moss on tree.xml')))
            self.assertEqual(mocked_critical_error_message_box.call_count, 0, 'No errors should have happened')
            shutil.rmtree(folder)
예제 #4
0
    def unzip_theme_invalid_version_test(self):
        """
        Test that themes with invalid (< 2.0) or with no version attributes are rejected
        """
        # GIVEN: An instance of ThemeManager whilst mocking a theme that returns a theme with no version attribute
        with patch('openlp.core.ui.thememanager.zipfile.ZipFile') as mocked_zip_file,\
                patch('openlp.core.ui.thememanager.ElementTree.getroot') as mocked_getroot,\
                patch('openlp.core.ui.thememanager.XML'),\
                patch('openlp.core.ui.thememanager.critical_error_message_box') as mocked_critical_error_message_box:

            mocked_zip_file.return_value = MagicMock(**{
                'namelist.return_value': [os.path.join('theme', 'theme.xml')]
            })
            mocked_getroot.return_value = MagicMock(
                **{'get.return_value': None})
            theme_manager = ThemeManager(None)

            # WHEN: unzip_theme is called
            theme_manager.unzip_theme('theme.file', 'folder')

            # THEN: The critical_error_message_box should have been called
            mocked_critical_error_message_box.assert_called_once(ANY, ANY)
예제 #5
0
    def test_unzip_theme(self):
        """
        Test that unzipping of themes works
        """
        # GIVEN: A theme file, a output folder and some mocked out internal functions
        with patch('openlp.core.ui.thememanager.critical_error_message_box') \
                as mocked_critical_error_message_box:
            theme_manager = ThemeManager(None)
            theme_manager._create_theme_from_xml = MagicMock()
            theme_manager.generate_and_save_image = MagicMock()
            theme_manager.theme_path = None
            folder_path = Path(mkdtemp())
            theme_file_path = RESOURCE_PATH / 'themes' / 'Moss_on_tree.otz'

            # WHEN: We try to unzip it
            theme_manager.unzip_theme(theme_file_path, folder_path)

            # THEN: Files should be unpacked
            assert (folder_path / 'Moss on tree' /
                    'Moss on tree.xml').exists() is True
            assert mocked_critical_error_message_box.call_count == 0, 'No errors should have happened'
            folder_path.rmtree()