2013-02-14 14:54:45 +00:00
|
|
|
"""
|
|
|
|
Package to test the openlp.core.lib.formattingtags package.
|
|
|
|
"""
|
2013-02-15 11:55:47 +00:00
|
|
|
import copy
|
2013-02-14 14:54:45 +00:00
|
|
|
from unittest import TestCase
|
|
|
|
|
|
|
|
from mock import patch
|
|
|
|
|
|
|
|
from openlp.core.lib import FormattingTags
|
|
|
|
|
2013-02-15 11:55:47 +00:00
|
|
|
|
2013-02-16 18:11:22 +00:00
|
|
|
TAG = {
|
|
|
|
u'end tag': '{/aa}',
|
|
|
|
u'start html': '<span>',
|
|
|
|
u'start tag': '{aa}',
|
|
|
|
u'protected': False,
|
|
|
|
u'end html': '</span>',
|
|
|
|
u'desc': 'name'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-14 14:54:45 +00:00
|
|
|
class TestFormattingTags(TestCase):
|
|
|
|
|
2013-02-15 11:09:51 +00:00
|
|
|
def tearDown(self):
|
|
|
|
"""
|
|
|
|
Clean up the FormattingTags class.
|
|
|
|
"""
|
|
|
|
FormattingTags.html_expands = []
|
|
|
|
|
2013-02-14 14:54:45 +00:00
|
|
|
def get_html_tags_no_user_tags_test(self):
|
|
|
|
"""
|
2013-02-16 18:11:22 +00:00
|
|
|
Test the FormattingTags class' get_html_tags static method.
|
2013-02-14 14:54:45 +00:00
|
|
|
"""
|
|
|
|
with patch(u'openlp.core.lib.translate') as mocked_translate, \
|
|
|
|
patch(u'openlp.core.lib.settings') as mocked_settings, \
|
|
|
|
patch(u'openlp.core.lib.formattingtags.cPickle') as mocked_cPickle:
|
|
|
|
# GIVEN: Our mocked modules and functions.
|
2013-02-15 11:09:51 +00:00
|
|
|
mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate
|
2013-02-14 14:54:45 +00:00
|
|
|
mocked_settings.value.return_value = u''
|
|
|
|
mocked_cPickle.load.return_value = []
|
|
|
|
|
|
|
|
# WHEN: Get the display tags.
|
|
|
|
FormattingTags.load_tags()
|
2013-02-16 11:46:57 +00:00
|
|
|
old_tags_list = copy.deepcopy(FormattingTags.get_html_tags())
|
2013-02-14 14:54:45 +00:00
|
|
|
FormattingTags.load_tags()
|
|
|
|
new_tags_list = FormattingTags.get_html_tags()
|
|
|
|
|
2013-02-27 21:40:55 +00:00
|
|
|
# THEN: Lists should be identical.
|
|
|
|
assert old_tags_list == new_tags_list, u'The formatting tag lists should be identical.'
|
2013-02-14 14:54:45 +00:00
|
|
|
|
|
|
|
def get_html_tags_with_user_tags_test(self):
|
|
|
|
"""
|
2013-02-19 07:27:55 +00:00
|
|
|
FormattingTags class - test the get_html_tags(), add_html_tags() and remove_html_tag() methods.
|
2013-02-14 14:54:45 +00:00
|
|
|
"""
|
|
|
|
with patch(u'openlp.core.lib.translate') as mocked_translate, \
|
|
|
|
patch(u'openlp.core.lib.settings') as mocked_settings, \
|
|
|
|
patch(u'openlp.core.lib.formattingtags.cPickle') as mocked_cPickle:
|
|
|
|
# GIVEN: Our mocked modules and functions.
|
|
|
|
mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate
|
|
|
|
mocked_settings.value.return_value = u''
|
2013-02-16 18:11:22 +00:00
|
|
|
mocked_cPickle.loads.side_effect = [[], [TAG]]
|
2013-02-14 14:54:45 +00:00
|
|
|
|
|
|
|
# WHEN: Get the display tags.
|
|
|
|
FormattingTags.load_tags()
|
2013-02-15 11:55:47 +00:00
|
|
|
old_tags_list = copy.deepcopy(FormattingTags.get_html_tags())
|
2013-02-15 11:09:51 +00:00
|
|
|
|
2013-02-15 11:55:47 +00:00
|
|
|
# WHEN: Add our tag and get the tags again.
|
2013-02-14 14:54:45 +00:00
|
|
|
FormattingTags.load_tags()
|
2013-02-16 18:11:22 +00:00
|
|
|
FormattingTags.add_html_tags([TAG])
|
2013-02-19 07:27:55 +00:00
|
|
|
new_tags_list = copy.deepcopy(FormattingTags.get_html_tags())
|
2013-02-14 14:54:45 +00:00
|
|
|
|
2013-02-27 21:40:55 +00:00
|
|
|
# THEN: Lists should not be identical.
|
2013-02-15 11:55:47 +00:00
|
|
|
assert old_tags_list != new_tags_list, u'The lists should be different.'
|
2013-02-14 14:54:45 +00:00
|
|
|
|
2013-02-15 11:55:47 +00:00
|
|
|
# THEN: Added tag and last tag should be the same.
|
|
|
|
new_tag = new_tags_list.pop()
|
2013-02-27 21:40:55 +00:00
|
|
|
assert TAG == new_tag, u'Tags should be identical.'
|
2013-02-14 14:54:45 +00:00
|
|
|
|
2013-02-19 07:30:41 +00:00
|
|
|
# WHEN: Remove the new tag.
|
2013-02-19 07:27:55 +00:00
|
|
|
FormattingTags.remove_html_tag(len(new_tags_list))
|
|
|
|
|
2013-02-27 21:40:55 +00:00
|
|
|
# THEN: The lists should now be identical.
|
|
|
|
assert old_tags_list == FormattingTags.get_html_tags(), u'The lists should be identical.'
|
2013-02-19 07:27:55 +00:00
|
|
|
|