Ejemplo n.º 1
0
 def test_placeholder_name_toolbar(self):
     placeholder_conf_name = 'test_placeholder'
     placeholder_conf_tag = '<div class="cms_placeholder-title">%s</div>' % placeholder_conf_name
     with SettingsOverride(CMS_PLACEHOLDER_CONF = {
                               'test': {'name':placeholder_conf_name}
                           }):
         placeholder = Placeholder()
         placeholder.slot = 'test'
         placeholder.pk = placeholder.id = 99
         context = SekizaiContext()
         context['request'] = AttributeObject(
             REQUEST={'language': 'en'},
             GET=[],
             session={},
             path='/',
             user=self.test_user,
             current_page=None,
             method='GET',
             )
         classes = [
             "cms_placeholder-bar-%s" % placeholder.pk,
             "cms_placeholder_slot::test",
             ]
         output = render_placeholder_toolbar(placeholder, context, '', 'test')
         self.assertTrue(placeholder_conf_tag in output, 'placeholder name %r is not in %r' % (placeholder_conf_name, output))
Ejemplo n.º 2
0
    def fill_placeholder(self, placeholder=None):
        if placeholder is None:
            placeholder = Placeholder(slot=u"some_slot")
            placeholder.save()  # a good idea, if not strictly necessary

        # plugin in placeholder
        plugin_1 = add_plugin(
            placeholder,
            u"TextPlugin",
            u"en",
            body=u"01",
        )
        plugin_1.save()

        # IMPORTANT: plugins must be reloaded, before they can be assigned
        # as a parent. Otherwise, the MPTT structure doesn't seem to rebuild
        # properly.

        # child of plugin_1
        plugin_2 = add_plugin(
            placeholder,
            u"TextPlugin",
            u"en",
            body=u"02",
        )
        plugin_1 = self.reload(plugin_1)
        plugin_2.parent = plugin_1
        plugin_2.save()
        return placeholder
Ejemplo n.º 3
0
 def test_placeholder_name_toolbar(self):
     placeholder_conf_name = 'test_placeholder'
     placeholder_conf_tag = '<div class="cms_placeholder-title">%s</div>' % placeholder_conf_name
     with SettingsOverride(
             CMS_PLACEHOLDER_CONF={'test': {
                 'name': placeholder_conf_name
             }}):
         placeholder = Placeholder()
         placeholder.slot = 'test'
         placeholder.pk = placeholder.id = 99
         context = SekizaiContext()
         context['request'] = AttributeObject(
             REQUEST={'language': 'en'},
             GET=[],
             session={},
             path='/',
             user=self.test_user,
             current_page=None,
             method='GET',
         )
         classes = [
             "cms_placeholder-bar-%s" % placeholder.pk,
             "cms_placeholder_slot::test",
         ]
         output = render_placeholder_toolbar(placeholder, context, '',
                                             'test')
         self.assertTrue(
             placeholder_conf_tag in output,
             'placeholder name %r is not in %r' %
             (placeholder_conf_name, output))
Ejemplo n.º 4
0
    def handle(self, *fixture_labels, **options):

        if len(fixture_labels) > 0:
            path = fixture_labels[0]
            if not os.path.exists(path):
                print "Path does not exist:", path
                return

            fields = fields_for_model(Product)
            print "fields:", fields.keys()
            reader = csv.reader(open(path), delimiter=";")
            self.header = reader.next()
            print "header", self.header
            columns = list(set(fields.keys()) & set(self.header))
            print "columns:", columns
            for row in reader:
                id = self.get_value("id", row)
                data = dict([(c, getattr(self, "resolve_" + c, self.get_value)(c, row)) for c in columns])
                prod = None
                try:
                    prod = Product.objects.get(id=id)
                except Product.DoesNotExist:
                    data["id"] = id
                    pl = Placeholder(slot="product_description")
                    pl.save()
                    data["description"] = pl
                    prod = Product(**data)
                else:
                    Product.objects.filter(id=id).update(**data)
                    prod = Product.objects.get(id=id)

                if prod:
                    prod.save()
                    self.post_create(prod, row)
Ejemplo n.º 5
0
    def test_links_plugin_item(self):
        """
        test the output of the link set plugin
        """
        placeholder = Placeholder(slot=u"some_slot")
        placeholder.save() # a good idea, if not strictly necessary

        # add the plugin
        plugin = add_plugin(placeholder, u"LinksPlugin", u"en",
            )
        plugin.save()

        # get the corresponding plugin instance
        instance = plugin.get_plugin_instance()[1]


        # add an item to the plugin
        item1 = GenericLinkListPluginItem(
            plugin=plugin,
            destination_content_type = ContentType.objects.get_for_model(self.school),
            destination_object_id = self.school.id,
            active=False,
            )
        item1.save()
        self.assertEquals(
            instance.render({}, plugin, placeholder),
            {}
        )

        # now the item is active
        item1.active=True
        item1.save()
        self.assertEqual(
            instance.render({}, plugin, placeholder)["links"],
            [item1]
        )

        # add a second image to the plugin
        item2 = GenericLinkListPluginItem(
            plugin=plugin,
            destination_content_type = ContentType.objects.get_for_model(self.school),
            destination_object_id = self.school.id,
            )
        item2.save()
        self.assertListEqual(
            instance.render({}, plugin, placeholder)["links"],
            [item1, item2]
        )

        # now the ordering should be reversed
        item1.inline_item_ordering=1
        item1.save()
        self.assertListEqual(
            instance.render({}, plugin, placeholder)["links"],
            [item2, item1]
        )
