From 9d8c757d0dff42884c92cae51007cf88014bf398 Mon Sep 17 00:00:00 2001 From: Simon Hanna Date: Sun, 10 Jan 2016 19:01:36 +0100 Subject: [PATCH 1/4] Re-enable the stylesheet, remove icon in mediamanager to fix rendering in plasma --- openlp/core/lib/plugin.py | 2 +- openlp/core/ui/mainwindow.py | 3 +-- openlp/core/ui/mediadockmanager.py | 19 ++++--------------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index adeacd81b..f01042002 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -275,7 +275,7 @@ class Plugin(QtCore.QObject, RegistryProperties): """ if self.media_item: self.media_item.initialise() - self.main_window.media_dock_manager.insert_dock(self.media_item, self.icon, self.weight) + self.main_window.media_dock_manager.add_item_to_dock(self.media_item) def finalise(self): """ diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 0b35cf890..aed44468e 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -153,8 +153,7 @@ class Ui_MainWindow(object): # Create the MediaManager self.media_manager_dock = OpenLPDockWidget(main_window, 'media_manager_dock', ':/system/system_mediamanager.png') - # TODO: Figure out how to fix the stylesheet and add it back in - # self.media_manager_dock.setStyleSheet(MEDIA_MANAGER_STYLE) + self.media_manager_dock.setStyleSheet(MEDIA_MANAGER_STYLE) # Create the media toolbox self.media_tool_box = QtWidgets.QToolBox(self.media_manager_dock) self.media_tool_box.setObjectName('media_tool_box') diff --git a/openlp/core/ui/mediadockmanager.py b/openlp/core/ui/mediadockmanager.py index 4b8dd71a8..ad786b3a0 100644 --- a/openlp/core/ui/mediadockmanager.py +++ b/openlp/core/ui/mediadockmanager.py @@ -39,23 +39,12 @@ class MediaDockManager(object): """ self.media_dock = media_dock - def add_dock(self, media_item, icon, weight): + def add_item_to_dock(self, media_item): """ Add a MediaManagerItem to the dock + If the item has been added before, it's silently skipped - :param media_item: The item to add to the dock - :param icon: An icon for this dock item - :param weight: - """ - visible_title = media_item.plugin.get_string(StringContent.VisibleName) - log.info('Adding %s dock' % visible_title) - self.media_dock.addItem(media_item, icon, visible_title['title']) - - def insert_dock(self, media_item, icon, weight): - """ - This should insert a dock item at a given location - This does not work as it gives a Segmentation error. - For now add at end of stack if not present + :param media_item: The item to add to the dock """ visible_title = media_item.plugin.get_string(StringContent.VisibleName) log.debug('Inserting %s dock' % visible_title['title']) @@ -65,7 +54,7 @@ class MediaDockManager(object): match = True break if not match: - self.media_dock.addItem(media_item, icon, visible_title['title']) + self.media_dock.addItem(media_item, visible_title['title']) def remove_dock(self, media_item): """ From 09faa0cb87a7d4433b9e11d83b72b205337f4a9c Mon Sep 17 00:00:00 2001 From: Simon Hanna Date: Sun, 10 Jan 2016 21:06:41 +0100 Subject: [PATCH 2/4] Add a test --- tests/functional/openlp_plugins/images/test_imagetab.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/functional/openlp_plugins/images/test_imagetab.py b/tests/functional/openlp_plugins/images/test_imagetab.py index 114c97bc2..3f1a798e3 100644 --- a/tests/functional/openlp_plugins/images/test_imagetab.py +++ b/tests/functional/openlp_plugins/images/test_imagetab.py @@ -80,12 +80,14 @@ class TestImageMediaItem(TestCase, TestMixin): def save_tab_change_test_test(self): """ - Test a change triggers post processing. + Test a color change is applied and triggers post processing. """ # GIVEN: Apply a change to the form. - self.form.background_color = '#999999' + self.form.on_background_color_changed('#999999') # WHEN: the save is invoked self.form.save() # THEN: the post process should be requested self.assertEqual(1, self.form.settings_form.register_post_process.call_count, 'Image Post processing should have been requested') + # THEN: The color should be set + self.assertEqual(self.form.background_color, '#999999', 'The updated color should have been saved') From 50df2e6258d9a0c87c12a1de609f041caf1eacf0 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 11 Jan 2016 21:04:24 +0000 Subject: [PATCH 3/4] fix json --- openlp/plugins/remotes/lib/httprouter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/remotes/lib/httprouter.py b/openlp/plugins/remotes/lib/httprouter.py index 04ad9b946..851bfa209 100644 --- a/openlp/plugins/remotes/lib/httprouter.py +++ b/openlp/plugins/remotes/lib/httprouter.py @@ -621,7 +621,7 @@ class HttpRouter(RegistryProperties): event = getattr(self.service_manager, 'servicemanager_%s_item' % action) if self.request_data: try: - data = json.loads(self.request_data)['request']['id'] + data = int(json.loads(self.request_data)['request']['id']) except KeyError: return self.do_http_error() event.emit(data) From 3f0025a013f9890b2a48e7b0509bb18839f7e884 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 11 Jan 2016 21:57:45 +0000 Subject: [PATCH 4/4] add tests --- .../openlp_plugins/media/test_mediaitem.py | 86 +++++++++++++++++++ .../openlp_plugins/remotes/test_router.py | 1 - 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 tests/functional/openlp_plugins/media/test_mediaitem.py diff --git a/tests/functional/openlp_plugins/media/test_mediaitem.py b/tests/functional/openlp_plugins/media/test_mediaitem.py new file mode 100644 index 000000000..47bc42d86 --- /dev/null +++ b/tests/functional/openlp_plugins/media/test_mediaitem.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2016 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 # +############################################################################### +""" +Test the media plugin +""" +from unittest import TestCase + +from openlp.core import Registry, Settings +from openlp.plugins.media.mediaplugin import MediaPlugin +from openlp.plugins.media.lib.mediaitem import MediaMediaItem +from openlp.core.ui.media.mediacontroller import MediaController + +from PyQt5 import QtCore + +from tests.functional import MagicMock, patch +from tests.helpers.testmixin import TestMixin + +__default_settings__ = { + 'media/media auto start': QtCore.Qt.Unchecked, + 'media/media files': [] +} + + +class MediaItemTest(TestCase, TestMixin): + """ + Test the media item for Media + """ + + def setUp(self): + """ + Set up the components need for all tests. + """ + with patch('openlp.plugins.media.lib.mediaitem.MediaManagerItem.__init__'),\ + patch('openlp.plugins.media.lib.mediaitem.MediaMediaItem.setup'): + self.media_item = MediaMediaItem(None, MagicMock()) + self.media_item.settings_section = 'media' + self.setup_application() + self.build_settings() + Settings().extend_default_settings(__default_settings__) + + def tearDown(self): + """ + Clean up after the tests + """ + self.destroy_settings() + + def test_search_found(self): + """ + Media Remote Search Successful find + """ + # GIVEN: The Mediaitem set up a list of media + Settings().setValue(self.media_item.settings_section + '/media files', ['test.mp3', 'test.mp4']) + # WHEN: Retrieving the test file + result = self.media_item.search('test.mp4', False) + # THEN: a file should be found + self.assertEqual(result, [['test.mp4', 'test.mp4']], 'The result file contain the file name') + + def test_search_not_found(self): + """ + Media Remote Search not find + """ + # GIVEN: The Mediaitem set up a list of media + Settings().setValue(self.media_item.settings_section + '/media files', ['test.mp3', 'test.mp4']) + # WHEN: Retrieving the test file + result = self.media_item.search('test.mpx', False) + # THEN: a file should be found + self.assertEqual(result, [], 'The result file should be empty') diff --git a/tests/functional/openlp_plugins/remotes/test_router.py b/tests/functional/openlp_plugins/remotes/test_router.py index 2a8b9b87c..28af5f2c1 100644 --- a/tests/functional/openlp_plugins/remotes/test_router.py +++ b/tests/functional/openlp_plugins/remotes/test_router.py @@ -29,7 +29,6 @@ from unittest import TestCase from openlp.core.common import Settings, Registry from openlp.core.ui import ServiceManager from openlp.plugins.remotes.lib.httpserver import HttpRouter -from urllib.parse import urlparse from tests.functional import MagicMock, patch, mock_open from tests.helpers.testmixin import TestMixin