コード例 #1
0
    def test_shit_input(self):
        """ Try put in bad data """

        self.loginAsPortalOwner()
        self.portal.invokeFactory("Document", "doc")
        doc = self.portal.doc
        behavior = IMultiChannelBehavior(doc)
        try:
            behavior.contentMedias = "xxx"
            raise AssertionError("Should not be never reached")
        except ConstraintNotSatisfied:
            pass
コード例 #2
0
    def test_set_media(self):
        """ Try behavior properties """
        self.loginAsPortalOwner()
        self.portal.invokeFactory("Document", "doc")
        doc = self.portal.doc

        self.assertTrue(IMobileContentish.providedBy(doc))
        behavior = IMultiChannelBehavior(doc)

        self.assertEqual(behavior.contentMedias, ContentMediaOption.USE_PARENT)

        behavior.contentMedias = ContentMediaOption.WEB
        behavior.save()

        # Recreate behavior
        behavior = IMultiChannelBehavior(doc)
        self.assertEqual(behavior.contentMedias, ContentMediaOption.WEB)
コード例 #3
0
    def make_some_evil_site_content(self):
        """ Test behavior and assignable works nicely.
        """

        self.loginAsPortalOwner()
        self.portal.invokeFactory("Document", "doc")
        doc = self.portal.doc
        doc.processForm()

        # Check assignable works
        from plone.behavior.interfaces import IBehaviorAssignable
        assignable = IBehaviorAssignable(doc, None)

        self.assertTrue(assignable.supports(IMultiChannelBehavior))
        self.assertNotEqual(assignable, None)


        # Check behavior works
        self.assertTrue(IMobileContentish.providedBy(doc))
        behavior = IMultiChannelBehavior(doc)
        behavior.contentMedias = ContentMediaOption.BOTH
        behavior.save()
コード例 #4
0
    def setContentMedia(self, content, strategy):
        """ Set content option on which medias the content should be visible.

        This method is permission aware.

        @param content: AT based object whose schema is patched by extender

        @param strategy: one of strings web, mobile, parent, both
        """

        try:
            behavior = IMultiChannelBehavior(content)
        except TypeError:
            raise RuntimeError("Content does not support multi channel behavior")

        if behavior == None:
            raise RuntimeError("Content does not support multi channel behavior")

        behavior.contentMedias = strategy
        
        # Make change persistent
        behavior.save()