Ejemplo n.º 6
0
    def test_links_plugin_item(self):
        """
        test the output of the link set plugin
        """
        placeholder = Placeholder(slot=u"some_slot")
        placeholder.save() # a good idea, if not strictly necessary

        # add the plugin
        plugin = add_plugin(placeholder, u"LinksPlugin", u"en",
            )
        plugin.save()

        # get the corresponding plugin instance
        instance = plugin.get_plugin_instance()[1]


        # add an item to the plugin
        item1 = GenericLinkListPluginItem(
            plugin=plugin,
            destination_content_type = ContentType.objects.get_for_model(self.school),
            destination_object_id = self.school.id,
            active=False,
            )
        item1.save()
        self.assertEquals(
            instance.render({}, plugin, placeholder),
            {}
        )

        # now the item is active
        item1.active=True
        item1.save()
        self.assertEqual(
            instance.render({}, plugin, placeholder)["links"],
            [item1]
        )

        # add a second image to the plugin
        item2 = GenericLinkListPluginItem(
            plugin=plugin,
            destination_content_type = ContentType.objects.get_for_model(self.school),
            destination_object_id = self.school.id,
            )
        item2.save()
        self.assertListEqual(
            instance.render({}, plugin, placeholder)["links"],
            [item1, item2]
        )

        # now the ordering should be reversed
        item1.inline_item_ordering=1
        item1.save()
        self.assertListEqual(
            instance.render({}, plugin, placeholder)["links"],
            [item2, item1]
        )
Ejemplo n.º 7
0
 def setUp(self):
     self.placeholder = Placeholder(slot=u"some_slot")
     self.placeholder.save()
     self.plugin = add_plugin(self.placeholder,
                              u"ImageSetPublisher",
                              u"en",
                              kind="basic")
     self.context = {
         "placeholder_width": 500,
     }  # fake context for testing widths
Ejemplo n.º 8
0
class ImageSetTypePluginMixinContainerWidthTests(TestCase):
    def setUp(self):
        self.placeholder = Placeholder(slot=u"some_slot")
        self.placeholder.save()
        self.plugin = add_plugin(self.placeholder,
                                 u"ImageSetPublisher",
                                 u"en",
                                 kind="basic")
        self.context = {
            "placeholder_width": 500,
        }  # fake context for testing widths

    def test_imagelinkset_plugin_container_width_1000(self):
        # automatic - will *usually* be 100%
        self.plugin.width = 1000.0
        self.plugin.get_container_width({
            "placeholder_width": 500,
        })
        self.assertEqual(self.plugin.container_width, 500)

    def test_imagelinkset_plugin_container_width_100_of_500(self):
        # 100% of 500
        self.plugin.width = 100
        self.plugin.get_container_width({
            "placeholder_width": 500,
        })
        self.assertEqual(self.plugin.container_width, 500)

    def test_imagelinkset_plugin_container_width_100_of_800(self):
        # 100% of 800
        self.plugin.width = 100
        self.plugin.get_container_width({
            "placeholder_width": 800,
        })
        self.assertEqual(self.plugin.container_width, 800)

    def test_imagelinkset_plugin_container_width_50_of_500(self):
        # 50% of 500
        self.plugin.width = 50
        self.plugin.get_container_width({
            "placeholder_width": 500,
        })
        self.assertEqual(self.plugin.container_width, 250)

    def test_imagelinkset_plugin_container_width_33_of_500(self):
        # 33.3% of 500 - coerced to integer
        self.plugin.width = 33.3
        self.plugin.get_container_width({
            "placeholder_width": 500,
        })
        self.assertEqual(self.plugin.container_width, 166)
 def get_plugin(self):
     instance = CMSPlugin(language='en',
                          plugin_type="BasePlugin",
                          placeholder=Placeholder(id=1111))
     instance.cmsplugin_ptr = instance
     instance.pk = 1110
     return instance
Ejemplo n.º 10
0
 def get_plugin(self):
     instance = CMSPlugin(language='en',
                          plugin_type="NotIndexedPlugin",
                          placeholder=Placeholder(id=1235))
     instance.cmsplugin_ptr = instance
     instance.pk = 1234  # otherwise plugin_meta_context_processor() crashes
     return instance
Ejemplo n.º 11
0
    def test_01_plugin(self):
        class MockRequest(object):
            LANGUAGE_CODE = 'en'
            REQUEST = {}

        r = MockRequest()
        published_at = datetime.datetime(2011, 8, 30, 11, 0)
        title, entry = self.create_entry_with_title(published=True,
                                                    published_at=published_at,
                                                    language='en',
                                                    title='english title')
        title, entry = self.create_entry_with_title(published=True,
                                                    published_at=published_at,
                                                    language='de',
                                                    title='german title')
        ph = Placeholder(slot='main')
        ph.save()
        from django.utils.translation import activate
        activate('en')
        plugin = LatestEntriesPlugin(placeholder=ph,
                                     plugin_type='CMSLatestEntriesPlugin',
                                     limit=2,
                                     current_language_only=True)
        plugin.insert_at(None, position='last-child', save=False)
        plugin.save()
        self.assertEquals(
            plugin.render_plugin({
                'request': r
            }).count('english title'), 1)
        self.assertEquals(
            plugin.render_plugin({
                'request': r
            }).count('german title'), 0)
        plugin = LatestEntriesPlugin(placeholder=ph,
                                     plugin_type='CMSLatestEntriesPlugin',
                                     limit=2,
                                     current_language_only=False)
        plugin.insert_at(None, position='last-child', save=False)
        plugin.save()
        self.assertEquals(
            plugin.render_plugin({
                'request': r
            }).count('english title'), 1)
        self.assertEquals(
            plugin.render_plugin({
                'request': r
            }).count('german title'), 1)
