def testRelations(self):
        rel_fti = DexterityFTI(
            'RelationsType',
            schema=
            'plone.app.versioningbehavior.tests.test_modifiers.IRelationsType')
        self.portal.portal_types._setObject('RelationsType', rel_fti)

        # Setup IIntIds utility which is required for relations to work
        from five.intid import site
        from zope.app.intid.interfaces import IIntIds
        site.add_intids(self.portal)
        intids = getUtility(IIntIds)

        source = createContentInContainer(self.portal, 'RelationsType')
        target = createContentInContainer(self.portal, 'RelationsType')

        # Test modifier when no relations are set
        modifier = SkipRelations('modifier', 'Modifier')
        pers_id, pers_load, empty1, empty2 = modifier.getOnCloneModifiers(
            source)
        self.assertTrue(pers_id(None) is None)
        self.assertTrue(pers_id(None) is None)
        self.assertTrue(pers_load(None) is None)
        self.assertTrue(pers_load(None) is None)
        self.assertTrue(empty1 == [])
        self.assertTrue(empty2 == [])

        repo_clone = createContent('RelationsType')
        modifier.afterRetrieveModifier(source, repo_clone)
        self.assertTrue(repo_clone.single is source.single)
        self.assertTrue(repo_clone.multiple is source.multiple)

        # Add some relations
        source.single = RelationValue(intids.getId(target))
        source.multiple = [RelationValue(intids.getId(target))]

        # Update relations
        from zope.lifecycleevent import ObjectModifiedEvent
        from zope.event import notify
        notify(ObjectModifiedEvent(source))

        modifier = SkipRelations('modifier', 'Modifier')
        pers_id, pers_load, empty1, empty2 = modifier.getOnCloneModifiers(
            source)
        self.assertTrue(pers_id(source.single))
        self.assertTrue(pers_id(source.multiple))
        self.assertTrue(pers_load(source.single) is None)
        self.assertTrue(pers_load(source.multiple) is None)
        self.assertTrue(empty1 == [])
        self.assertTrue(empty2 == [])

        repo_clone = createContent('RelationsType')
        modifier.afterRetrieveModifier(source, repo_clone)
        self.assertTrue(repo_clone.single is source.single)
        self.assertTrue(repo_clone.multiple is source.multiple)
Esempio n. 2
0
    def testRelations(self):
        rel_fti = DexterityFTI(
            'RelationsType',
            schema=IRelationsType.__identifier__
        )
        self.portal.portal_types._setObject('RelationsType', rel_fti)

        # Setup IIntIds utility which is required for relations to work
        from five.intid import site
        from zope.app.intid.interfaces import IIntIds
        site.add_intids(self.portal)
        intids = getUtility(IIntIds)

        source = createContentInContainer(self.portal, 'RelationsType')
        target = createContentInContainer(self.portal, 'RelationsType')

        # Test modifier when no relations are set
        modifier = SkipRelations('modifier', 'Modifier')
        on_clone_modifiers = modifier.getOnCloneModifiers(source)
        pers_id, pers_load, empty1, empty2 = on_clone_modifiers
        self.assertTrue(pers_id(None) is None)
        self.assertTrue(pers_id(None) is None)
        self.assertTrue(pers_load(None) is None)
        self.assertTrue(pers_load(None) is None)
        self.assertTrue(empty1 == [])
        self.assertTrue(empty2 == [])

        repo_clone = createContent('RelationsType')
        modifier.afterRetrieveModifier(source, repo_clone)
        self.assertTrue(repo_clone.single is source.single)
        self.assertTrue(repo_clone.multiple is source.multiple)

        # Add some relations
        source.single = RelationValue(intids.getId(target))
        source.multiple = [RelationValue(intids.getId(target))]

        # Update relations
        from zope.lifecycleevent import ObjectModifiedEvent
        from zope.event import notify
        notify(ObjectModifiedEvent(source))

        modifier = SkipRelations('modifier', 'Modifier')
        on_clone_modifiers = modifier.getOnCloneModifiers(source)
        pers_id, pers_load, empty1, empty2 = on_clone_modifiers
        self.assertTrue(pers_id(source.single))
        self.assertTrue(pers_id(source.multiple))
        self.assertTrue(pers_load(source.single) is None)
        self.assertTrue(pers_load(source.multiple) is None)
        self.assertTrue(empty1 == [])
        self.assertTrue(empty2 == [])

        repo_clone = createContent('RelationsType')
        modifier.afterRetrieveModifier(source, repo_clone)
        self.assertTrue(repo_clone.single is source.single)
        self.assertTrue(repo_clone.multiple is source.multiple)
