Exemplo n.º 1
0
    def test_get_html_tags_with_user_tags(self):
        """
        FormattingTags class - test the get_html_tags(), add_html_tags() and remove_html_tag() methods.
        """
        with patch('openlp.core.lib.translate') as mocked_translate, \
                patch('openlp.core.common.settings') as mocked_settings, \
                patch('openlp.core.lib.formattingtags.json') as mocked_json:
            # GIVEN: Our mocked modules and functions.
            mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate
            mocked_settings.value.return_value = ''
            mocked_json.loads.side_effect = [[], [TAG]]

            # WHEN: Get the display tags.
            FormattingTags.load_tags()
            old_tags_list = copy.deepcopy(FormattingTags.get_html_tags())

            # WHEN: Add our tag and get the tags again.
            FormattingTags.load_tags()
            FormattingTags.add_html_tags([TAG])
            new_tags_list = copy.deepcopy(FormattingTags.get_html_tags())

            # THEN: Lists should not be identical.
            assert old_tags_list != new_tags_list, 'The lists should be different.'

            # THEN: Added tag and last tag should be the same.
            new_tag = new_tags_list.pop()
            assert TAG == new_tag, 'Tags should be identical.'

            # WHEN: Remove the new tag.
            FormattingTags.remove_html_tag(len(new_tags_list))

            # THEN: The lists should now be identical.
            assert old_tags_list == FormattingTags.get_html_tags(), 'The lists should be identical.'
Exemplo n.º 2
0
    def get_html_tags_with_user_tags_test(self):
        """
        FormattingTags class - test the get_html_tags(), add_html_tags() and remove_html_tag() methods.
        """
        with patch('openlp.core.lib.translate') as mocked_translate, \
                patch('openlp.core.lib.settings') as mocked_settings, \
                patch('openlp.core.lib.formattingtags.json') as mocked_json:
            # GIVEN: Our mocked modules and functions.
            mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate
            mocked_settings.value.return_value = ''
            mocked_json.loads.side_effect = [[], [TAG]]

            # WHEN: Get the display tags.
            FormattingTags.load_tags()
            old_tags_list = copy.deepcopy(FormattingTags.get_html_tags())

            # WHEN: Add our tag and get the tags again.
            FormattingTags.load_tags()
            FormattingTags.add_html_tags([TAG])
            new_tags_list = copy.deepcopy(FormattingTags.get_html_tags())

            # THEN: Lists should not be identical.
            assert old_tags_list != new_tags_list, 'The lists should be different.'

            # THEN: Added tag and last tag should be the same.
            new_tag = new_tags_list.pop()
            assert TAG == new_tag, 'Tags should be identical.'

            # WHEN: Remove the new tag.
            FormattingTags.remove_html_tag(len(new_tags_list))

            # THEN: The lists should now be identical.
            assert old_tags_list == FormattingTags.get_html_tags(), 'The lists should be identical.'
Exemplo n.º 3
0
 def _setup(self):
     """
     Set up the class. This method is mocked out by the tests.
     """
     self.services = FormattingTagController()
     self.tag_table_widget.itemSelectionChanged.connect(self.on_row_selected)
     self.new_button.clicked.connect(self.on_new_clicked)
     self.delete_button.clicked.connect(self.on_delete_clicked)
     self.tag_table_widget.currentCellChanged.connect(self.on_current_cell_changed)
     self.button_box.rejected.connect(self.close)
     # Forces reloading of tags from openlp configuration.
     FormattingTags.load_tags()
     self.is_deleting = False
     self.reloading = False
Exemplo n.º 4
0
 def _setup(self):
     """
     Set up the class. This method is mocked out by the tests.
     """
     self.services = FormattingTagController()
     self.tag_table_widget.itemSelectionChanged.connect(self.on_row_selected)
     self.new_button.clicked.connect(self.on_new_clicked)
     self.delete_button.clicked.connect(self.on_delete_clicked)
     self.tag_table_widget.currentCellChanged.connect(self.on_current_cell_changed)
     self.button_box.rejected.connect(self.close)
     # Forces reloading of tags from openlp configuration.
     FormattingTags.load_tags()
     self.is_deleting = False
     self.reloading = False
Exemplo n.º 5
0
    def test_find_formatting_tags(self):
        """
        Test that find_formatting_tags works as expected
        """
        # GIVEN: Lyrics with formatting tags and a empty list of formatting tags
        lyrics = '{st}Amazing {r}grace{/r} how sweet the sound'
        tags = []
        FormattingTags.load_tags()

        # WHEN: Detecting active formatting tags
        active_tags = find_formatting_tags(lyrics, tags)

        # THEN: The list of active tags should contain only 'st'
        assert [
            'st'
        ] == active_tags, 'The list of active tags should contain only "st"'