Ejemplo n.º 12
0
    def test_repr(self):
        unsaved_ph = Placeholder()
        self.assertIn('id=None', repr(unsaved_ph))
        self.assertIn("slot=''", repr(unsaved_ph))

        saved_ph = Placeholder.objects.create(slot='test')
        self.assertIn('id={}'.format(saved_ph.pk), repr(saved_ph))
        self.assertIn("slot='{}'".format(saved_ph.slot), repr(saved_ph))
Ejemplo n.º 13
0
 def test_render_placeholder_toolbar(self):
     placeholder = Placeholder()
     placeholder.slot = "test"
     placeholder.pk = placeholder.id = 99
     context = SekizaiContext()
     context["request"] = AttributeObject(
         REQUEST={"language": "en"},
         GET=[],
         session={},
         path="/",
         user=self.test_user,
         current_page=None,
         method="GET",
     )
     classes = ["cms_placeholder-bar-%s" % placeholder.pk, "cms_placeholder_slot::test"]
     output = render_placeholder_toolbar(placeholder, context, "", "test")
     for cls in classes:
         self.assertTrue(cls in output, "%r is not in %r" % (cls, output))
Ejemplo n.º 14
0
 def setUp(self):
     placeholder = Placeholder(id=1235)
     instance = CMSPlugin(plugin_type="NotIndexedPlugin",
                          placeholder=placeholder)
     instance.cmsplugin_ptr = instance
     instance.pk = 1234  # otherwise plugin_meta_context_processor() crashes
     self.instance = instance
     self.index = TitleIndex()
     self.request = get_request_for_search(language='en')
Ejemplo n.º 15
0
 def setUp(self):
     self.placeholder = Placeholder(slot=u"some_slot")
     self.placeholder.save()
     self.plugin = add_plugin(
         self.placeholder,
         u"ImageSetPublisher",
         u"en",
         kind="basic"
     )
     self.context = {"placeholder_width": 500,} # fake context for testing widths
Ejemplo n.º 16
0
class ImageSetTypePluginMixinContainerWidthTests(TestCase):
    def setUp(self):
        self.placeholder = Placeholder(slot=u"some_slot")
        self.placeholder.save()
        self.plugin = add_plugin(
            self.placeholder,
            u"ImageSetPublisher",
            u"en",
            kind="basic"
        )
        self.context = {"placeholder_width": 500,} # fake context for testing widths


    def test_imagelinkset_plugin_container_width_1000(self):
        # automatic - will *usually* be 100%
        self.plugin.width = 1000.0
        self.plugin.get_container_width({"placeholder_width": 500,})
        self.assertEqual(self.plugin.container_width, 500)

    def test_imagelinkset_plugin_container_width_100_of_500(self):
        # 100% of 500
        self.plugin.width = 100
        self.plugin.get_container_width({"placeholder_width": 500,})
        self.assertEqual(self.plugin.container_width, 500)

    def test_imagelinkset_plugin_container_width_100_of_800(self):
        # 100% of 800
        self.plugin.width = 100
        self.plugin.get_container_width({"placeholder_width": 800,})
        self.assertEqual(self.plugin.container_width, 800)

    def test_imagelinkset_plugin_container_width_50_of_500(self):
        # 50% of 500
        self.plugin.width = 50
        self.plugin.get_container_width({"placeholder_width": 500,})
        self.assertEqual(self.plugin.container_width, 250)

    def test_imagelinkset_plugin_container_width_33_of_500(self):
        # 33.3% of 500 - coerced to integer
        self.plugin.width = 33.3
        self.plugin.get_container_width({"placeholder_width": 500,})
        self.assertEqual(self.plugin.container_width, 166)
Ejemplo n.º 17
0
 def test_render_placeholder_toolbar(self):
     placeholder = Placeholder()
     placeholder.slot = 'test'
     placeholder.pk = placeholder.id = 99
     context = SekizaiContext()
     context['request'] = AttributeObject(
         REQUEST={'language': 'en'},
         GET=[],
         session={},
         path='/',
         user=self.test_user,
         current_page=None,
         method='GET',
     )
     classes = [
         "cms_placeholder-%s" % placeholder.pk,
         'cms_placeholder',
     ]
     output = render_placeholder_toolbar(placeholder, context, 'test', 'en')
     for cls in classes:
         self.assertTrue(cls in output, '%r is not in %r' % (cls, output))
Ejemplo n.º 18
0
 def test_render_placeholder_toolbar(self):
     placeholder = Placeholder()
     placeholder.slot = 'test'
     placeholder.pk = placeholder.id = 99
     context = SekizaiContext()
     context['request'] = AttributeObject(
         REQUEST={'language': 'en'},
         GET=[],
         session={},
         path='/',
         user=self.test_user,
         current_page=None,
         method='GET',
     )
     classes = [
         "cms_placeholder-bar-%s" % placeholder.pk,
         "cms_placeholder_slot::test",
     ]
     output = render_placeholder_toolbar(placeholder, context, '', 'test')
     for cls in classes:
         self.assertTrue(cls in output, '%r is not in %r' % (cls, output))
Ejemplo n.º 19
0
    def setUp(self):

        p1 = Publication(guid="test-publication-1")
        p1.save()
        self.br1 = BibliographicRecord(
            publication=p1,
            publication_date=datetime.now()-timedelta(days=10)
            )
        self.br1.save()

        p2 = Publication(guid="test-publication-2")
        p2.save()
        self.br2 = BibliographicRecord(
            publication=p2,
            publication_date=datetime.now()-timedelta(days=20)
            )
        self.br2.save()

        e = Entity()
        e.save()

        p = Person()
        p.save()

        m = Membership(
            person=p,
            entity=e
            )
        m.save()

        r = Researcher(person=p)
        r.save()

        a2 = Authored(
            is_a_favourite=True, publication=p2, researcher=r,
            bibliographic_record=self.br2
            )
        a2.save()

        self.itemlist = PublicationsList()
        self.itemlist.items = BibliographicRecord.objects.all()

        self.ph = Placeholder(slot=u"some_slot")
        self.ph.save()
        self.pl = add_plugin(
            self.ph,
            u"CMSPublicationsPlugin",
            u"en",
            entity=e
            )
        self.pl.save()
