forked from openlp/openlp
Add a test.
This commit is contained in:
parent
7407d6a16c
commit
dc849f3ff2
@ -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
|
||||
|
@ -1 +0,0 @@
|
||||
__author__ = 'raoul'
|
1
tests/functional/openlp_plugins/__init__.py
Normal file
1
tests/functional/openlp_plugins/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
__author__ = 'raoul'
|
0
tests/functional/openlp_plugins/songs/__init__.py
Normal file
0
tests/functional/openlp_plugins/songs/__init__.py
Normal file
64
tests/functional/openlp_plugins/songs/test_lib.py
Normal file
64
tests/functional/openlp_plugins/songs/test_lib.py
Normal file
@ -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)
|
||||
|
@ -1 +0,0 @@
|
||||
__author__ = 'raoul'
|
Loading…
Reference in New Issue
Block a user