Ejemplo n.º 1
0
    def testMakeVocabulary(self):
        from Products.Archetypes.interfaces.base import IBaseFolder

        # filter
        self.ic.setAllowedTargetInterfaces([]) # allow any
        brains = [brain.makeBrainAggregate(self.portal, self.brains[1].UID)]
        brains2 = self.ic.makeVocabulary(self.brains[0], brains)
        self.assertEquals(len(brains), len(brains2))

        self.ic.setAllowedTargetInterfaces(['IBaseFolder'])
        brains2 = self.ic.makeVocabulary(self.brains[0], brains)
        self.assertEquals([b.UID for b in brains2], [self.brains[1].UID])
        
        # make list
        brains = self.ic.makeVocabulary(self.brains[0], None)
        for obj in [b.getObject() for b in brains]:
            self.assert_(implementedOrProvidedBy(IBaseFolder, obj))

        # disallowed source interface
        self.ic.setAllowedSourceInterfaces(['IFooBar'])
        self.assertEquals(
            self.ic.makeVocabulary(self.brains[0], None), [])

        # the first of the two allowed source interfaces is what
        # self.brains[0] implements
        self.ic.setAllowedSourceInterfaces(['IReferenceable', 'IBaseFolder'])
        brains = self.ic.makeVocabulary(self.brains[0], None)
        for obj in [b.getObject() for b in brains]:
            self.assert_(implementedOrProvidedBy(IBaseFolder, obj))
Ejemplo n.º 2
0
    def testMakeVocabulary(self):
        from Products.Archetypes.interfaces.base import IBaseFolder

        # filter
        self.ic.setAllowedTargetInterfaces([])  # allow any
        brains = [brain.makeBrainAggregate(self.portal, self.brains[1].UID)]
        brains2 = self.ic.makeVocabulary(self.brains[0], brains)
        self.assertEquals(len(brains), len(brains2))

        self.ic.setAllowedTargetInterfaces(['IBaseFolder'])
        brains2 = self.ic.makeVocabulary(self.brains[0], brains)
        self.assertEquals([b.UID for b in brains2], [self.brains[1].UID])

        # make list
        brains = self.ic.makeVocabulary(self.brains[0], None)
        for obj in [b.getObject() for b in brains]:
            self.assert_(implementedOrProvidedBy(IBaseFolder, obj))

        # disallowed source interface
        self.ic.setAllowedSourceInterfaces(['IFooBar'])
        self.assertEquals(self.ic.makeVocabulary(self.brains[0], None), [])

        # the first of the two allowed source interfaces is what
        # self.brains[0] implements
        self.ic.setAllowedSourceInterfaces(['IReferenceable', 'IBaseFolder'])
        brains = self.ic.makeVocabulary(self.brains[0], None)
        for obj in [b.getObject() for b in brains]:
            self.assert_(implementedOrProvidedBy(IBaseFolder, obj))
Ejemplo n.º 3
0
    def afterSetUp(self):
        self.objs = common.createObjects(self, self.TYPES)
        self.brains = [brain.makeBrainAggregate(self.portal, obj.UID())
                       for obj in self.objs]

        self.ruleset = common.createRuleset(self, 'AnotherRuleset')
        self.ruleset.invokeFactory('Interface Constraint', 'ic')
        self.ic = getattr(self.ruleset, 'ic')
Ejemplo n.º 4
0
    def afterSetUp(self):
        # create some objects
        objs = common.createObjects(self, self.TYPES)
        self.brains = [brain.makeBrainAggregate(self.portal, obj.UID())
                       for obj in objs]

        # construct and register a ruleset
        self.ruleset = common.createRuleset(self, 'ruleset')
Ejemplo n.º 5
0
    def afterSetUp(self):
        self.objs = common.createObjects(self, self.TYPES)
        self.brains = [brain.makeBrainAggregate(self.portal, obj.UID())
                       for obj in self.objs]

        self.ruleset = common.createRuleset(self, 'AThirdRuleset')
        self.ruleset.invokeFactory('Cardinality Constraint', 'cc')
        self.cc = getattr(self.ruleset, 'cc')
Ejemplo n.º 6
0
    def afterSetUp(self):
        # create some objects
        objs = common.createObjects(self, self.TYPES)
        self.brains = [
            brain.makeBrainAggregate(self.portal, obj.UID()) for obj in objs
        ]

        # construct and register a ruleset
        self.ruleset = common.createRuleset(self, 'ruleset')
Ejemplo n.º 7
0
    def afterSetUp(self):
        self.objs = common.createObjects(self, self.TYPES)
        self.brains = [
            brain.makeBrainAggregate(self.portal, obj.UID())
            for obj in self.objs
        ]

        self.ruleset = common.createRuleset(self, 'AnotherRuleset')
        self.ruleset.invokeFactory('Interface Constraint', 'ic')
        self.ic = getattr(self.ruleset, 'ic')