Ejemplo n.º 20
0
class PluginTests(TestCase):
    def setUp(self):
        self.school = Entity(
            name="School of Medicine", 
            slug="medicine",
            )
        self.school.save()
        self.placeholder = Placeholder(slot=u"some_slot")
        self.placeholder.save()
        self.plugin = add_plugin(
            self.placeholder, 
            u"CMSPublicationsPlugin", 
            u"en",
            entity=self.school
        )
        self.plugin.save()

    def test_kind_none(self):
        instance = self.plugin.get_plugin_instance()[1]
        self.plugin.type = None
        self.plugin.view = "current"
        self.plugin.favourites_only = False
        instance.get_items(self.plugin)
Ejemplo n.º 21
0
 def test_01_plugin(self):
     class MockRequest(object):
         LANGUAGE_CODE = 'en'
         REQUEST = {}
     r = MockRequest()
     published_at = datetime.datetime(2011, 8, 30, 11, 0)
     title, entry = self.create_entry_with_title(published=True, 
         published_at=published_at, language='en', title='english title')
     title, entry = self.create_entry_with_title(published=True, 
         published_at=published_at, language='de', title='german title')
     ph = Placeholder(slot='main')
     ph.save()
     from django.utils.translation import activate
     activate('en')
     plugin = LatestEntriesPlugin(placeholder=ph, plugin_type='CMSLatestEntriesPlugin', limit=2, current_language_only=True)
     plugin.insert_at(None, position='last-child', save=False)
     plugin.save()
     self.assertEquals(plugin.render_plugin({'request': r}).count('english title'), 1)
     self.assertEquals(plugin.render_plugin({'request': r}).count('german title'), 0)
     plugin = LatestEntriesPlugin(placeholder=ph, plugin_type='CMSLatestEntriesPlugin', limit=2, current_language_only=False)
     plugin.insert_at(None, position='last-child', save=False)
     plugin.save()
     self.assertEquals(plugin.render_plugin({'request': r}).count('english title'), 1)
     self.assertEquals(plugin.render_plugin({'request': r}).count('german title'), 1)
Ejemplo n.º 22
0
    def handle(self, *fixture_labels, **options):

        if len(fixture_labels) > 0:
            path = fixture_labels[0]
            if not os.path.exists(path):
                print 'Path does not exist:', path
                return

            fields = fields_for_model(Product)
            print 'fields:', fields.keys()
            reader = csv.reader(open(path), delimiter=";")
            self.header = reader.next()
            print 'header', self.header
            columns = list(set(fields.keys()) & set(self.header))
            print 'columns:', columns
            for row in reader:
                id = self.get_value('id', row)
                data = dict([(c, getattr(self, 'resolve_' + c,
                                         self.get_value)(c, row))
                             for c in columns])
                prod = None
                try:
                    prod = Product.objects.get(id=id)
                except Product.DoesNotExist:
                    data['id'] = id
                    pl = Placeholder(slot='product_description')
                    pl.save()
                    data['description'] = pl
                    prod = Product(**data)
                else:
                    Product.objects.filter(id=id).update(**data)
                    prod = Product.objects.get(id=id)

                if prod:
                    prod.save()
                    self.post_create(prod, row)
Ejemplo n.º 23
0
    def fill_placeholder(self, placeholder=None):
        if placeholder is None:
            placeholder = Placeholder(slot=u"some_slot")
            placeholder.save() # a good idea, if not strictly necessary


        # plugin in placeholder
        plugin_1 = add_plugin(placeholder, u"TextPlugin", u"en",
                              body=u"01",
        )
        plugin_1.save()

        # IMPORTANT: plugins must be reloaded, before they can be assigned
        # as a parent. Otherwise, the MPTT structure doesn't seem to rebuild
        # properly.

        # child of plugin_1
        plugin_2 = add_plugin(placeholder, u"TextPlugin", u"en",
                              body=u"02",
        )
        plugin_1 = self.reload(plugin_1)
        plugin_2.parent = plugin_1
        plugin_2.save()
        return placeholder
Ejemplo n.º 24
0
 def setUp(self):
     self.school = Entity(
         name="School of Medicine", 
         slug="medicine",
         )
     self.school.save()
     self.placeholder = Placeholder(slot=u"some_slot")
     self.placeholder.save()
     self.plugin = add_plugin(
         self.placeholder, 
         u"CMSPublicationsPlugin", 
         u"en",
         entity=self.school
     )
     self.plugin.save()
