2014-05-14 20:53:43 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2017-12-29 09:15:48 +00:00
|
|
|
# Copyright (c) 2008-2018 OpenLP Developers #
|
2014-05-14 20:53:43 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
|
|
|
"""
|
|
|
|
This module contains tests for the Zefania Bible importer.
|
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
2017-04-24 05:17:55 +00:00
|
|
|
from unittest.mock import MagicMock, patch
|
2014-05-14 20:53:43 +00:00
|
|
|
|
|
|
|
from openlp.plugins.bibles.lib.db import BibleDB
|
2017-12-22 22:21:38 +00:00
|
|
|
from openlp.plugins.bibles.lib.importers.zefania import ZefaniaBible
|
|
|
|
from tests.utils import load_external_result_data
|
2017-12-22 21:20:49 +00:00
|
|
|
from tests.utils.constants import RESOURCE_PATH
|
|
|
|
|
|
|
|
TEST_PATH = RESOURCE_PATH / 'bibles'
|
2014-05-14 20:53:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestZefaniaImport(TestCase):
|
|
|
|
"""
|
|
|
|
Test the functions in the :mod:`zefaniaimport` module.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
2016-09-04 21:16:43 +00:00
|
|
|
self.registry_patcher = patch('openlp.plugins.bibles.lib.bibleimport.Registry')
|
2016-08-14 10:00:27 +00:00
|
|
|
self.addCleanup(self.registry_patcher.stop)
|
2014-05-20 21:54:18 +00:00
|
|
|
self.registry_patcher.start()
|
|
|
|
self.manager_patcher = patch('openlp.plugins.bibles.lib.db.Manager')
|
2016-08-14 10:00:27 +00:00
|
|
|
self.addCleanup(self.manager_patcher.stop)
|
2014-05-20 21:54:18 +00:00
|
|
|
self.manager_patcher.start()
|
2014-05-14 20:53:43 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_create_importer(self):
|
2014-05-14 20:53:43 +00:00
|
|
|
"""
|
|
|
|
Test creating an instance of the Zefania file importer
|
|
|
|
"""
|
2014-05-21 09:30:36 +00:00
|
|
|
# GIVEN: A mocked out "manager"
|
2014-05-20 21:54:18 +00:00
|
|
|
mocked_manager = MagicMock()
|
2014-05-14 20:53:43 +00:00
|
|
|
|
2014-05-20 21:54:18 +00:00
|
|
|
# WHEN: An importer object is created
|
2017-10-10 19:09:20 +00:00
|
|
|
importer = ZefaniaBible(mocked_manager, path='.', name='.', file_path=None)
|
2014-05-14 20:53:43 +00:00
|
|
|
|
2014-05-21 09:30:36 +00:00
|
|
|
# THEN: The importer should be an instance of BibleDB
|
2017-12-22 16:53:40 +00:00
|
|
|
assert isinstance(importer, BibleDB)
|
2014-05-14 20:53:43 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_file_import(self):
|
2014-05-14 20:53:43 +00:00
|
|
|
"""
|
2014-08-24 14:37:51 +00:00
|
|
|
Test the actual import of Zefania Bible file
|
2014-05-14 20:53:43 +00:00
|
|
|
"""
|
2014-05-21 09:30:36 +00:00
|
|
|
# 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.
|
2017-12-22 22:21:38 +00:00
|
|
|
test_data = load_external_result_data(TEST_PATH / 'dk1933.json')
|
2014-08-24 14:37:51 +00:00
|
|
|
bible_file = 'zefania-dk1933.xml'
|
2016-08-09 20:45:25 +00:00
|
|
|
with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'):
|
2014-08-24 14:37:51 +00:00
|
|
|
mocked_manager = MagicMock()
|
|
|
|
mocked_import_wizard = MagicMock()
|
2017-10-10 19:09:20 +00:00
|
|
|
importer = ZefaniaBible(mocked_manager, path='.', name='.', file_path=None)
|
2014-08-24 14:37:51 +00:00
|
|
|
importer.wizard = mocked_import_wizard
|
|
|
|
importer.create_verse = MagicMock()
|
|
|
|
importer.create_book = MagicMock()
|
|
|
|
importer.session = MagicMock()
|
|
|
|
importer.get_language = MagicMock()
|
|
|
|
importer.get_language.return_value = 'Danish'
|
2014-05-14 20:53:43 +00:00
|
|
|
|
2014-08-24 14:37:51 +00:00
|
|
|
# WHEN: Importing bible file
|
2017-12-22 21:20:49 +00:00
|
|
|
importer.file_path = TEST_PATH / bible_file
|
2014-08-24 14:37:51 +00:00
|
|
|
importer.do_import()
|
2014-05-14 20:53:43 +00:00
|
|
|
|
2014-08-24 14:37:51 +00:00
|
|
|
# THEN: The create_verse() method should have been called with each verse in the file.
|
2017-12-22 16:53:40 +00:00
|
|
|
assert importer.create_verse.called is True
|
2014-08-24 14:37:51 +00:00
|
|
|
for verse_tag, verse_text in test_data['verses']:
|
2016-09-02 14:23:20 +00:00
|
|
|
importer.create_verse.assert_any_call(importer.create_book().id, 1, verse_tag, verse_text)
|
2015-02-02 20:40:31 +00:00
|
|
|
importer.create_book.assert_any_call('Genesis', 1, 1)
|
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_file_import_no_book_name(self):
|
2015-02-02 20:40:31 +00:00
|
|
|
"""
|
|
|
|
Test the import of Zefania Bible file without book names
|
|
|
|
"""
|
|
|
|
# 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.
|
2017-12-22 22:21:38 +00:00
|
|
|
test_data = load_external_result_data(TEST_PATH / 'rst.json')
|
2015-02-02 20:40:31 +00:00
|
|
|
bible_file = 'zefania-rst.xml'
|
2016-08-09 20:45:25 +00:00
|
|
|
with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'):
|
2015-02-02 20:40:31 +00:00
|
|
|
mocked_manager = MagicMock()
|
|
|
|
mocked_import_wizard = MagicMock()
|
2017-10-10 19:09:20 +00:00
|
|
|
importer = ZefaniaBible(mocked_manager, path='.', name='.', file_path=None)
|
2015-02-02 20:40:31 +00:00
|
|
|
importer.wizard = mocked_import_wizard
|
|
|
|
importer.create_verse = MagicMock()
|
|
|
|
importer.create_book = MagicMock()
|
|
|
|
importer.session = MagicMock()
|
|
|
|
importer.get_language = MagicMock()
|
|
|
|
importer.get_language.return_value = 'Russian'
|
|
|
|
|
|
|
|
# WHEN: Importing bible file
|
2017-12-22 21:20:49 +00:00
|
|
|
importer.file_path = TEST_PATH / bible_file
|
2015-02-02 20:40:31 +00:00
|
|
|
importer.do_import()
|
|
|
|
|
|
|
|
# THEN: The create_verse() method should have been called with each verse in the file.
|
2017-12-22 16:53:40 +00:00
|
|
|
assert importer.create_verse.called is True
|
2015-02-02 20:40:31 +00:00
|
|
|
for verse_tag, verse_text in test_data['verses']:
|
2016-09-02 14:23:20 +00:00
|
|
|
importer.create_verse.assert_any_call(importer.create_book().id, 1, verse_tag, verse_text)
|
2015-02-02 20:40:31 +00:00
|
|
|
importer.create_book.assert_any_call('Exodus', 2, 1)
|