From 63bfacf0d13d3445b6f418cf2862ac8adddb982d Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 17 Jul 2013 14:37:42 +0200 Subject: [PATCH 1/6] fixed presentations --- openlp/plugins/presentations/lib/mediaitem.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index cef30a498..6e5f20646 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -80,15 +80,15 @@ class PresentationMediaItem(MediaManagerItem): """ Build the list of file extensions to be used in the Open file dialog. """ - file_type_list = u'' + file_type_string = u'' for controller in self.controllers: if self.controllers[controller].enabled(): file_types = self.controllers[controller].supports + self.controllers[controller].also_supports for file_type in file_types: - if file_type.find(file_type) == -1: - file_type_list += u'*.%s ' % file_type + if file_type not in file_type_string: + file_type_string += u'*.%s ' % file_type self.service_manager.supported_suffixes(file_type) - self.on_new_file_masks = translate('PresentationPlugin.MediaItem', 'Presentations (%s)') % file_type_list + self.on_new_file_masks = translate('PresentationPlugin.MediaItem', 'Presentations (%s)') % file_type_string def required_icons(self): """ From 4fee73fc37f9d06b70c4310ac50a27ca71755edf Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 17 Jul 2013 15:59:35 +0200 Subject: [PATCH 2/6] added test --- openlp/plugins/presentations/lib/mediaitem.py | 2 +- .../presentations/test_mediaitem.py | 71 +++++++++++++++++++ .../openlp_plugins/songs/test_mediaitem.py | 2 +- 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 tests/functional/openlp_plugins/presentations/test_mediaitem.py diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 6e5f20646..c9f11a5d8 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -66,7 +66,7 @@ class PresentationMediaItem(MediaManagerItem): Registry().register_function(u'mediaitem_presentation_rebuild', self.populate_display_types) Registry().register_function(u'mediaitem_suffixes', self.build_file_mask_string) # Allow DnD from the desktop - self.list_view.activateDnD() + # self.list_view.activateDnD() def retranslateUi(self): """ diff --git a/tests/functional/openlp_plugins/presentations/test_mediaitem.py b/tests/functional/openlp_plugins/presentations/test_mediaitem.py new file mode 100644 index 000000000..488e76608 --- /dev/null +++ b/tests/functional/openlp_plugins/presentations/test_mediaitem.py @@ -0,0 +1,71 @@ +""" +This module contains tests for the lib submodule of the Presentations plugin. +""" +import os +from tempfile import mkstemp +from unittest import TestCase + +from mock import patch, MagicMock + +from PyQt4 import QtGui + +from openlp.core.lib import Registry + +from openlp.plugins.presentations.lib.mediaitem import PresentationMediaItem + + +class TestMediaItem(TestCase): + """ + Test the mediaitem methods. + """ + def setUp(self): + """ + Set up the components need for all tests. + """ + Registry.create() + Registry().register(u'service_manager', MagicMock()) + Registry().register(u'main_window', MagicMock()) + + with patch('openlp.core.lib.mediamanageritem.MediaManagerItem.__init__'), \ + patch('openlp.core.lib.mediamanageritem.ListWidgetWithDnD'): + self.media_item = PresentationMediaItem(MagicMock(), MagicMock(), MagicMock(), MagicMock()) + + self.application = QtGui.QApplication.instance() + + def tearDown(self): + """ + Delete all the C++ objects at the end so that we don't have a segfault + """ + del self.application + + def build_file_mask_string_test(self): + """ + Test the build_file_mask_string() method + """ + # GIVEN: Different controllers. + impress_controller = MagicMock() + impress_controller.enabled.return_value = True + impress_controller.supports = [u'odp'] + impress_controller.also_supports = [u'ppt'] + presentation_controller = MagicMock() + presentation_controller.enabled.return_value = True + presentation_controller.supports = [u'ppt'] + presentation_controller.also_supports = [] + presentation_viewer_controller = MagicMock() + presentation_viewer_controller.enabled.return_value = False + # Mock the controllers. + self.media_item.controllers = { + u'Impress': impress_controller, + u'Powerpoint': presentation_controller, + u'Powerpoint Viewer': presentation_viewer_controller + } + + # WHEN: Build the file mask. + with patch('openlp.plugins.presentations.lib.mediaitem.translate') as mocked_translate: + mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate + self.media_item.build_file_mask_string() + + # THEN: The file mask should be generated. + assert self.media_item.on_new_file_masks == u'Presentations (*.odp *.ppt )' + + diff --git a/tests/functional/openlp_plugins/songs/test_mediaitem.py b/tests/functional/openlp_plugins/songs/test_mediaitem.py index 21616e959..c55a45693 100644 --- a/tests/functional/openlp_plugins/songs/test_mediaitem.py +++ b/tests/functional/openlp_plugins/songs/test_mediaitem.py @@ -26,7 +26,7 @@ class TestMediaItem(TestCase): Registry().register(u'service_list', MagicMock()) Registry().register(u'main_window', MagicMock()) with patch('openlp.core.lib.mediamanageritem.MediaManagerItem.__init__'), \ - patch('openlp.plugins.songs.forms.editsongform.EditSongForm.__init__'): + patch('openlp.plugins.songs.forms.editsongform.EditSongForm.__init__'): self.media_item = SongMediaItem(MagicMock(), MagicMock()) fd, self.ini_file = mkstemp(u'.ini') From 6e66cdefcff29ab9949e81a5e152ac99de731c8e Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 17 Jul 2013 16:19:21 +0200 Subject: [PATCH 3/6] clean ups --- openlp/plugins/presentations/lib/mediaitem.py | 2 +- .../openlp_plugins/presentations/__init__.py | 0 .../openlp_plugins/custom/forms/test_customform.py | 12 +++--------- 3 files changed, 4 insertions(+), 10 deletions(-) create mode 100644 tests/functional/openlp_plugins/presentations/__init__.py diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index c9f11a5d8..6e5f20646 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -66,7 +66,7 @@ class PresentationMediaItem(MediaManagerItem): Registry().register_function(u'mediaitem_presentation_rebuild', self.populate_display_types) Registry().register_function(u'mediaitem_suffixes', self.build_file_mask_string) # Allow DnD from the desktop - # self.list_view.activateDnD() + self.list_view.activateDnD() def retranslateUi(self): """ diff --git a/tests/functional/openlp_plugins/presentations/__init__.py b/tests/functional/openlp_plugins/presentations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/interfaces/openlp_plugins/custom/forms/test_customform.py b/tests/interfaces/openlp_plugins/custom/forms/test_customform.py index 41671403b..fbf613661 100644 --- a/tests/interfaces/openlp_plugins/custom/forms/test_customform.py +++ b/tests/interfaces/openlp_plugins/custom/forms/test_customform.py @@ -80,9 +80,7 @@ class TestEditCustomForm(TestCase): # GIVEN: Mocked methods. with patch(u'openlp.plugins.custom.forms.editcustomform.critical_error_message_box') as \ mocked_critical_error_message_box: - mocked_displayText = MagicMock() - mocked_displayText.return_value = u'' - self.form.title_edit.displayText = mocked_displayText + self.form.title_edit.displayText = MagicMock(return_value=u'') mocked_setFocus = MagicMock() self.form.title_edit.setFocus = mocked_setFocus @@ -101,12 +99,8 @@ class TestEditCustomForm(TestCase): # GIVEN: Mocked methods. with patch(u'openlp.plugins.custom.forms.editcustomform.critical_error_message_box') as \ mocked_critical_error_message_box: - mocked_displayText = MagicMock() - mocked_displayText.return_value = u'something' - self.form.title_edit.displayText = mocked_displayText - mocked_count = MagicMock() - mocked_count.return_value = 0 - self.form.slide_list_view.count = mocked_count + self.form.title_edit.displayText = MagicMock(return_value=u'something') + self.form.slide_list_view.count = MagicMock(return_value=0) # WHEN: Call the method. result = self.form._validate() From b1290100592b95dcad74728ad2de35d5e5a1a25e Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 17 Jul 2013 16:28:22 +0200 Subject: [PATCH 4/6] added assertion message --- .../functional/openlp_plugins/presentations/test_mediaitem.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/functional/openlp_plugins/presentations/test_mediaitem.py b/tests/functional/openlp_plugins/presentations/test_mediaitem.py index 488e76608..b8abb2e51 100644 --- a/tests/functional/openlp_plugins/presentations/test_mediaitem.py +++ b/tests/functional/openlp_plugins/presentations/test_mediaitem.py @@ -66,6 +66,7 @@ class TestMediaItem(TestCase): self.media_item.build_file_mask_string() # THEN: The file mask should be generated. - assert self.media_item.on_new_file_masks == u'Presentations (*.odp *.ppt )' + assert self.media_item.on_new_file_masks == u'Presentations (*.odp *.ppt )', \ + u'The file mask should contain the odp and ppt extensions' From cec9689dce537454c8e36d46445871c5916fcf21 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 17 Jul 2013 23:07:52 +0200 Subject: [PATCH 5/6] Fix up the build_file_mask_string test. - Fix up the build_file_mask_string test by mocking out the __init__() method of the PresentationMediaItem class - Change the way of calling the parent __init__() method to something slightly better (though it has nothing to do with the test) --- openlp/plugins/presentations/lib/mediaitem.py | 2 +- .../openlp_plugins/presentations/test_mediaitem.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 6e5f20646..62e2cd78b 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -59,7 +59,7 @@ class PresentationMediaItem(MediaManagerItem): self.controllers = controllers self.icon_path = u'presentations/presentation' self.Automatic = u'' - MediaManagerItem.__init__(self, parent, plugin) + super(PresentationMediaItem, self).__init__(parent, plugin) self.message_listener = MessageListener(self) self.has_search = True self.single_service_item = False diff --git a/tests/functional/openlp_plugins/presentations/test_mediaitem.py b/tests/functional/openlp_plugins/presentations/test_mediaitem.py index b8abb2e51..294e21779 100644 --- a/tests/functional/openlp_plugins/presentations/test_mediaitem.py +++ b/tests/functional/openlp_plugins/presentations/test_mediaitem.py @@ -26,9 +26,9 @@ class TestMediaItem(TestCase): Registry().register(u'service_manager', MagicMock()) Registry().register(u'main_window', MagicMock()) - with patch('openlp.core.lib.mediamanageritem.MediaManagerItem.__init__'), \ - patch('openlp.core.lib.mediamanageritem.ListWidgetWithDnD'): - self.media_item = PresentationMediaItem(MagicMock(), MagicMock(), MagicMock(), MagicMock()) + with patch('openlp.plugins.presentations.lib.mediaitem.PresentationMediaItem.__init__') as mocked_init: + mocked_init.return_value = None + self.media_item = PresentationMediaItem(MagicMock(), MagicMock, MagicMock(), MagicMock()) self.application = QtGui.QApplication.instance() From 11597d7252441be0550b6439303cb624a8527abe Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 18 Jul 2013 06:53:20 +0200 Subject: [PATCH 6/6] missing empty line --- tests/functional/openlp_plugins/presentations/test_mediaitem.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/functional/openlp_plugins/presentations/test_mediaitem.py b/tests/functional/openlp_plugins/presentations/test_mediaitem.py index b8abb2e51..13b2c320f 100644 --- a/tests/functional/openlp_plugins/presentations/test_mediaitem.py +++ b/tests/functional/openlp_plugins/presentations/test_mediaitem.py @@ -69,4 +69,3 @@ class TestMediaItem(TestCase): assert self.media_item.on_new_file_masks == u'Presentations (*.odp *.ppt )', \ u'The file mask should contain the odp and ppt extensions' -