openlp/tests/functional/openlp_core/lib/test_serviceitem.py

470 lines
24 KiB
Python
Raw Normal View History

# -*- 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/>. #
##########################################################################
2012-12-08 08:50:21 +00:00
"""
Package to test the openlp.core.lib package.
2012-12-08 08:50:21 +00:00
"""
2013-01-19 20:46:11 +00:00
import os
from pathlib import Path
2012-12-08 08:50:21 +00:00
from unittest import TestCase
from unittest.mock import Mock, MagicMock, patch
2012-12-08 11:21:57 +00:00
2018-12-02 08:39:53 +00:00
from openlp.core.state import State
from openlp.core.common import ThemeLevel, md5_hash
from openlp.core.common.enum import ServiceItemType
2017-10-07 07:05:07 +00:00
from openlp.core.common.registry import Registry
2017-12-17 17:52:17 +00:00
from openlp.core.common.settings import Settings
from openlp.core.lib.formattingtags import FormattingTags
from openlp.core.lib.serviceitem import ItemCapabilities, ServiceItem
2017-12-17 17:52:17 +00:00
from tests.helpers.testmixin import TestMixin
2018-11-16 04:34:49 +00:00
from tests.utils import convert_file_service_item
2017-12-22 22:21:38 +00:00
from tests.utils.constants import RESOURCE_PATH
2018-10-02 04:39:42 +00:00
2013-08-31 18:17:38 +00:00
VERSE = 'The Lord said to {r}Noah{/r}: \n'\
2012-12-08 11:21:57 +00:00
'There\'s gonna be a {su}floody{/su}, {sb}floody{/sb}\n'\
'The Lord said to {g}Noah{/g}:\n'\
'There\'s gonna be a {st}floody{/st}, {it}floody{/it}\n'\
'Get those children out of the muddy, muddy \n'\
'{r}C{/r}{b}h{/b}{bl}i{/bl}{y}l{/y}{g}d{/g}{pk}'\
'r{/pk}{o}e{/o}{pp}n{/pp} of the Lord\n'
2018-12-01 05:52:49 +00:00
CLEANED_VERSE = 'Amazing Grace! how sweet the sound\n'\
'That saved a wretch like me;\n'\
'I once was lost, but now am found,\n'\
'Was blind, but now I see.\n'
2017-04-19 19:37:08 +00:00
RENDERED_VERSE = 'The Lord said to <span style="-webkit-text-fill-color:red">Noah</span>: \n'\
'There&#x27;s gonna be a <sup>floody</sup>, <sub>floody</sub>\n'\
'The Lord said to <span style="-webkit-text-fill-color:green">Noah</span>:\n'\
'There&#x27;s gonna be a <strong>floody</strong>, <em>floody</em>\n'\
'Get those children out of the muddy, muddy \n'\
'<span style="-webkit-text-fill-color:red">C</span><span style="-webkit-text-fill-color:black">h' \
'</span><span style="-webkit-text-fill-color:blue">i</span>'\
'<span style="-webkit-text-fill-color:yellow">l</span><span style="-webkit-text-fill-color:green">d'\
'</span><span style="-webkit-text-fill-color:#FFC0CB">r</span>'\
'<span style="-webkit-text-fill-color:#FFA500">e</span><span style="-webkit-text-fill-color:#800080">'\
'n</span> of the Lord\n'
2013-08-31 18:17:38 +00:00
FOOTER = ['Arky Arky (Unknown)', 'Public Domain', 'CCLI 123456']
2018-12-01 05:52:49 +00:00
TEST_PATH = RESOURCE_PATH / 'service'
2017-12-17 17:52:17 +00:00
__default_settings__ = {
'songs/enable chords': True,
}
2013-01-20 10:01:51 +00:00
2017-12-17 17:52:17 +00:00
class TestServiceItem(TestCase, TestMixin):
2012-12-08 08:50:21 +00:00
2013-01-22 21:59:45 +00:00
def setUp(self):
"""
Set up the Registry
"""
2017-12-17 17:52:17 +00:00
self.build_settings()
self.setting.extend_default_settings(__default_settings__)
self.setting.setValue('songs/chord notation', 'english')
2013-02-16 18:24:31 +00:00
Registry.create()
Registry().register('settings', self.setting)
2019-02-13 19:41:10 +00:00
# Mock the renderer and its format_slide method
2013-01-27 20:59:02 +00:00
mocked_renderer = MagicMock()
2019-02-13 20:28:10 +00:00
2019-02-13 19:41:10 +00:00
def side_effect_return_arg(arg1, arg2):
return [arg1]
mocked_slide_formater = MagicMock(side_effect=side_effect_return_arg)
mocked_renderer.format_slide = mocked_slide_formater
2013-08-31 18:17:38 +00:00
Registry().register('renderer', mocked_renderer)
Registry().register('image_manager', MagicMock())
2013-01-22 21:59:45 +00:00
2017-12-17 17:52:17 +00:00
def tearDown(self):
"""
Clean up
"""
self.destroy_settings()
2016-05-31 21:40:13 +00:00
def test_service_item_basic(self):
2012-12-08 08:50:21 +00:00
"""
2013-01-20 10:01:51 +00:00
Test the Service Item - basic test
2012-12-08 08:50:21 +00:00
"""
2013-01-19 18:31:22 +00:00
# GIVEN: A new service item
2012-12-09 20:57:41 +00:00
2013-02-16 20:00:31 +00:00
# WHEN: A service item is created (without a plugin)
2012-12-09 20:57:41 +00:00
service_item = ServiceItem(None)
2013-01-19 18:31:22 +00:00
# THEN: We should get back a valid service item
2017-12-17 17:52:17 +00:00
assert service_item.is_valid is True, 'The new service item should be valid'
assert service_item.missing_frames() is True, 'There should not be any frames in the service item'
2012-12-08 11:21:57 +00:00
2016-05-31 21:40:13 +00:00
def test_service_item_load_custom_from_service(self):
2013-01-20 10:01:51 +00:00
"""
2013-01-20 17:12:33 +00:00
Test the Service Item - adding a custom slide from a saved service
2013-01-20 10:01:51 +00:00
"""
# GIVEN: A new service item and a mocked add icon function
2013-01-20 10:01:51 +00:00
service_item = ServiceItem(None)
service_item.add_icon = MagicMock()
2017-04-19 19:37:08 +00:00
FormattingTags.load_tags()
2013-01-24 19:38:38 +00:00
2018-12-02 08:39:53 +00:00
# WHEN: We add a custom from a saved serviceand set the media state
2013-09-29 21:28:53 +00:00
line = convert_file_service_item(TEST_PATH, 'serviceitem_custom_1.osj')
2018-12-02 08:39:53 +00:00
State().add_service("media", 0)
State().update_pre_conditions("media", True)
State().flush_preconditions()
service_item.set_from_service(line)
2013-01-20 10:01:51 +00:00
# THEN: We should get back a valid service item
2017-12-18 17:10:04 +00:00
assert service_item.is_valid is True, 'The new service item should be valid'
2018-11-16 04:34:49 +00:00
assert len(service_item.get_frames()) == 2, 'The service item should have 2 display frames'
assert len(service_item.capabilities) == 5, 'There should be 5 default custom item capabilities'
2013-09-22 21:11:03 +00:00
# THEN: The frames should also be valid
2017-12-17 17:52:17 +00:00
assert 'Test Custom' == service_item.get_display_title(), 'The title should be "Test Custom"'
2019-02-13 19:41:10 +00:00
assert 'Slide 1' == service_item.get_frames()[0]['text']
assert 'Slide 2' == service_item.get_rendered_frame(1)
2019-02-12 19:55:08 +00:00
assert 'Slide 1' == service_item.get_frame_title(0), '"Slide 1" has been returned as the title'
assert 'Slide 2' == service_item.get_frame_title(1), '"Slide 2" has been returned as the title'
assert '' == service_item.get_frame_title(2), 'Blank has been returned as the title of slide 3'
2013-09-22 21:11:03 +00:00
2016-05-31 21:40:13 +00:00
def test_service_item_load_image_from_service(self):
2013-01-20 17:12:33 +00:00
"""
Test the Service Item - adding an image from a saved service
"""
# GIVEN: A new service item and a mocked add icon function
2013-08-31 18:17:38 +00:00
image_name = 'image_1.jpg'
2019-03-10 21:01:39 +00:00
test_file = TEST_PATH / image_name
frame_array = {'path': test_file, 'title': image_name}
2013-02-16 18:24:31 +00:00
2013-01-20 17:12:33 +00:00
service_item = ServiceItem(None)
service_item.add_icon = MagicMock()
2013-01-20 17:12:33 +00:00
2013-02-16 18:24:31 +00:00
# WHEN: adding an image from a saved Service and mocked exists
2013-09-22 21:11:03 +00:00
line = convert_file_service_item(TEST_PATH, 'serviceitem_image_1.osj')
2014-09-10 07:34:38 +00:00
with patch('openlp.core.ui.servicemanager.os.path.exists') as mocked_exists,\
patch('openlp.core.lib.serviceitem.AppLocation.get_section_data_path') as \
mocked_get_section_data_path:
mocked_exists.return_value = True
2018-12-01 05:52:49 +00:00
mocked_get_section_data_path.return_value = Path('/path/')
2019-03-15 20:56:32 +00:00
service_item.set_from_service(line, TEST_PATH)
2013-01-20 17:12:33 +00:00
# THEN: We should get back a valid service item
2017-12-17 17:52:17 +00:00
assert service_item.is_valid is True, 'The new service item should be valid'
2018-12-01 05:52:49 +00:00
assert test_file == service_item.get_rendered_frame(0), 'The first frame should match the path to the image'
2017-12-17 17:52:17 +00:00
assert frame_array == service_item.get_frames()[0], 'The return should match frame array1'
2019-03-15 20:56:32 +00:00
assert test_file == service_item.get_frame_path(0), \
2018-12-11 20:39:56 +00:00
'The frame path should match the full path to the image'
2017-12-17 17:52:17 +00:00
assert image_name == service_item.get_frame_title(0), 'The frame title should match the image name'
assert image_name == service_item.get_display_title(), 'The display title should match the first image name'
assert service_item.is_image() is True, 'This service item should be of an "image" type'
assert service_item.is_capable(ItemCapabilities.CanMaintain) is True, \
'This service item should be able to be Maintained'
assert service_item.is_capable(ItemCapabilities.CanPreview) is True, \
'This service item should be able to be be Previewed'
assert service_item.is_capable(ItemCapabilities.CanLoop) is True, \
'This service item should be able to be run in a can be made to Loop'
assert service_item.is_capable(ItemCapabilities.CanAppend) is True, \
'This service item should be able to have new items added to it'
2013-09-22 21:11:03 +00:00
2018-12-01 05:52:49 +00:00
@patch('openlp.core.lib.serviceitem.os.path.exists')
@patch('openlp.core.lib.serviceitem.AppLocation.get_section_data_path')
def test_service_item_load_image_from_local_service(self, mocked_get_section_data_path, mocked_exists):
2013-02-16 20:04:26 +00:00
"""
Test the Service Item - adding an image from a saved local service
"""
# GIVEN: A new service item and a mocked add icon function
2018-12-01 05:52:49 +00:00
mocked_get_section_data_path.return_value = Path('/path')
mocked_exists.return_value = True
2013-08-31 18:17:38 +00:00
image_name1 = 'image_1.jpg'
image_name2 = 'image_2.jpg'
2018-12-01 05:52:49 +00:00
test_file1 = os.path.join('/home', 'openlp', image_name1)
test_file2 = os.path.join('/home', 'openlp', image_name2)
frame_array1 = {'path': test_file1, 'title': image_name1}
frame_array2 = {'path': test_file2, 'title': image_name2}
2013-02-16 20:04:26 +00:00
service_item = ServiceItem(None)
service_item.add_icon = MagicMock()
service_item2 = ServiceItem(None)
service_item2.add_icon = MagicMock()
2013-02-16 20:04:26 +00:00
# WHEN: adding an image from a saved Service and mocked exists
2013-09-22 21:11:03 +00:00
line = convert_file_service_item(TEST_PATH, 'serviceitem_image_2.osj')
line2 = convert_file_service_item(TEST_PATH, 'serviceitem_image_2.osj', 1)
2018-12-01 05:52:49 +00:00
service_item2.set_from_service(line2)
service_item.set_from_service(line)
# THEN: We should get back a valid service item
2017-12-17 17:52:17 +00:00
assert service_item.is_valid is True, 'The first service item should be valid'
assert service_item2.is_valid is True, 'The second service item should be valid'
2014-03-13 20:59:10 +00:00
# These test will fail on windows due to the difference in folder seperators
if os.name != 'nt':
2017-12-17 17:52:17 +00:00
assert test_file1 == service_item.get_rendered_frame(0), \
'The first frame should match the path to the image'
assert test_file2 == service_item2.get_rendered_frame(0), \
'The Second frame should match the path to the image'
assert frame_array1 == service_item.get_frames()[0], 'The return should match the frame array1'
assert frame_array2 == service_item2.get_frames()[0], 'The return should match the frame array2'
2018-12-11 20:52:17 +00:00
assert test_file1 == str(service_item.get_frame_path(0)), \
2017-12-17 17:52:17 +00:00
'The frame path should match the full path to the image'
2018-12-11 21:01:03 +00:00
assert test_file2 == str(service_item2.get_frame_path(0)), \
2017-12-17 17:52:17 +00:00
'The frame path should match the full path to the image'
assert image_name1 == service_item.get_frame_title(0), 'The 1st frame title should match the image name'
assert image_name2 == service_item2.get_frame_title(0), 'The 2nd frame title should match the image name'
assert service_item.name == service_item.title.lower(), \
'The plugin name should match the display title, as there are > 1 Images'
assert service_item.is_image() is True, 'This service item should be of an "image" type'
assert service_item.is_capable(ItemCapabilities.CanMaintain) is True, \
'This service item should be able to be Maintained'
assert service_item.is_capable(ItemCapabilities.CanPreview) is True, \
'This service item should be able to be be Previewed'
assert service_item.is_capable(ItemCapabilities.CanLoop) is True, \
'This service item should be able to be run in a can be made to Loop'
assert service_item.is_capable(ItemCapabilities.CanAppend) is True, \
'This service item should be able to have new items added to it'
2016-05-31 21:40:13 +00:00
def test_add_from_command_for_a_presentation(self):
"""
Test the Service Item - adding a presentation
"""
# GIVEN: A service item, a mocked icon and presentation data
service_item = ServiceItem(None)
presentation_name = 'test.pptx'
image = MagicMock()
2013-10-28 02:33:28 +00:00
display_title = 'DisplayTitle'
notes = 'Note1\nNote2\n'
2013-12-30 08:35:05 +00:00
frame = {'title': presentation_name, 'image': image, 'path': TEST_PATH,
2018-11-16 04:34:49 +00:00
'display_title': display_title, 'notes': notes, 'thumbnail': image}
2013-12-30 08:35:05 +00:00
# WHEN: adding presentation to service_item
2013-10-28 02:33:28 +00:00
service_item.add_from_command(TEST_PATH, presentation_name, image, display_title, notes)
2013-12-30 08:35:05 +00:00
# THEN: verify that it is setup as a Command and that the frame data matches
2017-12-17 17:52:17 +00:00
assert service_item.service_item_type == ServiceItemType.Command, 'It should be a Command'
assert service_item.get_frames()[0] == frame, 'Frames should match'
2018-11-16 04:34:49 +00:00
def test_add_from_command_without_display_title_and_notes(self):
"""
Test the Service Item - add from command, but not presentation
"""
# GIVEN: A new service item, a mocked icon and image data
service_item = ServiceItem(None)
image_name = 'test.img'
image = MagicMock()
2013-12-30 08:35:05 +00:00
frame = {'title': image_name, 'image': image, 'path': TEST_PATH,
2018-11-16 04:34:49 +00:00
'display_title': None, 'notes': None, 'thumbnail': image}
2013-12-30 08:35:05 +00:00
# WHEN: adding image to service_item
service_item.add_from_command(TEST_PATH, image_name, image)
2013-12-30 08:35:05 +00:00
# THEN: verify that it is setup as a Command and that the frame data matches
2017-12-17 17:52:17 +00:00
assert service_item.service_item_type == ServiceItemType.Command, 'It should be a Command'
assert service_item.get_frames()[0] == frame, 'Frames should match'
2014-09-08 21:08:49 +00:00
@patch(u'openlp.core.lib.serviceitem.ServiceItem.image_manager')
2015-06-13 14:48:57 +00:00
@patch('openlp.core.lib.serviceitem.AppLocation.get_section_data_path')
2016-05-31 21:40:13 +00:00
def test_add_from_command_for_a_presentation_thumb(self, mocked_get_section_data_path, mocked_image_manager):
2015-06-10 21:43:03 +00:00
"""
Test the Service Item - adding a presentation, updating the thumb path & adding the thumb to image_manager
2015-06-10 21:43:03 +00:00
"""
2015-06-13 14:48:57 +00:00
# GIVEN: A service item, a mocked AppLocation and presentation data
2018-12-01 05:52:49 +00:00
mocked_get_section_data_path.return_value = Path('mocked') / 'section' / 'path'
2015-06-13 14:48:57 +00:00
service_item = ServiceItem(None)
service_item.add_capability(ItemCapabilities.HasThumbnails)
2015-06-13 14:48:57 +00:00
service_item.has_original_files = False
service_item.name = 'presentations'
presentation_name = 'test.pptx'
2018-12-01 05:52:49 +00:00
thumb = Path('tmp') / 'test' / 'thumb.png'
2015-06-13 14:48:57 +00:00
display_title = 'DisplayTitle'
notes = 'Note1\nNote2\n'
2018-12-01 05:52:49 +00:00
expected_thumb_path = Path('mocked') / 'section' / 'path' / 'thumbnails' / \
md5_hash(str(TEST_PATH / presentation_name).encode('utf8')) / 'thumb.png'
frame = {'title': presentation_name, 'image': str(expected_thumb_path), 'path': str(TEST_PATH),
'display_title': display_title, 'notes': notes, 'thumbnail': str(expected_thumb_path)}
2015-06-13 14:48:57 +00:00
# WHEN: adding presentation to service_item
2018-12-01 05:52:49 +00:00
service_item.add_from_command(str(TEST_PATH), presentation_name, thumb, display_title, notes)
2015-06-13 14:48:57 +00:00
# THEN: verify that it is setup as a Command and that the frame data matches
2017-12-17 17:52:17 +00:00
assert service_item.service_item_type == ServiceItemType.Command, 'It should be a Command'
assert service_item.get_frames()[0] == frame, 'Frames should match'
2018-11-16 04:34:49 +00:00
# assert 1 == mocked_image_manager.add_image.call_count, 'image_manager should be used'
2015-06-10 21:43:03 +00:00
2016-05-31 21:40:13 +00:00
def test_service_item_load_optical_media_from_service(self):
"""
Test the Service Item - load an optical media item
"""
# GIVEN: A new service item and a mocked add icon function
service_item = ServiceItem(None)
service_item.add_icon = MagicMock()
# WHEN: We load a serviceitem with optical media
line = convert_file_service_item(TEST_PATH, 'serviceitem-dvd.osj')
with patch('openlp.core.ui.servicemanager.os.path.exists') as mocked_exists:
mocked_exists.return_value = True
service_item.set_from_service(line)
# THEN: We should get back a valid service item with optical media info
2017-12-17 17:52:17 +00:00
assert service_item.is_valid is True, 'The service item should be valid'
2017-12-17 20:19:19 +00:00
assert service_item.is_capable(ItemCapabilities.IsOptical) is True, 'The item should be Optical'
assert service_item.start_time == 654.375, 'Start time should be 654.375'
assert service_item.end_time == 672.069, 'End time should be 672.069'
2017-12-17 17:52:17 +00:00
assert service_item.media_length == 17.694, 'Media length should be 17.694'
2016-05-31 21:40:13 +00:00
def test_service_item_load_song_and_audio_from_service(self):
"""
Test the Service Item - adding a song slide from a saved service
"""
# GIVEN: A new service item and a mocked add icon function
service_item = ServiceItem(None)
service_item.add_icon = MagicMock()
2017-04-19 19:37:08 +00:00
FormattingTags.load_tags()
# WHEN: We add a custom from a saved service
line = convert_file_service_item(TEST_PATH, 'serviceitem-song-linked-audio.osj')
2019-03-15 20:56:32 +00:00
service_item.set_from_service(line, Path('/test/'))
# THEN: We should get back a valid service item
2017-12-18 17:10:04 +00:00
assert service_item.is_valid is True, 'The new service item should be valid'
2018-12-01 05:52:49 +00:00
assert len(service_item.display_slides) == 6, 'The service item should have 6 display slides'
assert len(service_item.capabilities) == 7, 'There should be 7 default custom item capabilities'
2017-12-17 17:52:17 +00:00
assert 'Amazing Grace' == service_item.get_display_title(), 'The title should be "Amazing Grace"'
assert CLEANED_VERSE[:-1] == service_item.get_frames()[0]['text'], \
'The returned text matches the input, except the last line feed'
assert 'Amazing Grace! how sweet the s' == service_item.get_frame_title(0), \
'"Amazing Grace! how sweet the s" has been returned as the title'
assert 'Twas grace that taught my hea' == service_item.get_frame_title(1), \
'"Twas grace that taught my hea" has been returned as the title'
2018-01-13 07:24:20 +00:00
assert Path('/test/amazing_grace.mp3') == service_item.background_audio[0], \
2017-12-17 17:52:17 +00:00
'"/test/amazing_grace.mp3" should be in the background_audio list'
def test_service_item_get_theme_data_global_level(self):
"""
Test the service item - get theme data when set to global theme level
"""
# GIVEN: A service item with a theme and theme level set to global
service_item = ServiceItem(None)
service_item.theme = 'song_theme'
mocked_theme_manager = MagicMock()
mocked_theme_manager.global_theme = 'global_theme'
mocked_theme_manager.get_theme_data = Mock(side_effect=lambda value: value)
Registry().register('theme_manager', mocked_theme_manager)
Settings().setValue('servicemanager/service theme', 'service_theme')
Settings().setValue('themes/theme level', ThemeLevel.Global)
# WHEN: Get theme data is run
theme = service_item.get_theme_data()
# THEN: theme should be the global theme
assert theme == mocked_theme_manager.global_theme
def test_service_item_get_theme_data_service_level_service_undefined(self):
"""
Test the service item - get theme data when set to service theme level
"""
# GIVEN: A service item with a theme and theme level set to service
service_item = ServiceItem(None)
service_item.theme = 'song_theme'
mocked_theme_manager = MagicMock()
mocked_theme_manager.global_theme = 'global_theme'
mocked_theme_manager.get_theme_data = Mock(side_effect=lambda value: value)
Registry().register('theme_manager', mocked_theme_manager)
Settings().setValue('servicemanager/service theme', 'service_theme')
Settings().setValue('themes/theme level', ThemeLevel.Service)
# WHEN: Get theme data is run
theme = service_item.get_theme_data()
# THEN: theme should be the global theme
assert theme == mocked_theme_manager.global_theme
def test_service_item_get_theme_data_service_level_service_defined(self):
"""
Test the service item - get theme data when set to service theme level
"""
# GIVEN: A service item with a theme and theme level set to service
service_item = ServiceItem(None)
service_item.theme = 'song_theme'
service_item.from_service = True
mocked_theme_manager = MagicMock()
mocked_theme_manager.global_theme = 'global_theme'
mocked_theme_manager.get_theme_data = Mock(side_effect=lambda value: value)
Registry().register('theme_manager', mocked_theme_manager)
Settings().setValue('servicemanager/service theme', 'service_theme')
Settings().setValue('themes/theme level', ThemeLevel.Service)
# WHEN: Get theme data is run
theme = service_item.get_theme_data()
# THEN: theme should be the service theme
assert theme == Settings().value('servicemanager/service theme')
def test_service_item_get_theme_data_song_level(self):
"""
Test the service item - get theme data when set to song theme level
"""
# GIVEN: A service item with a theme and theme level set to song
service_item = ServiceItem(None)
service_item.theme = 'song_theme'
mocked_theme_manager = MagicMock()
mocked_theme_manager.global_theme = 'global_theme'
mocked_theme_manager.get_theme_data = Mock(side_effect=lambda value: value)
Registry().register('theme_manager', mocked_theme_manager)
Settings().setValue('servicemanager/service theme', 'service_theme')
Settings().setValue('themes/theme level', ThemeLevel.Song)
# WHEN: Get theme data is run
theme = service_item.get_theme_data()
# THEN: theme should be the song theme
assert theme == service_item.theme
def test_service_item_get_theme_data_song_level_service_fallback(self):
"""
Test the service item - get theme data when set to song theme level
but the song theme doesn't exist
"""
# GIVEN: A service item with a theme and theme level set to song
service_item = ServiceItem(None)
service_item.from_service = True
mocked_theme_manager = MagicMock()
mocked_theme_manager.global_theme = 'global_theme'
mocked_theme_manager.get_theme_data = Mock(side_effect=lambda value: value)
Registry().register('theme_manager', mocked_theme_manager)
Settings().setValue('servicemanager/service theme', 'service_theme')
Settings().setValue('themes/theme level', ThemeLevel.Song)
# WHEN: Get theme data is run
theme = service_item.get_theme_data()
# THEN: theme should be the serice theme
assert theme == Settings().value('servicemanager/service theme')
def test_service_item_get_theme_data_song_level_global_fallback(self):
"""
Test the service item - get theme data when set to song theme level
but the song and service theme don't exist
"""
# GIVEN: A service item with a theme and theme level set to song
service_item = ServiceItem(None)
mocked_theme_manager = MagicMock()
mocked_theme_manager.global_theme = 'global_theme'
mocked_theme_manager.get_theme_data = Mock(side_effect=lambda value: value)
Registry().register('theme_manager', mocked_theme_manager)
Settings().setValue('servicemanager/service theme', 'service_theme')
Settings().setValue('themes/theme level', ThemeLevel.Song)
# WHEN: Get theme data is run
theme = service_item.get_theme_data()
# THEN: theme should be the global theme
assert theme == mocked_theme_manager.global_theme