← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~trb143/openlp/bug-1402963 into lp:openlp

 

Tim Bentley has proposed merging lp:~trb143/openlp/bug-1402963 into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #1402963 in OpenLP: "Service Load duplicates Custom Items"
  https://bugs.launchpad.net/openlp/+bug/1402963

For more details, see:
https://code.launchpad.net/~trb143/openlp/bug-1402963/+merge/245159

Fix bug in Custom matching where theme was not set so match always failed.
-- 
Your team OpenLP Core is requested to review the proposed merge of lp:~trb143/openlp/bug-1402963 into lp:openlp.
=== modified file 'openlp/plugins/custom/lib/mediaitem.py'
--- openlp/plugins/custom/lib/mediaitem.py	2014-03-21 21:38:08 +0000
+++ openlp/plugins/custom/lib/mediaitem.py	2014-12-18 21:16:44 +0000
@@ -287,10 +287,15 @@
         log.debug('service_load')
         if self.plugin.status != PluginStatus.Active:
             return
-        custom = self.plugin.db_manager.get_object_filtered(CustomSlide, and_(CustomSlide.title == item.title,
-                                                                              CustomSlide.theme_name == item.theme,
-                                                                              CustomSlide.credits ==
-                                                                              item.raw_footer[0][len(item.title) + 1:]))
+        if item.theme:
+            custom = self.plugin.db_manager.get_object_filtered(CustomSlide, and_(CustomSlide.title == item.title,
+                                                                CustomSlide.theme_name == item.theme,
+                                                                CustomSlide.credits ==
+                                                                item.raw_footer[0][len(item.title) + 1:]))
+        else:
+            custom = self.plugin.db_manager.get_object_filtered(CustomSlide, and_(CustomSlide.title == item.title,
+                                                                CustomSlide.credits ==
+                                                                item.raw_footer[0][len(item.title) + 1:]))
         if custom:
             item.edit_id = custom.id
             return item

=== added directory 'tests/functional/openlp_plugins/custom'
=== added file 'tests/functional/openlp_plugins/custom/__init__.py'
--- tests/functional/openlp_plugins/custom/__init__.py	1970-01-01 00:00:00 +0000
+++ tests/functional/openlp_plugins/custom/__init__.py	2014-12-18 21:16:44 +0000
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection                                      #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2014 Raoul Snyman                                        #
+# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan      #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub,      #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer.   #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru,          #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith,             #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock,              #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann                         #
+# --------------------------------------------------------------------------- #
+# 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                          #
+###############################################################################

=== added file 'tests/functional/openlp_plugins/custom/test_mediaitem.py'
--- tests/functional/openlp_plugins/custom/test_mediaitem.py	1970-01-01 00:00:00 +0000
+++ tests/functional/openlp_plugins/custom/test_mediaitem.py	2014-12-18 21:16:44 +0000
@@ -0,0 +1,101 @@
+"""
+This module contains tests for the lib submodule of the Songs plugin.
+"""
+from unittest import TestCase
+
+from PyQt4 import QtCore, QtGui
+
+from openlp.core.common import Registry, Settings
+from openlp.core.lib import ServiceItem, PluginStatus
+from openlp.plugins.custom.lib import CustomMediaItem
+from openlp.plugins.custom.lib.db import CustomSlide
+from tests.functional import patch, MagicMock
+from tests.helpers.testmixin import TestMixin
+
+FOOTER = ['Arky Arky (Unknown)', 'Public Domain', 'CCLI 123456']
+
+
+class TestMediaItem(TestCase, TestMixin):
+    """
+    Test the functions in the :mod:`lib` module.
+    """
+    def setUp(self):
+        """
+        Set up the components need for all tests.
+        """
+        Registry.create()
+        Registry().register('service_list', MagicMock())
+        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'):
+            self.media_item = CustomMediaItem(None, MagicMock())
+        self.setup_application()
+        self.build_settings()
+        QtCore.QLocale.setDefault(QtCore.QLocale('en_GB'))
+
+    def tearDown(self):
+        """
+        Delete all the C++ objects at the end so that we don't have a segfault
+        """
+        self.destroy_settings()
+
+    def service_load_inactive_test(self):
+        """
+        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 = self.media_item.service_load(service_item)
+
+        # THEN: the processing should be ignored
+        self.assertEqual(item, None, 'The Service item is inactive so processing should be bypassed')
+
+    def service_load_basic_custom_false_test(self):
+        """
+        Test the service load in custom with a default service item and no requirement to add to the database
+        """
+        # GIVEN: An empty Service Item and an active plugin
+        service_item = ServiceItem(None)
+        service_item.raw_footer = FOOTER
+        self.media_item.plugin = MagicMock()
+        self.media_item.plugin.status = PluginStatus.Active
+        self.media_item.plugin.db_manager = MagicMock()
+        self.media_item.plugin.db_manager.get_object_filtered = MagicMock()
+        self.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
+            self.media_item.add_custom_from_service = False
+            self.media_item.create_from_service_item = MagicMock()
+            self.media_item.service_load(service_item)
+
+            # THEN: the item should not be added to the database.
+            self.assertEqual(self.media_item.create_from_service_item.call_count, 0,
+                             'The item should not have been added to the database')
+
+    def service_load_basic_custom_true_test(self):
+        """
+        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
+        self.media_item.plugin = MagicMock()
+        self.media_item.plugin.status = PluginStatus.Active
+        self.media_item.plugin.db_manager = MagicMock()
+        self.media_item.plugin.db_manager.get_object_filtered = MagicMock()
+        self.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
+            self.media_item.add_custom_from_service = True
+            self.media_item.create_from_service_item = MagicMock()
+            self.media_item.service_load(service_item)
+
+            # THEN: the item should not be added to the database.
+            self.assertEqual(self.media_item.create_from_service_item.call_count, 1,
+                             'The item should have been added to the database')
\ No newline at end of file


Follow ups