Esempio n. 3
0
    def testRelationsInBehaviors(self):
        self.register_RelationsType()
        intids = getUtility(IIntIds)

        source = createContentInContainer(self.portal, 'RelationsType')
        target = createContentInContainer(self.portal, 'RelationsType')

        # Test modifier when no relations are set
        modifier = SkipRelations('modifier', 'Modifier')
        on_clone_modifiers = modifier.getOnCloneModifiers(source)
        pers_id, pers_load, empty1, empty2 = on_clone_modifiers
        self.assertTrue(pers_id(None) is None)
        self.assertTrue(pers_id(None) is None)
        self.assertTrue(pers_load(None) is None)
        self.assertTrue(pers_load(None) is None)
        self.assertTrue(empty1 == [])
        self.assertTrue(empty2 == [])

        repo_clone = createContent('RelationsType')
        modifier.afterRetrieveModifier(source, repo_clone)
        self.assertTrue(repo_clone.single is None)
        self.assertTrue(repo_clone.multiple is None)

        # Add some relations
        IRelationsBehavior(source).single = RelationValue(intids.getId(target))
        IRelationsBehavior(source).multiple = [
            RelationValue(intids.getId(target))
        ]

        # Update relations
        from zope.lifecycleevent import ObjectModifiedEvent
        from zope.event import notify
        notify(ObjectModifiedEvent(source))

        modifier = SkipRelations('modifier', 'Modifier')
        on_clone_modifiers = modifier.getOnCloneModifiers(source)
        pers_id, pers_load, empty1, empty2 = on_clone_modifiers
        self.assertTrue(pers_id(IRelationsBehavior(source).single))
        self.assertTrue(pers_id(IRelationsBehavior(source).multiple))
        self.assertTrue(pers_load(IRelationsBehavior(source).single) is None)
        self.assertTrue(pers_load(IRelationsBehavior(source).multiple) is None)
        self.assertTrue(empty1 == [])
        self.assertTrue(empty2 == [])

        repo_clone = createContent('RelationsType')
        modifier.afterRetrieveModifier(source, repo_clone)
        self.assertTrue(
            IRelationsBehavior(repo_clone).single is IRelationsBehavior(
                source).single)
        self.assertTrue(
            IRelationsBehavior(repo_clone).multiple is IRelationsBehavior(
                source).multiple)
Esempio n. 4
0
    def testRelationsInBehaviors(self):
        self.register_RelationsType()
        intids = getUtility(IIntIds)

        source = createContentInContainer(self.portal, 'RelationsType')
        target = createContentInContainer(self.portal, 'RelationsType')

        # Test modifier when no relations are set
        modifier = SkipRelations('modifier', 'Modifier')
        on_clone_modifiers = modifier.getOnCloneModifiers(source)
        pers_id, pers_load, empty1, empty2 = on_clone_modifiers
        self.assertTrue(pers_id(None) is None)
        self.assertTrue(pers_id(None) is None)
        self.assertTrue(pers_load(None) is None)
        self.assertTrue(pers_load(None) is None)
        self.assertTrue(empty1 == [])
        self.assertTrue(empty2 == [])

        repo_clone = createContent('RelationsType')
        modifier.afterRetrieveModifier(source, repo_clone)
        self.assertTrue(repo_clone.single is None)
        self.assertTrue(repo_clone.multiple is None)

        # Add some relations
        IRelationsBehavior(source).single = RelationValue(
            intids.getId(target)
        )
        IRelationsBehavior(source).multiple = [
            RelationValue(intids.getId(target))
        ]

        # Update relations
        from zope.lifecycleevent import ObjectModifiedEvent
        from zope.event import notify
        notify(ObjectModifiedEvent(source))

        modifier = SkipRelations('modifier', 'Modifier')
        on_clone_modifiers = modifier.getOnCloneModifiers(source)
        pers_id, pers_load, empty1, empty2 = on_clone_modifiers
        self.assertTrue(pers_id(IRelationsBehavior(source).single))
        self.assertTrue(pers_id(IRelationsBehavior(source).multiple))
        self.assertTrue(pers_load(IRelationsBehavior(source).single) is None)
        self.assertTrue(pers_load(IRelationsBehavior(source).multiple) is None)
        self.assertTrue(empty1 == [])
        self.assertTrue(empty2 == [])

        repo_clone = createContent('RelationsType')
        modifier.afterRetrieveModifier(source, repo_clone)
        self.assertTrue(IRelationsBehavior(repo_clone).single
                        is IRelationsBehavior(source).single)
        self.assertTrue(IRelationsBehavior(repo_clone).multiple
                        is IRelationsBehavior(source).multiple)
