From 6ab2686b0971989e3d79e356f19c18065b5c2c79 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Tue, 16 Aug 2016 21:36:21 +0100 Subject: [PATCH] Modify CSV Importer and test to give 100% coverage! --- .../plugins/bibles/lib/importers/csvbible.py | 2 +- .../openlp_plugins/bibles/test_bibleimport.py | 31 ------------------- .../openlp_plugins/bibles/test_csvimport.py | 2 +- 3 files changed, 2 insertions(+), 33 deletions(-) diff --git a/openlp/plugins/bibles/lib/importers/csvbible.py b/openlp/plugins/bibles/lib/importers/csvbible.py index 549cec581..3733145b6 100644 --- a/openlp/plugins/bibles/lib/importers/csvbible.py +++ b/openlp/plugins/bibles/lib/importers/csvbible.py @@ -142,7 +142,7 @@ class CSVBible(BibleImport): book_ptr = None for verse in verses: if self.stop_import_flag: - return None + break verse_book = self.get_book_name(verse.book_id_name, books) if book_ptr != verse_book: book = self.get_book(verse_book) diff --git a/tests/functional/openlp_plugins/bibles/test_bibleimport.py b/tests/functional/openlp_plugins/bibles/test_bibleimport.py index 127c6fd16..37c6c3fda 100644 --- a/tests/functional/openlp_plugins/bibles/test_bibleimport.py +++ b/tests/functional/openlp_plugins/bibles/test_bibleimport.py @@ -83,37 +83,6 @@ class TestBibleImport(TestCase): self.assertEqual(instance.filename, 'bible.xml') self.assertIsInstance(instance, BibleDB) - def check_for_compression_test(self): - """ - Test the check_for_compression method when called with a path to an uncompressed file - """ - # GIVEN: A mocked is_zipfile which returns False and an instance of BibleImport - with patch('openlp.plugins.bibles.lib.bibleimport.is_zipfile', return_value=False) as mocked_is_zip: - instance = BibleImport(MagicMock()) - - # WHEN: Calling check_for_compression - result = instance.check_for_compression('filename.tst') - - # THEN: None should be returned - self.assertIsNone(result) - mocked_is_zip.assert_called_once_with('filename.tst') - - def check_for_compression_zip_file_test(self): - """ - Test the check_for_compression method when called with a path to a compressed file - """ - # GIVEN: A patched is_zipfile which returns True and an instance of BibleImport - with patch('openlp.plugins.bibles.lib.bibleimport.is_zipfile', return_value=True),\ - patch('openlp.plugins.bibles.lib.bibleimport.critical_error_message_box') as mocked_message_box: - instance = BibleImport(MagicMock()) - - # WHEN: Calling check_for_compression - # THEN: A Validation error should be raised and the user should be notified. - with self.assertRaises(ValidationError) as context: - instance.check_for_compression('filename.tst') - self.assertTrue(mocked_message_box.called) - self.assertEqual(context.exception.msg, '"filename.tst" is compressed') - def get_language_id_language_found_test(self): """ Test get_language_id() when called with a name found in the languages list diff --git a/tests/functional/openlp_plugins/bibles/test_csvimport.py b/tests/functional/openlp_plugins/bibles/test_csvimport.py index 7a56c1b85..f6d3697af 100644 --- a/tests/functional/openlp_plugins/bibles/test_csvimport.py +++ b/tests/functional/openlp_plugins/bibles/test_csvimport.py @@ -240,7 +240,7 @@ class TestCSVImport(TestCase): importer.wizard = MagicMock() # WHEN: Calling process_verses - result = importer.process_verses([], []) + result = importer.process_verses(['Dummy Verse'], []) # THEN: get_book_name should not be called and the return value should be None self.assertFalse(importer.get_book_name.called)