Exemplo n.º 6
0
    def get_html_tags_no_user_tags_test(self):
        """
        Test the FormattingTags class' get_html_tags static method.
        """
        with patch('openlp.core.lib.translate') as mocked_translate, \
                patch('openlp.core.lib.settings') as mocked_settings, \
                patch('openlp.core.lib.formattingtags.json') as mocked_json:
            # GIVEN: Our mocked modules and functions.
            mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate
            mocked_settings.value.return_value = ''
            mocked_json.load.return_value = []

            # WHEN: Get the display tags.
            FormattingTags.load_tags()
            old_tags_list = copy.deepcopy(FormattingTags.get_html_tags())
            FormattingTags.load_tags()
            new_tags_list = FormattingTags.get_html_tags()

            # THEN: Lists should be identical.
            assert old_tags_list == new_tags_list, 'The formatting tag lists should be identical.'
Exemplo n.º 7
0
    def test_get_html_tags_no_user_tags(self):
        """
        Test the FormattingTags class' get_html_tags static method.
        """
        with patch('openlp.core.lib.translate') as mocked_translate, \
                patch('openlp.core.common.settings') as mocked_settings, \
                patch('openlp.core.lib.formattingtags.json') as mocked_json:
            # GIVEN: Our mocked modules and functions.
            mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate
            mocked_settings.value.return_value = ''
            mocked_json.load.return_value = []

            # WHEN: Get the display tags.
            FormattingTags.load_tags()
            old_tags_list = copy.deepcopy(FormattingTags.get_html_tags())
            FormattingTags.load_tags()
            new_tags_list = FormattingTags.get_html_tags()

            # THEN: Lists should be identical.
            assert old_tags_list == new_tags_list, 'The formatting tag lists should be identical.'
Exemplo n.º 8
0
    def test_service_item_load_song_and_audio_from_service(self):
        """
        Test the Service Item - adding a song slide from a saved service
        """
        # GIVEN: A new service item and a mocked add icon function
        service_item = ServiceItem(None)
        service_item.add_icon = MagicMock()
        FormattingTags.load_tags()

        # WHEN: We add a custom from a saved service
        line = convert_file_service_item(TEST_PATH,
                                         'serviceitem-song-linked-audio.osj')
        service_item.set_from_service(line, '/test/')

        # THEN: We should get back a valid service item
        assert service_item.is_valid is True, 'The new service item should be valid'
        assert 0 == len(service_item._display_frames
                        ), 'The service item should have no display frames'
        assert 7 == len(service_item.capabilities
                        ), 'There should be 7 default custom item capabilities'

        # WHEN: We render the frames of the service item
        service_item.render(True)

        # THEN: The frames should also be valid
        assert 'Amazing Grace' == service_item.get_display_title(
        ), 'The title should be "Amazing Grace"'
        assert CLEANED_VERSE[:-1] == service_item.get_frames()[0]['text'], \
            'The returned text matches the input, except the last line feed'
        assert RENDERED_VERSE.split('\n', 1)[0] == service_item.get_rendered_frame(1), \
            'The first line has been returned'
        assert 'Amazing Grace! how sweet the s' == service_item.get_frame_title(0), \
            '"Amazing Grace! how sweet the s" has been returned as the title'
        assert '’Twas grace that taught my hea' == service_item.get_frame_title(1), \
            '"’Twas grace that taught my hea" has been returned as the title'
        assert Path('/test/amazing_grace.mp3') == service_item.background_audio[0], \
            '"/test/amazing_grace.mp3" should be in the background_audio list'
