From ae1888106d6bc1050e23900640200359ce23dde7 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 28 Nov 2015 15:37:26 +0000 Subject: [PATCH 1/4] Fix Presentations and Media --- openlp/core/ui/media/mediacontroller.py | 9 +++++++-- openlp/core/ui/servicemanager.py | 1 + openlp/plugins/presentations/lib/messagelistener.py | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/openlp/core/ui/media/mediacontroller.py b/openlp/core/ui/media/mediacontroller.py index 5209a8253..6d35f2478 100644 --- a/openlp/core/ui/media/mediacontroller.py +++ b/openlp/core/ui/media/mediacontroller.py @@ -514,9 +514,14 @@ class MediaController(RegistryMixin, OpenLPMixin, RegistryProperties): :param display: Which display to use :param service_item: The ServiceItem containing the details to be played. """ - used_players = get_media_players()[0] + used_players = get_media_players() + default_player = used_players[0] if service_item.processor and service_item.processor != UiStrings().Automatic: - used_players = [service_item.processor.lower()] + # check to see if the player is usable else use the default one. + if not service_item.processor.lower() in used_players: + used_players = default_player + else: + used_players = [service_item.processor.lower()] # If no player, we can't play if not used_players: return False diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index c3db9a071..ae4e8fd9a 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -396,6 +396,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage :param suffix_list: New Suffix's to be supported """ + print(suffix_list) if isinstance(suffix_list, str): self.suffixes.append(suffix_list) else: diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index 48d5722e0..52c93877b 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -346,6 +346,12 @@ class MessageListener(object): self.handler = self.media_item.find_controller_by_type(file) if not self.handler: return + else: + # the saved handler is not present so need to use one based on file suffix. + if not self.controllers[self.handler].available: + self.handler = self.media_item.find_controller_by_type(file) + if not self.handler: + return if is_live: controller = self.live_handler else: From 1ba865298561a2c5261c7c492f9e930a6b7cd11d Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 28 Nov 2015 15:38:31 +0000 Subject: [PATCH 2/4] Remove Prints --- openlp/core/ui/servicemanager.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index ae4e8fd9a..c3db9a071 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -396,7 +396,6 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage :param suffix_list: New Suffix's to be supported """ - print(suffix_list) if isinstance(suffix_list, str): self.suffixes.append(suffix_list) else: From 64867b52a80955fe458ab93ce0ddae79c9ecfc3d Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 28 Nov 2015 17:04:46 +0000 Subject: [PATCH 3/4] Add tests for Presentations --- .../presentations/lib/messagelistener.py | 7 ++ .../presentations/test_messagelistener.py | 107 ++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 tests/functional/openlp_plugins/presentations/test_messagelistener.py diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index 52c93877b..69eeb5c5c 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -290,6 +290,13 @@ class MessageListener(object): log.info('Message Listener loaded') def __init__(self, media_item): + self._setup(media_item) + + def _setup(self, media_item): + """ + Start up code moved out to make mocking easier + :param media_item: The plugin media item handing Presentations + """ self.controllers = media_item.controllers self.media_item = media_item self.preview_handler = Controller(False) diff --git a/tests/functional/openlp_plugins/presentations/test_messagelistener.py b/tests/functional/openlp_plugins/presentations/test_messagelistener.py new file mode 100644 index 000000000..2d00a6929 --- /dev/null +++ b/tests/functional/openlp_plugins/presentations/test_messagelistener.py @@ -0,0 +1,107 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2015 OpenLP Developers # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### +""" +This module contains tests for the lib submodule of the Presentations plugin. +""" +from unittest import TestCase + +from openlp.core.common import Registry +from openlp.plugins.presentations.lib.mediaitem import MessageListener, PresentationMediaItem +from tests.functional import patch, MagicMock, call +from tests.helpers.testmixin import TestMixin + + +class TestMessageListener(TestCase, TestMixin): + """ + Test the Presentation Message Listener. + """ + def setUp(self): + """ + Set up the components need for all tests. + """ + Registry.create() + Registry().register('service_manager', MagicMock()) + Registry().register('main_window', MagicMock()) + with patch('openlp.plugins.presentations.lib.mediaitem.MediaManagerItem._setup'), \ + patch('openlp.plugins.presentations.lib.mediaitem.PresentationMediaItem.setup_item'): + self.media_item = PresentationMediaItem(None, MagicMock, MagicMock()) + + @patch('openlp.plugins.presentations.lib.mediaitem.MessageListener._setup') + def start_presentation_test(self, media_mock): + """ + Find and chose a controller to play a presentations. + """ + # GIVEN: A single controller and service item wanting to use the controller + mock_item = MagicMock() + mock_item.processor = 'Powerpoint' + mock_item.get_frame_path.return_value = "test.ppt" + self.media_item.automatic = False + mocked_controller = MagicMock() + mocked_controller.available = True + mocked_controller.supports = ['ppt'] + controllers = { + 'Powerpoint': mocked_controller + } + ml = MessageListener(self.media_item) + ml.media_item = self.media_item + ml.controllers = controllers + ml.preview_handler = MagicMock() + ml.timer = MagicMock() + + # WHEN: request the presentation to start + ml.startup([mock_item, False, False, False]) + + # THEN: The controllers will be setup. + self.assertTrue(len(controllers), 'We have loaded a controller') + + @patch('openlp.plugins.presentations.lib.mediaitem.MessageListener._setup') + def start_presentation_with_no_player_test(self, media_mock): + """ + Find and chose a controller to play a presentations when the player is not available. + """ + # GIVEN: A single controller and service item wanting to use the controller + mock_item = MagicMock() + mock_item.processor = 'Powerpoint' + mock_item.get_frame_path.return_value = "test.ppt" + self.media_item.automatic = False + mocked_controller = MagicMock() + mocked_controller.available = True + mocked_controller.supports = ['ppt'] + mocked_controller1 = MagicMock() + mocked_controller1.available = False + mocked_controller1.supports = ['ppt'] + controllers = { + 'Impress': mocked_controller, + 'Powerpoint': mocked_controller1 + } + ml = MessageListener(self.media_item) + ml.media_item = self.media_item + ml.controllers = controllers + ml.preview_handler = MagicMock() + ml.timer = MagicMock() + + # WHEN: request the presentation to start + ml.startup([mock_item, False, False, False]) + + # THEN: The controllers will be setup. + self.assertTrue(len(controllers), 'We have loaded a controller') + From 6a48bb5ac260ccce1953c422b0c694092f1dfe10 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 28 Nov 2015 20:13:16 +0000 Subject: [PATCH 4/4] Style fixes --- .../openlp_plugins/presentations/test_messagelistener.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/functional/openlp_plugins/presentations/test_messagelistener.py b/tests/functional/openlp_plugins/presentations/test_messagelistener.py index 2d00a6929..d139c5b33 100644 --- a/tests/functional/openlp_plugins/presentations/test_messagelistener.py +++ b/tests/functional/openlp_plugins/presentations/test_messagelistener.py @@ -26,7 +26,7 @@ from unittest import TestCase from openlp.core.common import Registry from openlp.plugins.presentations.lib.mediaitem import MessageListener, PresentationMediaItem -from tests.functional import patch, MagicMock, call +from tests.functional import patch, MagicMock from tests.helpers.testmixin import TestMixin @@ -104,4 +104,3 @@ class TestMessageListener(TestCase, TestMixin): # THEN: The controllers will be setup. self.assertTrue(len(controllers), 'We have loaded a controller') -