diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 35b1f4bcb..4f912699c 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -504,7 +504,7 @@ class CWExtract(RegistryProperties): soup = get_soup_for_bible_ref(chapter_url) if not soup: return None - content = soup.find_all(('h4', {'class': 'small-header'})) + content = soup.find_all('h4', {'class': 'small-header'}) if not content: log.error('No books found in the Crosswalk response.') send_error_message('parse') diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 94937e61b..0520ba9dd 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -764,6 +764,9 @@ class BibleMediaItem(MediaManagerItem): except IndexError: log.exception('The second_search_results does not have as many verses as the search_results.') break + except TypeError: + log.exception('The second_search_results does not have this book.') + break bible_text = '%s %d%s%d (%s, %s)' % (book, verse.chapter, verse_separator, verse.verse, version, second_version) else: diff --git a/openlp/plugins/bibles/lib/zefania.py b/openlp/plugins/bibles/lib/zefania.py index 6e9f0b956..9b44cdf26 100644 --- a/openlp/plugins/bibles/lib/zefania.py +++ b/openlp/plugins/bibles/lib/zefania.py @@ -70,7 +70,8 @@ class ZefaniaBible(BibleDB): log.error('Importing books from "%s" failed' % self.filename) return False self.save_meta('language_id', language_id) - num_books = int(zefania_bible_tree.xpath("count(//BIBLEBOOK)")) + num_books = int(zefania_bible_tree.xpath('count(//BIBLEBOOK)')) + self.wizard.progress_bar.setMaximum(int(zefania_bible_tree.xpath('count(//CHAPTER)'))) # Strip tags we don't use - keep content etree.strip_tags(zefania_bible_tree, ('STYLE', 'GRAM', 'NOTE', 'SUP', 'XREF')) # Strip tags we don't use - remove content diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index ce80c4b1e..c12350bfd 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -256,6 +256,7 @@ class VerseType(object): for num, translation in enumerate(VerseType.translated_names): if verse_name == translation.lower(): return num + return None @staticmethod def from_loose_input(verse_name, default=Other): @@ -271,7 +272,7 @@ class VerseType(object): if verse_index is None: verse_index = VerseType.from_string(verse_name, default) elif len(verse_name) == 1: - verse_index = VerseType.from_translated_tag(verse_name, default) + verse_index = VerseType.from_translated_tag(verse_name, None) if verse_index is None: verse_index = VerseType.from_tag(verse_name, default) else: diff --git a/openlp/plugins/songs/lib/importers/songimport.py b/openlp/plugins/songs/lib/importers/songimport.py index 1b4550244..54c82da29 100644 --- a/openlp/plugins/songs/lib/importers/songimport.py +++ b/openlp/plugins/songs/lib/importers/songimport.py @@ -371,7 +371,7 @@ class SongImport(QtCore.QObject): song_book = self.manager.get_object_filtered(Book, Book.name == self.song_book_name) if song_book is None: song_book = Book.populate(name=self.song_book_name, publisher=self.song_book_pub) - song.book = song_book + song.add_songbook_entry(song_book, song.song_number) for topic_text in self.topics: if not topic_text: continue diff --git a/tests/functional/__init__.py b/tests/functional/__init__.py index d30361d63..33a4ee96b 100644 --- a/tests/functional/__init__.py +++ b/tests/functional/__init__.py @@ -26,12 +26,12 @@ import sys from PyQt5 import QtWidgets if sys.version_info[1] >= 3: - from unittest.mock import ANY, MagicMock, patch, mock_open, call + from unittest.mock import ANY, MagicMock, patch, mock_open, call, PropertyMock else: - from mock import ANY, MagicMock, patch, mock_open, call + from mock import ANY, MagicMock, patch, mock_open, call, PropertyMock # Only one QApplication can be created. Use QtWidgets.QApplication.instance() when you need to "create" a QApplication. application = QtWidgets.QApplication([]) application.setApplicationName('OpenLP') -__all__ = ['ANY', 'MagicMock', 'patch', 'mock_open', 'call', 'application'] +__all__ = ['ANY', 'MagicMock', 'patch', 'mock_open', 'call', 'application', 'PropertyMock'] diff --git a/tests/functional/openlp_plugins/songs/test_lib.py b/tests/functional/openlp_plugins/songs/test_lib.py index 8cca502b0..77da4f543 100644 --- a/tests/functional/openlp_plugins/songs/test_lib.py +++ b/tests/functional/openlp_plugins/songs/test_lib.py @@ -26,7 +26,7 @@ from unittest import TestCase from openlp.plugins.songs.lib import VerseType, clean_string, clean_title, strip_rtf from openlp.plugins.songs.lib.songcompare import songs_probably_equal, _remove_typos, _op_length -from tests.functional import patch, MagicMock +from tests.functional import patch, MagicMock, PropertyMock class TestLib(TestCase): @@ -477,3 +477,27 @@ class TestVerseType(TestCase): # THEN: The result should be None self.assertIsNone(result, 'The result should be None, but was "%s"' % result) + + @patch('openlp.plugins.songs.lib.VerseType.translated_tags', new_callable=PropertyMock, return_value=['x']) + def from_loose_input_with_invalid_input_test(self, mocked_translated_tags): + """ + Test that the from_loose_input() method returns a sane default when passed an invalid tag and None as default. + """ + # GIVEN: A mocked VerseType.translated_tags + # WHEN: We run the from_loose_input() method with an invalid verse type, we get the specified default back + result = VerseType.from_loose_input('m', None) + + # THEN: The result should be None + self.assertIsNone(result, 'The result should be None, but was "%s"' % result) + + @patch('openlp.plugins.songs.lib.VerseType.translated_tags', new_callable=PropertyMock, return_value=['x']) + def from_loose_input_with_valid_input_test(self, mocked_translated_tags): + """ + Test that the from_loose_input() method returns valid output on valid input. + """ + # GIVEN: A mocked VerseType.translated_tags + # WHEN: We run the from_loose_input() method with a valid verse type, we get the expected VerseType back + result = VerseType.from_loose_input('v') + + # THEN: The result should be a Verse + self.assertEqual(result, VerseType.Verse, 'The result should be a verse, but was "%s"' % result)