Ejemplo n.º 8
0
    def afterSetUp(self):
        self.objs = common.createObjects(self, self.TYPES)
        self.brains = [
            brain.makeBrainAggregate(self.portal, obj.UID())
            for obj in self.objs
        ]

        self.ruleset = common.createRuleset(self, 'AThirdRuleset')
        self.ruleset.invokeFactory('Cardinality Constraint', 'cc')
        self.cc = getattr(self.ruleset, 'cc')
Ejemplo n.º 9
0
    def afterSetUp(self):
        self.objs = common.createObjects(self, self.TYPES)
        self.brains = [brain.makeBrainAggregate(self.portal, obj.UID())
                       for obj in self.objs]

        self.ruleset = common.createRuleset(self, 'ARuleset')
        self.ruleset.invokeFactory('Inverse Implicator', 'ii')
        self.ii = getattr(self.ruleset, 'ii')
        self.ruleset2 = common.createRuleset(self, 'AnotherRuleset')
        self.ruleset2.invokeFactory('Inverse Implicator', 'ii')
        self.ii2 = getattr(self.ruleset2, 'ii')
Ejemplo n.º 10
0
    def afterSetUp(self):
        common.installWithinPortal(self, self.portal)
        self.objs = common.createObjects(self, self.TYPES)
        self.brains = [
            brain.makeBrainAggregate(self.portal, obj.UID())
            for obj in self.objs
        ]

        self.ruleset = common.createRuleset(self, 'SomeRuleset')
        self.ruleset.invokeFactory('Type Constraint', 'tc')
        self.tc = getattr(self.ruleset, 'tc')
Ejemplo n.º 11
0
    def afterSetUp(self):
        # create some objects
        self.objs = common.createObjects(self, self.TYPES)
        self.brains = [brain.makeBrainAggregate(self.portal, obj.UID())
                       for obj in self.objs]

        # construct and register a ruleset
        self.ruleset = common.createRuleset(self, 'ruleset')

        # Allow self.TYPES as target
        self.ruleset.invokeFactory('Type Constraint', 'tc')
        self.ruleset.tc.setAllowedTargetTypes(self.TYPES)
Ejemplo n.º 12
0
    def afterSetUp(self):
        self.objs = common.createObjects(self, self.TYPES)
        self.brains = [
            brain.makeBrainAggregate(self.portal, obj.UID())
            for obj in self.objs
        ]

        self.ruleset = common.createRuleset(self, 'ARuleset')
        self.ruleset.invokeFactory('Inverse Implicator', 'ii')
        self.ii = getattr(self.ruleset, 'ii')
        self.ruleset2 = common.createRuleset(self, 'AnotherRuleset')
        self.ruleset2.invokeFactory('Inverse Implicator', 'ii')
        self.ii2 = getattr(self.ruleset2, 'ii')
Ejemplo n.º 13
0
    def afterSetUp(self):
        # create some objects
        self.objs = common.createObjects(self, self.TYPES)
        self.brains = [
            brain.makeBrainAggregate(self.portal, obj.UID())
            for obj in self.objs
        ]

        # construct and register a ruleset
        self.ruleset = common.createRuleset(self, 'ruleset')

        # Allow self.TYPES as target
        self.ruleset.invokeFactory('Type Constraint', 'tc')
        self.ruleset.tc.setAllowedTargetTypes(self.TYPES)
Ejemplo n.º 14
0
    def makeVocabulary(self, source, targets=None):
        # source type not valid
        ast = self.getAllowedSourceTypes()
        att = self.getAllowedTargetTypes()
        if ast and source.portal_type not in ast:
            return []
        
        if targets is not None: # filter
            return [t for t in targets if not att or t.portal_type in att]

        else: # create list
            uc = getToolByName(self, UID_CATALOG)
            objs = uc(**self.getSearchTerms())
            return [brain.makeBrainAggregate(self, o) for o in objs]
Ejemplo n.º 15
0
    def testMakeBrainAggregate(self):
        portal = self.portal
        catalog = portal.uid_catalog

        def assertions(obj, b):
            self.assertEquals(b.getObject(), obj)
            self.assertEquals(b.UID, obj.UID())
            verifyObject(interfaces.IBrainAggregate, b)
            self.assertEquals(b.sources, ['portal_catalog'])
            self.failUnless(hasattr(b, 'EffectiveDate')) # of portal_catalog

        # three different types to use makeBrainAggregate:
        for obj in self.objects:
            # use UID
            b = brain.makeBrainAggregate(portal, obj.UID())
            assertions(obj, b)

            # use uid_catalog brain
            b = brain.makeBrainAggregate(portal, catalog(UID=obj.UID())[0])
            assertions(obj, b)

            # aggregated brain
            b = brain.makeBrainAggregate(portal, b)
            assertions(obj, b)