Esempio n. 5
0
    def testRelations(self):
        rel_fti = DexterityFTI('RelationsType',
                               schema=IRelationsType.__identifier__)
        self.portal.portal_types._setObject('RelationsType', rel_fti)

        intids = getUtility(IIntIds)

        source = createContentInContainer(self.portal, 'RelationsType')
        target = createContentInContainer(self.portal, 'RelationsType')

        # Test modifier when no relations are set
        modifier = SkipRelations('modifier', 'Modifier')
        on_clone_modifiers = modifier.getOnCloneModifiers(source)
        pers_id, pers_load, empty1, empty2 = on_clone_modifiers
        self.assertTrue(pers_id(None) is None)
        self.assertTrue(pers_id(None) is None)
        self.assertTrue(pers_load(None) is None)
        self.assertTrue(pers_load(None) is None)
        self.assertTrue(empty1 == [])
        self.assertTrue(empty2 == [])

        repo_clone = createContent('RelationsType')
        modifier.afterRetrieveModifier(source, repo_clone)
        self.assertTrue(repo_clone.single is source.single)
        self.assertTrue(repo_clone.multiple is source.multiple)

        # Add some relations
        source.single = RelationValue(intids.getId(target))
        source.multiple = [RelationValue(intids.getId(target))]

        # Update relations
        from zope.lifecycleevent import ObjectModifiedEvent
        from zope.event import notify
        notify(ObjectModifiedEvent(source))

        modifier = SkipRelations('modifier', 'Modifier')
        on_clone_modifiers = modifier.getOnCloneModifiers(source)
        pers_id, pers_load, empty1, empty2 = on_clone_modifiers
        self.assertTrue(pers_id(source.single))
        self.assertTrue(pers_id(source.multiple))
        self.assertTrue(pers_load(source.single) is None)
        self.assertTrue(pers_load(source.multiple) is None)
        self.assertTrue(empty1 == [])
        self.assertTrue(empty2 == [])

        repo_clone = createContent('RelationsType')
        modifier.afterRetrieveModifier(source, repo_clone)
        self.assertTrue(repo_clone.single is source.single)
        self.assertTrue(repo_clone.multiple is source.multiple)
Esempio n. 6
0
    def testRelationsInBehaviorsForMigratedDXObjects(self):
        ''' Do not break in the case of
        dexterity objects with relations migrated from something else
        (e.g. Archetypes)
        '''
        self.register_RelationsType()
        source = createContentInContainer(self.portal, 'RelationsType')

        # Test modifier when no relations are set
        class Dummy(object):
            pass

        repo_clone = Dummy()

        modifier = SkipRelations('modifier', 'Modifier')
        modifier.afterRetrieveModifier(source, repo_clone)

        self.assertFalse(hasattr(repo_clone, 'single'))
        self.assertFalse(hasattr(repo_clone, 'multiple'))
