forked from openlp/openlp
Fix up test
This commit is contained in:
parent
30825cb8d1
commit
748eb9cd0b
@ -34,60 +34,21 @@ class TestThemeManager(TestCase):
|
|||||||
"""
|
"""
|
||||||
Test the functions in the ThemeManager Class
|
Test the functions in the ThemeManager Class
|
||||||
"""
|
"""
|
||||||
def test_select_image_file_dialog_cancelled(self):
|
def setUp(self):
|
||||||
"""
|
with patch('openlp.core.ui.ThemeForm._setup'):
|
||||||
Test the select image file dialog when the user presses cancel
|
self.instance = ThemeForm(None)
|
||||||
"""
|
|
||||||
# GIVEN: An instance of Theme Form and mocked QFileDialog which returns an empty string (similating a user
|
|
||||||
# pressing cancel)
|
|
||||||
with patch('openlp.core.ui.ThemeForm._setup'),\
|
|
||||||
patch('openlp.core.ui.themeform.get_images_filter',
|
|
||||||
**{'return_value': 'Image Files (*.bmp; *.gif)(*.bmp *.gif)'}),\
|
|
||||||
patch('openlp.core.ui.themeform.QtWidgets.QFileDialog.getOpenFileName',
|
|
||||||
**{'return_value': ('', '')}) as mocked_get_open_file_name,\
|
|
||||||
patch('openlp.core.ui.themeform.translate', **{'return_value': 'Translated String'}),\
|
|
||||||
patch('openlp.core.ui.ThemeForm.set_background_page_values') as mocked_set_background_page_values:
|
|
||||||
instance = ThemeForm(None)
|
|
||||||
mocked_image_file_edit = MagicMock()
|
|
||||||
mocked_image_file_edit.text.return_value = '/original_path/file.ext'
|
|
||||||
instance.image_path_edit = mocked_image_file_edit
|
|
||||||
|
|
||||||
# WHEN: on_image_browse_button is clicked
|
def test_on_image_path_edit_path_changed(self):
|
||||||
instance.on_image_path_edit_path_changed()
|
"""
|
||||||
|
Test the `image_path_edit.pathChanged` handler
|
||||||
|
"""
|
||||||
|
# GIVEN: An instance of Theme Form
|
||||||
|
with patch.object(self.instance, 'set_background_page_values') as mocked_set_background_page_values:
|
||||||
|
self.instance.theme = MagicMock()
|
||||||
|
|
||||||
# THEN: The QFileDialog getOpenFileName and set_background_page_values moethods should have been called
|
# WHEN: `on_image_path_edit_path_changed` is clicked
|
||||||
# with known arguments
|
self.instance.on_image_path_edit_path_changed('/new/pat.h')
|
||||||
mocked_get_open_file_name.assert_called_once_with(instance, 'Translated String', '/original_path/file.ext',
|
|
||||||
'Image Files (*.bmp; *.gif)(*.bmp *.gif);;'
|
# THEN: The theme background file should be set and `set_background_page_values` should have been called
|
||||||
'All Files (*.*)')
|
self.assertEqual(self.instance.theme.background_filename, '/new/pat.h')
|
||||||
mocked_set_background_page_values.assert_called_once_with()
|
mocked_set_background_page_values.assert_called_once_with()
|
||||||
|
|
||||||
def test_select_image_file_dialog_new_file(self):
|
|
||||||
"""
|
|
||||||
Test the select image file dialog when the user presses ok
|
|
||||||
"""
|
|
||||||
# GIVEN: An instance of Theme Form and mocked QFileDialog which returns a file path
|
|
||||||
with patch('openlp.core.ui.ThemeForm._setup'),\
|
|
||||||
patch('openlp.core.ui.themeform.get_images_filter',
|
|
||||||
**{'return_value': 'Image Files (*.bmp; *.gif)(*.bmp *.gif)'}),\
|
|
||||||
patch('openlp.core.ui.themeform.QtWidgets.QFileDialog.getOpenFileName',
|
|
||||||
**{'return_value': ('/new_path/file.ext', '')}) as mocked_get_open_file_name,\
|
|
||||||
patch('openlp.core.ui.themeform.translate', **{'return_value': 'Translated String'}),\
|
|
||||||
patch('openlp.core.ui.ThemeForm.set_background_page_values') as mocked_background_page_values:
|
|
||||||
instance = ThemeForm(None)
|
|
||||||
mocked_image_file_edit = MagicMock()
|
|
||||||
mocked_image_file_edit.text.return_value = '/original_path/file.ext'
|
|
||||||
instance.image_path_edit = mocked_image_file_edit
|
|
||||||
instance.theme = MagicMock()
|
|
||||||
|
|
||||||
# WHEN: on_image_browse_button is clicked
|
|
||||||
instance.on_image_path_edit_path_changed()
|
|
||||||
|
|
||||||
# THEN: The QFileDialog getOpenFileName and set_background_page_values moethods should have been called
|
|
||||||
# with known arguments and theme.background_filename should be set
|
|
||||||
mocked_get_open_file_name.assert_called_once_with(instance, 'Translated String', '/original_path/file.ext',
|
|
||||||
'Image Files (*.bmp; *.gif)(*.bmp *.gif);;'
|
|
||||||
'All Files (*.*)')
|
|
||||||
self.assertEqual(instance.theme.background_filename, '/new_path/file.ext',
|
|
||||||
'theme.background_filename should be set to the path that the file dialog returns')
|
|
||||||
mocked_background_page_values.assert_called_once_with()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user