Ejemplo n.º 16
0
    def testMakeBrainAggregate(self):
        portal = self.portal
        catalog = portal.uid_catalog

        def assertions(obj, b):
            self.assertEquals(b.getObject(), obj)
            self.assertEquals(b.UID, obj.UID())
            verifyObject(interfaces.IBrainAggregate, b)
            self.assertEquals(b.sources, ['portal_catalog'])
            self.failUnless(hasattr(b, 'EffectiveDate')) # of portal_catalog

        # three different types to use makeBrainAggregate:
        for obj in self.objects:
            # use UID
            b = brain.makeBrainAggregate(portal, obj.UID())
            assertions(obj, b)

            # use uid_catalog brain
            b = brain.makeBrainAggregate(portal, catalog(UID=obj.UID())[0])
            assertions(obj, b)

            # aggregated brain
            b = brain.makeBrainAggregate(portal, b)
            assertions(obj, b)
Ejemplo n.º 17
0
    def afterSetUp(self):
        self.objs = common.createObjects(self, self.TYPES)
        self.brains = [brain.makeBrainAggregate(self.portal, obj.UID())
                       for obj in self.objs]

        for name in ('ruleset1', 'ruleset2'):
            ruleset = common.createRuleset(self, name)
            setattr(self, name, ruleset)
            ruleset.invokeFactory('Inverse Implicator', 'ii')
            ruleset.invokeFactory('Content Reference', 'cr')

        for ruleset in self.ruleset1, self.ruleset2:
            ruleset.ii.setInverseRuleset(
                ruleset is self.ruleset1 and self.ruleset2 or self.ruleset1)
            ruleset.cr.setPortalType(self.TYPES[0])
Ejemplo n.º 18
0
    def afterSetUp(self):
        self.objs = common.createObjects(self, self.TYPES)
        self.brains = [
            brain.makeBrainAggregate(self.portal, obj.UID())
            for obj in self.objs
        ]

        for name in ('ruleset1', 'ruleset2'):
            ruleset = common.createRuleset(self, name)
            setattr(self, name, ruleset)
            ruleset.invokeFactory('Inverse Implicator', 'ii')
            ruleset.invokeFactory('Content Reference', 'cr')

        for ruleset in self.ruleset1, self.ruleset2:
            ruleset.ii.setInverseRuleset(
                ruleset is self.ruleset1 and self.ruleset2 or self.ruleset1)
            ruleset.cr.setPortalType(self.TYPES[0])
Ejemplo n.º 19
0
    def testMakeVocabulary(self):
        # filter
        self.tc.setAllowedTargetTypes([])  # allow any
        uc = getToolByName(self.portal, UID_CATALOG)
        brains = [brain.makeBrainAggregate(self.portal, b) for b in uc()]
        brains2 = self.tc.makeVocabulary(self.brains[0], brains)
        self.assertEquals(len(brains), len(brains2))

        self.tc.setAllowedTargetTypes(self.TYPES)
        self.assert_(len(brains) > 2)
        brains2 = self.tc.makeVocabulary(self.brains[0], brains)
        self.assertEquals(len(brains2), 2)

        # make list
        brains = self.tc.makeVocabulary(self.brains[0], None)
        self.assertEquals(len(brains), 2)

        # disallowed source type
        self.tc.setAllowedSourceTypes([self.TYPES[1]])
        self.assertEquals(self.tc.makeVocabulary(self.brains[0], None), [])

        self.tc.setAllowedTargetTypes([])
        self.assertNotEquals(self.tc.makeVocabulary(self.brains[1], None), [])
Ejemplo n.º 20
0
    def testMakeVocabulary(self):
        # filter
        self.tc.setAllowedTargetTypes([]) # allow any
        uc = getToolByName(self.portal, UID_CATALOG)
        brains = [brain.makeBrainAggregate(self.portal, b) for b in uc()]
        brains2 = self.tc.makeVocabulary(self.brains[0], brains)
        self.assertEquals(len(brains), len(brains2))
        
        self.tc.setAllowedTargetTypes(self.TYPES)
        self.assert_(len(brains) > 2)
        brains2 = self.tc.makeVocabulary(self.brains[0], brains)
        self.assertEquals(len(brains2), 2)

        # make list
        brains = self.tc.makeVocabulary(self.brains[0], None)
        self.assertEquals(len(brains), 2)

        # disallowed source type
        self.tc.setAllowedSourceTypes([self.TYPES[1]])
        self.assertEquals(
            self.tc.makeVocabulary(self.brains[0], None), [])

        self.tc.setAllowedTargetTypes([])
        self.assertNotEquals(self.tc.makeVocabulary(self.brains[1], None), [])