Ejemplo n.º 25
0
    def setUp(self):
        # create a placeholder
        self.placeholder = Placeholder(slot=u"some_slot")

        # create a fake context and request
        request = HttpRequest()
        self.context = {"request": request}

        # create a form
        self.form = FormDefinition(name="testform")
        self.form.save()

        # add the plugin
        self.plugin = add_plugin(self.placeholder,
                                 u"FormDesignerPlugin",
                                 u"en",
                                 form_definition=self.form)
        self.plugin.save()
    def test_plugin_deep_nesting_and_copying(self):
        """
        Create a deeply-nested plugin structure, tests its properties, and tests
        that it is copied accurately when the placeholder containing them is
        copied.
        
        The structure below isn't arbitrary, but has been designed to test
        various conditions, including:
        
        * nodes four levels deep
        * multiple successive level increases 
        * multiple successive level decreases
        * successive nodes on the same level followed by level changes
        * multiple level decreases between successive nodes
        * siblings with and without children
        * nodes and branches added to the tree out of sequence  
   
        First we create the structure:
        
             11
             1 
                 2 
                     12
                     4 
                          10  
                     8 
                 3 
                     9 
              5 
                 6 
                 7 
                 13
              14
        
        and then we move it all around.     
        """

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

        # plugin in placeholder
        plugin_1 = add_plugin(
            placeholder,
            u"TextPlugin",
            u"en",
            body=u"01",
        )
        plugin_1.save()

        # IMPORTANT: plugins must be reloaded, before they can be assigned
        # as a parent. Otherwise, the MPTT structure doesn't seem to rebuild
        # properly.

        # child of plugin_1
        plugin_2 = add_plugin(
            placeholder,
            u"TextPlugin",
            u"en",
            body=u"02",
        )
        plugin_1 = self.reload(plugin_1)
        plugin_2.parent = plugin_1
        plugin_2.save()

        # plugin_2 should be plugin_1's only child
        # for a single item we use assertSequenceEqual
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_1.pk).get_children(),
            [CMSPlugin.objects.get(id=plugin_2.pk)])

        # create a second child of plugin_1
        plugin_3 = add_plugin(
            placeholder,
            u"TextPlugin",
            u"en",
            body=u"03",
        )
        plugin_1 = self.reload(plugin_1)
        plugin_3.parent = plugin_1
        plugin_3.save()

        # plugin_2 & plugin_3 should be plugin_1's children
        # for multiple items we use assertSequenceEqual, because
        # assertSequenceEqual may re-order the list without warning
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_1.pk).get_children(), [
                CMSPlugin.objects.get(id=plugin_2.pk),
                CMSPlugin.objects.get(id=plugin_3.pk),
            ])

        # child of plugin_2
        plugin_4 = add_plugin(
            placeholder,
            u"TextPlugin",
            u"en",
            body=u"04",
        )
        plugin_2 = self.reload(plugin_2)
        plugin_4.parent = plugin_2
        plugin_4.save()

        # plugin_4 should be plugin_2's child
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_2.pk).get_children(),
            [CMSPlugin.objects.get(id=plugin_4.pk)])

        # 2,3 & 4 should be descendants of 1
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_1.pk).get_descendants(),
            [
                # note tree_id ordering of MPTT reflected here:
                CMSPlugin.objects.get(id=plugin_2.pk),
                CMSPlugin.objects.get(id=plugin_4.pk),
                CMSPlugin.objects.get(id=plugin_3.pk),
            ],
        )

        # create a second root plugin
        plugin_5 = add_plugin(
            placeholder,
            u"TextPlugin",
            u"en",
            # force this to first-child, to make the tree more challenging
            position='first-child',
            body=u"05",
        )
        plugin_5.save()

        # child of plugin_5
        plugin_6 = add_plugin(
            placeholder,
            u"TextPlugin",
            u"en",
            body=u"06",
        )
        plugin_5 = self.reload(plugin_5)
        plugin_6.parent = plugin_5
        plugin_6.save()

        # plugin_6 should be plugin_5's child
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_5.pk).get_children(),
            [CMSPlugin.objects.get(id=plugin_6.pk)])

        # child of plugin_6
        plugin_7 = add_plugin(
            placeholder,
            u"TextPlugin",
            u"en",
            body=u"07",
        )
        plugin_5 = self.reload(plugin_5)
        plugin_7.parent = plugin_5
        plugin_7.save()

        # plugin_7 should be plugin_5's child
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_5.pk).get_children(), [
                CMSPlugin.objects.get(id=plugin_6.pk),
                CMSPlugin.objects.get(id=plugin_7.pk)
            ])

        # 6 & 7 should be descendants of 5
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_5.pk).get_descendants(), [
                CMSPlugin.objects.get(id=plugin_6.pk),
                CMSPlugin.objects.get(id=plugin_7.pk),
            ])

        # another child of plugin_2
        plugin_8 = add_plugin(
            placeholder,
            u"TextPlugin",
            u"en",
            body=u"08",
        )
        plugin_2 = self.reload(plugin_2)
        plugin_8.parent = plugin_2
        plugin_8.save()

        # plugin_4 should be plugin_2's child
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_2.pk).get_children(), [
                CMSPlugin.objects.get(id=plugin_4.pk),
                CMSPlugin.objects.get(id=plugin_8.pk),
            ])

        # child of plugin_3
        plugin_9 = add_plugin(
            placeholder,
            u"TextPlugin",
            u"en",
            body=u"09",
        )
        plugin_3 = self.reload(plugin_3)
        plugin_9.parent = plugin_3
        plugin_9.save()

        # plugin_9 should be plugin_3's child
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_3.pk).get_children(),
            [CMSPlugin.objects.get(id=plugin_9.pk)])

        # child of plugin_4
        plugin_10 = add_plugin(
            placeholder,
            u"TextPlugin",
            u"en",
            body=u"10",
        )
        plugin_4 = self.reload(plugin_4)
        plugin_10.parent = plugin_4
        plugin_10.save()

        # plugin_10 should be plugin_4's child
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_4.pk).get_children(),
            [CMSPlugin.objects.get(id=plugin_10.pk)])

        original_plugins = placeholder.get_plugins()
        self.assertEquals(original_plugins.count(), 10)

        # elder sibling of plugin_1
        plugin_1 = self.reload(plugin_1)
        plugin_11 = add_plugin(placeholder,
                               u"TextPlugin",
                               u"en",
                               body=u"11",
                               target=plugin_1,
                               position="left")
        plugin_11.save()

        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_1.pk).get_children(), [
                CMSPlugin.objects.get(id=plugin_2.pk),
                CMSPlugin.objects.get(id=plugin_3.pk)
            ])

        # elder sibling of plugin_4
        plugin_4 = self.reload(plugin_4)
        plugin_12 = add_plugin(placeholder,
                               u"TextPlugin",
                               u"en",
                               body=u"12",
                               target=plugin_4,
                               position="left")
        plugin_12.save()

        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_2.pk).get_children(), [
                CMSPlugin.objects.get(id=plugin_12.pk),
                CMSPlugin.objects.get(id=plugin_4.pk),
                CMSPlugin.objects.get(id=plugin_8.pk)
            ])

        # younger sibling of plugin_7
        plugin_7 = self.reload(plugin_7)
        plugin_13 = add_plugin(placeholder,
                               u"TextPlugin",
                               u"en",
                               body=u"13",
                               target=plugin_7,
                               position="right")
        plugin_13.save()

        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_5.pk).get_children(), [
                CMSPlugin.objects.get(id=plugin_6.pk),
                CMSPlugin.objects.get(id=plugin_7.pk),
                CMSPlugin.objects.get(id=plugin_13.pk)
            ])

        # new sibling of plugin_5
        plugin_5 = self.reload(plugin_5)
        plugin_14 = add_plugin(placeholder, u"TextPlugin", u"en", body=u"14")
        plugin_14.save()

        self.assertSequenceEqual(CMSPlugin.objects.filter(level=0), [
            CMSPlugin.objects.get(id=plugin_11.pk),
            CMSPlugin.objects.get(id=plugin_1.pk),
            CMSPlugin.objects.get(id=plugin_5.pk),
            CMSPlugin.objects.get(id=plugin_14.pk)
        ])
        self.assertEquals(CMSPlugin.objects.get(id=plugin_11.pk).tree_id, 1)
        self.copy_placeholders_and_check_results([placeholder])

        # now let's move plugins around in the tree

        # move plugin_2 before plugin_11
        plugin_2 = self.reload(plugin_2)
        plugin_2.move_to(target=plugin_1, position="left")
        plugin_2.save()
        self.assertEquals(CMSPlugin.objects.get(id=plugin_2.pk).tree_id, 1)
        self.copy_placeholders_and_check_results([placeholder])

        # move plugin_6 after plugin_7
        plugin_6 = self.reload(plugin_6)
        plugin_7 = self.reload(plugin_7)
        plugin_6.move_to(target=plugin_7, position="right")
        plugin_6.save()
        self.copy_placeholders_and_check_results([placeholder])

        # move plugin_3 before plugin_2
        plugin_2 = self.reload(plugin_2)
        plugin_3 = self.reload(plugin_3)
        plugin_3.move_to(target=plugin_2, position="left")
        plugin_3.save()
        self.copy_placeholders_and_check_results([placeholder])

        # make plugin_3 plugin_2's first-child
        plugin_2 = self.reload(plugin_2)
        plugin_3 = self.reload(plugin_3)
        plugin_3.move_to(target=plugin_2, position="first-child")
        plugin_3.save()
        self.copy_placeholders_and_check_results([placeholder])

        # make plugin_7 plugin_2's first-child
        plugin_2 = self.reload(plugin_2)
        plugin_7 = self.reload(plugin_7)
        plugin_7.move_to(target=plugin_3, position="right")
        plugin_7.save()
        self.copy_placeholders_and_check_results([
            placeholder,
        ])
