Esempio n. 1
0
def save_image(folder, dir, filename, user):
    base, _ =  os.path.splitext(filename)
    filepath = os.path.join(dir, filename)
    file = DjangoFile(open(filepath, 'rb'), name=filename)
    image = Image(owner=user, folder=folder, name=base, original_filename=filename, file=file, is_public=True)
    image.save()
    return image
    def test_creating_and_requesting_images(self):
        filer1 = FilerImage()
        filer1.save()
        image = Image()
        image.filer = filer1
        image.title = 'This is the first image'
        image.description = 'This first image has been taken, at a place yet unknown.'
        image.save()

        filer2 = FilerImage()
        filer2.save()
        image_wo_desc = Image()
        image_wo_desc.filer = filer2
        image_wo_desc.title = 'Image without description'
        image_wo_desc.save()

        saved_images = Image.objects.all()
        self.assertEqual(len(saved_images), 2)

        first_img = saved_images[0]
        self.assertEqual(first_img.filer, filer1)
        self.assertEqual(first_img.title, 'This is the first image')
        self.assertEqual(first_img.description, 'This first image has been taken, at a place yet unknown.')

        second_img = saved_images[1]
        self.assertEqual(second_img.filer, filer2)
        self.assertEqual(second_img.title, 'Image without description')
        self.assertIsNone(second_img.description)
class ImageSetTypePluginMixinContainerGetPluginWidthTests(TestCase):
    """
    For testing methods of the Imageset plugin that don't require fully-
    constructed plugin instances
    """
    def setUp(self):
        # create & save plugin
        self.plugin = ImageSetPlugin()
        self.plugin.save()
        # create & save images
        self.image1 = Image(_width=100, _height=100)
        self.image1.save()

    # output: 0 = auto, +ve if set explicitly
    # native only acts if an image is provided

    def test_defaults(self):
        # automatic
        self.assertEqual(self.plugin.get_plugin_width(), 0)

    def test_defaults_with_image(self):
        # automatic; ignore image
        self.assertEqual(self.plugin.get_plugin_width(self.image1), 0)

    def test_no_image_native_plugin_width(self):
        # native but no image so auto
        self.plugin.width = 0
        self.assertEqual(self.plugin.get_plugin_width(), 0)

    def test_no_image_absolute_plugin_width(self):
        # absolute
        self.plugin.width = -250
        self.assertEqual(self.plugin.get_plugin_width(), 250)

    def test_image_native_plugin_width(self):
        # native and image so use image's width
        self.plugin.width = 0
        self.assertEqual(self.plugin.get_plugin_width(self.image1), 100)

    def test_image_absolute_width(self):
        # absolute; ignore image
        self.plugin.width = -250
        self.assertEqual(self.plugin.get_plugin_width(self.image1), 250)
Esempio n. 4
0
class ImageSetTypePluginMixinContainerGetPluginWidthTests(TestCase):
    """
    For testing methods of the Imageset plugin that don't require fully-
    constructed plugin instances
    """
    def setUp(self):
        # create & save plugin
        self.plugin = ImageSetPlugin()
        self.plugin.save()
        # create & save images
        self.image1 = Image(_width=100, _height=100)
        self.image1.save()

    # output: 0 = auto, +ve if set explicitly
    # native only acts if an image is provided

    def test_defaults(self):
        # automatic
        self.assertEqual(self.plugin.get_plugin_width(), 0)

    def test_defaults_with_image(self):
        # automatic; ignore image
        self.assertEqual(self.plugin.get_plugin_width(self.image1), 0)

    def test_no_image_native_plugin_width(self):
        # native but no image so auto
        self.plugin.width = 0
        self.assertEqual(self.plugin.get_plugin_width(), 0)

    def test_no_image_absolute_plugin_width(self):
        # absolute
        self.plugin.width = -250
        self.assertEqual(self.plugin.get_plugin_width(), 250)

    def test_image_native_plugin_width(self):
        # native and image so use image's width
        self.plugin.width = 0
        self.assertEqual(self.plugin.get_plugin_width(self.image1), 100)

    def test_image_absolute_width(self):
        # absolute; ignore image
        self.plugin.width = -250
        self.assertEqual(self.plugin.get_plugin_width(self.image1), 250)
