diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index fdcaf47bb..deac92829 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -187,7 +187,7 @@ class VerseType(object): for num, tag in enumerate(VerseType.Tags): if verse_tag == tag: return VerseType.TranslatedTags[num].upper() - if default in VerseType.TranslatedTags: + if len(VerseType.TranslatedTags) > default: return VerseType.TranslatedTags[default].upper() @staticmethod diff --git a/tests/functional/openlp_core_utils/__init__.py b/tests/functional/openlp_core_utils/__init__.py index 33507f08b..e69de29bb 100644 --- a/tests/functional/openlp_core_utils/__init__.py +++ b/tests/functional/openlp_core_utils/__init__.py @@ -1 +0,0 @@ -__author__ = 'raoul' diff --git a/tests/functional/openlp_plugins/__init__.py b/tests/functional/openlp_plugins/__init__.py new file mode 100644 index 000000000..33507f08b --- /dev/null +++ b/tests/functional/openlp_plugins/__init__.py @@ -0,0 +1 @@ +__author__ = 'raoul' diff --git a/tests/functional/openlp_plugins/songs/__init__.py b/tests/functional/openlp_plugins/songs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/functional/openlp_plugins/songs/test_lib.py b/tests/functional/openlp_plugins/songs/test_lib.py new file mode 100644 index 000000000..7c85aa397 --- /dev/null +++ b/tests/functional/openlp_plugins/songs/test_lib.py @@ -0,0 +1,64 @@ +""" +This module contains tests for the lib submodule of the Songs plugin. +""" + +from unittest import TestCase + +from mock import patch + +from openlp.plugins.songs.lib import VerseType + + +class TestVerseType(TestCase): + """ + This is a test case to test various methods in the VerseType enumeration class. + """ + + def translated_tag_test(self): + """ + Test that the translated_tag() method returns the correct tags + """ + # GIVEN: A mocked out translate() function that just returns what it was given + with patch(u'openlp.plugins.songs.lib.translate') as mocked_translate: + mocked_translate.side_effect = lambda x, y: y + + # WHEN: We run the translated_tag() method with a "verse" + result = VerseType.translated_tag(u'v') + + # THEN: The result should be "V" + self.assertEqual(result, u'V', u'The result should be "V"') + + # WHEN: We run the translated_tag() method with a "chorus" + result = VerseType.translated_tag(u'c') + + # THEN: The result should be "C" + self.assertEqual(result, u'C', u'The result should be "C"') + + def translated_invalid_tag_test(self): + """ + Test that the translated_tag() method returns the default tag when passed an invalid tag + """ + # GIVEN: A mocked out translate() function that just returns what it was given + with patch(u'openlp.plugins.songs.lib.translate') as mocked_translate: + mocked_translate.side_effect = lambda x, y: y + + # WHEN: We run the translated_tag() method with an invalid verse type + result = VerseType.translated_tag(u'z') + + # THEN: The result should be "O" + self.assertEqual(result, u'O', u'The result should be "O", but was "%s"' % result) + + def translated_invalid_tag_with_specified_default_test(self): + """ + Test that the translated_tag() method returns the specified default tag when passed an invalid tag + """ + # GIVEN: A mocked out translate() function that just returns what it was given + with patch(u'openlp.plugins.songs.lib.translate') as mocked_translate: + mocked_translate.side_effect = lambda x, y: y + + # WHEN: We run the translated_tag() method with an invalid verse type and specify a default + result = VerseType.translated_tag(u'q', VerseType.Bridge) + + # THEN: The result should be "B" + self.assertEqual(result, u'B', u'The result should be "B", but was "%s"' % result) + diff --git a/tests/interfaces/openlp_plugins_songs_forms/__init__.py b/tests/interfaces/openlp_plugins_songs_forms/__init__.py index 33507f08b..e69de29bb 100644 --- a/tests/interfaces/openlp_plugins_songs_forms/__init__.py +++ b/tests/interfaces/openlp_plugins_songs_forms/__init__.py @@ -1 +0,0 @@ -__author__ = 'raoul'