2013-10-23 19:25:46 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2016-12-31 11:01:36 +00:00
|
|
|
# Copyright (c) 2008-2017 OpenLP Developers #
|
2013-10-23 19:25:46 +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; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# 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, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
|
|
|
"""
|
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 unittest import TestCase
|
2017-04-24 05:17:55 +00:00
|
|
|
from unittest.mock import patch, MagicMock
|
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
|
2017-09-26 16:39:13 +00:00
|
|
|
from openlp.core.common.path import Path
|
|
|
|
from openlp.core.ui import ThemeManager
|
2017-04-24 05:17:55 +00:00
|
|
|
|
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
|
|
|
|
"""
|
2014-10-22 20:43:05 +00:00
|
|
|
self.setup_application()
|
2017-11-03 22:52:24 +00:00
|
|
|
self.build_settings()
|
2013-12-31 20:29:03 +00:00
|
|
|
Registry.create()
|
|
|
|
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()
|
2014-11-26 23:34:48 +00:00
|
|
|
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
|
2017-10-10 01:08:09 +00:00
|
|
|
self.theme_manager.setup_ui = MagicMock()
|
2013-12-31 20:29:03 +00:00
|
|
|
self.theme_manager.build_theme_path = MagicMock()
|
|
|
|
self.theme_manager.load_first_time_themes = MagicMock()
|
2017-10-10 01:08:09 +00:00
|
|
|
self.theme_manager.upgrade_themes = 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
|
2013-12-31 20:29:03 +00:00
|
|
|
self.theme_manager.bootstrap_initialise()
|
2013-10-23 19:25:46 +00:00
|
|
|
|
|
|
|
# THEN:
|
2017-10-10 01:08:09 +00:00
|
|
|
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()
|
|
|
|
self.theme_manager.load_first_time_themes.assert_called_once_with()
|
|
|
|
self.theme_manager.upgrade_themes.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:
|
|
|
|
self.theme_manager.load_themes = MagicMock()
|
2017-09-26 16:39:13 +00:00
|
|
|
self.theme_manager.theme_path = MagicMock()
|
2015-02-28 09:41:06 +00:00
|
|
|
|
|
|
|
# WHEN:
|
|
|
|
self.theme_manager.bootstrap_post_set_up()
|
|
|
|
|
|
|
|
# THEN:
|
|
|
|
self.assertEqual(1, self.theme_manager.load_themes.call_count, "load_themes should have been called once")
|