From 54c23cc7bd37c1c73685f994eb048d583e0d28a2 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sat, 7 Mar 2015 00:18:51 +0200 Subject: [PATCH] Fix bug #1419300 by checking if we are doing single-click previewing and not engaging preview on double-click Fixes: https://launchpad.net/bugs/1419300 --- openlp/core/lib/mediamanageritem.py | 5 +- .../openlp_core_lib/test_mediamanageritem.py | 100 ++++++++++++++++++ .../openlp_core_ui/test_listpreviewwidget.py | 7 +- tests/functional/openlp_core_ui/test_media.py | 3 - .../openlp_core_ui/test_servicemanager.py | 6 -- 5 files changed, 104 insertions(+), 17 deletions(-) create mode 100644 tests/functional/openlp_core_lib/test_mediamanageritem.py diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 155e484ee..2cd30ad53 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -345,7 +345,7 @@ class MediaManagerItem(QtGui.QWidget, RegistryProperties): def dnd_move_internal(self, target): """ Handle internal moving of media manager items -s + :param target: The target of the DnD action """ pass @@ -460,7 +460,8 @@ s """ if Settings().value('advanced/double click live'): self.on_live_click() - else: + elif not Settings().value('advanced/single click preview'): + # NOTE: The above check is necessary to prevent bug #1419300 self.on_preview_click() def on_selection_change(self): diff --git a/tests/functional/openlp_core_lib/test_mediamanageritem.py b/tests/functional/openlp_core_lib/test_mediamanageritem.py new file mode 100644 index 000000000..4af4029ef --- /dev/null +++ b/tests/functional/openlp_core_lib/test_mediamanageritem.py @@ -0,0 +1,100 @@ +# -*- 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 # +############################################################################### +""" +Package to test the openlp.core.lib.mediamanageritem package. +""" +from unittest import TestCase + +from openlp.core.lib import MediaManagerItem + +from tests.functional import MagicMock, patch +from tests.helpers.testmixin import TestMixin + + +class TestMediaManagerItem(TestCase, TestMixin): + """ + Test the MediaManagerItem class + """ + def setUp(self): + """ + Mock out stuff for all the tests + """ + self.setup_patcher = patch('openlp.core.lib.mediamanageritem.MediaManagerItem._setup') + self.mocked_setup = self.setup_patcher.start() + self.addCleanup(self.setup_patcher.stop) + + @patch(u'openlp.core.lib.mediamanageritem.Settings') + @patch(u'openlp.core.lib.mediamanageritem.MediaManagerItem.on_preview_click') + def on_double_clicked_test(self, mocked_on_preview_click, MockedSettings): + """ + Test that when an item is double-clicked then the item is previewed + """ + # GIVEN: A setting to enable "Double-click to go live" and a media manager item + mocked_settings = MagicMock() + mocked_settings.value.return_value = False + MockedSettings.return_value = mocked_settings + mmi = MediaManagerItem(None) + + # WHEN: on_double_clicked() is called + mmi.on_double_clicked() + + # THEN: on_preview_click() should have been called + mocked_on_preview_click.assert_called_with() + + @patch(u'openlp.core.lib.mediamanageritem.Settings') + @patch(u'openlp.core.lib.mediamanageritem.MediaManagerItem.on_live_click') + def on_double_clicked_go_live_test(self, mocked_on_live_click, MockedSettings): + """ + Test that when "Double-click to go live" is enabled that the item goes live + """ + # GIVEN: A setting to enable "Double-click to go live" and a media manager item + mocked_settings = MagicMock() + mocked_settings.value.side_effect = lambda x: x == 'advanced/double click live' + MockedSettings.return_value = mocked_settings + mmi = MediaManagerItem(None) + + # WHEN: on_double_clicked() is called + mmi.on_double_clicked() + + # THEN: on_live_click() should have been called + mocked_on_live_click.assert_called_with() + + @patch(u'openlp.core.lib.mediamanageritem.Settings') + @patch(u'openlp.core.lib.mediamanageritem.MediaManagerItem.on_live_click') + @patch(u'openlp.core.lib.mediamanageritem.MediaManagerItem.on_preview_click') + def on_double_clicked_single_click_preview_test(self, mocked_on_preview_click, mocked_on_live_click, + MockedSettings): + """ + Test that when "Single-click preview" is enabled then nothing happens on double-click + """ + # GIVEN: A setting to enable "Double-click to go live" and a media manager item + mocked_settings = MagicMock() + mocked_settings.value.side_effect = lambda x: x == 'advanced/single click preview' + MockedSettings.return_value = mocked_settings + mmi = MediaManagerItem(None) + + # WHEN: on_double_clicked() is called + mmi.on_double_clicked() + + # THEN: on_live_click() should have been called + self.assertEqual(0, mocked_on_live_click.call_count, u'on_live_click() should not have been called') + self.assertEqual(0, mocked_on_preview_click.call_count, u'on_preview_click() should not have been called') diff --git a/tests/functional/openlp_core_ui/test_listpreviewwidget.py b/tests/functional/openlp_core_ui/test_listpreviewwidget.py index bb111f5f3..fc835e3fe 100644 --- a/tests/functional/openlp_core_ui/test_listpreviewwidget.py +++ b/tests/functional/openlp_core_ui/test_listpreviewwidget.py @@ -36,12 +36,7 @@ class TestListPreviewWidget(TestCase): """ self.setup_patcher = patch('openlp.core.ui.listpreviewwidget.ListPreviewWidget._setup') self.mocked_setup = self.setup_patcher.start() - - def tearDown(self): - """ - Remove the mocks - """ - self.setup_patcher.stop() + self.addCleanup(self.setup_patcher.stop) def new_list_preview_widget_test(self): """ diff --git a/tests/functional/openlp_core_ui/test_media.py b/tests/functional/openlp_core_ui/test_media.py index ae168803a..49b33e77b 100644 --- a/tests/functional/openlp_core_ui/test_media.py +++ b/tests/functional/openlp_core_ui/test_media.py @@ -33,9 +33,6 @@ from tests.helpers.testmixin import TestMixin class TestMedia(TestCase, TestMixin): - def setUp(self): - pass - def test_get_media_players_no_config(self): """ Test that when there's no config, get_media_players() returns an empty list of players (not a string) diff --git a/tests/functional/openlp_core_ui/test_servicemanager.py b/tests/functional/openlp_core_ui/test_servicemanager.py index 68a11b0e9..f08a35bb3 100644 --- a/tests/functional/openlp_core_ui/test_servicemanager.py +++ b/tests/functional/openlp_core_ui/test_servicemanager.py @@ -39,12 +39,6 @@ class TestServiceManager(TestCase): """ Registry.create() - def tearDown(self): - """ - Delete all the C++ objects at the end so that we don't have a segfault - """ - pass - def initial_service_manager_test(self): """ Test the initial of service manager.