openlp/tests/openlp_plugins/custom/test_mediaitem.py

111 lines
4.9 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
2022-02-06 09:10:17 +00:00
# Copyright (c) 2008-2022 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/>. #
##########################################################################
2014-12-16 07:47:46 +00:00
"""
This module contains tests for the lib submodule of the Custom plugin.
2014-12-16 07:47:46 +00:00
"""
import pytest
2018-10-02 04:39:42 +00:00
from unittest.mock import MagicMock, patch
2014-12-16 07:47:46 +00:00
2017-10-07 07:05:07 +00:00
from openlp.core.common.registry import Registry
from openlp.core.lib.plugin import PluginStatus
from openlp.core.lib.serviceitem import ServiceItem
from openlp.plugins.custom.lib.mediaitem import CustomMediaItem
2014-12-16 07:47:46 +00:00
2018-10-02 04:39:42 +00:00
2014-12-18 21:15:14 +00:00
FOOTER = ['Arky Arky (Unknown)', 'Public Domain', 'CCLI 123456']
2014-12-16 07:47:46 +00:00
@pytest.fixture()
def media_item(mock_settings):
Registry().register('main_window', MagicMock())
with patch('openlp.core.lib.mediamanageritem.MediaManagerItem._setup'), \
patch('openlp.core.lib.mediamanageritem.MediaManagerItem.setup_item'), \
patch('openlp.plugins.custom.forms.editcustomform.EditCustomForm.__init__'), \
patch('openlp.plugins.custom.lib.mediaitem.CustomMediaItem.setup_item'):
m_item = CustomMediaItem(None, MagicMock())
media_item.plugin = MagicMock()
m_item.settings_section = 'bibles'
m_item.results_view_tab = MagicMock()
return m_item
def test_service_load_inactive(media_item):
"""
Test the service load in custom with a default service item
"""
# GIVEN: An empty Service Item
service_item = ServiceItem(None)
# WHEN: I search for the custom in the database
item = media_item.service_load(service_item)
# THEN: the processing should be ignored
assert item is None, 'The Service item is inactive so processing should be bypassed'
def test_service_load_basic_custom_false(media_item):
2014-12-16 07:47:46 +00:00
"""
Test the service load in custom with a default service item and no requirement to add to the database
2014-12-16 07:47:46 +00:00
"""
# GIVEN: An empty Service Item and an active plugin
service_item = ServiceItem(None)
service_item.raw_footer = FOOTER
media_item.plugin = MagicMock()
media_item.plugin.status = PluginStatus.Active
media_item.plugin.db_manager = MagicMock()
media_item.plugin.db_manager.get_object_filtered = MagicMock()
media_item.plugin.db_manager.get_object_filtered.return_value = None
with patch('openlp.plugins.custom.lib.mediaitem.CustomSlide'):
# WHEN: I search for the custom in the database
media_item.add_custom_from_service = False
media_item.create_from_service_item = MagicMock()
media_item.service_load(service_item)
# THEN: the item should not be added to the database.
assert media_item.create_from_service_item.call_count == 0, \
'The item should not have been added to the database'
2014-12-16 07:47:46 +00:00
def test_service_load_basic_custom_true(media_item):
"""
Test the service load in custom with a default service item and a requirement to add to the database
"""
# GIVEN: An empty Service Item and an active plugin
service_item = ServiceItem(None)
service_item.raw_footer = FOOTER
media_item.plugin = MagicMock()
media_item.plugin.status = PluginStatus.Active
media_item.plugin.db_manager = MagicMock()
media_item.plugin.db_manager.get_object_filtered = MagicMock()
media_item.plugin.db_manager.get_object_filtered.return_value = None
with patch('openlp.plugins.custom.lib.mediaitem.CustomSlide'):
2014-12-16 07:47:46 +00:00
# WHEN: I search for the custom in the database
media_item.add_custom_from_service = True
media_item.create_from_service_item = MagicMock()
media_item.service_load(service_item)
# THEN: the item should not be added to the database.
assert media_item.create_from_service_item.call_count == 1, \
'The item should have been added to the database'