forked from openlp/openlp
updates
This commit is contained in:
parent
ff4dc581b4
commit
9e376c1e85
@ -516,11 +516,12 @@ class ThemePreviewRenderer(LogMixin, DisplayWindow):
|
||||
# theme.
|
||||
if self.theme_level != ThemeLevel.Global:
|
||||
# When the theme level is at Service and we actually have a service theme then use it.
|
||||
if self.theme_level != ThemeLevel.Service:
|
||||
if self.theme_level == ThemeLevel.Service:
|
||||
theme_name = Registry().get('service_manager').service_theme
|
||||
# If we have Item level and have an item theme then use it.
|
||||
if self.theme_level == ThemeLevel.Song and item.theme:
|
||||
theme_name = item.theme
|
||||
print(theme_name)
|
||||
return theme_name
|
||||
|
||||
def format_slide(self, text, item):
|
||||
|
@ -22,10 +22,20 @@
|
||||
"""
|
||||
Test the :mod:`~openlp.core.display.render` package.
|
||||
"""
|
||||
from unittest.mock import patch
|
||||
import sys
|
||||
|
||||
from unittest import TestCase
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from openlp.core.common import ThemeLevel
|
||||
from tests.helpers.testmixin import TestMixin
|
||||
|
||||
from PyQt5 import QtWidgets
|
||||
sys.modules['PyQt5.QtWebEngineWidgets'] = MagicMock()
|
||||
|
||||
from openlp.core.common.registry import Registry
|
||||
from openlp.core.display.render import compare_chord_lyric_width, find_formatting_tags, remove_tags, render_chords, \
|
||||
render_chords_for_printing, render_tags
|
||||
render_chords_for_printing, render_tags, ThemePreviewRenderer
|
||||
from openlp.core.lib.formattingtags import FormattingTags
|
||||
|
||||
|
||||
@ -208,3 +218,108 @@ def test_find_formatting_tags():
|
||||
|
||||
# THEN: The list of active tags should contain only 'st'
|
||||
assert active_tags == ['st'], 'The list of active tags should contain only "st"'
|
||||
|
||||
|
||||
class TestThemePreviewRenderer(TestMixin, TestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""
|
||||
Set up the components need for all tests.
|
||||
"""
|
||||
# Create the Registry
|
||||
self.application = QtWidgets.QApplication.instance()
|
||||
Registry.create()
|
||||
self.application.setOrganizationName('OpenLP-tests')
|
||||
self.application.setOrganizationDomain('openlp.org')
|
||||
|
||||
def tearDown(self):
|
||||
"""
|
||||
Delete QApplication.
|
||||
"""
|
||||
pass
|
||||
#self.destroy_settings()
|
||||
|
||||
def test_get_theme_global(self):
|
||||
"""
|
||||
Test the return of the global theme if set to Global level
|
||||
"""
|
||||
# GIVEN: A set up with a Global Theme and settings at Global
|
||||
mocked_theme_manager = MagicMock()
|
||||
mocked_theme_manager.global_theme = 'my_global_theme'
|
||||
Registry().register('theme_manager', mocked_theme_manager)
|
||||
with patch('openlp.core.display.webengine.WebEngineView') as mocked_display, \
|
||||
patch('PyQt5.QtWidgets.QVBoxLayout') as mocked_box:
|
||||
tpr = ThemePreviewRenderer()
|
||||
tpr.theme_level = ThemeLevel.Global
|
||||
# WHEN: I Request the theme to Use
|
||||
theme = tpr.get_theme(MagicMock())
|
||||
|
||||
# THEN: The list of active tags should contain only 'st'
|
||||
assert theme == mocked_theme_manager.global_theme, 'The Theme returned is not that of the global theme'
|
||||
|
||||
def test_get_theme_service(self):
|
||||
"""
|
||||
Test the return of the global theme if set to Global level
|
||||
"""
|
||||
# GIVEN: A set up with a Global Theme and settings at Global
|
||||
mocked_theme_manager = MagicMock()
|
||||
mocked_theme_manager.global_theme = 'my_global_theme'
|
||||
mocked_service_manager = MagicMock()
|
||||
mocked_service_manager.service_theme = 'my_service_theme'
|
||||
Registry().register('theme_manager', mocked_theme_manager)
|
||||
Registry().register('service_manager', mocked_service_manager)
|
||||
with patch('openlp.core.display.webengine.WebEngineView') as mocked_display, \
|
||||
patch('PyQt5.QtWidgets.QVBoxLayout') as mocked_box:
|
||||
tpr = ThemePreviewRenderer()
|
||||
tpr.theme_level = ThemeLevel.Service
|
||||
# WHEN: I Request the theme to Use
|
||||
theme = tpr.get_theme(MagicMock())
|
||||
|
||||
# THEN: The list of active tags should contain only 'st'
|
||||
assert theme == mocked_service_manager.service_theme, 'The Theme returned is not that of the Service theme'
|
||||
|
||||
def test_get_theme_item_level_none(self):
|
||||
"""
|
||||
Test the return of the global theme if set to Global level
|
||||
"""
|
||||
# GIVEN: A set up with a Global Theme and settings at Global
|
||||
mocked_theme_manager = MagicMock()
|
||||
mocked_theme_manager.global_theme = 'my_global_theme'
|
||||
mocked_service_manager = MagicMock()
|
||||
mocked_service_manager.service_theme = 'my_service_theme'
|
||||
mocked_item = MagicMock()
|
||||
mocked_item.theme = None
|
||||
Registry().register('theme_manager', mocked_theme_manager)
|
||||
Registry().register('service_manager', mocked_service_manager)
|
||||
with patch('openlp.core.display.webengine.WebEngineView') as mocked_display, \
|
||||
patch('PyQt5.QtWidgets.QVBoxLayout') as mocked_box:
|
||||
tpr = ThemePreviewRenderer()
|
||||
tpr.theme_level = ThemeLevel.Song
|
||||
# WHEN: I Request the theme to Use
|
||||
theme = tpr.get_theme(mocked_item)
|
||||
|
||||
# THEN: The list of active tags should contain only 'st'
|
||||
assert theme == mocked_theme_manager.global_theme, 'The Theme returned is not that of the global theme'
|
||||
|
||||
def test_get_theme_item_level_set(self):
|
||||
"""
|
||||
Test the return of the global theme if set to Global level
|
||||
"""
|
||||
# GIVEN: A set up with a Global Theme and settings at Global
|
||||
mocked_theme_manager = MagicMock()
|
||||
mocked_theme_manager.global_theme = 'my_global_theme'
|
||||
mocked_service_manager = MagicMock()
|
||||
mocked_service_manager.service_theme = 'my_service_theme'
|
||||
mocked_item = MagicMock()
|
||||
mocked_item.theme = "my_item_theme"
|
||||
Registry().register('theme_manager', mocked_theme_manager)
|
||||
Registry().register('service_manager', mocked_service_manager)
|
||||
with patch('openlp.core.display.webengine.WebEngineView') as mocked_display, \
|
||||
patch('PyQt5.QtWidgets.QVBoxLayout') as mocked_box:
|
||||
tpr = ThemePreviewRenderer()
|
||||
tpr.theme_level = ThemeLevel.Song
|
||||
# WHEN: I Request the theme to Use
|
||||
theme = tpr.get_theme(mocked_item)
|
||||
|
||||
# THEN: The list of active tags should contain only 'st'
|
||||
assert theme == mocked_item.theme, 'The Theme returned is not that of the item theme'
|
||||
|
Loading…
Reference in New Issue
Block a user