Exemple #1
0
    def test_build_song_footer_one_author_hide_written_by(
            self, MockedSettings):
        """
        Test build songs footer with basic song and one author
        """
        # GIVEN: A Song and a Service Item, mocked settings: False for 'songs/display written by'
        # and False for 'core/ccli number' (ccli will cause traceback if true)

        mocked_settings = MagicMock()
        mocked_settings.value.side_effect = [False, False]
        MockedSettings.return_value = mocked_settings

        mock_song = MagicMock()
        mock_song.title = 'My Song'
        mock_song.authors_songs = []
        mock_author = MagicMock()
        mock_author.display_name = 'my author'
        mock_author_song = MagicMock()
        mock_author_song.author = mock_author
        mock_song.authors_songs.append(mock_author_song)
        mock_song.copyright = 'My copyright'
        service_item = ServiceItem(None)

        # WHEN: I generate the Footer with default settings
        author_list = self.media_item.generate_footer(service_item, mock_song)

        # THEN: I get the following Array returned
        assert service_item.raw_footer == ['My Song', 'my author', 'My copyright'], \
            'The array should be returned correctly with a song, one author and copyright, ' \
            'text Written by should not be part of the text.'
        assert author_list == [
            'my author'
        ], 'The author list should be returned correctly with one author'
Exemple #2
0
 def test_build_context_menu(self):
     """
     Test the creation of a context menu from a null service item.
     """
     # GIVEN: A new service manager instance and a default service item.
     service_manager = ServiceManager(None)
     item = MagicMock()
     item.parent.return_value = False
     item.data.return_value = 0
     service_manager.service_manager_list = MagicMock()
     service_manager.service_manager_list.itemAt.return_value = item
     service_item = ServiceItem(None)
     service_manager.service_items.insert(1, {'service_item': service_item})
     service_manager.edit_action = MagicMock()
     service_manager.rename_action = MagicMock()
     service_manager.create_custom_action = MagicMock()
     service_manager.maintain_action = MagicMock()
     service_manager.notes_action = MagicMock()
     service_manager.time_action = MagicMock()
     service_manager.auto_start_action = MagicMock()
     service_manager.auto_play_slides_menu = MagicMock()
     service_manager.auto_play_slides_once = MagicMock()
     service_manager.auto_play_slides_loop = MagicMock()
     service_manager.timed_slide_interval = MagicMock()
     service_manager.theme_menu = MagicMock()
     service_manager.menu = MagicMock()
     # WHEN I define a context menu
     service_manager.context_menu(1)
     # THEN the following calls should have occurred.
     self.assertEqual(service_manager.edit_action.setVisible.call_count, 1,
                      'Should have been called once')
     self.assertEqual(service_manager.rename_action.setVisible.call_count,
                      1, 'Should have been called once')
     self.assertEqual(
         service_manager.create_custom_action.setVisible.call_count, 1,
         'Should have been called once')
     self.assertEqual(service_manager.maintain_action.setVisible.call_count,
                      1, 'Should have been called once')
     self.assertEqual(service_manager.notes_action.setVisible.call_count, 1,
                      'Should have been called once')
     self.assertEqual(service_manager.time_action.setVisible.call_count, 1,
                      'Should have been called once')
     self.assertEqual(
         service_manager.auto_start_action.setVisible.call_count, 1,
         'Should have been called once')
     self.assertEqual(
         service_manager.auto_play_slides_menu.menuAction().setVisible.
         call_count, 1, 'Should have been called once')
     self.assertEqual(
         service_manager.auto_play_slides_once.setChecked.call_count, 0,
         'Should not be called')
     self.assertEqual(
         service_manager.auto_play_slides_loop.setChecked.call_count, 0,
         'Should not be called')
     self.assertEqual(
         service_manager.timed_slide_interval.setChecked.call_count, 0,
         'Should not be called')
     self.assertEqual(
         service_manager.theme_menu.menuAction().setVisible.call_count, 1,
         'Should have been called once')
