Fix theme import in windows. Test included.

This commit is contained in:
Tomas Groth 2014-10-31 13:01:07 +01:00
parent f05a4344af
commit 74b582032f
3 changed files with 27 additions and 3 deletions

View File

@ -563,12 +563,12 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager, R
else: else:
abort_import = False abort_import = False
for name in theme_zip.namelist(): for name in theme_zip.namelist():
name = name.replace('/', os.path.sep) out_name = name.replace('/', os.path.sep)
split_name = name.split(os.path.sep) split_name = out_name.split(os.path.sep)
if split_name[-1] == '' or len(split_name) == 1: if split_name[-1] == '' or len(split_name) == 1:
# is directory or preview file # is directory or preview file
continue continue
full_name = os.path.join(directory, name) full_name = os.path.join(directory, out_name)
check_directory_exists(os.path.dirname(full_name)) check_directory_exists(os.path.dirname(full_name))
if os.path.splitext(name)[1].lower() == '.xml': if os.path.splitext(name)[1].lower() == '.xml':
file_xml = str(theme_zip.read(name), 'utf-8') file_xml = str(theme_zip.read(name), 'utf-8')

View File

@ -31,9 +31,11 @@ Package to test the openlp.core.ui.thememanager package.
""" """
import zipfile import zipfile
import os import os
import shutil
from unittest import TestCase from unittest import TestCase
from tests.interfaces import MagicMock from tests.interfaces import MagicMock
from tempfile import mkdtemp
from openlp.core.ui import ThemeManager from openlp.core.ui import ThemeManager
from openlp.core.common import Registry from openlp.core.common import Registry
@ -135,3 +137,25 @@ class TestThemeManager(TestCase):
# THEN: The mocked_copyfile should not have been called # THEN: The mocked_copyfile should not have been called
self.assertTrue(mocked_copyfile.called, 'shutil.copyfile should be 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)

Binary file not shown.