Ejemplo n.º 27
0
    def test_embedded_video_plugin_item(self):
        """
        test the output of the embedded video plugin
        """
        # create a placeholder
        placeholder = Placeholder(slot=u"some_slot")
        placeholder.save() # a good idea, if not strictly necessary

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

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

        # add a video to the plugin - but it's not active
        item1 = EmbeddedVideoSetItem(
            plugin=plugin,
            service="vimeo",
            video_code="1234",
            video_title="one",
            active=False,
            inline_item_ordering=1
            )
        item1.save()
        self.assertEquals(instance.render({}, plugin, placeholder), {})
        self.assertEquals(instance.render_template, "null.html")

        # now the item is active
        item1.active=True
        item1.save()
        self.assertDictEqual(
            instance.render({}, plugin, placeholder),
            {
                'width': 100,
                'video': item1,
                'embeddedvideoset': plugin,
                'height': 75,
            }
            )
        self.assertEquals(instance.render_template, "embedded_video/vimeo.html")

        # change aspect_ratio
        item1.aspect_ratio=1.0
        item1.save()
        self.assertDictEqual(
            instance.render({}, plugin, placeholder),
            {
                'width': 100,
                'video': item1,
                'embeddedvideoset': plugin,
                'height': 100,
            }
            )

        # add a second video to the plugin
        item2 = EmbeddedVideoSetItem(
            plugin=plugin,
            service="vimeo",
            video_code="5678",
            video_title="two",
            )
        item2.save()
        self.assertEquals(list(plugin.active_items), [item2, item1])
Ejemplo n.º 28
0
    def test_embedded_video_plugin_item(self):
        """
        test the output of the embedded video plugin
        """
        # create a placeholder
        placeholder = Placeholder(slot=u"some_slot")
        placeholder.save()  # a good idea, if not strictly necessary

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

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

        # add a video to the plugin - but it's not active
        item1 = EmbeddedVideoSetItem(plugin=plugin,
                                     service="vimeo",
                                     video_code="1234",
                                     video_title="one",
                                     active=False,
                                     inline_item_ordering=1)
        item1.save()
        self.assertEquals(instance.render({}, plugin, placeholder), {})
        self.assertEquals(instance.render_template, "null.html")

        # now the item is active
        item1.active = True
        item1.save()
        self.assertDictEqual(
            instance.render({}, plugin, placeholder), {
                'width': 100,
                'video': item1,
                'embeddedvideoset': plugin,
                'height': 75,
            })
        self.assertEquals(instance.render_template,
                          "embedded_video/vimeo.html")

        # change aspect_ratio
        item1.aspect_ratio = 1.0
        item1.save()
        self.assertDictEqual(
            instance.render({}, plugin, placeholder), {
                'width': 100,
                'video': item1,
                'embeddedvideoset': plugin,
                'height': 100,
            })

        # add a second video to the plugin
        item2 = EmbeddedVideoSetItem(
            plugin=plugin,
            service="vimeo",
            video_code="5678",
            video_title="two",
        )
        item2.save()
        self.assertEquals(list(plugin.active_items), [item2, item1])
