- Fixed tests for creating creator lists

This commit is contained in:
Olli Suutari 2016-10-04 11:43:52 +03:00
parent ce4d8224a2
commit 400595adf5

View File

@ -689,50 +689,38 @@ class TestLib(TestCase):
""" """
Test the create_separated_list function with a list consisting of only one entry Test the create_separated_list function with a list consisting of only one entry
""" """
with patch('openlp.core.lib.Qt') as mocked_qt: # GIVEN: A list with a string.
# GIVEN: A list with a string and the mocked Qt module. string_list = ['Author 1']
mocked_qt.PYQT_VERSION_STR = '4.8'
mocked_qt.qVersion.return_value = '4.7'
string_list = ['Author 1']
# WHEN: We get a string build from the entries it the list and a separator. # WHEN: We get a string build from the entries it the list and a separator.
string_result = create_separated_list(string_list) string_result = create_separated_list(string_list)
# THEN: We should have "Author 1" # THEN: We should have "Author 1"
assert string_result == 'Author 1', 'The string should be u\'Author 1\'.' assert string_result == 'Author 1', 'The string should be u\'Author 1\'.'
def test_create_separated_list_with_two_items(self): def test_create_separated_list_with_two_items(self):
""" """
Test the create_separated_list function with a list of two entries Test the create_separated_list function with a list of two entries
""" """
with patch('openlp.core.lib.Qt') as mocked_qt, patch('openlp.core.lib.translate') as mocked_translate: # GIVEN: A list with two strings.
# GIVEN: A list of strings and the mocked Qt module. string_list = ['Author 1', 'Author 2']
mocked_qt.PYQT_VERSION_STR = '4.8'
mocked_qt.qVersion.return_value = '4.7'
mocked_translate.return_value = '%s and %s'
string_list = ['Author 1', 'Author 2']
# WHEN: We get a string build from the entries it the list and a seperator. # WHEN: We get a string build from the entries it the list and a seperator.
string_result = create_separated_list(string_list) string_result = create_separated_list(string_list)
# THEN: We should have "Author 1 and Author 2" # THEN: We should have "Author 1 and Author 2"
assert string_result == 'Author 1 and Author 2', 'The string should be u\'Author 1 and Author 2\'.' assert string_result == 'Author 1 and Author 2', 'The string should be u\'Author 1 and Author 2\'.'
def test_create_separated_list_with_three_items(self): def test_create_separated_list_with_three_items(self):
""" """
Test the create_separated_list function with a list of three items Test the create_separated_list function with a list of three items
""" """
with patch('openlp.core.lib.Qt') as mocked_qt, patch('openlp.core.lib.translate') as mocked_translate: # GIVEN: A list with three strings.
# GIVEN: A list with a string and the mocked Qt module. string_list = ['Author 1', 'Author 2', 'Author 3']
mocked_qt.PYQT_VERSION_STR = '4.8'
mocked_qt.qVersion.return_value = '4.7'
# Always return the untranslated string.
mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate
string_list = ['Author 1', 'Author 2', 'Author 3']
# WHEN: We get a string build from the entries it the list and a seperator. # WHEN: We get a string build from the entries it the list and a seperator.
string_result = create_separated_list(string_list) string_result = create_separated_list(string_list)
# THEN: We should have "Author 1, Author 2, and Author 3" # THEN: We should have "Author 1, Author 2, and Author 3"
assert string_result == 'Author 1, Author 2, and Author 3', 'The string should be u\'Author 1, ' \ assert string_result == 'Author 1, Author 2, and Author 3', 'The string should be u\'Author 1, ' \
'Author 2, and Author 3\'.' 'Author 2, and Author 3\'.'