Exemple #3
0
    def build_song_footer_base_songbook_test(self):
        """
        Test build songs footer with basic song and a songbook
        """
        # GIVEN: A Song and a Service Item
        mock_song = MagicMock()
        mock_song.title = 'My Song'
        mock_song.copyright = 'My copyright'
        mock_song.book = MagicMock()
        mock_song.book.name = "My songbook"
        mock_song.song_number = 12
        service_item = ServiceItem(None)

        # WHEN: I generate the Footer with default settings
        self.media_item.generate_footer(service_item, mock_song)

        # THEN: The songbook should not be in the footer
        self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright'])

        # WHEN: I activate the "display songbook" option
        self.media_item.display_songbook = True
        self.media_item.generate_footer(service_item, mock_song)

        # THEN: The songbook should be in the footer
        self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'My songbook #12'])
Exemple #4
0
    def service_item_load_song_and_audio_from_service_test(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()

        # 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
        self.assertTrue(service_item.is_valid, 'The new service item should be valid')
        assert_length(0, service_item._display_frames, 'The service item should have no display frames')
        assert_length(7, 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
        self.assertEqual('Amazing Grace', service_item.get_display_title(), 'The title should be "Amazing Grace"')
        self.assertEqual(VERSE[:-1], service_item.get_frames()[0]['text'],
                         'The returned text matches the input, except the last line feed')
        self.assertEqual(VERSE.split('\n', 1)[0], service_item.get_rendered_frame(1),
                         'The first line has been returned')
        self.assertEqual('Amazing Grace! how sweet the s', service_item.get_frame_title(0),
                         '"Amazing Grace! how sweet the s" has been returned as the title')
        self.assertEqual('’Twas grace that taught my hea', service_item.get_frame_title(1),
                         '"’Twas grace that taught my hea" has been returned as the title')
        self.assertEqual('/test/amazing_grace.mp3', service_item.background_audio[0],
                         '"/test/amazing_grace.mp3" should be in the background_audio list')
Exemple #5
0
 def setup(self):
     """
     Set up and build the output screen
     """
     self.log_debug('Start MainDisplay setup (live = %s)' % self.is_live)
     self.screen = self.screens.current
     self.setVisible(False)
     Display.setup(self)
     if self.is_live:
         # Build the initial frame.
         background_color = QtGui.QColor()
         background_color.setNamedColor(Settings().value('advanced/default color'))
         if not background_color.isValid():
             background_color = QtCore.Qt.white
         image_file = Settings().value('advanced/default image')
         splash_image = QtGui.QImage(image_file)
         self.initial_fame = QtGui.QImage(
             self.screen['size'].width(),
             self.screen['size'].height(),
             QtGui.QImage.Format_ARGB32_Premultiplied)
         painter_image = QtGui.QPainter()
         painter_image.begin(self.initial_fame)
         painter_image.fillRect(self.initial_fame.rect(), background_color)
         painter_image.drawImage(
             (self.screen['size'].width() - splash_image.width()) // 2,
             (self.screen['size'].height() - splash_image.height()) // 2,
             splash_image)
         service_item = ServiceItem()
         service_item.bg_image_bytes = image_to_byte(self.initial_fame)
         self.web_view.setHtml(build_html(service_item, self.screen, self.is_live, None,
                               plugins=self.plugin_manager.plugins))
         self._hide_mouse()
Exemple #6
0
    def add_from_command_for_a_presentation_thumb_test(self, mocked_get_section_data_path):
        """
        Test the Service Item - adding a presentation, and updating the thumb path
        """
        # GIVEN: A service item, a mocked AppLocation and presentation data
        mocked_get_section_data_path.return_value = os.path.join('mocked', 'section', 'path')
        service_item = ServiceItem(None)
        service_item.has_original_files = False
        service_item.name = 'presentations'
        presentation_name = 'test.pptx'
        thumb = os.path.join('tmp', 'test', 'thumb.png')
        display_title = 'DisplayTitle'
        notes = 'Note1\nNote2\n'
        expected_thumb_path = os.path.join('mocked', 'section', 'path', 'thumbnails',
                                           md5_hash(os.path.join(TEST_PATH, presentation_name).encode('utf-8')),
                                           'thumb.png')
        frame = {'title': presentation_name, 'image': expected_thumb_path, 'path': TEST_PATH,
                 'display_title': display_title, 'notes': notes}

        # WHEN: adding presentation to service_item
        service_item.add_from_command(TEST_PATH, presentation_name, thumb, display_title, notes)

        # THEN: verify that it is setup as a Command and that the frame data matches
        self.assertEqual(service_item.service_item_type, ServiceItemType.Command, 'It should be a Command')
        self.assertEqual(service_item.get_frames()[0], frame, 'Frames should match')
Exemple #7
0
    def service_item_load_custom_from_service_test(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()

        # 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
        self.assertTrue(service_item.is_valid, '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
        self.assertEqual('Test Custom', service_item.get_display_title(), 'The title should be "Test Custom"')
        self.assertEqual(VERSE[:-1], service_item.get_frames()[0]['text'],
                         'The returned text matches the input, except the last line feed')
        self.assertEqual(VERSE.split('\n', 1)[0], service_item.get_rendered_frame(1),
                         'The first line has been returned')
        self.assertEqual('Slide 1', service_item.get_frame_title(0), '"Slide 1" has been returned as the title')
        self.assertEqual('Slide 2', service_item.get_frame_title(1), '"Slide 2" has been returned as the title')
        self.assertEqual('', service_item.get_frame_title(2), 'Blank has been returned as the title of slide 3')
Exemple #8
0
    def test_build_song_footer_base_ccli(self):
        """
        Test build songs footer with basic song and a CCLI number
        """
        # GIVEN: A Song and a Service Item and a configured CCLI license
        mock_song = MagicMock()
        mock_song.title = 'My Song'
        mock_song.copyright = 'My copyright'
        service_item = ServiceItem(None)
        Settings().setValue('core/ccli number', '1234')

        # WHEN: I generate the Footer with default settings
        self.media_item.generate_footer(service_item, mock_song)

        # THEN: I get the following Array returned
        assert service_item.raw_footer == ['My Song', 'My copyright', 'CCLI License: 1234'], \
            'The array should be returned correctly with a song, an author, copyright and ccli'

        # WHEN: I amend the CCLI value
        Settings().setValue('core/ccli number', '4321')
        self.media_item.generate_footer(service_item, mock_song)

        # THEN: I would get an amended footer string
        assert service_item.raw_footer == ['My Song', 'My copyright', 'CCLI License: 4321'], \
            'The array should be returned correctly with a song, an author, copyright and amended ccli'
Exemple #9
0
 def on_replace_click(self):
     """
     Called to replace Live background with the media selected.
     """
     if check_item_selected(
             self.list_view,
             translate(
                 'MediaPlugin.MediaItem',
                 'You must select a media file to replace the background with.'
             )):
         item = self.list_view.currentItem()
         filename = item.data(QtCore.Qt.UserRole)
         if os.path.exists(filename):
             service_item = ServiceItem()
             service_item.title = 'webkit'
             service_item.processor = 'webkit'
             (path, name) = os.path.split(filename)
             service_item.add_from_command(path, name, CLAPPERBOARD)
             if self.media_controller.video(DisplayControllerType.Live,
                                            service_item,
                                            video_behind_text=True):
                 self.reset_action.setVisible(True)
             else:
                 critical_error_message_box(
                     UiStrings().LiveBGError,
                     translate('MediaPlugin.MediaItem',
                               'There was no display item to amend.'))
         else:
             critical_error_message_box(
                 UiStrings().LiveBGError,
                 translate(
                     'MediaPlugin.MediaItem',
                     'There was a problem replacing your background, '
                     'the media file "%s" no longer exists.') % filename)
Exemple #10
0
    def generate_preview(self, theme_data, force_page=False):
        """
        Generate a preview of a theme.

        :param theme_data:  The theme to generated a preview for.
        :param force_page: Flag to tell message lines per page need to be generated.
        """
        # save value for use in format_slide
        self.force_page = force_page
        # build a service item to generate preview
        service_item = ServiceItem()
        if self.force_page:
            # make big page for theme edit dialog to get line count
            service_item.add_from_text(VERSE_FOR_LINE_COUNT)
        else:
            service_item.add_from_text(VERSE)
        service_item.raw_footer = FOOTER
        # if No file do not update cache
        if theme_data.background_filename:
            self.image_manager.add_image(
                theme_data.background_filename, ImageSource.Theme,
                QtGui.QColor(theme_data.background_border_color))
        theme_data, main, footer = self.pre_render(theme_data)
        service_item.theme_data = theme_data
        service_item.main = main
        service_item.footer = footer
        service_item.render(True)
        if not self.force_page:
            self.display.build_html(service_item)
            raw_html = service_item.get_rendered_frame(0)
            self.display.text(raw_html, False)
            preview = self.display.preview()
            return preview
        self.force_page = False
Exemple #11
0
    def test_build_song_footer_base_songbook(self):
        """
        Test build songs footer with basic song and multiple songbooks
        """
        # GIVEN: A Song and a Service Item
        song = Song()
        song.title = 'My Song'
        song.copyright = 'My copyright'
        song.authors_songs = []
        song.songbook_entries = []
        song.ccli_number = ''
        book1 = MagicMock()
        book1.name = "My songbook"
        book2 = MagicMock()
        book2.name = "Thy songbook"
        song.songbookentries = []
        song.add_songbook_entry(book1, '12')
        song.add_songbook_entry(book2, '502A')
        service_item = ServiceItem(None)

        # WHEN: I generate the Footer with default settings
        self.media_item.generate_footer(service_item, song)

        # THEN: The songbook should not be in the footer
        self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright'])

        # WHEN: I activate the "display songbook" option
        self.media_item.display_songbook = True
        self.media_item.generate_footer(service_item, song)

        # THEN: The songbook should be in the footer
        self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'My songbook #12, Thy songbook #502A'])
Exemple #12
0
    def test_add_from_command_for_a_presentation(self):
        """
        Test the Service Item - adding a presentation
        """
        # GIVEN: A service item, a mocked icon and presentation data
        service_item = ServiceItem(None)
        presentation_name = 'test.pptx'
        image = MagicMock()
        display_title = 'DisplayTitle'
        notes = 'Note1\nNote2\n'
        frame = {
            'title': presentation_name,
            'image': image,
            'path': TEST_PATH,
            'display_title': display_title,
            'notes': notes
        }

        # WHEN: adding presentation to service_item
        service_item.add_from_command(TEST_PATH, presentation_name, image,
                                      display_title, notes)

        # THEN: verify that it is setup as a Command and that the frame data matches
        assert service_item.service_item_type == ServiceItemType.Command, 'It should be a Command'
        assert service_item.get_frames()[0] == frame, 'Frames should match'
Exemple #13
0
 def test_build_media_context_menu(self):
     """
     Test the creation of a context menu from service item of type Command from Media.
     """
     # GIVEN: A new service manager instance and a default service item.
     Registry().register('plugin_manager', MagicMock())
     Registry().register('renderer', MagicMock())
     service_manager = ServiceManager(None)
     item = MagicMock()
     item.parent.return_value = False
     item.data.return_value = 0
     service_manager.service_manager_list = MagicMock()
     service_manager.service_manager_list.itemAt.return_value = item
     service_item = ServiceItem(None)
     service_item.add_capability(ItemCapabilities.CanAutoStartForLive)
     service_item.add_capability(ItemCapabilities.CanEditTitle)
     service_item.add_capability(ItemCapabilities.RequiresMedia)
     service_item.service_item_type = ServiceItemType.Command
     service_item.edit_id = 1
     service_item._raw_frames.append(MagicMock())
     service_manager.service_items.insert(1, {'service_item': service_item})
     service_manager.edit_action = MagicMock()
     service_manager.rename_action = MagicMock()
     service_manager.create_custom_action = MagicMock()
     service_manager.maintain_action = MagicMock()
     service_manager.notes_action = MagicMock()
     service_manager.time_action = MagicMock()
     service_manager.auto_start_action = MagicMock()
     service_manager.auto_play_slides_menu = MagicMock()
     service_manager.auto_play_slides_once = MagicMock()
     service_manager.auto_play_slides_loop = MagicMock()
     service_manager.timed_slide_interval = MagicMock()
     service_manager.theme_menu = MagicMock()
     service_manager.menu = MagicMock()
     # WHEN I define a context menu
     service_manager.context_menu(1)
     # THEN the following calls should have occurred.
     assert service_manager.edit_action.setVisible.call_count == 1, 'Should have be called once'
     assert service_manager.rename_action.setVisible.call_count == 2, 'Should have be called twice'
     assert service_manager.create_custom_action.setVisible.call_count == 1, 'Should have be called once'
     assert service_manager.maintain_action.setVisible.call_count == 1, 'Should have be called once'
     assert service_manager.notes_action.setVisible.call_count == 1, 'Should have be called once'
     assert service_manager.time_action.setVisible.call_count == 1, 'Should have be called once'
     assert service_manager.auto_start_action.setVisible.call_count == 2, 'Should have be called twice'
     assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 1, \
         'Should have be called once'
     assert service_manager.auto_play_slides_once.setChecked.call_count == 0, 'Should not be called'
     assert service_manager.auto_play_slides_loop.setChecked.call_count == 0, 'Should not be called'
     assert service_manager.timed_slide_interval.setChecked.call_count == 0, 'Should not be called'
     assert service_manager.theme_menu.menuAction().setVisible.call_count == 1, \
         'Should have be called once'
     # THEN I change the length of the media and regenerate the menu.
     service_item.set_media_length(5)
     service_manager.context_menu(1)
     # THEN the following additional calls should have occurred.
     assert service_manager.time_action.setVisible.call_count == 3, 'Should have be called three times'
Exemple #14
0
    def service_load_inactive_test(self):
        """
        Test the service load in custom with a default service item
        """
        # GIVEN: An empty Service Item
        service_item = ServiceItem(None)

        # WHEN: I search for the custom in the database
        item = self.media_item.service_load(service_item)

        # THEN: the processing should be ignored
        self.assertEqual(item, None, 'The Service item is inactive so processing should be bypassed')
Exemple #15
0
    def service_item_basic_test(self):
        """
        Test the Service Item - basic test
        """
        # GIVEN: A new service item

        # WHEN: A service item is created (without a plugin)
        service_item = ServiceItem(None)

        # THEN: We should get back a valid service item
        self.assertTrue(service_item.is_valid, 'The new service item should be valid')
        self.assertTrue(service_item.missing_frames(), 'There should not be any frames in the service item')
Exemple #16
0
 def test_build_presentation_pdf_context_menu(self):
     """
     Test the creation of a context menu from service item of type Command with PDF from Presentation.
     """
     # GIVEN: A new service manager instance and a default service item.
     Registry().register('plugin_manager', MagicMock())
     Registry().register('renderer', MagicMock())
     service_manager = ServiceManager(None)
     item = MagicMock()
     item.parent.return_value = False
     item.data.return_value = 0
     service_manager.service_manager_list = MagicMock()
     service_manager.service_manager_list.itemAt.return_value = item
     service_item = ServiceItem(None)
     service_item.add_capability(ItemCapabilities.CanMaintain)
     service_item.add_capability(ItemCapabilities.CanPreview)
     service_item.add_capability(ItemCapabilities.CanLoop)
     service_item.add_capability(ItemCapabilities.CanAppend)
     service_item.service_item_type = ServiceItemType.Command
     service_item.edit_id = 1
     service_item._raw_frames.append(MagicMock())
     service_manager.service_items.insert(1, {'service_item': service_item})
     service_manager.edit_action = MagicMock()
     service_manager.rename_action = MagicMock()
     service_manager.create_custom_action = MagicMock()
     service_manager.maintain_action = MagicMock()
     service_manager.notes_action = MagicMock()
     service_manager.time_action = MagicMock()
     service_manager.auto_start_action = MagicMock()
     service_manager.auto_play_slides_menu = MagicMock()
     service_manager.auto_play_slides_once = MagicMock()
     service_manager.auto_play_slides_loop = MagicMock()
     service_manager.timed_slide_interval = MagicMock()
     service_manager.theme_menu = MagicMock()
     service_manager.menu = MagicMock()
     # WHEN I define a context menu
     service_manager.context_menu(1)
     # THEN the following calls should have occurred.
     assert service_manager.edit_action.setVisible.call_count == 1, 'Should have be called once'
     assert service_manager.rename_action.setVisible.call_count == 1, 'Should have be called once'
     assert service_manager.create_custom_action.setVisible.call_count == 1, 'Should have be called once'
     assert service_manager.maintain_action.setVisible.call_count == 2, 'Should have be called twice'
     assert service_manager.notes_action.setVisible.call_count == 1, 'Should have be called once'
     assert service_manager.time_action.setVisible.call_count == 1, 'Should have be called once'
     assert service_manager.auto_start_action.setVisible.call_count == 1, 'Should have be called once'
     assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 1, \
         'Should have be called once'
     assert service_manager.auto_play_slides_once.setChecked.call_count == 0, 'Should not be called'
     assert service_manager.auto_play_slides_loop.setChecked.call_count == 0, 'Should not be called'
     assert service_manager.timed_slide_interval.setChecked.call_count == 0, 'Should not be called'
     assert service_manager.theme_menu.menuAction().setVisible.call_count == 1, \
         'Should have be called once'
Exemple #17
0
    def test_build_song_footer_copyright_disabled(self):
        """
        Test building song footer without displaying the copyright symbol
        """
        # GIVEN: A Song and a Service Item; displaying the copyright symbol should be disabled by default
        mock_song = MagicMock()
        mock_song.title = 'My Song'
        mock_song.copyright = 'My copyright'
        service_item = ServiceItem(None)

        # WHEN: I generate the Footer with default settings
        self.media_item.generate_footer(service_item, mock_song)

        # THEN: The copyright symbol should not be in the footer
        assert service_item.raw_footer == ['My Song', 'My copyright']
Exemple #18
0
 def change_slide_test(self):
     """
     Test the change_slide method.
     """
     # GIVEN: A ServiceItem with two frames content.
     service_item = ServiceItem(None)
     service = read_service_from_file('serviceitem_image_3.osj')
     with patch('os.path.exists'):
         service_item.set_from_service(service[0])
     # WHEN: Added to the preview widget and switched to the second frame.
     self.preview_widget.replace_service_item(service_item, 1, 0)
     self.preview_widget.change_slide(1)
     # THEN: The current_slide_number should reflect the change.
     self.assertEqual(self.preview_widget.current_slide_number(), 1,
                      'The current slide number should  be 1.')
Exemple #19
0
 def test_controller_text(self):
     """
     Remote API Tests : test the controller text method can be called with a real service item
     """
     # GIVEN: A mocked service with a dummy service item
     line = convert_file_service_item(TEST_PATH, 'serviceitem_custom_1.osj')
     self.mocked_live_controller.service_item = ServiceItem(None)
     self.mocked_live_controller.service_item.set_from_service(line)
     self.mocked_live_controller.service_item.render(True)
     # WHEN: I trigger the method
     ret = controller_text("SomeText")
     # THEN: I get a basic set of results
     results = ret['results']
     assert isinstance(ret, dict)
     assert len(results['slides']) == 2
Exemple #20
0
 def _setup(self, screen_ratio):
     """
     Set up the widget
     """
     self.setColumnCount(1)
     self.horizontalHeader().setVisible(False)
     self.setColumnWidth(0, self.parent().width())
     self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
     self.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
     self.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
     self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
     self.setAlternatingRowColors(True)
     # Initialize variables.
     self.service_item = ServiceItem()
     self.screen_ratio = screen_ratio
Exemple #21
0
    def test_format_slide_logical_split(self):
        """
        Test that a line with text and a logic break does not break the renderer just returns the input
        """
        # GIVEN: A line of with a space text and the logical split
        renderer = Renderer()
        renderer.empty_height = 480
        given_line = 'a\n[---]\nb'
        expected_words = ['a<br>[---]<br>b']
        service_item = ServiceItem(None)

        # WHEN: Split the line based on word split rules
        result_words = renderer.format_slide(given_line, service_item)

        # THEN: The word lists should be the same.
        self.assertListEqual(result_words, expected_words)
Exemple #22
0
    def test_format_slide_blank_after_split(self):
        """
        Test that a line with blanks before the logical split at handled
        """
        # GIVEN: A line of with a space after the logical split
        renderer = Renderer()
        renderer.empty_height = 480
        given_line = '\n[---]  \n'
        expected_words = ['<br>[---]  ']
        service_item = ServiceItem(None)

        # WHEN: Split the line based on word split rules
        result_words = renderer.format_slide(given_line, service_item)

        # THEN: The blanks have been removed.
        self.assertListEqual(result_words, expected_words)
Exemple #23
0
    def test_build_song_footer_copyright_enabled(self):
        """
        Test building song footer with displaying the copyright symbol
        """
        # GIVEN: A Song and a Service Item; displaying the copyright symbol is enabled
        self.media_item.display_copyright_symbol = True
        mock_song = MagicMock()
        mock_song.title = 'My Song'
        mock_song.copyright = 'My copyright'
        service_item = ServiceItem(None)

        # WHEN: I generate the Footer with default settings
        self.media_item.generate_footer(service_item, mock_song)

        # THEN: The copyright symbol should be in the footer
        self.assertEqual(service_item.raw_footer, ['My Song', '© My copyright'])
Exemple #24
0
 def replace_service_item_test(self):
     """
     Test item counts and current number with a service item.
     """
     # GIVEN: A ServiceItem with two frames.
     service_item = ServiceItem(None)
     service = read_service_from_file('serviceitem_image_3.osj')
     with patch('os.path.exists'):
         service_item.set_from_service(service[0])
     # WHEN: Added to the preview widget.
     self.preview_widget.replace_service_item(service_item, 1, 1)
     # THEN: The slide count and number should fit.
     self.assertEqual(self.preview_widget.slide_count(), 2,
                      'The slide count should be 2.')
     self.assertEqual(self.preview_widget.current_slide_number(), 1,
                      'The current slide number should  be 1.')
Exemple #25
0
    def add_from_comamnd_without_display_title_and_notes_test(self):
        """
        Test the Service Item - add from command, but not presentation
        """
        # GIVEN: A new service item, a mocked icon and image data
        service_item = ServiceItem(None)
        image_name = 'test.img'
        image = MagicMock()
        frame = {'title': image_name, 'image': image, 'path': TEST_PATH,
                 'display_title': None, 'notes': None}

        # WHEN: adding image to service_item
        service_item.add_from_command(TEST_PATH, image_name, image)

        # THEN: verify that it is setup as a Command and that the frame data matches
        self.assertEqual(service_item.service_item_type, ServiceItemType.Command, 'It should be a Command')
        self.assertEqual(service_item.get_frames()[0], frame, 'Frames should match')
    def test_auto_start_context_menu(self):
        """
        Test the context_menu() method with can auto start
        """
        # GIVEN: A service item added
        self.service_manager.setup_ui(self.service_manager)
        with patch('PyQt5.QtWidgets.QTreeWidget.itemAt') as mocked_item_at_method, \
                patch('PyQt5.QtWidgets.QWidget.mapToGlobal'), \
                patch('PyQt5.QtWidgets.QMenu.exec'):
            mocked_item = MagicMock()
            mocked_item.parent.return_value = None
            mocked_item_at_method.return_value = mocked_item
            # We want 1 to be returned for the position
            mocked_item.data.return_value = 1
            # A service item without capabilities.
            service_item = ServiceItem()
            service_item.add_capability(ItemCapabilities.CanAutoStartForLive)
            self.service_manager.service_items = [{'service_item': service_item}]
            q_point = None
            # Mocked actions.
            self.service_manager.edit_action.setVisible = MagicMock()
            self.service_manager.create_custom_action.setVisible = MagicMock()
            self.service_manager.maintain_action.setVisible = MagicMock()
            self.service_manager.notes_action.setVisible = MagicMock()
            self.service_manager.time_action.setVisible = MagicMock()
            self.service_manager.auto_start_action.setVisible = MagicMock()
            self.service_manager.rename_action.setVisible = MagicMock()

            # WHEN: Show the context menu.
            self.service_manager.context_menu(q_point)

            # THEN: The following actions should be not visible.
            self.service_manager.edit_action.setVisible.assert_called_once_with(False), \
                'The action should be set invisible.'
            self.service_manager.create_custom_action.setVisible.assert_called_once_with(False), \
                'The action should be set invisible.'
            self.service_manager.maintain_action.setVisible.assert_called_once_with(False), \
                'The action should be set invisible.'
            self.service_manager.notes_action.setVisible.assert_called_with(True), 'The action should be set visible.'
            self.service_manager.time_action.setVisible.assert_called_once_with(False), \
                'The action should be set invisible.'
            self.service_manager.auto_start_action.setVisible.assert_called_with(True), \
                'The action should be set visible.'
            self.service_manager.rename_action.setVisible.assert_called_once_with(False), \
                'The action should be set invisible.'
Exemple #27
0
    def test_service_item_load_image_from_service(self):
        """
        Test the Service Item - adding an image from a saved service
        """
        # GIVEN: A new service item and a mocked add icon function
        image_name = 'image_1.jpg'
        test_file = os.path.join(TEST_PATH, image_name)
        frame_array = {'path': test_file, 'title': image_name}

        service_item = ServiceItem(None)
        service_item.add_icon = MagicMock()

        # WHEN: adding an image from a saved Service and mocked exists
        line = convert_file_service_item(TEST_PATH, 'serviceitem_image_1.osj')
        with patch('openlp.core.ui.servicemanager.os.path.exists') as mocked_exists,\
                patch('openlp.core.lib.serviceitem.AppLocation.get_section_data_path') as \
                mocked_get_section_data_path:
            mocked_exists.return_value = True
            mocked_get_section_data_path.return_value = os.path.normpath(
                '/path/')
            service_item.set_from_service(line, TEST_PATH)

        # THEN: We should get back a valid service item
        assert service_item.is_valid is True, 'The new service item should be valid'
        assert os.path.normpath(test_file) == os.path.normpath(service_item.get_rendered_frame(0)), \
            'The first frame should match the path to the image'
        assert frame_array == service_item.get_frames(
        )[0], 'The return should match frame array1'
        assert test_file == service_item.get_frame_path(
            0), 'The frame path should match the full path to the image'
        assert image_name == service_item.get_frame_title(
            0), 'The frame title should match the image name'
        assert image_name == service_item.get_display_title(
        ), 'The display title should match the first image name'
        assert service_item.is_image(
        ) is True, 'This service item should be of an "image" type'
        assert service_item.is_capable(ItemCapabilities.CanMaintain) is True, \
            'This service item should be able to be Maintained'
        assert service_item.is_capable(ItemCapabilities.CanPreview) is True, \
            'This service item should be able to be be Previewed'
        assert service_item.is_capable(ItemCapabilities.CanLoop) is True, \
            'This service item should be able to be run in a can be made to Loop'
        assert service_item.is_capable(ItemCapabilities.CanAppend) is True, \
            'This service item should be able to have new items added to it'
Exemple #28
0
 def build_service_item(self,
                        item=None,
                        xml_version=False,
                        remote=False,
                        context=ServiceItemContext.Live):
     """
     Common method for generating a service item
     :param item: Service Item to be built.
     :param xml_version: version of XML (False)
     :param remote: Remote triggered (False)
     :param context: The context on which this is called
     """
     service_item = ServiceItem(self.plugin)
     service_item.add_icon(self.plugin.icon_path)
     if self.generate_slide_data(service_item, item, xml_version, remote,
                                 context):
         return service_item
     else:
         return None
Exemple #29
0
    def service_item_load_optical_media_from_service_test(self):
        """
        Test the Service Item - load an optical media item
        """
        # GIVEN: A new service item and a mocked add icon function
        service_item = ServiceItem(None)
        service_item.add_icon = MagicMock()

        # WHEN: We load a serviceitem with optical media
        line = convert_file_service_item(TEST_PATH, 'serviceitem-dvd.osj')
        with patch('openlp.core.ui.servicemanager.os.path.exists') as mocked_exists:
            mocked_exists.return_value = True
            service_item.set_from_service(line)

        # THEN: We should get back a valid service item with optical media info
        self.assertTrue(service_item.is_valid, 'The service item should be valid')
        self.assertTrue(service_item.is_capable(ItemCapabilities.IsOptical), 'The item should be Optical')
        self.assertEqual(service_item.start_time, 654.375, 'Start time should be 654.375')
        self.assertEqual(service_item.end_time, 672.069, 'End time should be 672.069')
        self.assertEqual(service_item.media_length, 17.694, 'Media length should be 17.694')
Exemple #30
0
    def service_load_basic_custom_true_test(self):
        """
        Test the service load in custom with a default service item and a requirement to add to the database
        """
        # GIVEN: An empty Service Item and an active plugin
        service_item = ServiceItem(None)
        service_item.raw_footer = FOOTER
        self.media_item.plugin = MagicMock()
        self.media_item.plugin.status = PluginStatus.Active
        self.media_item.plugin.db_manager = MagicMock()
        self.media_item.plugin.db_manager.get_object_filtered = MagicMock()
        self.media_item.plugin.db_manager.get_object_filtered.return_value = None

        with patch('openlp.plugins.custom.lib.mediaitem.CustomSlide'):
            # WHEN: I search for the custom in the database
            self.media_item.add_custom_from_service = True
            self.media_item.create_from_service_item = MagicMock()
            self.media_item.service_load(service_item)

            # THEN: the item should not be added to the database.
            self.assertEqual(self.media_item.create_from_service_item.call_count, 1,
                             'The item should have been added to the database')