From 9e376c1e857933f49c8e482bcbb7e3e203887242 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 30 Aug 2019 10:23:12 +0100 Subject: [PATCH] updates --- openlp/core/display/render.py | 3 +- .../openlp_core/display/test_render.py | 119 +++++++++++++++++- 2 files changed, 119 insertions(+), 3 deletions(-) diff --git a/openlp/core/display/render.py b/openlp/core/display/render.py index 8d4bff425..625f8fd42 100644 --- a/openlp/core/display/render.py +++ b/openlp/core/display/render.py @@ -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): diff --git a/tests/functional/openlp_core/display/test_render.py b/tests/functional/openlp_core/display/test_render.py index ac47b42fe..9ef1235e7 100644 --- a/tests/functional/openlp_core/display/test_render.py +++ b/tests/functional/openlp_core/display/test_render.py @@ -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'