forked from openlp/openlp
Fix traceback in OSIS import on empty verse tag.
This commit is contained in:
parent
4e3b1c0e8f
commit
25ce352047
@ -153,6 +153,7 @@ class OSISBible(BibleDB):
|
|||||||
# Verse-tags contains the text
|
# Verse-tags contains the text
|
||||||
for verse in chapter:
|
for verse in chapter:
|
||||||
verse_number = verse.get("osisID").split('.')[2]
|
verse_number = verse.get("osisID").split('.')[2]
|
||||||
|
if verse.text:
|
||||||
self.create_verse(db_book.id, chapter_number, verse_number, verse.text.strip())
|
self.create_verse(db_book.id, chapter_number, verse_number, verse.text.strip())
|
||||||
self.wizard.increment_progress_bar(
|
self.wizard.increment_progress_bar(
|
||||||
translate('BiblesPlugin.OsisImport', 'Importing %(bookname)s %(chapter)s...') %
|
translate('BiblesPlugin.OsisImport', 'Importing %(bookname)s %(chapter)s...') %
|
||||||
|
@ -152,3 +152,33 @@ class TestOsisImport(TestCase):
|
|||||||
self.assertTrue(importer.create_verse.called)
|
self.assertTrue(importer.create_verse.called)
|
||||||
for verse_tag, verse_text in test_data['verses']:
|
for verse_tag, verse_text in test_data['verses']:
|
||||||
importer.create_verse.assert_any_call(importer.create_book().id, '1', verse_tag, verse_text)
|
importer.create_verse.assert_any_call(importer.create_book().id, '1', verse_tag, verse_text)
|
||||||
|
|
||||||
|
def file_import_empty_verse_tags_test(self):
|
||||||
|
"""
|
||||||
|
Test the actual import of OSIS Bible file, with an empty verse tags.
|
||||||
|
"""
|
||||||
|
# GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions
|
||||||
|
# get_book_ref_id_by_name, create_verse, create_book, session and get_language.
|
||||||
|
result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb')
|
||||||
|
test_data = json.loads(result_file.read().decode())
|
||||||
|
bible_file = 'osis-dk1933-empty-verse.xml'
|
||||||
|
with patch('openlp.plugins.bibles.lib.osis.OSISBible.application'):
|
||||||
|
mocked_manager = MagicMock()
|
||||||
|
mocked_import_wizard = MagicMock()
|
||||||
|
importer = OSISBible(mocked_manager, path='.', name='.', filename='')
|
||||||
|
importer.wizard = mocked_import_wizard
|
||||||
|
importer.get_book_ref_id_by_name = MagicMock()
|
||||||
|
importer.create_verse = MagicMock()
|
||||||
|
importer.create_book = MagicMock()
|
||||||
|
importer.session = MagicMock()
|
||||||
|
importer.get_language = MagicMock()
|
||||||
|
importer.get_language.return_value = 'Danish'
|
||||||
|
|
||||||
|
# WHEN: Importing bible file
|
||||||
|
importer.filename = os.path.join(TEST_PATH, bible_file)
|
||||||
|
importer.do_import()
|
||||||
|
|
||||||
|
# THEN: The create_verse() method should have been called with each verse in the file.
|
||||||
|
self.assertTrue(importer.create_verse.called)
|
||||||
|
for verse_tag, verse_text in test_data['verses']:
|
||||||
|
importer.create_verse.assert_any_call(importer.create_book().id, '1', verse_tag, verse_text)
|
||||||
|
33
tests/resources/bibles/osis-dk1933-empty-verse.xml
Normal file
33
tests/resources/bibles/osis-dk1933-empty-verse.xml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
|
<osis xmlns="http://www.bibletechnologies.net/2003/OSIS/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bibletechnologies.net/2003/OSIS/namespace http://www.bibletechnologies.net/osisCore.2.1.1.xsd">
|
||||||
|
<osisText osisIDWork="DanDetteBiblen" osisRefWork="defaultReferenceScheme" xml:lang="da">
|
||||||
|
<header>
|
||||||
|
<work osisWork="DanDetteBiblen">
|
||||||
|
<title>Dette er Biblen</title>
|
||||||
|
<identifier type="OSIS">Bible.DanDetteBiblen</identifier>
|
||||||
|
<refSystem>Bible.KJV</refSystem>
|
||||||
|
</work>
|
||||||
|
<work osisWork="defaultReferenceScheme">
|
||||||
|
<refSystem>Bible.KJV</refSystem>
|
||||||
|
</work>
|
||||||
|
</header>
|
||||||
|
<div type="x-testament">
|
||||||
|
<div type="book" osisID="Gen">
|
||||||
|
<chapter osisID="Gen.1">
|
||||||
|
<verse osisID="Gen.1.1">I Begyndelsen skabte Gud Himmelen og Jorden.</verse>
|
||||||
|
<verse osisID="Gen.1.2">Og Jorden var øde og tom, og der var Mørke over Verdensdybet. Men Guds Ånd svævede over Vandene.<p /></verse>
|
||||||
|
<verse osisID="Gen.1.3">Og Gud sagde: "Der blive Lys!" Og der blev Lys.</verse>
|
||||||
|
<verse osisID="Gen.1.4">Og Gud så, at Lyset var godt, og Gud satte Skel mellem Lyset og Mørket,</verse>
|
||||||
|
<verse osisID="Gen.1.5">og Gud kaldte Lyset Dag, og Mørket kaldte han Nat. Og det blev Aften, og det blev Morgen, første Dag.<p /></verse>
|
||||||
|
<verse osisID="Gen.1.6">Derpå sagde Gud: "Der blive en Hvælving midt i Vandene til at skille Vandene ad!"</verse>
|
||||||
|
<verse osisID="Gen.1.7">Og således skete det: Gud gjorde Hvælvingen og skilte Vandet under Hvælvingen fra Vandet over Hvælvingen;</verse>
|
||||||
|
<verse osisID="Gen.1.8">og Gud kaldte Hvælvingen Himmel. Og det blev Aften, og det blev Morgen, anden Dag.<p /></verse>
|
||||||
|
<verse osisID="Gen.1.9">Derpå sagde Gud: "Vandet under Himmelen samle sig på eet Sted, så det faste Land kommer til Syne!" Og således skete det;</verse>
|
||||||
|
<verse osisID="Gen.1.10">og Gud kaldte det faste Land Jord, og Stedet, hvor Vandet samlede sig, kaldte han Hav. Og Gud så, at det var godt.</verse>
|
||||||
|
<verse osisID="Gen.1.11"></verse>
|
||||||
|
</chapter>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</osisText>
|
||||||
|
</osis>
|
Loading…
Reference in New Issue
Block a user