Ejemplo n.º 29
0
    def test_plugin_deep_nesting_and_copying(self):
        """
        Create a deeply-nested plugin structure, tests its properties, and tests
        that it is copied accurately when the placeholder containing them is
        copied.
        
        The structure below isn't arbitrary, but has been designed to test
        various conditions, including:
        
        * nodes four levels deep
        * multiple successive level increases 
        * multiple successive level decreases
        * successive nodes on the same level followed by level changes
        * multiple level decreases between successive nodes
        * siblings with and without children
        * nodes and branches added to the tree out of sequence  
   
        First we create the structure:
        
             11
             1 
                 2 
                     12
                     4 
                          10  
                     8 
                 3 
                     9 
              5 
                 6 
                 7 
                 13
              14
        
        and then we move it all around.     
        """

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


        # plugin in placeholder
        plugin_1 = add_plugin(placeholder, u"TextPlugin", u"en",
                              body=u"01",
        )
        plugin_1.save()

        # IMPORTANT: plugins must be reloaded, before they can be assigned 
        # as a parent. Otherwise, the MPTT structure doesn't seem to rebuild 
        # properly.

        # child of plugin_1
        plugin_2 = add_plugin(placeholder, u"TextPlugin", u"en",
                              body=u"02",
        )
        plugin_1 = self.reload(plugin_1)
        plugin_2.parent = plugin_1
        plugin_2.save()

        # plugin_2 should be plugin_1's only child 
        # for a single item we use assertSequenceEqual
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_1.pk).get_children(),
            [CMSPlugin.objects.get(id=plugin_2.pk)])

        # create a second child of plugin_1
        plugin_3 = add_plugin(placeholder, u"TextPlugin", u"en",
                              body=u"03",
        )
        plugin_1 = self.reload(plugin_1)
        plugin_3.parent = plugin_1
        plugin_3.save()

        # plugin_2 & plugin_3 should be plugin_1's children
        # for multiple items we use assertSequenceEqual, because
        # assertSequenceEqual may re-order the list without warning
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_1.pk).get_children(),
            [
                CMSPlugin.objects.get(id=plugin_2.pk),
                CMSPlugin.objects.get(id=plugin_3.pk),
            ])

        # child of plugin_2
        plugin_4 = add_plugin(placeholder, u"TextPlugin", u"en",
                              body=u"04",
        )
        plugin_2 = self.reload(plugin_2)
        plugin_4.parent = plugin_2
        plugin_4.save()

        # plugin_4 should be plugin_2's child
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_2.pk).get_children(),
            [CMSPlugin.objects.get(id=plugin_4.pk)])

        # 2,3 & 4 should be descendants of 1
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_1.pk).get_descendants(),
            [
                # note tree_id ordering of MPTT reflected here:
                CMSPlugin.objects.get(id=plugin_2.pk),
                CMSPlugin.objects.get(id=plugin_4.pk),
                CMSPlugin.objects.get(id=plugin_3.pk),
            ],
        )

        # create a second root plugin
        plugin_5 = add_plugin(placeholder, u"TextPlugin", u"en",
                              # force this to first-child, to make the tree more challenging
                              position='first-child',
                              body=u"05",
        )
        plugin_5.save()

        # child of plugin_5
        plugin_6 = add_plugin(placeholder, u"TextPlugin", u"en",
                              body=u"06",
        )
        plugin_5 = self.reload(plugin_5)
        plugin_6.parent = plugin_5
        plugin_6.save()

        # plugin_6 should be plugin_5's child
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_5.pk).get_children(),
            [CMSPlugin.objects.get(id=plugin_6.pk)])

        # child of plugin_6
        plugin_7 = add_plugin(placeholder, u"TextPlugin", u"en",
                              body=u"07",
        )
        plugin_5 = self.reload(plugin_5)
        plugin_7.parent = plugin_5
        plugin_7.save()

        # plugin_7 should be plugin_5's child
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_5.pk).get_children(),
            [
                CMSPlugin.objects.get(id=plugin_6.pk),
                CMSPlugin.objects.get(id=plugin_7.pk)
            ])

        # 6 & 7 should be descendants of 5
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_5.pk).get_descendants(),
            [
                CMSPlugin.objects.get(id=plugin_6.pk),
                CMSPlugin.objects.get(id=plugin_7.pk),
            ])

        # another child of plugin_2
        plugin_8 = add_plugin(placeholder, u"TextPlugin", u"en",
                              body=u"08",
        )
        plugin_2 = self.reload(plugin_2)
        plugin_8.parent = plugin_2
        plugin_8.save()

        # plugin_4 should be plugin_2's child
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_2.pk).get_children(),
            [
                CMSPlugin.objects.get(id=plugin_4.pk),
                CMSPlugin.objects.get(id=plugin_8.pk),
            ])

        # child of plugin_3
        plugin_9 = add_plugin(placeholder, u"TextPlugin", u"en",
                              body=u"09",
        )
        plugin_3 = self.reload(plugin_3)
        plugin_9.parent = plugin_3
        plugin_9.save()

        # plugin_9 should be plugin_3's child
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_3.pk).get_children(),
            [CMSPlugin.objects.get(id=plugin_9.pk)])

        # child of plugin_4
        plugin_10 = add_plugin(placeholder, u"TextPlugin", u"en",
                               body=u"10",
        )
        plugin_4 = self.reload(plugin_4)
        plugin_10.parent = plugin_4
        plugin_10.save()

        # plugin_10 should be plugin_4's child
        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_4.pk).get_children(),
            [CMSPlugin.objects.get(id=plugin_10.pk)])

        original_plugins = placeholder.get_plugins()
        self.assertEquals(original_plugins.count(), 10)

        # elder sibling of plugin_1
        plugin_1 = self.reload(plugin_1)
        plugin_11 = add_plugin(placeholder, u"TextPlugin", u"en",
                               body=u"11",
                               target=plugin_1,
                               position="left"
        )
        plugin_11.save()

        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_1.pk).get_children(),
            [
                CMSPlugin.objects.get(id=plugin_2.pk),
                CMSPlugin.objects.get(id=plugin_3.pk)
            ])

        # elder sibling of plugin_4
        plugin_4 = self.reload(plugin_4)
        plugin_12 = add_plugin(placeholder, u"TextPlugin", u"en",
                               body=u"12",
                               target=plugin_4,
                               position="left"
        )
        plugin_12.save()

        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_2.pk).get_children(),
            [
                CMSPlugin.objects.get(id=plugin_12.pk),
                CMSPlugin.objects.get(id=plugin_4.pk),
                CMSPlugin.objects.get(id=plugin_8.pk)
            ])

        # younger sibling of plugin_7
        plugin_7 = self.reload(plugin_7)
        plugin_13 = add_plugin(placeholder, u"TextPlugin", u"en",
                               body=u"13",
                               target=plugin_7,
                               position="right"
        )
        plugin_13.save()

        self.assertSequenceEqual(
            CMSPlugin.objects.get(id=plugin_5.pk).get_children(),
            [
                CMSPlugin.objects.get(id=plugin_6.pk),
                CMSPlugin.objects.get(id=plugin_7.pk),
                CMSPlugin.objects.get(id=plugin_13.pk)
            ])

        # new sibling of plugin_5
        plugin_5 = self.reload(plugin_5)
        plugin_14 = add_plugin(placeholder, u"TextPlugin", u"en",
                               body=u"14"
        )
        plugin_14.save()

        self.assertSequenceEqual(
            CMSPlugin.objects.filter(level=0),
            [
                CMSPlugin.objects.get(id=plugin_11.pk),
                CMSPlugin.objects.get(id=plugin_1.pk),
                CMSPlugin.objects.get(id=plugin_5.pk),
                CMSPlugin.objects.get(id=plugin_14.pk)
            ])
        self.assertEquals(CMSPlugin.objects.get(id=plugin_11.pk).tree_id, 1)
        self.copy_placeholders_and_check_results([placeholder])

        # now let's move plugins around in the tree

        # move plugin_2 before plugin_11
        plugin_2 = self.reload(plugin_2)
        plugin_2.move_to(target=plugin_1, position="left")
        plugin_2.save()
        self.assertEquals(CMSPlugin.objects.get(id=plugin_2.pk).tree_id, 1)
        self.copy_placeholders_and_check_results([placeholder])

        # move plugin_6 after plugin_7
        plugin_6 = self.reload(plugin_6)
        plugin_7 = self.reload(plugin_7)
        plugin_6.move_to(target=plugin_7, position="right")
        plugin_6.save()
        self.copy_placeholders_and_check_results([placeholder])

        # move plugin_3 before plugin_2
        plugin_2 = self.reload(plugin_2)
        plugin_3 = self.reload(plugin_3)
        plugin_3.move_to(target=plugin_2, position="left")
        plugin_3.save()
        self.copy_placeholders_and_check_results([placeholder])

        # make plugin_3 plugin_2's first-child
        plugin_2 = self.reload(plugin_2)
        plugin_3 = self.reload(plugin_3)
        plugin_3.move_to(target=plugin_2, position="first-child")
        plugin_3.save()
        self.copy_placeholders_and_check_results([placeholder])

        # make plugin_7 plugin_2's first-child
        plugin_2 = self.reload(plugin_2)
        plugin_7 = self.reload(plugin_7)
        plugin_7.move_to(target=plugin_3, position="right")
        plugin_7.save()
        self.copy_placeholders_and_check_results([placeholder, ])