Esempio n. 7
0
    def testRelationsInBehaviorsForMigratedDXObjects(self):
        ''' Do not break in the case of
        dexterity objects with relations migrated from something else
        (e.g. Archetypes)
        '''
        self.register_RelationsType()
        source = createContentInContainer(self.portal, 'RelationsType')

        # Test modifier when no relations are set
        class Dummy(object):
            pass

        repo_clone = Dummy()

        modifier = SkipRelations('modifier', 'Modifier')
        modifier.afterRetrieveModifier(source, repo_clone)

        self.assertFalse(hasattr(repo_clone, 'single'))
        self.assertFalse(hasattr(repo_clone, 'multiple'))
    def testRelationsInBehaviors(self):
        configuration = """\
        <configure
             package="plone.behavior"
             xmlns="http://namespaces.zope.org/zope"
             xmlns:plone="http://namespaces.plone.org/plone"
             i18n_domain="plone.behavior.tests">

             <include package="plone.behavior" file="meta.zcml" />

            <plone:behavior
                title="Relations behavior"
                description="A behavior"
                provides="plone.app.versioningbehavior.tests.test_modifiers.IRelationsBehavior"
                />
        </configure>
        """
        xmlconfig.xmlconfig(StringIO(configuration))
        rel_fti = DexterityFTI('RelationsType',
                               behaviors=[IRelationsBehavior.__identifier__])
        self.portal.portal_types._setObject('RelationsType', rel_fti)

        # Setup IIntIds utility which is required for relations to work
        from five.intid import site
        from zope.app.intid.interfaces import IIntIds
        site.add_intids(self.portal)
        intids = getUtility(IIntIds)

        source = createContentInContainer(self.portal, 'RelationsType')
        target = createContentInContainer(self.portal, 'RelationsType')

        # Test modifier when no relations are set
        modifier = SkipRelations('modifier', 'Modifier')
        pers_id, pers_load, empty1, empty2 = modifier.getOnCloneModifiers(
            source)
        self.assertTrue(pers_id(None) is None)
        self.assertTrue(pers_id(None) is None)
        self.assertTrue(pers_load(None) is None)
        self.assertTrue(pers_load(None) is None)
        self.assertTrue(empty1 == [])
        self.assertTrue(empty2 == [])

        repo_clone = createContent('RelationsType')
        modifier.afterRetrieveModifier(source, repo_clone)
        self.assertTrue(repo_clone.single is None)
        self.assertTrue(repo_clone.multiple is None)

        # Add some relations
        IRelationsBehavior(source).single = RelationValue(intids.getId(target))
        IRelationsBehavior(source).multiple = [
            RelationValue(intids.getId(target))
        ]

        # Update relations
        from zope.lifecycleevent import ObjectModifiedEvent
        from zope.event import notify
        notify(ObjectModifiedEvent(source))

        modifier = SkipRelations('modifier', 'Modifier')
        pers_id, pers_load, empty1, empty2 = modifier.getOnCloneModifiers(
            source)
        self.assertTrue(pers_id(IRelationsBehavior(source).single))
        self.assertTrue(pers_id(IRelationsBehavior(source).multiple))
        self.assertTrue(pers_load(IRelationsBehavior(source).single) is None)
        self.assertTrue(pers_load(IRelationsBehavior(source).multiple) is None)
        self.assertTrue(empty1 == [])
        self.assertTrue(empty2 == [])

        repo_clone = createContent('RelationsType')
        modifier.afterRetrieveModifier(source, repo_clone)
        self.assertTrue(
            IRelationsBehavior(repo_clone).single is IRelationsBehavior(
                source).single)
        self.assertTrue(
            IRelationsBehavior(repo_clone).multiple is IRelationsBehavior(
                source).multiple)
    def testRelationsInBehaviors(self):
        configuration = """\
        <configure
             package="plone.behavior"
             xmlns="http://namespaces.zope.org/zope"
             xmlns:plone="http://namespaces.plone.org/plone"
             i18n_domain="plone.behavior.tests">

             <include package="plone.behavior" file="meta.zcml" />

            <plone:behavior
                title="Relations behavior"
                description="A behavior"
                provides="plone.app.versioningbehavior.tests.test_modifiers.IRelationsBehavior"
                />
        </configure>
        """
        xmlconfig.xmlconfig(StringIO(configuration))
        rel_fti = DexterityFTI(
            'RelationsType',
            behaviors=[IRelationsBehavior.__identifier__])
        self.portal.portal_types._setObject('RelationsType', rel_fti)

        # Setup IIntIds utility which is required for relations to work
        from five.intid import site
        from zope.app.intid.interfaces import IIntIds
        site.add_intids(self.portal)
        intids = getUtility(IIntIds)

        source = createContentInContainer(self.portal, 'RelationsType')
        target = createContentInContainer(self.portal, 'RelationsType')

        # Test modifier when no relations are set
        modifier = SkipRelations('modifier', 'Modifier')
        pers_id, pers_load, empty1, empty2 = modifier.getOnCloneModifiers(source)
        self.assertTrue(pers_id(None) is None)
        self.assertTrue(pers_id(None) is None)
        self.assertTrue(pers_load(None) is None)
        self.assertTrue(pers_load(None) is None)
        self.assertTrue(empty1 == [])
        self.assertTrue(empty2 == [])

        repo_clone = createContent('RelationsType')
        modifier.afterRetrieveModifier(source, repo_clone)
        self.assertTrue(repo_clone.single is None)
        self.assertTrue(repo_clone.multiple is None)

        # Add some relations
        IRelationsBehavior(source).single = RelationValue(intids.getId(target))
        IRelationsBehavior(source).multiple = [RelationValue(intids.getId(target))]

        # Update relations
        from zope.lifecycleevent import ObjectModifiedEvent
        from zope.event import notify
        notify(ObjectModifiedEvent(source))

        modifier = SkipRelations('modifier', 'Modifier')
        pers_id, pers_load, empty1, empty2 = modifier.getOnCloneModifiers(source)
        self.assertTrue(pers_id(IRelationsBehavior(source).single))
        self.assertTrue(pers_id(IRelationsBehavior(source).multiple))
        self.assertTrue(pers_load(IRelationsBehavior(source).single) is None)
        self.assertTrue(pers_load(IRelationsBehavior(source).multiple) is None)
        self.assertTrue(empty1 == [])
        self.assertTrue(empty2 == [])

        repo_clone = createContent('RelationsType')
        modifier.afterRetrieveModifier(source, repo_clone)
        self.assertTrue(IRelationsBehavior(repo_clone).single
                        is IRelationsBehavior(source).single)
        self.assertTrue(IRelationsBehavior(repo_clone).multiple
                        is IRelationsBehavior(source).multiple)