From 5bcdc85ce11a0fe857edd6e2f3586a60cb1f05ea Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 28 May 2015 22:38:43 +0200 Subject: [PATCH 1/2] Fix a left-over from the VLC 2.2 fix; fix a problem when video player from the UI is None --- openlp/core/ui/media/mediacontroller.py | 2 +- openlp/plugins/media/lib/mediaitem.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/openlp/core/ui/media/mediacontroller.py b/openlp/core/ui/media/mediacontroller.py index 158c44e71..39e7d3b65 100644 --- a/openlp/core/ui/media/mediacontroller.py +++ b/openlp/core/ui/media/mediacontroller.py @@ -515,7 +515,7 @@ class MediaController(RegistryMixin, OpenLPMixin, RegistryProperties): :param service_item: The ServiceItem containing the details to be played. """ used_players = get_media_players()[0] - if service_item.processor != UiStrings().Automatic: + if service_item.processor and service_item.processor != UiStrings().Automatic: used_players = [service_item.processor.lower()] # If no player, we can't play if not used_players: diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index f34e88926..f61d5c960 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -34,6 +34,7 @@ from openlp.core.ui import DisplayController, Display, DisplayControllerType from openlp.core.ui.media import get_media_players, set_media_players, parse_optical_path, format_milliseconds from openlp.core.utils import get_locale_key from openlp.core.ui.media.vlcplayer import get_vlc + if get_vlc() is not None: from openlp.plugins.media.forms.mediaclipselectorform import MediaClipSelectorForm @@ -412,7 +413,7 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties): When the load optical button is clicked, open the clip selector window. """ # self.media_clip_selector_form.exec_() - if VLC_AVAILABLE: + if get_vlc(): media_clip_selector_form = MediaClipSelectorForm(self, self.main_window, None) media_clip_selector_form.exec_() del media_clip_selector_form From 8c5a7d27b2ea1975b02c518e47998777ee4f8fda Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 29 May 2015 23:01:44 +0200 Subject: [PATCH 2/2] Some tests --- .../test_mediacontroller.py | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/tests/functional/openlp_core_ui_media/test_mediacontroller.py b/tests/functional/openlp_core_ui_media/test_mediacontroller.py index a16bc2df4..d78f9a06b 100644 --- a/tests/functional/openlp_core_ui_media/test_mediacontroller.py +++ b/tests/functional/openlp_core_ui_media/test_mediacontroller.py @@ -59,6 +59,21 @@ class TestMediaController(TestCase, TestMixin): self.assertListEqual(media_player.audio_extensions_list, media_controller.audio_extensions_list, 'Audio extensions should be the same') + def resize_test(self): + """ + Test that the resize method is called correctly + """ + # GIVEN: A media controller, a player and a display + media_controller = MediaController() + mocked_player = MagicMock() + mocked_display = MagicMock() + + # WHEN: resize() is called + media_controller.resize(mocked_display, mocked_player) + + # THEN: The player's resize method should be called correctly + mocked_player.resize.assert_called_with(mocked_display) + def check_file_type_no_players_test(self): """ Test that we don't try to play media when no players available @@ -81,3 +96,101 @@ class TestMediaController(TestCase, TestMixin): # THEN: it should return False self.assertFalse(ret, '_check_file_type should return False when no mediaplayers are available.') + + @patch('openlp.core.ui.media.mediacontroller.get_media_players') + @patch('openlp.core.ui.media.mediacontroller.UiStrings') + def check_file_type_no_processor_test(self, mocked_uistrings, mocked_get_media_players): + """ + Test that we don't try to play media when the processor for the service item is None + """ + # GIVEN: A mocked UiStrings, get_media_players, controller, display and service_item + mocked_get_media_players.return_value = ([], '') + mocked_ret_uistrings = MagicMock() + mocked_ret_uistrings.Automatic = 1 + mocked_uistrings.return_value = mocked_ret_uistrings + media_controller = MediaController() + mocked_controller = MagicMock() + mocked_display = MagicMock() + mocked_service_item = MagicMock() + mocked_service_item.processor = None + + # WHEN: calling _check_file_type when the processor for the service item is None + ret = media_controller._check_file_type(mocked_controller, mocked_display, mocked_service_item) + + # THEN: it should return False + self.assertFalse(ret, '_check_file_type should return False when the processor for service_item is None.') + + def media_play_msg_test(self): + """ + Test that the media controller responds to the request to play a loaded video + """ + # GIVEN: A media controller and a message with two elements + media_controller = MediaController() + message = (1, 2) + + # WHEN: media_play_msg() is called + with patch.object(media_controller, u'media_play') as mocked_media_play: + media_controller.media_play_msg(message, False) + + # THEN: The underlying method is called + mocked_media_play.assert_called_with(1, False) + + def media_pause_msg_test(self): + """ + Test that the media controller responds to the request to pause a loaded video + """ + # GIVEN: A media controller and a message with two elements + media_controller = MediaController() + message = (1, 2) + + # WHEN: media_play_msg() is called + with patch.object(media_controller, u'media_pause') as mocked_media_pause: + media_controller.media_pause_msg(message) + + # THEN: The underlying method is called + mocked_media_pause.assert_called_with(1) + + def media_stop_msg_test(self): + """ + Test that the media controller responds to the request to stop a loaded video + """ + # GIVEN: A media controller and a message with two elements + media_controller = MediaController() + message = (1, 2) + + # WHEN: media_play_msg() is called + with patch.object(media_controller, u'media_stop') as mocked_media_stop: + media_controller.media_stop_msg(message) + + # THEN: The underlying method is called + mocked_media_stop.assert_called_with(1) + + def media_volume_msg_test(self): + """ + Test that the media controller responds to the request to change the volume + """ + # GIVEN: A media controller and a message with two elements + media_controller = MediaController() + message = (1, [50]) + + # WHEN: media_play_msg() is called + with patch.object(media_controller, u'media_volume') as mocked_media_volume: + media_controller.media_volume_msg(message) + + # THEN: The underlying method is called + mocked_media_volume.assert_called_with(1, 50) + + def media_seek_msg_test(self): + """ + Test that the media controller responds to the request to seek to a particular position + """ + # GIVEN: A media controller and a message with two elements + media_controller = MediaController() + message = (1, [800]) + + # WHEN: media_play_msg() is called + with patch.object(media_controller, u'media_seek') as mocked_media_seek: + media_controller.media_seek_msg(message) + + # THEN: The underlying method is called + mocked_media_seek.assert_called_with(1, 800)