fix up tests

This commit is contained in:
Tim Bentley 2017-05-24 20:31:48 +01:00
parent 6fe9dfeb04
commit 32668193c6
4 changed files with 15 additions and 6 deletions

View File

@ -209,13 +209,23 @@ class Theme(object):
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
"""
jsn = json.loads(theme)
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):
"""
Read in an XML string and parse it.

View File

@ -666,7 +666,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage
:param image_to: Where the Theme Image is to be saved to
"""
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)
check_directory_exists(theme_dir)
theme_file = os.path.join(theme_dir, name + '.json')

View File

@ -102,7 +102,7 @@ class TestTheme(TestCase):
# WHEN: A theme object is created
default_theme = Theme()
# 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.load_theme(save_theme_json)
self.check_theme(lt)

View File

@ -149,14 +149,13 @@ class TestThemeManager(TestCase):
theme_manager.path = self.temp_folder
mocked_theme = MagicMock()
mocked_theme.theme_name = 'theme 愛 name'
mocked_theme.extract_formatted_xml = MagicMock()
mocked_theme.extract_formatted_xml.return_value = 'fake theme 愛 XML'.encode()
mocked_theme.export_theme.return_value = "{}"
# WHEN: Calling _write_theme with a theme with a name with special characters in it
theme_manager._write_theme(mocked_theme, None, None)
# 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!')
def test_over_write_message_box_yes(self):