Exemplo n.º 9
0
    def test_expand_chords_for_printing(self):
        """
        Test that the expanding of chords for printing works as expected.
        """
        # GIVEN: A lyrics-line with chords
        text_with_chords = '{st}[D]Amazing {r}gr[D7]ace{/r}  how [G]sweet the [D]sound  [F]{/st}'
        FormattingTags.load_tags()

        # WHEN: Expanding the chords
        text_with_expanded_chords = expand_chords_for_printing(
            text_with_chords, '{br}')

        # THEN: We should get html that looks like below
        expected_html = '<table class="line" width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td><table ' \
                        'class="segment" cellpadding="0" cellspacing="0" border="0" align="left"><tr class="chordrow">'\
                        '<td class="chord">&nbsp;</td><td class="chord">D</td></tr><tr><td class="lyrics">{st}{/st}' \
                        '</td><td class="lyrics">{st}Amazing&nbsp;{/st}</td></tr></table><table class="segment" ' \
                        'cellpadding="0" cellspacing="0" border="0" align="left"><tr class="chordrow">' \
                        '<td class="chord">&nbsp;</td><td class="chord">D7</td></tr><tr><td class="lyrics">{st}{r}gr' \
                        '{/r}{/st}</td><td class="lyrics">{r}{st}ace{/r}&nbsp;{/st}</td></tr></table><table ' \
                        'class="segment" cellpadding="0" cellspacing="0" border="0" align="left"><tr class="chordrow">'\
                        '<td class="chord">&nbsp;</td></tr><tr><td class="lyrics">{st}&nbsp;{/st}</td></tr></table>' \
                        '<table class="segment" cellpadding="0" cellspacing="0" border="0" align="left"><tr ' \
                        'class="chordrow"><td class="chord">&nbsp;</td></tr><tr><td class="lyrics">{st}how&nbsp;{/st}' \
                        '</td></tr></table><table class="segment" cellpadding="0" cellspacing="0" border="0" ' \
                        'align="left"><tr class="chordrow"><td class="chord">G</td></tr><tr><td class="lyrics">{st}' \
                        'sweet&nbsp;{/st}</td></tr></table><table class="segment" cellpadding="0" cellspacing="0" ' \
                        'border="0" align="left"><tr class="chordrow"><td class="chord">&nbsp;</td></tr><tr><td ' \
                        'class="lyrics">{st}the&nbsp;{/st}</td></tr></table><table class="segment" cellpadding="0" ' \
                        'cellspacing="0" border="0" align="left"><tr class="chordrow"><td class="chord">D</td></tr>' \
                        '<tr><td class="lyrics">{st}sound&nbsp;{/st}</td></tr></table><table class="segment" ' \
                        'cellpadding="0" cellspacing="0" border="0" align="left"><tr class="chordrow"><td ' \
                        'class="chord">&nbsp;</td></tr><tr><td class="lyrics">{st}&nbsp;{/st}</td></tr></table>' \
                        '<table class="segment" cellpadding="0" cellspacing="0" border="0" align="left"><tr ' \
                        'class="chordrow"><td class="chord">F</td></tr><tr><td class="lyrics">{st}{/st}&nbsp;</td>' \
                        '</tr></table></td></tr></table>'
        assert expected_html == text_with_expanded_chords, 'The expanded chords should look as expected!'
Exemplo n.º 10
0
    def test_service_item_load_custom_from_service(self):
        """
        Test the Service Item - adding a custom slide from a saved service
        """
        # GIVEN: A new service item and a mocked add icon function
        service_item = ServiceItem(None)
        service_item.add_icon = MagicMock()
        FormattingTags.load_tags()

        # WHEN: We add a custom from a saved service
        line = convert_file_service_item(TEST_PATH, 'serviceitem_custom_1.osj')
        service_item.set_from_service(line)

        # THEN: We should get back a valid service item
        assert service_item.is_valid is True, 'The new service item should be valid'
        assert_length(0, service_item._display_frames,
                      'The service item should have no display frames')
        assert_length(5, service_item.capabilities,
                      'There should be 5 default custom item capabilities')

        # WHEN: We render the frames of the service item
        service_item.render(True)

        # THEN: The frames should also be valid
        assert 'Test Custom' == service_item.get_display_title(
        ), 'The title should be "Test Custom"'
        assert CLEANED_VERSE[:-1] == service_item.get_frames()[0]['text'], \
            'The returned text matches the input, except the last line feed'
        assert RENDERED_VERSE.split('\n', 1)[0] == service_item.get_rendered_frame(1), \
            'The first line has been returned'
        assert 'Slide 1' == service_item.get_frame_title(
            0), '"Slide 1" has been returned as the title'
        assert 'Slide 2' == service_item.get_frame_title(
            1), '"Slide 2" has been returned as the title'
        assert '' == service_item.get_frame_title(
            2), 'Blank has been returned as the title of slide 3'
Exemplo n.º 11
0
 def save_tags(self):
     """
     Save the new tags if they are valid.
     """
     FormattingTags.save_html_tags(self.custom_tags)
     FormattingTags.load_tags()
Exemplo n.º 12
0
 def __init__(self, manager):
     self.manager = manager
     FormattingTags.load_tags()
Exemplo n.º 13
0
 def save_tags(self):
     """
     Save the new tags if they are valid.
     """
     FormattingTags.save_html_tags(self.custom_tags)
     FormattingTags.load_tags()
Exemplo n.º 14
0
 def __init__(self, manager):
     self.manager = manager
     FormattingTags.load_tags()