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..d4993039b 100644 --- a/openlp/plugins/songs/lib/songselect.py +++ b/openlp/plugins/songs/lib/songselect.py @@ -23,11 +23,12 @@ 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 - +from html import unescape from bs4 import BeautifulSoup, NavigableString @@ -130,8 +131,8 @@ class SongSelectImport(object): 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')], + '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: @@ -167,7 +168,7 @@ 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']) + 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') @@ -180,9 +181,9 @@ class SongSelectImport(object): else: verse['lyrics'] += '\n' verse['lyrics'] = verse['lyrics'].strip(' \n\r\t') - song['verses'].append(self.html_parser.unescape(verse)) + song['verses'].append(unescape(verse)) for counter, author in enumerate(song['authors']): - song['authors'][counter] = self.html_parser.unescape(author) + song['authors'][counter] = unescape(author) return song def save_song(self, song): 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 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_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() 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): """