Ejemplo n.º 30
0
class PluginTests(TestCase):
    def setUp(self):

        p1 = Publication(guid="test-publication-1")
        p1.save()
        self.br1 = BibliographicRecord(
            publication=p1,
            publication_date=datetime.now()-timedelta(days=10)
            )
        self.br1.save()

        p2 = Publication(guid="test-publication-2")
        p2.save()
        self.br2 = BibliographicRecord(
            publication=p2,
            publication_date=datetime.now()-timedelta(days=20)
            )
        self.br2.save()

        e = Entity()
        e.save()

        p = Person()
        p.save()

        m = Membership(
            person=p,
            entity=e
            )
        m.save()

        r = Researcher(person=p)
        r.save()

        a2 = Authored(
            is_a_favourite=True, publication=p2, researcher=r,
            bibliographic_record=self.br2
            )
        a2.save()

        self.itemlist = PublicationsList()
        self.itemlist.items = BibliographicRecord.objects.all()

        self.ph = Placeholder(slot=u"some_slot")
        self.ph.save()
        self.pl = add_plugin(
            self.ph,
            u"CMSPublicationsPlugin",
            u"en",
            entity=e
            )
        self.pl.save()

    def test_context_contains_a_lister(self):
        pp = self.pl.get_plugin_instance()[1]
        context = pp.render({}, self.pl, self.ph)
        self.assertIsInstance(context["lister"], PublicationsLister)
        self.assertIsInstance(
            context["lister"].lists[0],
            PublicationsListPlugin
            )
Ejemplo n.º 31
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), {})
Ejemplo n.º 32
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), {})