openlp/tests/functional/openlp_plugins/bibles/test_versereferencelist.py

141 lines
6.4 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2016-12-31 11:01:36 +00:00
# Copyright (c) 2008-2017 OpenLP Developers #
# --------------------------------------------------------------------------- #
# 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-31 20:04:36 +00:00
"""
This module contains tests for the versereferencelist submodule of the Bibles plugin.
"""
from unittest import TestCase
2013-08-31 20:04:36 +00:00
from openlp.plugins.bibles.lib.versereferencelist import VerseReferenceList
2013-08-31 20:04:36 +00:00
class TestVerseReferenceList(TestCase):
"""
Test the VerseReferenceList class
"""
2016-05-31 21:40:13 +00:00
def test_add_first_verse(self):
2013-08-31 20:04:36 +00:00
"""
Test the addition of a verse to the empty list
"""
# GIVEN: an empty list
reference_list = VerseReferenceList()
book = 'testBook'
chapter = 1
verse = 1
version = 'testVersion'
copyright_ = 'testCopyright'
2014-03-14 22:08:44 +00:00
permission = 'testPermission'
2013-08-31 20:04:36 +00:00
# WHEN: We add it to the verse list
reference_list.add(book, chapter, verse, version, copyright_, permission)
2013-08-31 20:04:36 +00:00
# THEN: The entries should be in the first entry of the list
self.assertEqual(reference_list.current_index, 0, 'The current index should be 0')
self.assertEqual(reference_list.verse_list[0]['book'], book, 'The book in first entry should be %s' % book)
2014-03-14 22:08:44 +00:00
self.assertEqual(reference_list.verse_list[0]['chapter'], chapter, 'The chapter in first entry should be %u' %
chapter)
2013-08-31 20:04:36 +00:00
self.assertEqual(reference_list.verse_list[0]['start'], verse, 'The start in first entry should be %u' % verse)
2014-03-14 22:08:44 +00:00
self.assertEqual(reference_list.verse_list[0]['version'], version, 'The version in first entry should be %s' %
version)
2013-08-31 20:04:36 +00:00
self.assertEqual(reference_list.verse_list[0]['end'], verse, 'The end in first entry should be %u' % verse)
2016-05-31 21:40:13 +00:00
def test_add_next_verse(self):
2013-08-31 20:04:36 +00:00
"""
Test the addition of the following verse
"""
# GIVEN: 1 line in the list of verses
book = 'testBook'
chapter = 1
verse = 1
next_verse = 2
version = 'testVersion'
copyright_ = 'testCopyright'
2014-03-14 22:08:44 +00:00
permission = 'testPermission'
2013-08-31 20:04:36 +00:00
reference_list = VerseReferenceList()
reference_list.add(book, chapter, verse, version, copyright_, permission)
2013-08-31 20:04:36 +00:00
# WHEN: We add the following verse to the verse list
reference_list.add(book, chapter, next_verse, version, copyright_, permission)
2013-08-31 20:04:36 +00:00
# THEN: The current index should be 0 and the end pointer of the entry should be '2'
self.assertEqual(reference_list.current_index, 0, 'The current index should be 0')
2013-10-02 21:37:00 +00:00
self.assertEqual(reference_list.verse_list[0]['end'], next_verse,
2014-03-11 20:10:46 +00:00
'The end in first entry should be %u' % next_verse)
2013-08-31 20:04:36 +00:00
2016-05-31 21:40:13 +00:00
def test_add_another_verse(self):
2013-08-31 20:04:36 +00:00
"""
Test the addition of a verse in another book
"""
# GIVEN: 1 line in the list of verses
book = 'testBook'
chapter = 1
verse = 1
another_book = 'testBook2'
another_chapter = 2
another_verse = 5
version = 'testVersion'
copyright_ = 'testCopyright'
2014-03-14 22:08:44 +00:00
permission = 'testPermission'
2013-08-31 20:04:36 +00:00
reference_list = VerseReferenceList()
reference_list.add(book, chapter, verse, version, copyright_, permission)
2013-08-31 20:04:36 +00:00
# WHEN: We add a verse of another book to the verse list
reference_list.add(another_book, another_chapter, another_verse, version, copyright_, permission)
2013-08-31 20:04:36 +00:00
# THEN: the current index should be 1
self.assertEqual(reference_list.current_index, 1, 'The current index should be 1')
2016-05-31 21:40:13 +00:00
def test_add_version(self):
2013-08-31 20:04:36 +00:00
"""
Test the addition of a version to the list
"""
# GIVEN: version, copyright and permission
reference_list = VerseReferenceList()
version = 'testVersion'
copyright_ = 'testCopyright'
2014-03-14 22:08:44 +00:00
permission = 'testPermission'
2013-08-31 20:04:36 +00:00
# WHEN: a not existing version will be added
reference_list.add_version(version, copyright_, permission)
2013-08-31 20:04:36 +00:00
# THEN: the data will be appended to the list
self.assertEqual(len(reference_list.version_list), 1, 'The version data should be appended')
self.assertEqual(reference_list.version_list[0],
2014-03-11 20:10:46 +00:00
{'version': version, 'copyright': copyright_, 'permission': permission},
'The version data should be appended')
2016-05-31 21:40:13 +00:00
def test_add_existing_version(self):
2013-08-31 20:04:36 +00:00
"""
Test the addition of an existing version to the list
"""
# GIVEN: version, copyright and permission, added to the version list
reference_list = VerseReferenceList()
version = 'testVersion'
copyright_ = 'testCopyright'
2014-03-14 22:08:44 +00:00
permission = 'testPermission'
reference_list.add_version(version, copyright_, permission)
2013-08-31 20:04:36 +00:00
# WHEN: an existing version will be added
reference_list.add_version(version, copyright_, permission)
2013-08-31 20:04:36 +00:00
# THEN: the data will not be appended to the list
self.assertEqual(len(reference_list.version_list), 1, 'The version data should not be appended')