From 512df1451d7380344582bb2faaac284bd952c64e Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Mon, 9 Mar 2015 20:42:03 +0000 Subject: [PATCH] Use the language id when importing bibles. And fixed presentationcontroller tests. --- openlp/plugins/bibles/lib/osis.py | 3 ++- openlp/plugins/bibles/lib/zefania.py | 3 ++- .../presentations/test_presentationcontroller.py | 12 ++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index 7d3251b37..e0d62045c 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -71,6 +71,7 @@ class OSISBible(BibleDB): if not language_id: log.error('Importing books from "%s" failed' % self.filename) return False + self.save_meta('language_id', language_id) num_books = int(osis_bible_tree.xpath("count(//ns:div[@type='book'])", namespaces=namespace)) self.wizard.increment_progress_bar(translate('BiblesPlugin.OsisImport', 'Removing unused tags (this may take a few minutes)...')) @@ -124,7 +125,7 @@ class OSISBible(BibleDB): break # Remove div-tags in the book etree.strip_tags(book, ('{http://www.bibletechnologies.net/2003/OSIS/namespace}div')) - book_ref_id = self.get_book_ref_id_by_name(book.get('osisID'), num_books) + book_ref_id = self.get_book_ref_id_by_name(book.get('osisID'), num_books, language_id) if not book_ref_id: book_ref_id = self.get_book_ref_id_by_localised_name(book.get('osisID')) if not book_ref_id: diff --git a/openlp/plugins/bibles/lib/zefania.py b/openlp/plugins/bibles/lib/zefania.py index 3bc92eedf..b7d000c3a 100644 --- a/openlp/plugins/bibles/lib/zefania.py +++ b/openlp/plugins/bibles/lib/zefania.py @@ -69,6 +69,7 @@ class ZefaniaBible(BibleDB): if not language_id: 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)")) # Strip tags we don't use - keep content etree.strip_tags(zefania_bible_tree, ('STYLE', 'GRAM', 'NOTE', 'SUP', 'XREF')) @@ -83,7 +84,7 @@ class ZefaniaBible(BibleDB): if not bname and not bnumber: continue if bname: - book_ref_id = self.get_book_ref_id_by_name(bname, num_books) + book_ref_id = self.get_book_ref_id_by_name(bname, num_books, language_id) if not book_ref_id: book_ref_id = self.get_book_ref_id_by_localised_name(bname) else: diff --git a/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py b/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py index 48aed1518..739816147 100644 --- a/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_presentationcontroller.py @@ -81,9 +81,9 @@ class TestPresentationController(TestCase): self.document.save_titles_and_notes(titles, notes) # THEN: the last call to open should have been for slideNotes2.txt - mocked_open.assert_any_call(os.path.join('test', 'titles.txt'), mode='w') - mocked_open.assert_any_call(os.path.join('test', 'slideNotes1.txt'), mode='w') - mocked_open.assert_any_call(os.path.join('test', 'slideNotes2.txt'), mode='w') + mocked_open.assert_any_call(os.path.join('test', 'titles.txt'), mode='wt', encoding='utf-8') + mocked_open.assert_any_call(os.path.join('test', 'slideNotes1.txt'), mode='wt', encoding='utf-8') + 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') @@ -126,9 +126,9 @@ class TestPresentationController(TestCase): self.assertIs(type(result_notes), list, 'result_notes should be of type list') self.assertEqual(len(result_notes), 2, 'There should be two items in the notes') self.assertEqual(mocked_open.call_count, 3, 'Three files should be opened') - mocked_open.assert_any_call(os.path.join('test', 'titles.txt')) - mocked_open.assert_any_call(os.path.join('test', 'slideNotes1.txt')) - mocked_open.assert_any_call(os.path.join('test', 'slideNotes2.txt')) + mocked_open.assert_any_call(os.path.join('test', 'titles.txt'), encoding='utf-8') + mocked_open.assert_any_call(os.path.join('test', 'slideNotes1.txt'), encoding='utf-8') + mocked_open.assert_any_call(os.path.join('test', 'slideNotes2.txt'), encoding='utf-8') self.assertEqual(mocked_exists.call_count, 3, 'Three files should have been checked') def get_titles_and_notes_with_file_not_found_test(self):