2014-03-11 19:01:09 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-04-13 13:00:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
2020-01-01 02:53:08 +00:00
|
|
|
# Copyright (c) 2008-2020 OpenLP Developers #
|
2019-04-13 13:00:22 +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, either version 3 of the License, or #
|
|
|
|
# (at your option) any later version. #
|
|
|
|
# #
|
|
|
|
# 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, see <https://www.gnu.org/licenses/>. #
|
|
|
|
##########################################################################
|
2014-03-11 19:01:09 +00:00
|
|
|
"""
|
|
|
|
Functional tests to test the Bible Manager class and related methods.
|
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
2017-04-24 05:17:55 +00:00
|
|
|
from unittest.mock import MagicMock, patch
|
2014-03-11 19:01:09 +00:00
|
|
|
|
2019-12-16 03:37:54 +00:00
|
|
|
from openlp.core.common.enum import LanguageSelection
|
2017-10-07 07:05:07 +00:00
|
|
|
from openlp.core.common.registry import Registry
|
|
|
|
from openlp.core.common.settings import Settings
|
2018-10-26 23:15:31 +00:00
|
|
|
from openlp.plugins.bibles.lib.manager import BibleManager
|
2014-03-15 06:29:41 +00:00
|
|
|
from tests.helpers.testmixin import TestMixin
|
2017-12-28 08:27:44 +00:00
|
|
|
from tests.utils.constants import TEST_RESOURCES_PATH
|
2014-03-11 19:01:09 +00:00
|
|
|
|
|
|
|
|
2014-03-15 06:29:41 +00:00
|
|
|
class TestBibleManager(TestCase, TestMixin):
|
2014-03-11 19:01:09 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Set up the environment for testing bible queries with 1 Timothy 3
|
|
|
|
"""
|
2017-06-03 23:27:19 +00:00
|
|
|
self.setup_application()
|
2014-03-15 06:29:41 +00:00
|
|
|
self.build_settings()
|
2014-03-11 19:01:09 +00:00
|
|
|
Registry.create()
|
|
|
|
Registry().register('service_list', MagicMock())
|
|
|
|
Registry().register('application', MagicMock())
|
|
|
|
bible_settings = {
|
|
|
|
'bibles/proxy name': '',
|
|
|
|
'bibles/db type': 'sqlite',
|
|
|
|
'bibles/book name language': LanguageSelection.Bible,
|
|
|
|
'bibles/verse separator': '',
|
|
|
|
'bibles/range separator': '',
|
|
|
|
'bibles/list separator': '',
|
|
|
|
'bibles/end separator': '',
|
|
|
|
}
|
|
|
|
Settings().extend_default_settings(bible_settings)
|
2020-01-29 06:50:09 +00:00
|
|
|
with patch('openlp.core.common.applocation.AppLocation.get_section_data_path') as mocked_get_data_path, \
|
2017-10-07 07:05:07 +00:00
|
|
|
patch('openlp.core.common.applocation.AppLocation.get_files') as mocked_get_files:
|
2014-03-11 19:01:09 +00:00
|
|
|
# GIVEN: A mocked out Settings class and a mocked out AppLocation.get_files()
|
2020-01-29 06:50:09 +00:00
|
|
|
mocked_class = MagicMock()
|
|
|
|
Registry().register('settings', mocked_class.return_value)
|
2014-03-11 19:01:09 +00:00
|
|
|
mocked_settings = mocked_class.return_value
|
|
|
|
mocked_settings.contains.return_value = False
|
|
|
|
mocked_get_files.return_value = ["tests.sqlite"]
|
2017-10-07 07:05:07 +00:00
|
|
|
mocked_get_data_path.return_value = TEST_RESOURCES_PATH + "/bibles"
|
2014-03-11 19:01:09 +00:00
|
|
|
self.manager = BibleManager(MagicMock())
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""
|
|
|
|
Delete all the C++ objects at the end so that we don't have a segfault
|
|
|
|
"""
|
2014-11-26 23:34:48 +00:00
|
|
|
del self.manager
|
2014-03-15 06:29:41 +00:00
|
|
|
self.destroy_settings()
|
2014-03-11 19:01:09 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_get_books(self):
|
2014-03-11 19:01:09 +00:00
|
|
|
"""
|
|
|
|
Test the get_books method
|
|
|
|
"""
|
|
|
|
# GIVEN given a bible in the bible manager
|
|
|
|
# WHEN asking for the books of the bible
|
|
|
|
books = self.manager.get_books('tests')
|
|
|
|
# THEN a list of books should be returned
|
2017-12-23 09:09:45 +00:00
|
|
|
assert 66 == len(books), 'There should be 66 books in the bible'
|
2014-03-11 19:01:09 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_get_book_by_id(self):
|
2014-03-11 19:01:09 +00:00
|
|
|
"""
|
|
|
|
Test the get_book_by_id method
|
|
|
|
"""
|
|
|
|
# GIVEN given a bible in the bible manager
|
|
|
|
# WHEN asking for the book of the bible
|
|
|
|
book = self.manager.get_book_by_id('tests', 54)
|
|
|
|
# THEN a book should be returned
|
2017-12-23 09:09:45 +00:00
|
|
|
assert '1 Timothy' == book.name, '1 Timothy should have been returned from the bible'
|
2014-03-11 19:01:09 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_get_chapter_count(self):
|
2014-03-11 19:01:09 +00:00
|
|
|
"""
|
|
|
|
Test the get_chapter_count method
|
|
|
|
"""
|
|
|
|
# GIVEN given a bible in the bible manager
|
|
|
|
# WHEN asking for the chapters in a book of the bible
|
|
|
|
book = self.manager.get_book_by_id('tests', 54)
|
|
|
|
chapter = self.manager.get_chapter_count('tests', book)
|
|
|
|
# THEN the chapter count should be returned
|
2017-12-23 09:09:45 +00:00
|
|
|
assert 6 == chapter, '1 Timothy should have 6 chapters returned from the bible'
|
2014-03-11 19:01:09 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_get_verse_count_by_book_ref_id(self):
|
2014-03-11 19:01:09 +00:00
|
|
|
"""
|
|
|
|
Test the get_verse_count_by_book_ref_id method
|
|
|
|
"""
|
|
|
|
# GIVEN given a bible in the bible manager
|
|
|
|
# WHEN asking for the number of verses in a book of the bible
|
|
|
|
verses = self.manager.get_verse_count_by_book_ref_id('tests', 54, 3)
|
|
|
|
# THEN the chapter count should be returned
|
2017-12-23 09:09:45 +00:00
|
|
|
assert 16 == verses, '1 Timothy v3 should have 16 verses returned from the bible'
|