Ejemplo n.º 21
0
def adddeleteVocab(context, test_only=0, ruleset_ids=None):
    """Make Relations vocabularies by querying all rulesets.

    What we return here is a list of dictionaries with the following
    keys:
    
      - id      the ruleset's id, which is the relationship
      - title   the ruleset's title
      - tuples  a list of tuples, see below.

    Each 'tuples' item is a 2-tuple in the form (aggregated brain,
    selected), where selected is true if there's a reference
    (source=context, target=vocab item, relationship=ruleset.id).

    If test_only=1, I will return true if *any* vocabulary item
    exists. Otherwise I will return a false value.
    """

    value = []

    membership = getToolByName(context, 'portal_membership')
    if not membership.checkPermission(permissions.ModifyPortalContent,
                                      context):
        return []

    if not isReferenceable(context):
        return []

    library = context.relations_library
    refctl = context.reference_catalog
    mtool = context.portal_membership

    if not ruleset_ids:
        rulesets = library.getRulesets()
        if None in rulesets:
            #XXX: to be fixed
            rulesets=[r for r in rulesets if r]
    else:
        rulesets = [library.getRuleset(rid) for rid in ruleset_ids]

    for ruleset in rulesets:
        if not mtool.checkPermission('View', ruleset): continue
        relationship = ruleset.getId()
        vocabulary = ruleset.makeVocabulary(context)
        if vocabulary is None: vocabulary = []
        refs = refctl(sourceUID=context.UID(), relationship=relationship)
        existing_targetUIDs = [r.targetUID for r in refs]
        if not vocabulary and not existing_targetUIDs:
            continue # we don't add an entry
        elif test_only:
            return True

        entry = {'id': relationship,
                 'title': ruleset.Title(),
                 'tuples': []}
        value.append(entry)

        tuples = entry['tuples']

        # first add all vocabulary items to 'tuples' in entry dict
        for item in vocabulary:
            selected = False
            if item.UID in existing_targetUIDs:
                selected = True
            tuples.append((item, selected))

        # now find existing refs that are not part of the vocab, which we add
        vocab_uids = [item.UID for (item, selected) in tuples]
        for uid in existing_targetUIDs:
            if uid not in vocab_uids:
                tuples.append((makeBrainAggregate(context, uid), True))

    return value
Ejemplo n.º 22
0
def adddeleteVocab(context, test_only=0, ruleset_ids=None):
    """Make Relations vocabularies by querying all rulesets.

    What we return here is a list of dictionaries with the following
    keys:
    
      - id      the ruleset's id, which is the relationship
      - title   the ruleset's title
      - tuples  a list of tuples, see below.

    Each 'tuples' item is a 2-tuple in the form (aggregated brain,
    selected), where selected is true if there's a reference
    (source=context, target=vocab item, relationship=ruleset.id).

    If test_only=1, I will return true if *any* vocabulary item
    exists. Otherwise I will return a false value.
    """

    value = []

    membership = getToolByName(context, 'portal_membership')
    if not membership.checkPermission(permissions.ModifyPortalContent,
                                      context):
        return []

    if not isReferenceable(context):
        return []

    library = context.relations_library
    refctl = context.reference_catalog
    mtool = context.portal_membership

    if not ruleset_ids:
        rulesets = library.getRulesets()
        if None in rulesets:
            #XXX: to be fixed
            rulesets = [r for r in rulesets if r]
    else:
        rulesets = [library.getRuleset(rid) for rid in ruleset_ids]

    for ruleset in rulesets:
        if not mtool.checkPermission('View', ruleset): continue
        relationship = ruleset.getId()
        vocabulary = ruleset.makeVocabulary(context)
        if vocabulary is None: vocabulary = []
        refs = refctl(sourceUID=context.UID(), relationship=relationship)
        existing_targetUIDs = [r.targetUID for r in refs]
        if not vocabulary and not existing_targetUIDs:
            continue  # we don't add an entry
        elif test_only:
            return True

        entry = {'id': relationship, 'title': ruleset.Title(), 'tuples': []}
        value.append(entry)

        tuples = entry['tuples']

        # first add all vocabulary items to 'tuples' in entry dict
        for item in vocabulary:
            selected = False
            if item.UID in existing_targetUIDs:
                selected = True
            tuples.append((item, selected))

        # now find existing refs that are not part of the vocab, which we add
        vocab_uids = [item.UID for (item, selected) in tuples]
        for uid in existing_targetUIDs:
            if uid not in vocab_uids:
                tuples.append((makeBrainAggregate(context, uid), True))

    return value