From 498d17b00008ed24d24174835352828b17bba6e9 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Fri, 13 Feb 2015 23:10:16 +0000 Subject: [PATCH] Added tests --- openlp/core/ui/thememanager.py | 1 - .../openlp_core_ui/test_thememanager.py | 24 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 6cd3febca..1f6c6bede 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -535,7 +535,6 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ThemeManager, R :param directory: """ self.log_debug('Unzipping theme %s' % file_name) - file_name = str(file_name) theme_zip = None out_file = None file_xml = None diff --git a/tests/functional/openlp_core_ui/test_thememanager.py b/tests/functional/openlp_core_ui/test_thememanager.py index 31efa1f5e..329f8a202 100644 --- a/tests/functional/openlp_core_ui/test_thememanager.py +++ b/tests/functional/openlp_core_ui/test_thememanager.py @@ -27,14 +27,13 @@ import os import shutil from unittest import TestCase -from tests.functional import MagicMock from tempfile import mkdtemp from openlp.core.ui import ThemeManager from openlp.core.common import Registry from tests.utils.constants import TEST_RESOURCES_PATH -from tests.functional import MagicMock, patch +from tests.functional import ANY, MagicMock, patch class TestThemeManager(TestCase): @@ -152,3 +151,24 @@ class TestThemeManager(TestCase): 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) + + 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)