diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index e1407404c..3d02228ca 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -40,7 +40,7 @@ from openlp.core.ui.lib.wizard import OpenLPWizard, WizardStrings from openlp.core.common.languagemanager import get_locale_key from openlp.plugins.bibles.lib.manager import BibleFormat from openlp.plugins.bibles.lib.db import clean_filename -from openlp.plugins.bibles.lib.http import CWExtract, BGExtract, BSExtract +from openlp.plugins.bibles.lib.importers.http import CWExtract, BGExtract, BSExtract log = logging.getLogger(__name__) diff --git a/openlp/plugins/bibles/lib/csvbible.py b/openlp/plugins/bibles/lib/importers/csvbible.py similarity index 100% rename from openlp/plugins/bibles/lib/csvbible.py rename to openlp/plugins/bibles/lib/importers/csvbible.py diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/importers/http.py similarity index 100% rename from openlp/plugins/bibles/lib/http.py rename to openlp/plugins/bibles/lib/importers/http.py diff --git a/openlp/plugins/bibles/lib/opensong.py b/openlp/plugins/bibles/lib/importers/opensong.py similarity index 100% rename from openlp/plugins/bibles/lib/opensong.py rename to openlp/plugins/bibles/lib/importers/opensong.py diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/importers/osis.py similarity index 100% rename from openlp/plugins/bibles/lib/osis.py rename to openlp/plugins/bibles/lib/importers/osis.py diff --git a/openlp/plugins/bibles/lib/sword.py b/openlp/plugins/bibles/lib/importers/sword.py similarity index 100% rename from openlp/plugins/bibles/lib/sword.py rename to openlp/plugins/bibles/lib/importers/sword.py diff --git a/openlp/plugins/bibles/lib/zefania.py b/openlp/plugins/bibles/lib/importers/zefania.py similarity index 100% rename from openlp/plugins/bibles/lib/zefania.py rename to openlp/plugins/bibles/lib/importers/zefania.py diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 3d7f7f3cf..d2286bed2 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -26,13 +26,13 @@ import os from openlp.core.common import RegistryProperties, AppLocation, Settings, translate, delete_file, UiStrings from openlp.plugins.bibles.lib import parse_reference, LanguageSelection from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta -from .csvbible import CSVBible -from .http import HTTPBible -from .opensong import OpenSongBible -from .osis import OSISBible -from .zefania import ZefaniaBible +from .importers.csvbible import CSVBible +from .importers.http import HTTPBible +from .importers.opensong import OpenSongBible +from .importers.osis import OSISBible +from .importers.zefania import ZefaniaBible try: - from .sword import SwordBible + from .importers.sword import SwordBible except: pass diff --git a/tests/functional/openlp_plugins/bibles/test_csvimport.py b/tests/functional/openlp_plugins/bibles/test_csvimport.py index b52cb0cd4..f24bfe5de 100644 --- a/tests/functional/openlp_plugins/bibles/test_csvimport.py +++ b/tests/functional/openlp_plugins/bibles/test_csvimport.py @@ -32,7 +32,7 @@ from unittest import TestCase from tests.functional import ANY, MagicMock, PropertyMock, call, patch from openlp.core.lib.exceptions import ValidationError from openlp.plugins.bibles.lib.bibleimport import BibleImport -from openlp.plugins.bibles.lib.csvbible import Book, CSVBible, Verse +from openlp.plugins.bibles.lib.importers.csvbible import Book, CSVBible, Verse TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), @@ -133,10 +133,10 @@ class TestCSVImport(TestCase): test_data = [['1', 'Line 1', 'Data 1'], ['2', 'Line 2', 'Data 2'], ['3', 'Line 3', 'Data 3']] TestTuple = namedtuple('TestTuple', 'line_no line_description line_data') - with patch('openlp.plugins.bibles.lib.csvbible.get_file_encoding', + with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding', return_value={'encoding': 'utf-8', 'confidence': 0.99}),\ - patch('openlp.plugins.bibles.lib.csvbible.open', create=True) as mocked_open,\ - patch('openlp.plugins.bibles.lib.csvbible.csv.reader', return_value=iter(test_data)) as mocked_reader: + patch('openlp.plugins.bibles.lib.importers.csvbible.open', create=True) as mocked_open,\ + patch('openlp.plugins.bibles.lib.importers.csvbible.csv.reader', return_value=iter(test_data)) as mocked_reader: # WHEN: Calling the CSVBible parse_csv_file method with a file name and TestTuple result = CSVBible.parse_csv_file('file.csv', TestTuple) @@ -152,9 +152,9 @@ class TestCSVImport(TestCase): Test the parse_csv_file() handles an OSError correctly """ # GIVEN: Mocked a mocked open object which raises an OSError - with patch('openlp.plugins.bibles.lib.csvbible.get_file_encoding', + with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding', return_value={'encoding': 'utf-8', 'confidence': 0.99}),\ - patch('openlp.plugins.bibles.lib.csvbible.open', side_effect=OSError, create=True): + patch('openlp.plugins.bibles.lib.importers.csvbible.open', side_effect=OSError, create=True): # WHEN: Calling CSVBible.parse_csv_file # THEN: A ValidationError should be raised @@ -167,10 +167,10 @@ class TestCSVImport(TestCase): Test the parse_csv_file() handles an csv.Error correctly """ # GIVEN: Mocked a csv.reader which raises an csv.Error - with patch('openlp.plugins.bibles.lib.csvbible.get_file_encoding', + with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding', return_value={'encoding': 'utf-8', 'confidence': 0.99}),\ - patch('openlp.plugins.bibles.lib.csvbible.open', create=True),\ - patch('openlp.plugins.bibles.lib.csvbible.csv.reader', side_effect=csv.Error): + patch('openlp.plugins.bibles.lib.importers.csvbible.open', create=True),\ + patch('openlp.plugins.bibles.lib.importers.csvbible.csv.reader', side_effect=csv.Error): # WHEN: Calling CSVBible.parse_csv_file # THEN: A ValidationError should be raised @@ -204,7 +204,7 @@ class TestCSVImport(TestCase): # GIVEN: An instance of CSVBible with the stop_import_flag set to False, and some sample data mocked_manager = MagicMock() with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\ - patch('openlp.plugins.bibles.lib.csvbible.translate'): + patch('openlp.plugins.bibles.lib.importers.csvbible.translate'): importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv') type(importer).application = PropertyMock() importer.find_and_create_book = MagicMock() @@ -254,7 +254,7 @@ class TestCSVImport(TestCase): # GIVEN: An instance of CSVBible with the application and wizard attributes mocked out, and some test data. mocked_manager = MagicMock() with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\ - patch('openlp.plugins.bibles.lib.csvbible.translate'): + patch('openlp.plugins.bibles.lib.importers.csvbible.translate'): importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv') type(importer).application = PropertyMock() importer.create_verse = MagicMock() @@ -288,7 +288,7 @@ class TestCSVImport(TestCase): # GIVEN: An instance of CSVBible and a mocked get_language which simulates the user cancelling the language box mocked_manager = MagicMock() with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\ - patch('openlp.plugins.bibles.lib.csvbible.log') as mocked_log: + patch('openlp.plugins.bibles.lib.importers.csvbible.log') as mocked_log: importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv') importer.get_language = MagicMock(return_value=None) @@ -308,7 +308,7 @@ class TestCSVImport(TestCase): # GIVEN: An instance of CSVBible with stop_import set to True mocked_manager = MagicMock() with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\ - patch('openlp.plugins.bibles.lib.csvbible.log') as mocked_log: + patch('openlp.plugins.bibles.lib.importers.csvbible.log') as mocked_log: importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv') importer.get_language = MagicMock(return_value=10) importer.parse_csv_file = MagicMock(return_value=['Book 1', 'Book 2', 'Book 3']) @@ -333,7 +333,7 @@ class TestCSVImport(TestCase): # GIVEN: An instance of CSVBible with stop_import which is True the second time of calling mocked_manager = MagicMock() with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\ - patch('openlp.plugins.bibles.lib.csvbible.log') as mocked_log: + patch('openlp.plugins.bibles.lib.importers.csvbible.log') as mocked_log: CSVBible.stop_import_flag = PropertyMock(side_effect=[False, True]) importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verses.csv') importer.get_language = MagicMock(return_value=10) @@ -362,7 +362,7 @@ class TestCSVImport(TestCase): # GIVEN: An instance of CSVBible mocked_manager = MagicMock() with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\ - patch('openlp.plugins.bibles.lib.csvbible.log') as mocked_log: + patch('openlp.plugins.bibles.lib.importers.csvbible.log') as mocked_log: importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verses.csv') importer.get_language = MagicMock(return_value=10) importer.parse_csv_file = MagicMock(side_effect=[['Book 1'], ['Verse 1']]) @@ -393,7 +393,7 @@ class TestCSVImport(TestCase): test_data = json.loads(result_file.read().decode()) books_file = os.path.join(TEST_PATH, 'dk1933-books.csv') verses_file = os.path.join(TEST_PATH, 'dk1933-verses.csv') - with patch('openlp.plugins.bibles.lib.csvbible.CSVBible.application'): + with patch('openlp.plugins.bibles.lib.importers.csvbible.CSVBible.application'): mocked_manager = MagicMock() mocked_import_wizard = MagicMock() importer = CSVBible(mocked_manager, path='.', name='.', booksfile=books_file, versefile=verses_file) diff --git a/tests/functional/openlp_plugins/bibles/test_http.py b/tests/functional/openlp_plugins/bibles/test_http.py index 4074f2708..839c81008 100644 --- a/tests/functional/openlp_plugins/bibles/test_http.py +++ b/tests/functional/openlp_plugins/bibles/test_http.py @@ -26,7 +26,7 @@ from unittest import TestCase from bs4 import BeautifulSoup from tests.functional import patch, MagicMock -from openlp.plugins.bibles.lib.http import BSExtract +from openlp.plugins.bibles.lib.importers.http import BSExtract # TODO: Items left to test # BGExtract @@ -68,11 +68,11 @@ class TestBSExtract(TestCase): # get_books_from_http # _get_application def setUp(self): - self.get_soup_for_bible_ref_patcher = patch('openlp.plugins.bibles.lib.http.get_soup_for_bible_ref') - self.log_patcher = patch('openlp.plugins.bibles.lib.http.log') - self.send_error_message_patcher = patch('openlp.plugins.bibles.lib.http.send_error_message') - self.socket_patcher = patch('openlp.plugins.bibles.lib.http.socket') - self.urllib_patcher = patch('openlp.plugins.bibles.lib.http.urllib') + self.get_soup_for_bible_ref_patcher = patch('openlp.plugins.bibles.lib.importers.http.get_soup_for_bible_ref') + self.log_patcher = patch('openlp.plugins.bibles.lib.importers.http.log') + self.send_error_message_patcher = patch('openlp.plugins.bibles.lib.importers.http.send_error_message') + self.socket_patcher = patch('openlp.plugins.bibles.lib.importers.http.socket') + self.urllib_patcher = patch('openlp.plugins.bibles.lib.importers.http.urllib') self.mock_get_soup_for_bible_ref = self.get_soup_for_bible_ref_patcher.start() self.mock_log = self.log_patcher.start() diff --git a/tests/functional/openlp_plugins/bibles/test_opensongimport.py b/tests/functional/openlp_plugins/bibles/test_opensongimport.py index 8a53e341a..d6997135b 100644 --- a/tests/functional/openlp_plugins/bibles/test_opensongimport.py +++ b/tests/functional/openlp_plugins/bibles/test_opensongimport.py @@ -28,7 +28,7 @@ import json from unittest import TestCase from tests.functional import MagicMock, patch -from openlp.plugins.bibles.lib.opensong import OpenSongBible +from openlp.plugins.bibles.lib.importers.opensong import OpenSongBible from openlp.plugins.bibles.lib.db import BibleDB TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), @@ -72,7 +72,7 @@ class TestOpenSongImport(TestCase): result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb') test_data = json.loads(result_file.read().decode()) bible_file = 'opensong-dk1933.xml' - with patch('openlp.plugins.bibles.lib.opensong.OpenSongBible.application'): + with patch('openlp.plugins.bibles.lib.importers.opensong.OpenSongBible.application'): mocked_manager = MagicMock() mocked_import_wizard = MagicMock() importer = OpenSongBible(mocked_manager, path='.', name='.', filename='') @@ -98,7 +98,7 @@ class TestOpenSongImport(TestCase): Test that we give an error message if trying to import a zefania bible """ # GIVEN: A mocked out "manager" and mocked out critical_error_message_box and an import - with patch('openlp.plugins.bibles.lib.opensong.critical_error_message_box') as \ + with patch('openlp.plugins.bibles.lib.importers.opensong.critical_error_message_box') as \ mocked_critical_error_message_box: mocked_manager = MagicMock() importer = OpenSongBible(mocked_manager, path='.', name='.', filename='') diff --git a/tests/functional/openlp_plugins/bibles/test_osisimport.py b/tests/functional/openlp_plugins/bibles/test_osisimport.py index c6c767397..e1700fbb7 100644 --- a/tests/functional/openlp_plugins/bibles/test_osisimport.py +++ b/tests/functional/openlp_plugins/bibles/test_osisimport.py @@ -28,7 +28,7 @@ import json from unittest import TestCase from tests.functional import MagicMock, patch -from openlp.plugins.bibles.lib.osis import OSISBible +from openlp.plugins.bibles.lib.importers.osis import OSISBible from openlp.plugins.bibles.lib.db import BibleDB TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), @@ -72,7 +72,7 @@ class TestOsisImport(TestCase): result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb') test_data = json.loads(result_file.read().decode()) bible_file = 'osis-dk1933.xml' - with patch('openlp.plugins.bibles.lib.osis.OSISBible.application'): + with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): mocked_manager = MagicMock() mocked_import_wizard = MagicMock() importer = OSISBible(mocked_manager, path='.', name='.', filename='') @@ -102,7 +102,7 @@ class TestOsisImport(TestCase): result_file = open(os.path.join(TEST_PATH, 'kjv.json'), 'rb') test_data = json.loads(result_file.read().decode()) bible_file = 'osis-kjv.xml' - with patch('openlp.plugins.bibles.lib.osis.OSISBible.application'): + with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): mocked_manager = MagicMock() mocked_import_wizard = MagicMock() importer = OSISBible(mocked_manager, path='.', name='.', filename='') @@ -132,7 +132,7 @@ class TestOsisImport(TestCase): result_file = open(os.path.join(TEST_PATH, 'web.json'), 'rb') test_data = json.loads(result_file.read().decode()) bible_file = 'osis-web.xml' - with patch('openlp.plugins.bibles.lib.osis.OSISBible.application'): + with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): mocked_manager = MagicMock() mocked_import_wizard = MagicMock() importer = OSISBible(mocked_manager, path='.', name='.', filename='') @@ -162,7 +162,7 @@ class TestOsisImport(TestCase): 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'): + with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): mocked_manager = MagicMock() mocked_import_wizard = MagicMock() importer = OSISBible(mocked_manager, path='.', name='.', filename='') diff --git a/tests/functional/openlp_plugins/bibles/test_swordimport.py b/tests/functional/openlp_plugins/bibles/test_swordimport.py index 25b6ab355..51e629f53 100644 --- a/tests/functional/openlp_plugins/bibles/test_swordimport.py +++ b/tests/functional/openlp_plugins/bibles/test_swordimport.py @@ -29,7 +29,7 @@ from unittest import TestCase, skipUnless from tests.functional import MagicMock, patch try: - from openlp.plugins.bibles.lib.sword import SwordBible + from openlp.plugins.bibles.lib.importers.sword import SwordBible HAS_PYSWORD = True except ImportError: HAS_PYSWORD = False @@ -68,8 +68,8 @@ class TestSwordImport(TestCase): # THEN: The importer should be an instance of BibleDB self.assertIsInstance(importer, BibleDB) - @patch('openlp.plugins.bibles.lib.sword.SwordBible.application') - @patch('openlp.plugins.bibles.lib.sword.modules') + @patch('openlp.plugins.bibles.lib.importers.sword.SwordBible.application') + @patch('openlp.plugins.bibles.lib.importers.sword.modules') @patch('openlp.core.common.languages') def test_simple_import(self, mocked_languages, mocked_pysword_modules, mocked_application): """ diff --git a/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py b/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py index 34ecf2c58..200a36f45 100644 --- a/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py +++ b/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py @@ -28,7 +28,7 @@ import json from unittest import TestCase from tests.functional import MagicMock, patch -from openlp.plugins.bibles.lib.zefania import ZefaniaBible +from openlp.plugins.bibles.lib.importers.zefania import ZefaniaBible from openlp.plugins.bibles.lib.db import BibleDB TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), @@ -72,7 +72,7 @@ class TestZefaniaImport(TestCase): result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb') test_data = json.loads(result_file.read().decode()) bible_file = 'zefania-dk1933.xml' - with patch('openlp.plugins.bibles.lib.zefania.ZefaniaBible.application'): + with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'): mocked_manager = MagicMock() mocked_import_wizard = MagicMock() importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='') @@ -102,7 +102,7 @@ class TestZefaniaImport(TestCase): result_file = open(os.path.join(TEST_PATH, 'rst.json'), 'rb') test_data = json.loads(result_file.read().decode()) bible_file = 'zefania-rst.xml' - with patch('openlp.plugins.bibles.lib.zefania.ZefaniaBible.application'): + with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'): mocked_manager = MagicMock() mocked_import_wizard = MagicMock() importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='')