openlp/tests/interfaces/openlp_core/ui/test_thememanager.py

137 lines
5.5 KiB
Python
Raw Normal View History

2013-10-23 19:25:46 +00:00
# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2020 OpenLP Developers #
2019-04-13 13:00:22 +00:00
# ---------------------------------------------------------------------- #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
2013-10-23 19:25:46 +00:00
"""
2013-12-31 20:29:03 +00:00
Interface tests to test the themeManager class and related methods.
2013-10-23 19:25:46 +00:00
"""
from pathlib import Path
2013-10-23 19:25:46 +00:00
from unittest import TestCase
2018-10-02 04:39:42 +00:00
from unittest.mock import MagicMock, patch
2013-10-23 19:25:46 +00:00
2017-10-07 07:05:07 +00:00
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.core.ui.thememanager import ThemeManager
2014-03-13 20:34:46 +00:00
from tests.helpers.testmixin import TestMixin
2013-10-23 19:25:46 +00:00
2014-03-13 20:34:46 +00:00
class TestThemeManager(TestCase, TestMixin):
2013-10-23 19:25:46 +00:00
"""
2013-12-31 20:29:03 +00:00
Test the functions in the ThemeManager module
2013-10-23 19:25:46 +00:00
"""
def setUp(self):
"""
Create the UI
"""
self.setup_application()
2017-11-03 22:52:24 +00:00
self.build_settings()
2013-12-31 20:29:03 +00:00
Registry.create()
Registry().register('settings', Settings())
2013-12-31 20:29:03 +00:00
self.theme_manager = ThemeManager()
2013-10-23 19:25:46 +00:00
def tearDown(self):
"""
Delete all the C++ objects at the end so that we don't have a segfault
"""
2014-03-13 20:34:46 +00:00
self.destroy_settings()
del self.theme_manager
2013-10-23 19:25:46 +00:00
2016-05-31 21:40:13 +00:00
def test_initialise(self):
2013-10-23 19:25:46 +00:00
"""
2013-12-31 20:29:03 +00:00
Test the thememanager initialise - basic test
2013-10-23 19:25:46 +00:00
"""
# GIVEN: A new a call to initialise
self.theme_manager.setup_ui = MagicMock()
2013-12-31 20:29:03 +00:00
self.theme_manager.build_theme_path = MagicMock()
2013-10-23 19:25:46 +00:00
Settings().setValue('themes/global theme', 'my_theme')
2014-03-13 20:37:02 +00:00
# WHEN: the initialisation is run
self.theme_manager.bootstrap_initialise()
2013-10-23 19:25:46 +00:00
# THEN:
self.theme_manager.setup_ui.assert_called_once_with(self.theme_manager)
assert self.theme_manager.global_theme == 'my_theme'
self.theme_manager.build_theme_path.assert_called_once_with()
2013-10-23 19:25:46 +00:00
2017-10-07 07:05:07 +00:00
@patch('openlp.core.ui.thememanager.create_paths')
@patch('openlp.core.ui.thememanager.AppLocation.get_section_data_path')
def test_build_theme_path(self, mocked_get_section_data_path, mocked_create_paths):
2013-10-23 19:25:46 +00:00
"""
2017-10-07 07:05:07 +00:00
Test the thememanager build_theme_path
2013-10-23 19:25:46 +00:00
"""
2017-10-07 07:05:07 +00:00
# GIVEN: A mocked out AppLocation.get_directory() and mocked create_paths
mocked_get_section_data_path.return_value = Path('tests/my_theme')
2013-10-23 19:25:46 +00:00
# WHEN: the build_theme_path is run
2013-12-31 20:29:03 +00:00
self.theme_manager.build_theme_path()
2013-10-23 19:25:46 +00:00
2017-10-07 07:05:07 +00:00
# THEN: The theme path and the thumb path should be correct
assert self.theme_manager.theme_path == Path('tests/my_theme')
assert self.theme_manager.thumb_path == Path('tests/my_theme/thumbnails')
mocked_create_paths.assert_called_once_with(Path('tests/my_theme'), Path('tests/my_theme/thumbnails'))
2017-09-26 16:39:13 +00:00
2016-05-31 21:40:13 +00:00
def test_click_on_new_theme(self):
2013-12-31 21:02:35 +00:00
"""
Test the on_add_theme event handler is called by the UI
"""
# GIVEN: An initial form
Settings().setValue('themes/global theme', 'my_theme')
mocked_event = MagicMock()
self.theme_manager.on_add_theme = mocked_event
self.theme_manager.setup_ui(self.theme_manager)
# WHEN displaying the UI and pressing cancel
new_theme = self.theme_manager.toolbar.actions['newTheme']
new_theme.trigger()
assert mocked_event.call_count == 1, 'The on_add_theme method should have been called once'
2015-02-28 09:41:06 +00:00
@patch('openlp.core.ui.themeform.ThemeForm._setup')
@patch('openlp.core.ui.filerenameform.FileRenameForm._setup')
2017-09-26 16:39:13 +00:00
def test_bootstrap_post(self, mocked_rename_form, mocked_theme_form):
2015-02-28 09:41:06 +00:00
"""
Test the functions of bootstrap_post_setup are called.
"""
# GIVEN:
2017-09-26 16:39:13 +00:00
self.theme_manager.theme_path = MagicMock()
2015-02-28 09:41:06 +00:00
# WHEN:
with patch('openlp.core.ui.thememanager.ThemeProgressForm'):
self.theme_manager.bootstrap_post_set_up()
2015-02-28 09:41:06 +00:00
# THEN:
assert self.theme_manager.progress_form is not None
assert self.theme_manager.theme_form is not None
assert self.theme_manager.file_rename_form is not None
def test_bootstrap_completion(self):
"""
Test the functions of bootstrap_post_setup are called.
"""
# GIVEN:
self.theme_manager.load_themes = MagicMock()
self.theme_manager.upgrade_themes = MagicMock()
# WHEN:
self.theme_manager.bootstrap_completion()
# THEN:
self.theme_manager.upgrade_themes.assert_called_once()
self.theme_manager.load_themes.assert_called_once()