2013-09-19 21:02:28 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2015-12-31 22:46:06 +00:00
|
|
|
# Copyright (c) 2008-2016 OpenLP Developers #
|
2013-09-19 21:02:28 +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 #
|
|
|
|
###############################################################################
|
2013-08-15 19:49:51 +00:00
|
|
|
"""
|
|
|
|
This module contains tests for the lib submodule of the Bibles plugin.
|
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
|
|
|
|
2015-01-20 21:38:34 +00:00
|
|
|
from openlp.plugins.bibles import lib
|
2013-08-15 19:49:51 +00:00
|
|
|
from openlp.plugins.bibles.lib import SearchResults
|
2016-06-01 23:14:58 +00:00
|
|
|
from tests.functional import patch
|
2013-08-15 19:49:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestLib(TestCase):
|
|
|
|
"""
|
|
|
|
Test the functions in the :mod:`lib` module.
|
|
|
|
"""
|
2016-06-01 23:14:58 +00:00
|
|
|
@patch('openlp.plugins.bibles.lib.update_reference_separators')
|
|
|
|
def test_get_reference_separator(self, mocked_update_reference_separators):
|
2015-01-20 21:38:34 +00:00
|
|
|
"""
|
|
|
|
Test the get_reference_separator method
|
|
|
|
"""
|
2016-06-01 23:14:58 +00:00
|
|
|
# GIVEN: A list of expected separators and the lib module's constant is empty
|
|
|
|
lib.REFERENCE_SEPARATORS = None
|
2015-01-20 21:38:34 +00:00
|
|
|
separators = {'sep_r': '\\s*(?:e)\\s*', 'sep_e_default': 'end', 'sep_v_display': 'w', 'sep_l_display': 'r',
|
2015-01-20 21:45:37 +00:00
|
|
|
'sep_v_default': ':|v|V|verse|verses', 'sep_l': '\\s*(?:r)\\s*', 'sep_l_default': ',|and',
|
|
|
|
'sep_e': '\\s*(?:t)\\s*', 'sep_v': '\\s*(?:w)\\s*', 'sep_r_display': 'e', 'sep_r_default': '-|to'}
|
2016-06-02 10:32:34 +00:00
|
|
|
|
2016-06-01 23:14:58 +00:00
|
|
|
def _update_side_effect():
|
|
|
|
"""
|
|
|
|
Update the references after mocking out the method
|
|
|
|
"""
|
2015-01-20 21:38:34 +00:00
|
|
|
lib.REFERENCE_SEPARATORS = separators
|
|
|
|
|
2016-06-01 23:14:58 +00:00
|
|
|
mocked_update_reference_separators.side_effect = _update_side_effect
|
2015-01-20 21:38:34 +00:00
|
|
|
|
2016-06-01 23:14:58 +00:00
|
|
|
# WHEN: Calling get_reference_separator
|
|
|
|
for key, value in separators.items():
|
|
|
|
_ = lib.get_reference_separator(key)
|
2015-01-20 21:38:34 +00:00
|
|
|
|
2016-06-01 23:14:58 +00:00
|
|
|
# THEN: get_reference_separator should return the correct separator
|
|
|
|
self.assertEqual(separators[key], value)
|
|
|
|
mocked_update_reference_separators.assert_called_once_with()
|
2015-01-20 21:38:34 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_search_results_creation(self):
|
2013-08-15 19:49:51 +00:00
|
|
|
"""
|
|
|
|
Test the creation and construction of the SearchResults class
|
|
|
|
"""
|
|
|
|
# GIVEN: A book, chapter and a verse list
|
2013-08-31 18:17:38 +00:00
|
|
|
book = 'Genesis'
|
2013-08-15 19:49:51 +00:00
|
|
|
chapter = 1
|
|
|
|
verse_list = {
|
2013-08-31 18:17:38 +00:00
|
|
|
1: 'In the beginning God created the heavens and the earth.',
|
|
|
|
2: 'The earth was without form and void, and darkness was over the face of the deep. And the Spirit of '
|
|
|
|
'God was hovering over the face of the waters.'
|
2013-08-15 19:49:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# WHEN: We create the search results object
|
|
|
|
search_results = SearchResults(book, chapter, verse_list)
|
|
|
|
|
|
|
|
# THEN: It should have a book, a chapter and a verse list
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertIsNotNone(search_results, 'The search_results object should not be None')
|
|
|
|
self.assertEqual(search_results.book, book, 'The book should be "Genesis"')
|
|
|
|
self.assertEqual(search_results.chapter, chapter, 'The chapter should be 1')
|
|
|
|
self.assertDictEqual(search_results.verse_list, verse_list, 'The verse lists should be identical')
|
2013-08-15 19:49:51 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_search_results_has_verse_list(self):
|
2013-08-15 19:49:51 +00:00
|
|
|
"""
|
|
|
|
Test that a SearchResults object with a valid verse list returns True when checking ``has_verse_list()``
|
|
|
|
"""
|
|
|
|
# GIVEN: A valid SearchResults object with a proper verse list
|
2013-08-31 18:17:38 +00:00
|
|
|
search_results = SearchResults('Genesis', 1, {1: 'In the beginning God created the heavens and the earth.'})
|
2013-08-15 19:49:51 +00:00
|
|
|
|
|
|
|
# WHEN: We check that the SearchResults object has a verse list
|
|
|
|
has_verse_list = search_results.has_verse_list()
|
|
|
|
|
|
|
|
# THEN: It should be True
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertTrue(has_verse_list, 'The SearchResults object should have a verse list')
|
2013-08-15 19:49:51 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_search_results_has_no_verse_list(self):
|
2013-08-15 19:49:51 +00:00
|
|
|
"""
|
|
|
|
Test that a SearchResults object with an empty verse list returns False when checking ``has_verse_list()``
|
|
|
|
"""
|
|
|
|
# GIVEN: A valid SearchResults object with an empty verse list
|
2013-08-31 18:17:38 +00:00
|
|
|
search_results = SearchResults('Genesis', 1, {})
|
2013-08-15 19:49:51 +00:00
|
|
|
|
|
|
|
# WHEN: We check that the SearchResults object has a verse list
|
|
|
|
has_verse_list = search_results.has_verse_list()
|
|
|
|
|
|
|
|
# THEN: It should be False
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertFalse(has_verse_list, 'The SearchResults object should have a verse list')
|