forked from openlp/openlp
fix up tests
This commit is contained in:
parent
6fe9dfeb04
commit
32668193c6
@ -209,13 +209,23 @@ class Theme(object):
|
|||||||
|
|
||||||
def load_theme(self, theme):
|
def load_theme(self, theme):
|
||||||
"""
|
"""
|
||||||
Pull out the XML string formatted for human consumption
|
Convert the JSON file and expand it.
|
||||||
|
|
||||||
:param theme: the theme string
|
:param theme: the theme string
|
||||||
"""
|
"""
|
||||||
jsn = json.loads(theme)
|
jsn = json.loads(theme)
|
||||||
self.expand_json(jsn)
|
self.expand_json(jsn)
|
||||||
|
|
||||||
|
def export_theme(self):
|
||||||
|
"""
|
||||||
|
Loop through the fields and build a dictionary of them
|
||||||
|
|
||||||
|
"""
|
||||||
|
theme_data = {}
|
||||||
|
for attr, value in self.__dict__.items():
|
||||||
|
theme_data["{attr}".format(attr=attr)] = value
|
||||||
|
return json.dumps(theme_data)
|
||||||
|
|
||||||
def parse(self, xml):
|
def parse(self, xml):
|
||||||
"""
|
"""
|
||||||
Read in an XML string and parse it.
|
Read in an XML string and parse it.
|
||||||
|
@ -666,7 +666,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage
|
|||||||
:param image_to: Where the Theme Image is to be saved to
|
:param image_to: Where the Theme Image is to be saved to
|
||||||
"""
|
"""
|
||||||
name = theme.theme_name
|
name = theme.theme_name
|
||||||
theme_pretty = json.dumps(theme, default=json_default)
|
theme_pretty = theme.export_theme()
|
||||||
theme_dir = os.path.join(self.path, name)
|
theme_dir = os.path.join(self.path, name)
|
||||||
check_directory_exists(theme_dir)
|
check_directory_exists(theme_dir)
|
||||||
theme_file = os.path.join(theme_dir, name + '.json')
|
theme_file = os.path.join(theme_dir, name + '.json')
|
||||||
|
@ -102,7 +102,7 @@ class TestTheme(TestCase):
|
|||||||
# WHEN: A theme object is created
|
# WHEN: A theme object is created
|
||||||
default_theme = Theme()
|
default_theme = Theme()
|
||||||
# THEN: The default values should be correct
|
# THEN: The default values should be correct
|
||||||
save_theme_json = json.dumps(default_theme, default=json_default)
|
save_theme_json = default_theme.export_theme()
|
||||||
lt = Theme()
|
lt = Theme()
|
||||||
lt.load_theme(save_theme_json)
|
lt.load_theme(save_theme_json)
|
||||||
self.check_theme(lt)
|
self.check_theme(lt)
|
||||||
|
@ -149,14 +149,13 @@ class TestThemeManager(TestCase):
|
|||||||
theme_manager.path = self.temp_folder
|
theme_manager.path = self.temp_folder
|
||||||
mocked_theme = MagicMock()
|
mocked_theme = MagicMock()
|
||||||
mocked_theme.theme_name = 'theme 愛 name'
|
mocked_theme.theme_name = 'theme 愛 name'
|
||||||
mocked_theme.extract_formatted_xml = MagicMock()
|
mocked_theme.export_theme.return_value = "{}"
|
||||||
mocked_theme.extract_formatted_xml.return_value = 'fake theme 愛 XML'.encode()
|
|
||||||
|
|
||||||
# WHEN: Calling _write_theme with a theme with a name with special characters in it
|
# WHEN: Calling _write_theme with a theme with a name with special characters in it
|
||||||
theme_manager._write_theme(mocked_theme, None, None)
|
theme_manager._write_theme(mocked_theme, None, None)
|
||||||
|
|
||||||
# THEN: It should have been created
|
# THEN: It should have been created
|
||||||
self.assertTrue(os.path.exists(os.path.join(self.temp_folder, 'theme 愛 name', 'theme 愛 name.xml')),
|
self.assertTrue(os.path.exists(os.path.join(self.temp_folder, 'theme 愛 name', 'theme 愛 name.json')),
|
||||||
'Theme with special characters should have been created!')
|
'Theme with special characters should have been created!')
|
||||||
|
|
||||||
def test_over_write_message_box_yes(self):
|
def test_over_write_message_box_yes(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user