From a5a2b8b02b0cf9898c56ea59b792c93dbf99fc62 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 15 Nov 2015 15:13:40 +0000 Subject: [PATCH 1/9] fix remote call data --- openlp/plugins/alerts/lib/alertsmanager.py | 6 +- .../openlp_plugins/alerts/__init__.py | 21 +++++ .../openlp_plugins/alerts/test_manager.py | 84 +++++++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 tests/functional/openlp_plugins/alerts/__init__.py create mode 100644 tests/functional/openlp_plugins/alerts/test_manager.py diff --git a/openlp/plugins/alerts/lib/alertsmanager.py b/openlp/plugins/alerts/lib/alertsmanager.py index 8d691c2bb..7eb3f07c0 100644 --- a/openlp/plugins/alerts/lib/alertsmanager.py +++ b/openlp/plugins/alerts/lib/alertsmanager.py @@ -48,7 +48,11 @@ class AlertsManager(OpenLPMixin, RegistryMixin, QtCore.QObject, RegistryProperti :param message: The message text to be displayed """ if message: - self.display_alert(message[0]) + text = message[0] + # remove line breaks as these crash javascript code on display + while '\n' in text: + text = text.replace('\n', ' ') + self.display_alert(text) def display_alert(self, text=''): """ diff --git a/tests/functional/openlp_plugins/alerts/__init__.py b/tests/functional/openlp_plugins/alerts/__init__.py new file mode 100644 index 000000000..c9e117b57 --- /dev/null +++ b/tests/functional/openlp_plugins/alerts/__init__.py @@ -0,0 +1,21 @@ +# -*- 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 # +############################################################################### diff --git a/tests/functional/openlp_plugins/alerts/test_manager.py b/tests/functional/openlp_plugins/alerts/test_manager.py new file mode 100644 index 000000000..e81ec8cb2 --- /dev/null +++ b/tests/functional/openlp_plugins/alerts/test_manager.py @@ -0,0 +1,84 @@ +# -*- 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 CSV Bible importer. +""" + +import os +import json +from unittest import TestCase + +from tests.functional import MagicMock, patch +from openlp.core.common.registry import Registry +from openlp.plugins.alerts.lib.alertsmanager import AlertsManager + + +class TestAlertManager(TestCase): + + def setUp(self): + """ + Create the UI + """ + Registry.create() + + def remove_message_text_test(self): + """ + Test that Alerts are not triggered with empty strings + """ + # GIVEN: A valid Alert Manager + alert_manager = AlertsManager(None) + alert_manager.display_alert = MagicMock() + + # WHEN: Called with an empty string + alert_manager.alert_text('') + + # THEN: the display should not have been triggered + self.assertFalse(alert_manager.display_alert.called, 'The Alert should not have been called') + + def trigger_message_text_test(self): + """ + Test that Alerts are triggered with a text string + """ + # GIVEN: A valid Alert Manager + alert_manager = AlertsManager(None) + alert_manager.display_alert = MagicMock() + + # WHEN: Called with an empty string + alert_manager.alert_text(['This is a string']) + + # THEN: the display should have been triggered + self.assertTrue(alert_manager.display_alert.called, 'The Alert should have been called') + + def line_break_message_text_test(self): + """ + Test that Alerts are triggered with a text string but line breaks are removed + """ + # GIVEN: A valid Alert Manager + alert_manager = AlertsManager(None) + alert_manager.display_alert = MagicMock() + + # WHEN: Called with an empty string + alert_manager.alert_text(['This is \n a string']) + + # THEN: the display should have been triggered + self.assertTrue(alert_manager.display_alert.called, 'The Alert should have been called') + alert_manager.display_alert.assert_called_once_with('This is a string') From 78078fb2ed0812ffa56015b8dcc13c487b3b7f03 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 21 Nov 2015 08:31:17 +0000 Subject: [PATCH 2/9] catchup late fixes from 2.2.1 --- openlp/core/ui/media/vendor/vlc.py | 1 + openlp/plugins/bibles/lib/http.py | 5 ++- openlp/plugins/songs/lib/songselect.py | 35 ++++++++++++++----- .../openlp_core_ui_media/test_vlcplayer.py | 22 +++++++++--- 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/openlp/core/ui/media/vendor/vlc.py b/openlp/core/ui/media/vendor/vlc.py index f56d3ef56..102af034f 100644 --- a/openlp/core/ui/media/vendor/vlc.py +++ b/openlp/core/ui/media/vendor/vlc.py @@ -107,6 +107,7 @@ def find_lib(): except OSError: # may fail dll = ctypes.CDLL('libvlc.so.5') elif sys.platform.startswith('win'): + ctypes.windll.kernel32.SetDllDirectoryW(None) p = find_library('libvlc.dll') if p is None: try: # some registry settings diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 9d7ad916d..fcf4b049d 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -27,7 +27,6 @@ import re import socket import urllib.parse import urllib.error -from html.parser import HTMLParseError from bs4 import BeautifulSoup, NavigableString, Tag @@ -290,7 +289,7 @@ class BGExtract(RegistryProperties): page_source = str(page_source, 'cp1251') try: soup = BeautifulSoup(page_source) - except HTMLParseError: + except Exception: log.error('BeautifulSoup could not parse the Bible page.') send_error_message('parse') return None @@ -762,7 +761,7 @@ def get_soup_for_bible_ref(reference_url, header=None, pre_parse_regex=None, pre try: soup = BeautifulSoup(page_source) CLEANER_REGEX.sub('', str(soup)) - except HTMLParseError: + except Exception: log.exception('BeautifulSoup could not parse the bible page.') if not soup: send_error_message('parse') diff --git a/openlp/plugins/songs/lib/songselect.py b/openlp/plugins/songs/lib/songselect.py index c09be65c0..e1641ae0c 100644 --- a/openlp/plugins/songs/lib/songselect.py +++ b/openlp/plugins/songs/lib/songselect.py @@ -23,10 +23,13 @@ The :mod:`~openlp.plugins.songs.lib.songselect` module contains the SongSelect importer itself. """ import logging +import sys from http.cookiejar import CookieJar from urllib.parse import urlencode from urllib.request import HTTPCookieProcessor, URLError, build_opener from html.parser import HTMLParser +if sys.version_info > (3, 4): + from html import unescape from bs4 import BeautifulSoup, NavigableString @@ -129,11 +132,18 @@ class SongSelectImport(object): if not search_results: break for result in search_results: - song = { - 'title': self.html_parser.unescape(result.find('h3').string), - 'authors': [self.html_parser.unescape(author.string) for author in result.find_all('li')], - 'link': BASE_URL + result.find('a')['href'] - } + if sys.version_info > (3, 4): + song = { + 'title': unescape(result.find('h3').string), + 'authors': [unescape(author.string) for author in result.find_all('li')], + 'link': BASE_URL + result.find('a')['href'] + } + else: + song = { + 'title': self.html_parser.unescape(result.find('h3').string), + 'authors': [self.html_parser.unescape(author.string) for author in result.find_all('li')], + 'link': BASE_URL + result.find('a')['href'] + } if callback: callback(song) songs.append(song) @@ -167,7 +177,10 @@ class SongSelectImport(object): if callback: callback() song['copyright'] = '/'.join([li.string for li in song_page.find('ul', 'copyright').find_all('li')]) - song['copyright'] = self.html_parser.unescape(song['copyright']) + if sys.version_info > (3, 4): + song['copyright'] = unescape(song['copyright']) + else: + song['copyright'] = self.html_parser.unescape(song['copyright']) song['ccli_number'] = song_page.find('ul', 'info').find('li').string.split(':')[1].strip() song['verses'] = [] verses = lyrics_page.find('section', 'lyrics').find_all('p') @@ -180,9 +193,15 @@ class SongSelectImport(object): else: verse['lyrics'] += '\n' verse['lyrics'] = verse['lyrics'].strip(' \n\r\t') - song['verses'].append(self.html_parser.unescape(verse)) + if sys.version_info > (3, 4): + song['verses'].append(unescape(verse)) + else: + song['verses'].append(self.html_parser.unescape(verse)) for counter, author in enumerate(song['authors']): - song['authors'][counter] = self.html_parser.unescape(author) + if sys.version_info > (3, 4): + song['authors'][counter] = unescape(author) + else: + song['authors'][counter] = self.html_parser.unescape(author) return song def save_song(self, song): diff --git a/tests/functional/openlp_core_ui_media/test_vlcplayer.py b/tests/functional/openlp_core_ui_media/test_vlcplayer.py index eccac6893..a8d3fd52b 100644 --- a/tests/functional/openlp_core_ui_media/test_vlcplayer.py +++ b/tests/functional/openlp_core_ui_media/test_vlcplayer.py @@ -25,7 +25,7 @@ Package to test the openlp.core.ui.media.vlcplayer package. import os import sys from datetime import datetime, timedelta -from unittest import TestCase +from unittest import TestCase, skip from openlp.core.common import Registry from openlp.core.ui.media import MediaState, MediaType @@ -50,6 +50,22 @@ class TestVLCPlayer(TestCase, TestMixin): del sys.modules['openlp.core.ui.media.vendor.vlc'] MockDateTime.revert() + @skip('No way to test this') + @patch('openlp.core.ui.media.vlcplayer.vlc') + def get_vlc_fails_and_removes_module_test(self, mocked_vlc): + """ + Test that when the VLC import fails, it removes the module from sys.modules + """ + # GIVEN: We're on OS X and we don't have the VLC plugin path set + mocked_vlc.Instance.side_effect = NameError + mocked_vlc.libvlc_get_version.return_value = b'0.0.0' + + # WHEN: An checking if the player is available + get_vlc() + + # THEN: The extra environment variable should be there + self.assertNotIn('openlp.core.ui.media.vendor.vlc', sys.modules) + @patch('openlp.core.ui.media.vlcplayer.is_macosx') def fix_vlc_22_plugin_path_test(self, mocked_is_macosx): """ @@ -74,10 +90,6 @@ class TestVLCPlayer(TestCase, TestMixin): """ # GIVEN: We're not on OS X and we don't have the VLC plugin path set mocked_is_macosx.return_value = False - if 'VLC_PLUGIN_PATH' in os.environ: - del os.environ['VLC_PLUGIN_PATH'] - if 'openlp.core.ui.media.vendor.vlc' in sys.modules: - del sys.modules['openlp.core.ui.media.vendor.vlc'] # WHEN: An checking if the player is available get_vlc() From fba6767e79e12b302d6430ddb2b58b141de846d0 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 22 Nov 2015 14:06:54 +0000 Subject: [PATCH 3/9] fix old versions --- openlp/core/ui/media/vendor/vlc.py | 1 - openlp/plugins/songs/lib/songselect.py | 36 +++++++------------------- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/openlp/core/ui/media/vendor/vlc.py b/openlp/core/ui/media/vendor/vlc.py index 102af034f..f56d3ef56 100644 --- a/openlp/core/ui/media/vendor/vlc.py +++ b/openlp/core/ui/media/vendor/vlc.py @@ -107,7 +107,6 @@ def find_lib(): except OSError: # may fail dll = ctypes.CDLL('libvlc.so.5') elif sys.platform.startswith('win'): - ctypes.windll.kernel32.SetDllDirectoryW(None) p = find_library('libvlc.dll') if p is None: try: # some registry settings diff --git a/openlp/plugins/songs/lib/songselect.py b/openlp/plugins/songs/lib/songselect.py index e1641ae0c..d4993039b 100644 --- a/openlp/plugins/songs/lib/songselect.py +++ b/openlp/plugins/songs/lib/songselect.py @@ -28,9 +28,7 @@ from http.cookiejar import CookieJar from urllib.parse import urlencode from urllib.request import HTTPCookieProcessor, URLError, build_opener from html.parser import HTMLParser -if sys.version_info > (3, 4): - from html import unescape - +from html import unescape from bs4 import BeautifulSoup, NavigableString @@ -132,18 +130,11 @@ class SongSelectImport(object): if not search_results: break for result in search_results: - if sys.version_info > (3, 4): - song = { - 'title': unescape(result.find('h3').string), - 'authors': [unescape(author.string) for author in result.find_all('li')], - 'link': BASE_URL + result.find('a')['href'] - } - else: - song = { - 'title': self.html_parser.unescape(result.find('h3').string), - 'authors': [self.html_parser.unescape(author.string) for author in result.find_all('li')], - 'link': BASE_URL + result.find('a')['href'] - } + song = { + 'title': unescape(result.find('h3').string), + 'authors': [unescape(author.string) for author in result.find_all('li')], + 'link': BASE_URL + result.find('a')['href'] + } if callback: callback(song) songs.append(song) @@ -177,10 +168,7 @@ class SongSelectImport(object): if callback: callback() song['copyright'] = '/'.join([li.string for li in song_page.find('ul', 'copyright').find_all('li')]) - if sys.version_info > (3, 4): - song['copyright'] = unescape(song['copyright']) - else: - song['copyright'] = self.html_parser.unescape(song['copyright']) + song['copyright'] = unescape(song['copyright']) song['ccli_number'] = song_page.find('ul', 'info').find('li').string.split(':')[1].strip() song['verses'] = [] verses = lyrics_page.find('section', 'lyrics').find_all('p') @@ -193,15 +181,9 @@ class SongSelectImport(object): else: verse['lyrics'] += '\n' verse['lyrics'] = verse['lyrics'].strip(' \n\r\t') - if sys.version_info > (3, 4): - song['verses'].append(unescape(verse)) - else: - song['verses'].append(self.html_parser.unescape(verse)) + song['verses'].append(unescape(verse)) for counter, author in enumerate(song['authors']): - if sys.version_info > (3, 4): - song['authors'][counter] = unescape(author) - else: - song['authors'][counter] = self.html_parser.unescape(author) + song['authors'][counter] = unescape(author) return song def save_song(self, song): From be222ca597094f447eb80a193cf323f68a03a436 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Wed, 25 Nov 2015 22:47:56 +0100 Subject: [PATCH 4/9] Fix tests that fails on py35. --- tests/functional/openlp_core_ui/test_thememanager.py | 2 +- .../presentations/test_presentationcontroller.py | 10 ++++++++-- tests/functional/openlp_plugins/remotes/test_router.py | 10 ++++++---- tests/functional/openlp_plugins/songs/test_ewimport.py | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/functional/openlp_core_ui/test_thememanager.py b/tests/functional/openlp_core_ui/test_thememanager.py index 3dc168f77..908251ff8 100644 --- a/tests/functional/openlp_core_ui/test_thememanager.py +++ b/tests/functional/openlp_core_ui/test_thememanager.py @@ -240,4 +240,4 @@ class TestThemeManager(TestCase): theme_manager.unzip_theme('theme.file', 'folder') # THEN: The critical_error_message_box should have been called - mocked_critical_error_message_box.assert_called_once(ANY, ANY) + self.assertEqual(mocked_critical_error_message_box.call_count, 1, 'Should have been called once') diff --git a/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py b/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py index 739816147..77cfcae06 100644 --- a/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py @@ -49,11 +49,17 @@ class TestPresentationController(TestCase): # _get_plugin_manager def setUp(self): + self.get_thumbnail_folder_patcher = \ + patch('openlp.plugins.presentations.lib.presentationcontroller.PresentationDocument.get_thumbnail_folder') + self.get_thumbnail_folder_patcher.start() mocked_plugin = MagicMock() mocked_plugin.settings_section = 'presentations' self.presentation = PresentationController(mocked_plugin) self.document = PresentationDocument(self.presentation, '') + def tearDown(self): + self.get_thumbnail_folder_patcher.stop() + def constructor_test(self): """ Test the Constructor @@ -86,8 +92,8 @@ class TestPresentationController(TestCase): mocked_open.assert_any_call(os.path.join('test', 'slideNotes2.txt'), mode='wt', encoding='utf-8') self.assertEqual(mocked_open.call_count, 3, 'There should be exactly three files opened') mocked_open().writelines.assert_called_once_with(['uno', 'dos']) - mocked_open().write.assert_called_any('one') - mocked_open().write.assert_called_any('two') + mocked_open().write.assert_any_call('one') + mocked_open().write.assert_any_call('two') def save_titles_and_notes_with_None_test(self): """ diff --git a/tests/functional/openlp_plugins/remotes/test_router.py b/tests/functional/openlp_plugins/remotes/test_router.py index 70a2033a4..e62ee9c14 100644 --- a/tests/functional/openlp_plugins/remotes/test_router.py +++ b/tests/functional/openlp_plugins/remotes/test_router.py @@ -272,7 +272,6 @@ class TestRouter(TestCase, TestMixin): self.router.end_headers = MagicMock() self.router.wfile = MagicMock() mocked_image_manager = MagicMock() - Registry.create() Registry().register('image_manager', mocked_image_manager) file_name = 'another%20test/slide1.png' full_path = os.path.normpath(os.path.join('thumbnails', file_name)) @@ -295,9 +294,12 @@ class TestRouter(TestCase, TestMixin): self.assertEqual(self.router.end_headers.call_count, 1, 'end_headers called once') mocked_exists.assert_called_with(urllib.parse.unquote(full_path)) self.assertEqual(mocked_image_to_byte.call_count, 1, 'Called once') - mocked_image_manager.assert_called_any(os.path.normpath('thumbnails\\another test'), - 'slide1.png', None, '120x90') - mocked_image_manager.assert_called_any(os.path.normpath('thumbnails\\another test'), 'slide1.png', '120x90') + mocked_image_manager.add_image.assert_any_call(os.path.normpath(os.path.join('thumbnails', 'another test', + 'slide1.png')), + 'slide1.png', None, width, height) + mocked_image_manager.get_image.assert_any_call(os.path.normpath(os.path.join('thumbnails', 'another test', + 'slide1.png')), + 'slide1.png', width, height) def remote_next_test(self): """ diff --git a/tests/functional/openlp_plugins/songs/test_ewimport.py b/tests/functional/openlp_plugins/songs/test_ewimport.py index d41100444..7b78a4d85 100644 --- a/tests/functional/openlp_plugins/songs/test_ewimport.py +++ b/tests/functional/openlp_plugins/songs/test_ewimport.py @@ -403,7 +403,7 @@ class TestEasyWorshipSongImport(TestCase): # THEN: do_import should return None having called retrieve_windows_encoding with the correct encoding. self.assertIsNone(importer.do_import(), 'do_import should return None when db_size is less than 0x800') - mocked_retrieve_windows_encoding.assert_call(encoding) + mocked_retrieve_windows_encoding.assert_any_call(encoding) def db_file_import_test(self): """ From a5525e96c1b675436ebe7f1db8e1948c04652bad Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Thu, 26 Nov 2015 21:44:19 +0100 Subject: [PATCH 5/9] Fix projector tests. --- tests/functional/openlp_core_lib/test_projectordb.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/functional/openlp_core_lib/test_projectordb.py b/tests/functional/openlp_core_lib/test_projectordb.py index a96267fe9..bf6c1688e 100644 --- a/tests/functional/openlp_core_lib/test_projectordb.py +++ b/tests/functional/openlp_core_lib/test_projectordb.py @@ -94,6 +94,12 @@ class TestProjectorDB(TestCase): mocked_init_url.return_value = 'sqlite:///%s' % tmpfile self.projector = ProjectorDB() + def tearDown(self): + """ + Clean up + """ + self.projector = None + def find_record_by_ip_test(self): """ Test find record by IP From ae1888106d6bc1050e23900640200359ce23dde7 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 28 Nov 2015 15:37:26 +0000 Subject: [PATCH 6/9] 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 7/9] 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 8/9] 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 9/9] 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') -