diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index b07c7fd2b..03890a028 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -563,12 +563,12 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager, R else: abort_import = False for name in theme_zip.namelist(): - name = name.replace('/', os.path.sep) - split_name = name.split(os.path.sep) + out_name = name.replace('/', os.path.sep) + split_name = out_name.split(os.path.sep) if split_name[-1] == '' or len(split_name) == 1: # is directory or preview file continue - full_name = os.path.join(directory, name) + full_name = os.path.join(directory, out_name) check_directory_exists(os.path.dirname(full_name)) if os.path.splitext(name)[1].lower() == '.xml': file_xml = str(theme_zip.read(name), 'utf-8') diff --git a/tests/functional/openlp_core_ui/test_thememanager.py b/tests/functional/openlp_core_ui/test_thememanager.py index d8f2116f9..287ab6219 100644 --- a/tests/functional/openlp_core_ui/test_thememanager.py +++ b/tests/functional/openlp_core_ui/test_thememanager.py @@ -31,9 +31,11 @@ Package to test the openlp.core.ui.thememanager package. """ import zipfile import os +import shutil from unittest import TestCase from tests.interfaces import MagicMock +from tempfile import mkdtemp from openlp.core.ui import ThemeManager from openlp.core.common import Registry @@ -135,3 +137,25 @@ class TestThemeManager(TestCase): # THEN: The mocked_copyfile should not have been called self.assertTrue(mocked_copyfile.called, 'shutil.copyfile should be called') + + 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) diff --git a/tests/resources/themes/Moss_on_tree.otz b/tests/resources/themes/Moss_on_tree.otz new file mode 100755 index 000000000..14d8c829e Binary files /dev/null and b/tests/resources/themes/Moss_on_tree.otz differ