Esempio n. 5
0
class ImagesetsReturnCorrectItems(TestCase):
    def setUp(self):
        # create & save plugin
        self.plugin = ImageSetPlugin()
        self.plugin.save()
        # create & save images
        self.image1 = Image(_width=100, _height=100)
        self.image2 = Image(_width=200, _height=100)
        self.image3 = Image(_width=300, _height=100)
        self.image1.save()
        self.image2.save()
        self.image3.save()
        # create & save plugin items
        self.item1 = ImageSetItem(plugin=self.plugin, image=self.image1)
        self.item2 = ImageSetItem(plugin=self.plugin, image=self.image2)
        self.item3 = ImageSetItem(plugin=self.plugin, image=self.image3)
        self.item1.save()
        self.item2.save()
        self.item3.save()

    # basic
    # multiple
    # slider
    # lightbox single

    # are the right items being returned?

    def test_imagelinkset_plugin_basic_returns_one_active_item(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.single_image()
        self.assertIn(self.plugin.item, self.plugin.active_items)

    def test_imagelinkset_plugin_multiple_returns_all_active_item(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.multiple_images()
        self.assertListEqual(list(self.plugin.items),
                             list(self.plugin.active_items))

    def test_imagelinkset_plugin_slider_returns_all_active_item(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.slider()
        self.assertListEqual(list(self.plugin.items),
                             list(self.plugin.active_items))

    def test_imagelinkset_plugin_lightbox_single_one_active_item(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.lightbox_single()
        self.assertListEqual(list(self.plugin.items),
                             list(self.plugin.active_items))
        self.assertEqual(self.plugin.item, list(self.plugin.active_items)[0])
Esempio n. 6
0
class ImagesetsReturnCorrectImageSizesAutomaticForcedAspectRatio(TestCase):
    def setUp(self):
        # create & save plugin
        self.plugin = ImageSetPlugin()
        self.plugin.aspect_ratio = 1.333
        self.plugin.save()
        # create & save images
        self.image1 = Image(_width=100, _height=100)
        self.image2 = Image(_width=200, _height=100)
        self.image3 = Image(_width=300, _height=100)
        self.image1.save()
        self.image2.save()
        self.image3.save()
        # create & save plugin items
        self.item1 = ImageSetItem(plugin=self.plugin, image=self.image1)
        self.item2 = ImageSetItem(plugin=self.plugin, image=self.image2)
        self.item3 = ImageSetItem(plugin=self.plugin, image=self.image3)
        self.item1.save()
        self.item2.save()
        self.item3.save()

    def test_imagelinkset_plugin_item_size(self):
        self.item1.active = self.item2.active = False
        self.item1.save()
        self.item2.save()
        self.plugin.items = self.plugin.active_items
        self.plugin.single_image()
        item = self.plugin.item
        self.assertEqual((item.width, item.height), (500, 375))

    def test_imagelinkset_plugin_multiple_image_sizes(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.multiple_images()
        item = self.plugin.items[0]
        self.assertEqual((item.width, item.height), (152, 125))

    def test_imagelinkset_plugin_slider_image_sizes(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.slider()
        item = self.plugin.items[0]
        self.assertEqual(self.plugin.size, (500, 375))
        self.assertEqual((item.width, item.height), (500, 375))

    def test_imagelinkset_plugin_lightbox_single_image_sizes(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.lightbox_single()
        item = self.plugin.items[0]
        self.assertEqual((item.width, item.height), (480, 360))
Esempio n. 7
0
class ImagesetsReturnCorrectImageSizesOneThirdWidthAndAspectRatio(TestCase):
    def setUp(self):
        # create & save plugin
        self.plugin = ImageSetPlugin()
        self.plugin.width = 33.3
        self.plugin.save()
        # create & save images
        self.image1 = Image(_width=100, _height=100)
        self.image2 = Image(_width=200, _height=100)
        self.image3 = Image(_width=300, _height=100)
        self.image1.save()
        self.image2.save()
        self.image3.save()
        # create & save plugin items
        self.item1 = ImageSetItem(plugin=self.plugin, image=self.image1)
        self.item2 = ImageSetItem(plugin=self.plugin, image=self.image2)
        self.item3 = ImageSetItem(plugin=self.plugin, image=self.image3)
        self.item1.save()
        self.item2.save()
        self.item3.save()

    def test_imagelinkset_plugin_item_size(self):
        self.item1.active = self.item2.active = False
        self.item1.save()
        self.item2.save()
        self.plugin.items = self.plugin.active_items
        self.plugin.single_image()
        item = self.plugin.item
        self.assertEqual((item.width, item.height), (166, 55))

    def test_imagelinkset_plugin_multiple_image_sizes(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.multiple_images()
        item = self.plugin.items[0]
        self.assertEqual((item.width, item.height), (41, 27))

    def test_imagelinkset_plugin_slider_image_sizes(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.slider()
        item = self.plugin.items[0]
        self.assertEqual(self.plugin.size, (166, 83))
        self.assertEqual((item.width, item.height), (166, 83))

    def test_imagelinkset_plugin_lightbox_single_image_sizes(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.lightbox_single()
        item = self.plugin.items[0]
        self.assertEqual((item.width, item.height), (146, 146))
    def test_carousel_plugin(self):
        """
        test the output of the link set plugin
        """
        img = Image(_width=100, _height=100)
        img.save()

        placeholder = Placeholder(slot=u"some_slot")
        placeholder.save() # a good idea, if not strictly necessary

        # add the plugin
        plugin = add_plugin(
            placeholder,
            u"CarouselPluginPublisher",
            u"en",
            width = 1000.0
        )
        plugin.save()

        # get the corresponding plugin instance
        instance = plugin.get_plugin_instance()[1]
        self.assertEquals(instance.render({}, plugin, placeholder), {})

        # add an item to the plugin
        item1 = CarouselPluginItem(
            plugin=plugin,
            destination_content_type = ContentType.objects.get_for_model(self.school),
            destination_object_id = self.school.id,
            link_title=u"item1 link title",
            active=False,
            image_id=img.id,
            )
        item1.save()
        self.assertEquals(instance.render({}, plugin, placeholder), {})

        # now the item is active
        item1.active=True
        item1.save()
        self.assertEquals(instance.render({}, plugin, placeholder), {})

        # add a second image to the plugin
        item2 = CarouselPluginItem(
            plugin=plugin,
            destination_content_type = ContentType.objects.get_for_model(self.school),
            destination_object_id = self.school.id,
            link_title=u"item1 link title",
            image_id=img.id,
            )
        item2.save()
        self.assertListEqual(
            instance.render({}, plugin, placeholder)["segments"],
            [item1, item2]
        )

        # now the ordering should be reversed
        item1.inline_item_ordering=1
        item1.save()
        rendered_plugin = instance.render({}, plugin, placeholder)
        self.assertListEqual(
            rendered_plugin["segments"],
            [item2, item1]
        )

        # check size calculations
        self.assertEqual(
            rendered_plugin["size"],
            (98,65)
        )
        # if we delete the image the items should be deleted too
        img.delete()
        self.assertEquals(instance.render({}, plugin, placeholder), {})
Esempio n. 9
0
class ImageSetTypePluginEasyMethodTests(TestCase):
    """
    For testing methods of the Imageset plugin that don't require fully-
    constructed plugin instances
    """
    def setUp(self):
        # create & save plugin
        self.plugin = ImageSetPlugin()
        self.plugin.save()
        # create & save images
        self.image1 = Image(_width=100, _height=100)
        self.image2 = Image(_width=200, _height=100)
        self.image3 = Image(_width=200, _height=100)
        self.image1.save()
        self.image2.save()
        self.image3.save()
        # create & save plugin items
        self.item1 = ImageSetItem(plugin=self.plugin, image=self.image1)
        self.item2 = ImageSetItem(plugin=self.plugin, image=self.image2)
        self.item3 = ImageSetItem(plugin=self.plugin, image=self.image3)
        self.item1.save()
        self.item2.save()
        self.item3.save()

    def test_calculate_aspect_ratio(self):
        # calculated aspect ratio should be mean aspect ratio of all items
        self.assertEqual(
            self.plugin.calculate_aspect_ratio([self.item1, self.item2]), 1.5)

    def test_active_items(self):
        self.assertListEqual(list(self.plugin.active_items),
                             [self.item1, self.item2, self.item3])

    def test_active_items_one_inactive(self):
        self.item2.active = False
        self.item2.save()
        self.assertListEqual(list(self.plugin.active_items),
                             [self.item1, self.item3])

    def test_active_items_reordered(self):
        self.item1.inline_item_ordering = 1
        self.item1.save()
        self.assertListEqual(list(self.plugin.active_items),
                             [self.item2, self.item3, self.item1])

    def test_imagelinkset_select_imageset_kind_single(self):
        # basic = single_image, single_image.html
        self.plugin.kind = "basic"
        self.item1.save()
        self.item2.save()
        self.item3.save()
        self.assertEquals(self.plugin.select_imageset_kind(), "single_image")
        self.assertEquals(self.plugin.template,
                          "arkestra_image_plugin/single_image.html")

    def test_imagelinkset_select_imageset_kind_multiple(self):
        # multiple = multiple_images, multiple_images.html
        self.plugin.kind = "multiple"
        self.item1.save()
        self.item2.save()
        self.item3.save()
        self.assertEquals(self.plugin.select_imageset_kind(),
                          "multiple_images")
        self.assertEquals(self.plugin.template,
                          "arkestra_image_plugin/multiple.html")

    def test_imagelinkset_select_imageset_kind_lightbox(self):
        # lightbox = lightbox, lightbox.html
        self.plugin.kind = "lightbox"
        self.item1.save()
        self.item2.save()
        self.item3.save()
        self.assertEquals(self.plugin.select_imageset_kind(),
                          "multiple_images")
        self.assertEquals(self.plugin.template,
                          "arkestra_image_plugin/lightbox.html")

    def test_imagelinkset_select_imageset_kind_lightbox_single(self):
        # lightbox = lightbox, lightbox.html
        self.plugin.kind = "lightbox-single"
        self.item1.save()
        self.item2.save()
        self.item3.save()
        self.assertEquals(self.plugin.select_imageset_kind(),
                          "lightbox_single")
        self.assertEquals(self.plugin.template,
                          "arkestra_image_plugin/lightbox.html")

    def test_imagelinkset_select_imageset_kind_items_no_kind(self):
        # no kind declared? single_image, single_image.html
        self.assertEquals(self.plugin.select_imageset_kind(), "single_image")
        self.assertEquals(self.plugin.template,
                          "arkestra_image_plugin/single_image.html")

    def test_imagelinkset_select_imageset_kind_no_items(self):
        # no active_items? None, null.html
        self.item1.active = False
        self.item2.active = False
        self.item3.active = False
        self.item1.save()
        self.item2.save()
        self.item3.save()
        self.assertEquals(self.plugin.select_imageset_kind(), None)
        self.assertEquals(self.plugin.template, "null.html")

    def test_imagelinkset_select_imageset_kind_multiple_one_item(self):
        # only one item? single_image, single_image.html
        self.plugin.kind = "multiple"
        self.item1.active = False
        self.item2.active = False
        self.item1.save()
        self.item2.save()
        self.assertEquals(self.plugin.select_imageset_kind(), "single_image")
        self.assertEquals(self.plugin.template,
                          "arkestra_image_plugin/single_image.html")

    def test_imagelinkset_select_imageset_kind_lightbox_single_one_item(self):
        # only one item lightbox single item? use lightbox_single
        self.plugin.kind = "lightbox-single"
        self.item1.active = False
        self.item2.active = False
        self.item1.save()
        self.item2.save()
        self.assertEquals(self.plugin.select_imageset_kind(),
                          "lightbox_single")
        self.assertEquals(self.plugin.template,
                          "arkestra_image_plugin/lightbox.html")

    def test_imagelinkset_calculate_plugin_dimensions_positive_self_aspect_ratio(
            self):
        # calculated_width and self.aspect_ratio determine height
        self.plugin.width = 1000.0  # automatic
        self.plugin.aspect_ratio = 2
        self.plugin.height = 0
        self.assertEquals(self.plugin.calculate_plugin_dimensions(299, 7.353),
                          (299, 149))

    def test_imagelinkset_calculate_plugin_dimensions_height_no_aspect_ratio_width(
            self):
        # self.height and calculated_width determine size
        self.plugin.width = 1000.0  # automatic
        self.plugin.aspect_ratio = 0
        self.plugin.height = 200.1
        self.assertEquals(
            self.plugin.calculate_plugin_dimensions(130.7, 7.353), (130, 200))

    def test_imagelinkset_calculate_plugin_dimensions_height_no_aspect_ratio_no_width(
            self):
        # self.height and calculated_width determine size
        self.plugin.width = 0  # native
        self.plugin.aspect_ratio = 0
        self.plugin.height = 200
        self.assertEquals(self.plugin.calculate_plugin_dimensions(130, 7.353),
                          (1470, 200))

    def test_imagelinkset_calculate_plugin_dimensions_no_height_no_aspect_ratio_no_width(
            self):
        # self.height and calculated_width determine size
        self.plugin.width = 0  # native
        self.plugin.aspect_ratio = 0
        self.plugin.height = None
        self.assertEquals(self.plugin.calculate_plugin_dimensions(500.5, 2.5),
                          (500, 200))

    def test_imagelinkset_calculate_plugin_dimensions_no_height_aspect_ratio_no_width(
            self):
        # self.height and calculated_width determine size
        self.plugin.width = 0  # native
        self.plugin.aspect_ratio = 1
        self.plugin.height = None
        self.assertEquals(self.plugin.calculate_plugin_dimensions(505.5, 2),
                          (505, 505))
class ImagesetsReturnCorrectImageSizesAutomaticForcedAspectRatio(TestCase):

    def setUp(self):
        # create & save plugin
        self.plugin = ImageSetPlugin()
        self.plugin.aspect_ratio = 1.333
        self.plugin.save()
        # create & save images
        self.image1 = Image(_width=100, _height=100)
        self.image2 = Image(_width=200, _height=100)
        self.image3 = Image(_width=300, _height=100)
        self.image1.save()
        self.image2.save()
        self.image3.save()
        # create & save plugin items
        self.item1 = ImageSetItem(
            plugin=self.plugin,
            image=self.image1)
        self.item2 = ImageSetItem(
            plugin=self.plugin,
            image=self.image2)
        self.item3 = ImageSetItem(
            plugin=self.plugin,
            image=self.image3)
        self.item1.save()
        self.item2.save()
        self.item3.save()

    def test_imagelinkset_plugin_item_size(self):
        self.item1.active = self.item2.active = False
        self.item1.save()
        self.item2.save()
        self.plugin.items = self.plugin.active_items
        self.plugin.single_image()
        item = self.plugin.item
        self.assertEqual(
            (item.width, item.height),
            (500, 375)
        )

    def test_imagelinkset_plugin_multiple_image_sizes(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.multiple_images()
        item = self.plugin.items[0]
        self.assertEqual(
            (item.width, item.height),
            (152, 125)
        )

    def test_imagelinkset_plugin_slider_image_sizes(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.slider()
        item = self.plugin.items[0]
        self.assertEqual(
            self.plugin.size,
            (500,375)
        )
        self.assertEqual(
            (item.width, item.height),
            (500, 375)
        )

    def test_imagelinkset_plugin_lightbox_single_image_sizes(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.lightbox_single()
        item = self.plugin.items[0]
        self.assertEqual(
            (item.width, item.height),
            (480, 360)
        )
class ImagesetsReturnCorrectImageSizesOneThirdWidthAndAspectRatio(TestCase):

    def setUp(self):
        # create & save plugin
        self.plugin = ImageSetPlugin()
        self.plugin.width = 33.3
        self.plugin.save()
        # create & save images
        self.image1 = Image(_width=100, _height=100)
        self.image2 = Image(_width=200, _height=100)
        self.image3 = Image(_width=300, _height=100)
        self.image1.save()
        self.image2.save()
        self.image3.save()
        # create & save plugin items
        self.item1 = ImageSetItem(
            plugin=self.plugin,
            image=self.image1)
        self.item2 = ImageSetItem(
            plugin=self.plugin,
            image=self.image2)
        self.item3 = ImageSetItem(
            plugin=self.plugin,
            image=self.image3)
        self.item1.save()
        self.item2.save()
        self.item3.save()

    def test_imagelinkset_plugin_item_size(self):
        self.item1.active = self.item2.active = False
        self.item1.save()
        self.item2.save()
        self.plugin.items = self.plugin.active_items
        self.plugin.single_image()
        item = self.plugin.item
        self.assertEqual(
            (item.width, item.height),
            (166, 55)
        )

    def test_imagelinkset_plugin_multiple_image_sizes(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.multiple_images()
        item = self.plugin.items[0]
        self.assertEqual(
            (item.width, item.height),
            (41, 27)
        )

    def test_imagelinkset_plugin_slider_image_sizes(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.slider()
        item = self.plugin.items[0]
        self.assertEqual(
            self.plugin.size,
            (166, 83)
        )
        self.assertEqual(
            (item.width, item.height),
            (166, 83)
        )

    def test_imagelinkset_plugin_lightbox_single_image_sizes(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.lightbox_single()
        item = self.plugin.items[0]
        self.assertEqual(
            (item.width, item.height),
            (146, 146)
        )
class ImagesetsReturnCorrectItems(TestCase):

    def setUp(self):
        # create & save plugin
        self.plugin = ImageSetPlugin()
        self.plugin.save()
        # create & save images
        self.image1 = Image(_width=100, _height=100)
        self.image2 = Image(_width=200, _height=100)
        self.image3 = Image(_width=300, _height=100)
        self.image1.save()
        self.image2.save()
        self.image3.save()
        # create & save plugin items
        self.item1 = ImageSetItem(
            plugin=self.plugin,
            image=self.image1)
        self.item2 = ImageSetItem(
            plugin=self.plugin,
            image=self.image2)
        self.item3 = ImageSetItem(
            plugin=self.plugin,
            image=self.image3)
        self.item1.save()
        self.item2.save()
        self.item3.save()

    # basic
    # multiple
    # slider
    # lightbox single

    # are the right items being returned?

    def test_imagelinkset_plugin_basic_returns_one_active_item(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.single_image()
        self.assertIn(self.plugin.item, self.plugin.active_items)

    def test_imagelinkset_plugin_multiple_returns_all_active_item(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.multiple_images()
        self.assertListEqual(
            list(self.plugin.items),
            list(self.plugin.active_items)
        )

    def test_imagelinkset_plugin_slider_returns_all_active_item(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.slider()
        self.assertListEqual(
            list(self.plugin.items),
            list(self.plugin.active_items)
        )

    def test_imagelinkset_plugin_lightbox_single_one_active_item(self):
        self.plugin.items = self.plugin.active_items
        self.plugin.lightbox_single()
        self.assertListEqual(
            list(self.plugin.items),
            list(self.plugin.active_items)
        )
        self.assertEqual(
            self.plugin.item,
            list(self.plugin.active_items)[0]
        )
class ImageSetTypePluginEasyMethodTests(TestCase):
    """
    For testing methods of the Imageset plugin that don't require fully-
    constructed plugin instances
    """
    def setUp(self):
        # create & save plugin
        self.plugin = ImageSetPlugin()
        self.plugin.save()
        # create & save images
        self.image1 = Image(_width=100, _height=100)
        self.image2 = Image(_width=200, _height=100)
        self.image3 = Image(_width=200, _height=100)
        self.image1.save()
        self.image2.save()
        self.image3.save()
        # create & save plugin items
        self.item1 = ImageSetItem(
            plugin=self.plugin,
            image=self.image1)
        self.item2 = ImageSetItem(
            plugin=self.plugin,
            image=self.image2)
        self.item3 = ImageSetItem(
            plugin=self.plugin,
            image=self.image3)
        self.item1.save()
        self.item2.save()
        self.item3.save()

    def test_calculate_aspect_ratio(self):
        # calculated aspect ratio should be mean aspect ratio of all items
        self.assertEqual(
            self.plugin.calculate_aspect_ratio([self.item1, self.item2]),
            1.5
        )

    def test_active_items(self):
        self.assertListEqual(
            list(self.plugin.active_items),
            [self.item1, self.item2, self.item3]
        )

    def test_active_items_one_inactive(self):
        self.item2.active = False
        self.item2.save()
        self.assertListEqual(
            list(self.plugin.active_items),
            [self.item1, self.item3]
        )

    def test_active_items_reordered(self):
        self.item1.inline_item_ordering = 1
        self.item1.save()
        self.assertListEqual(
            list(self.plugin.active_items),
            [self.item2, self.item3, self.item1]
        )

    def test_imagelinkset_select_imageset_kind_single(self):
        # basic = single_image, single_image.html
        self.plugin.kind = "basic"
        self.item1.save()
        self.item2.save()
        self.item3.save()
        self.assertEquals(self.plugin.select_imageset_kind(), "single_image")
        self.assertEquals(self.plugin.template, "arkestra_image_plugin/single_image.html")

    def test_imagelinkset_select_imageset_kind_multiple(self):
        # multiple = multiple_images, multiple_images.html
        self.plugin.kind = "multiple"
        self.item1.save()
        self.item2.save()
        self.item3.save()
        self.assertEquals(self.plugin.select_imageset_kind(), "multiple_images")
        self.assertEquals(self.plugin.template, "arkestra_image_plugin/multiple.html")

    def test_imagelinkset_select_imageset_kind_lightbox(self):
        # lightbox = lightbox, lightbox.html
        self.plugin.kind = "lightbox"
        self.item1.save()
        self.item2.save()
        self.item3.save()
        self.assertEquals(self.plugin.select_imageset_kind(), "multiple_images")
        self.assertEquals(self.plugin.template, "arkestra_image_plugin/lightbox.html")

    def test_imagelinkset_select_imageset_kind_lightbox_single(self):
        # lightbox = lightbox, lightbox.html
        self.plugin.kind = "lightbox-single"
        self.item1.save()
        self.item2.save()
        self.item3.save()
        self.assertEquals(self.plugin.select_imageset_kind(), "lightbox_single")
        self.assertEquals(self.plugin.template, "arkestra_image_plugin/lightbox.html")

    def test_imagelinkset_select_imageset_kind_items_no_kind(self):
        # no kind declared? single_image, single_image.html
        self.assertEquals(self.plugin.select_imageset_kind(), "single_image")
        self.assertEquals(self.plugin.template, "arkestra_image_plugin/single_image.html")

    def test_imagelinkset_select_imageset_kind_no_items(self):
        # no active_items? None, null.html
        self.item1.active = False
        self.item2.active = False
        self.item3.active = False
        self.item1.save()
        self.item2.save()
        self.item3.save()
        self.assertEquals(self.plugin.select_imageset_kind(), None)
        self.assertEquals(self.plugin.template, "null.html")

    def test_imagelinkset_select_imageset_kind_multiple_one_item(self):
        # only one item? single_image, single_image.html
        self.plugin.kind = "multiple"
        self.item1.active = False
        self.item2.active = False
        self.item1.save()
        self.item2.save()
        self.assertEquals(self.plugin.select_imageset_kind(), "single_image")
        self.assertEquals(self.plugin.template, "arkestra_image_plugin/single_image.html")

    def test_imagelinkset_select_imageset_kind_lightbox_single_one_item(self):
        # only one item lightbox single item? use lightbox_single
        self.plugin.kind = "lightbox-single"
        self.item1.active = False
        self.item2.active = False
        self.item1.save()
        self.item2.save()
        self.assertEquals(self.plugin.select_imageset_kind(), "lightbox_single")
        self.assertEquals(self.plugin.template, "arkestra_image_plugin/lightbox.html")

    def test_imagelinkset_calculate_plugin_dimensions_positive_self_aspect_ratio(self):
        # calculated_width and self.aspect_ratio determine height
        self.plugin.width = 1000.0 # automatic
        self.plugin.aspect_ratio = 2
        self.plugin.height = 0
        self.assertEquals(
            self.plugin.calculate_plugin_dimensions(299, 7.353),
            (299,149)
        )

    def test_imagelinkset_calculate_plugin_dimensions_height_no_aspect_ratio_width(self):
        # self.height and calculated_width determine size
        self.plugin.width = 1000.0 # automatic
        self.plugin.aspect_ratio = 0
        self.plugin.height = 200.1
        self.assertEquals(
            self.plugin.calculate_plugin_dimensions(130.7, 7.353),
            (130,200)
        )

    def test_imagelinkset_calculate_plugin_dimensions_height_no_aspect_ratio_no_width(self):
        # self.height and calculated_width determine size
        self.plugin.width = 0 # native
        self.plugin.aspect_ratio = 0
        self.plugin.height = 200
        self.assertEquals(
            self.plugin.calculate_plugin_dimensions(130, 7.353),
            (1470,200)
        )

    def test_imagelinkset_calculate_plugin_dimensions_no_height_no_aspect_ratio_no_width(self):
        # self.height and calculated_width determine size
        self.plugin.width = 0 # native
        self.plugin.aspect_ratio = 0
        self.plugin.height = None
        self.assertEquals(
            self.plugin.calculate_plugin_dimensions(500.5, 2.5),
            (500,200)
        )

    def test_imagelinkset_calculate_plugin_dimensions_no_height_aspect_ratio_no_width(self):
        # self.height and calculated_width determine size
        self.plugin.width = 0 # native
        self.plugin.aspect_ratio = 1
        self.plugin.height = None
        self.assertEquals(
            self.plugin.calculate_plugin_dimensions(505.5, 2),
            (505,505)
        )
Esempio n. 14
0
    def test_carousel_plugin(self):
        """
        test the output of the link set plugin
        """
        img = Image(_width=100, _height=100)
        img.save()

        placeholder = Placeholder(slot=u"some_slot")
        placeholder.save() # a good idea, if not strictly necessary

        # add the plugin
        plugin = add_plugin(
            placeholder,
            u"CarouselPluginPublisher",
            u"en",
            width = 1000.0
        )
        plugin.save()

        # get the corresponding plugin instance
        instance = plugin.get_plugin_instance()[1]
        self.assertEquals(instance.render({}, plugin, placeholder), {})

        # add an item to the plugin
        item1 = CarouselPluginItem(
            plugin=plugin,
            destination_content_type = ContentType.objects.get_for_model(self.school),
            destination_object_id = self.school.id,
            link_title=u"item1 link title",
            active=False,
            image_id=img.id,
            )
        item1.save()
        self.assertEquals(instance.render({}, plugin, placeholder), {})

        # now the item is active
        item1.active=True
        item1.save()
        self.assertEquals(instance.render({}, plugin, placeholder), {})

        # add a second image to the plugin
        item2 = CarouselPluginItem(
            plugin=plugin,
            destination_content_type = ContentType.objects.get_for_model(self.school),
            destination_object_id = self.school.id,
            link_title=u"item1 link title",
            image_id=img.id,
            )
        item2.save()
        self.assertListEqual(
            instance.render({}, plugin, placeholder)["segments"],
            [item1, item2]
        )

        # now the ordering should be reversed
        item1.inline_item_ordering=1
        item1.save()
        rendered_plugin = instance.render({}, plugin, placeholder)
        self.assertListEqual(
            rendered_plugin["segments"],
            [item2, item1]
        )

        # check size calculations
        self.assertEqual(
            rendered_plugin["size"],
            (98,65)
        )
        # if we delete the image the items should be deleted too
        img.delete()
        self.assertEquals(instance.render({}, plugin, placeholder), {})