Beispiel #1
0
    def test_service_item_load_image_from_local_service(
            self, mocked_get_section_data_path, mocked_exists):
        """
        Test the Service Item - adding an image from a saved local service
        """
        # GIVEN: A new service item and a mocked add icon function
        mocked_get_section_data_path.return_value = Path('/path')
        mocked_exists.return_value = True
        image_name1 = 'image_1.jpg'
        image_name2 = 'image_2.jpg'
        test_file1 = os.path.join('/home', 'openlp', image_name1)
        test_file2 = os.path.join('/home', 'openlp', image_name2)
        frame_array1 = {'path': test_file1, 'title': image_name1}
        frame_array2 = {'path': test_file2, 'title': image_name2}
        service_item = ServiceItem(None)
        service_item.add_icon = MagicMock()
        service_item2 = ServiceItem(None)
        service_item2.add_icon = MagicMock()

        # WHEN: adding an image from a saved Service and mocked exists
        line = convert_file_service_item(TEST_PATH, 'serviceitem_image_2.osj')
        line2 = convert_file_service_item(TEST_PATH, 'serviceitem_image_2.osj',
                                          1)
        service_item2.set_from_service(line2)
        service_item.set_from_service(line)

        # THEN: We should get back a valid service item
        assert service_item.is_valid is True, 'The first service item should be valid'
        assert service_item2.is_valid is True, 'The second service item should be valid'
        # These test will fail on windows due to the difference in folder seperators
        if os.name != 'nt':
            assert test_file1 == service_item.get_rendered_frame(0), \
                'The first frame should match the path to the image'
            assert test_file2 == service_item2.get_rendered_frame(0), \
                'The Second frame should match the path to the image'
            assert frame_array1 == service_item.get_frames(
            )[0], 'The return should match the frame array1'
            assert frame_array2 == service_item2.get_frames(
            )[0], 'The return should match the frame array2'
            assert test_file1 == str(service_item.get_frame_path(0)), \
                'The frame path should match the full path to the image'
            assert test_file2 == str(service_item2.get_frame_path(0)), \
                'The frame path should match the full path to the image'
        assert image_name1 == service_item.get_frame_title(
            0), 'The 1st frame title should match the image name'
        assert image_name2 == service_item2.get_frame_title(
            0), 'The 2nd frame title should match the image name'
        assert service_item.name == service_item.title.lower(), \
            'The plugin name should match the display title, as there are > 1 Images'
        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'
Beispiel #2
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, Path('/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 len(service_item.display_slides
                   ) == 6, 'The service item should have 6 display slides'
        assert len(service_item.capabilities
                   ) == 7, 'There should be 7 default custom item capabilities'
        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 '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'
Beispiel #3
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 serviceand set the media state
        line = convert_file_service_item(TEST_PATH, 'serviceitem_custom_1.osj')
        State().add_service("media", 0)
        State().update_pre_conditions("media", True)
        State().flush_preconditions()
        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 len(service_item.get_frames()
                   ) == 2, 'The service item should have 2 display frames'
        assert len(service_item.capabilities
                   ) == 5, 'There should be 5 default custom item capabilities'

        # THEN: The frames should also be valid
        assert 'Test Custom' == service_item.get_display_title(
        ), 'The title should be "Test Custom"'
        assert 'Slide 1' == service_item.get_frames()[0]['text']
        assert 'Slide 2' == service_item.get_rendered_frame(1)
        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'
Beispiel #4
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 = 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 = Path('/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 test_file == 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'
Beispiel #5
0
    def test_service_item_load_optical_media_from_service(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
        assert service_item.is_valid is True, 'The service item should be valid'
        assert service_item.is_capable(
            ItemCapabilities.IsOptical) is True, 'The item should be Optical'
        assert service_item.start_time == 654.375, 'Start time should be 654.375'
        assert service_item.end_time == 672.069, 'End time should be 672.069'
        assert service_item.media_length == 17.694, 'Media length should be 17.694'