From 99a07ad91e40c80271197150f3255a1d8e5a38be Mon Sep 17 00:00:00 2001 From: Oliver Wieland Date: Sat, 31 Aug 2013 22:04:36 +0200 Subject: [PATCH] added tests --- openlp/plugins/bibles/lib/mediaitem.py | 4 +- .../bibles/test_versereferencelist.py | 116 ++++++++++++++++++ 2 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 tests/functional/openlp_plugins/bibles/test_versereferencelist.py diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 3d94c7e93..01ba525a8 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -944,7 +944,7 @@ class BibleMediaItem(MediaManagerItem): """ verse_separator = get_reference_separator('sep_v_display') if not self.settings.is_verse_number_visible: - return u'' + return '' if not self.settings.show_new_chapters or old_chapter != chapter: verse_text = str(chapter) + verse_separator + str(verse) else: @@ -955,7 +955,7 @@ class BibleMediaItem(MediaManagerItem): return '{su}{%s}{/su}' % verse_text if self.settings.display_style == DisplayStyle.Square: return '{su}[%s]{/su}' % verse_text - return u'{su}%s{/su}' % verse_text + return '{su}%s{/su}' % verse_text def search(self, string, showError): """ diff --git a/tests/functional/openlp_plugins/bibles/test_versereferencelist.py b/tests/functional/openlp_plugins/bibles/test_versereferencelist.py new file mode 100644 index 000000000..372264a76 --- /dev/null +++ b/tests/functional/openlp_plugins/bibles/test_versereferencelist.py @@ -0,0 +1,116 @@ +""" +This module contains tests for the versereferencelist submodule of the Bibles plugin. +""" +from unittest import TestCase +from openlp.plugins.bibles.lib.versereferencelist import VerseReferenceList + +class TestVerseReferenceList(TestCase): + def setUp(self): + """ + Initializes all we need + """ + + def add_first_verse_test(self): + """ + 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' + permission = 'testPermision' + + # WHEN: We add it to the verse list + reference_list.add(book, chapter, verse, version, copyright, permission) + + # 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) + self.assertEqual(reference_list.verse_list[0]['chapter'], chapter, 'The chapter in first entry should be %u' % chapter) + self.assertEqual(reference_list.verse_list[0]['start'], verse, 'The start in first entry should be %u' % verse) + self.assertEqual(reference_list.verse_list[0]['version'], version, 'The version in first entry should be %s' % version) + self.assertEqual(reference_list.verse_list[0]['end'], verse, 'The end in first entry should be %u' % verse) + + def add_next_verse_test(self): + """ + 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' + permission = 'testPermision' + reference_list = VerseReferenceList() + reference_list.add(book, chapter, verse, version, copyright, permission) + + # WHEN: We add the following verse to the verse list + reference_list.add(book, chapter, next_verse, version, copyright, permission) + + # 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') + self.assertEqual(reference_list.verse_list[0]['end'], next_verse, 'The end in first entry should be %u' % next_verse) + + def add_another_verse_test(self): + """ + Test the addition of a verse in another book + """ + # GIVEN: 1 line in the list of verses + book = 'testBook' + chapter = 1 + verse = 1 + next_verse = 2 + another_book = 'testBook2' + another_chapter = 2 + another_verse = 5 + version = 'testVersion' + copyright = 'testCopyright' + permission = 'testPermision' + reference_list = VerseReferenceList() + reference_list.add(book, chapter, verse, version, copyright, permission) + + # WHEN: We add a verse of another book to the verse list + reference_list.add(another_book, another_chapter, another_verse, version, copyright, permission) + + # THEN: the current index should be 1 + self.assertEqual(reference_list.current_index, 1, 'The current index should be 1') + + def add_version_test(self): + """ + Test the addition of a version to the list + """ + # GIVEN: version, copyright and permission + reference_list = VerseReferenceList() + version = 'testVersion' + copyright = 'testCopyright' + permission = 'testPermision' + + # WHEN: a not existing version will be added + reference_list.add_version(version, copyright, permission) + + # 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], {'version': version, 'copyright': copyright, 'permission': permission}, + 'The version data should be appended') + + def add_existing_version_test(self): + """ + 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' + permission = 'testPermision' + reference_list.add_version(version, copyright, permission) + + # WHEN: an existing version will be added + reference_list.add_version(version, copyright, permission) + + # 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')