コード例 #1
0
    def setUp(self):
        super(TypesTest, self).setUp()

        view = self.view
        self.kind = view.findPath(self._KIND_KIND)
        self.itemKind = view.findPath(self._ITEM_KIND)
        self.attrKind = self.itemKind.itsParent['Attribute']
        self.newKind = self.kind.newItem('newKind', view)
        self.typeKind = view.findPath('//Schema/Core/Type')

        self.typenames=['String', 'Symbol', 'Integer', 'Long', 'Float',
                        'Complex', 'Boolean', 'UUID', 'ItemRef', 'Path',
                        'NoneType', 'Class', 'Enumeration', 'Struct',
                        'DateTime', 'TimeDelta',
                        'Collection', 'Dictionary', 'List', 'Lob']

        # make dict of attribute and  type items.
        self.atts = {}
        self.types = {}
        for a in self.typenames:
            tempAtt = Attribute('%sAttribute' % a, view, self.attrKind)
            classobj = eval('chandlerdb.schema.Types.%s' % a)
            typeItem = view.findPath('//Schema/Core/%s' % a)
            self.types[a] = typeItem
            tempAtt.type = typeItem
            self.atts[a] = tempAtt
            self.newKind.addValue('attributes', tempAtt, alias='%sAttribute' % a)
コード例 #2
0
    def setUp(self):
        super(KindTest, self).setUp()

        view = self.view
        self.kind = view.findPath("//Schema/Core/Kind")
        self.itemKind = view.findPath("//Schema/Core/Item")
        self.attrKind = self.itemKind.itsParent['Attribute']

        self.kind1 = self.kind.newItem('kind1', view)
        self.kind1.addValue('superKinds', self.itemKind)
        self.kind1Attr1 = Attribute('k1a1', view, self.attrKind)
        self.kind1Attr1.cardinality = 'list'
        self.kind1Attr1.otherName = 'owner'
        self.kind1.addValue('attributes', self.kind1Attr1, alias='k1a1')

        kind1Attr1Bad = Attribute('k1a1bad', self.kind1, self.attrKind)
        kind1Attr1Bad.cardinality = 'list'
        kind1Attr1Bad.otherName = 'owner'
        try:
            self.kind1.addValue('attribute', kind1Attr1Bad, alias='k1a1bad')
        except AttributeError:
            pass
        
        self.kind2 = self.kind.newItem('kind2', self.kind1)
        self.kind2.addValue('superKinds', self.itemKind)
        self.kind2.addValue('attributes', self.kind1Attr1, alias='k1a1')
        self.kind2Attr2 = Attribute('k2a2', view, self.attrKind)
        self.kind2Attr2.cardinality = 'list'
        self.kind2.addValue('attributes', self.kind2Attr2, alias='k2a2')
コード例 #3
0
    def testSubAttributes(self):
        """Test attributes which have sub attributes (subAttributes and superAttribute attributes)"""
        view = self.view
        itemKind = view.findPath('//Schema/Core/Item')
        attrKind = view.findPath('//Schema/Core/Attribute')
        self.assert_(itemKind is not None)

        attr = Attribute('references', view.findPath('//Schema/Core'), attrKind,
                         cardinality='list', otherName='item')
        itemKind.attributes.append(attr, alias='references')
        
        attr_name = 'references'
        
        item = Item('item1', view, itemKind)
        attrKind = itemKind.itsParent['Attribute']

        # subattributes are created by assigning the "parent" attribute
        # to the superAttribute attribute of the "child" attribute
        testAttr = itemKind.getAttribute(attr_name)
        criticalSubAttr = Attribute('critical', testAttr, attrKind)
        criticalSubAttr.superAttribute = testAttr
        self.assert_(criticalSubAttr.superAttribute is testAttr)
        self.assert_(criticalSubAttr in testAttr.subAttributes)

        # now do it by assigning to the subAttributes list to ensure that
        # the bidirectional ref is getting updated.
        normalSubAttr = Attribute('normal', testAttr, attrKind)
        testAttr.subAttributes.append(normalSubAttr)
        self.assert_(normalSubAttr.superAttribute is testAttr)
        self.assert_(normalSubAttr in testAttr.subAttributes)
        
        # now do it by callin addValue on the Attribute item
        minorSubAttr = Attribute('minor', testAttr, attrKind)
        testAttr.addValue('subAttributes', minorSubAttr)
        self.assert_(minorSubAttr.superAttribute is testAttr)
        self.assert_(minorSubAttr in testAttr.subAttributes)

        # now write what we've done and read it back
        self._reopenRepository()
        view = self.view
        item = view.findPath('//item1')
        itemKind = item.itsKind
        testAttr = itemKind.getAttribute(attr_name)

        attMap = {}
        for i in testAttr.subAttributes:
            attMap[i.itsName] = i 
            
        criticalSubAttr = attMap['critical']
        normalSubAttr = attMap['normal']
        minorSubAttr = attMap['minor']
        self.assert_(criticalSubAttr.superAttribute is testAttr)
        self.assert_(criticalSubAttr in testAttr.subAttributes)
        self.assert_(normalSubAttr.superAttribute is testAttr)
        self.assert_(normalSubAttr in testAttr.subAttributes)
        self.assert_(minorSubAttr.superAttribute is testAttr)
        self.assert_(minorSubAttr in testAttr.subAttributes)
コード例 #4
0
    def _createBlockKind(self, cardinality):
        view = self.view
        kind = view.findPath('//Schema/Core/Kind')
        itemKind = view.findPath('//Schema/Core/Item')
        attrKind = itemKind.itsParent['Attribute']

        # blockKind has a 'blocks' reference collection, and an inverse 'blockParent'
        blockKind = kind.newItem('Block', view)
        blocksAttribute = Attribute('blocks', blockKind, attrKind)
        blocksAttribute.cardinality = cardinality
        blocksAttribute.otherName = 'blockParent'
        blockKind.addValue('attributes', blocksAttribute, alias='blocks')
        blockParentAttribute = Attribute('blockParent', blockKind, attrKind)
        blockParentAttribute.cardinality = 'single'
        blockParentAttribute.otherName = 'blocks'
        blockKind.addValue('attributes',
                           blockParentAttribute,
                           alias='blockParent')
        return blockKind
コード例 #5
0
    def _createManagerAndEmployeeKinds(self, type):

        view = self.view

        kind = view.findPath('//Schema/Core/Kind')
        itemKind = view.findPath('//Schema/Core/Item')
        attrKind = itemKind.itsParent['Attribute']

        managerKind = kind.newItem('manager', view)
        employeesAttribute = Attribute('employees', managerKind, attrKind)
        employeesAttribute.cardinality = type
        employeesAttribute.otherName = 'manager'
        managerKind.addValue('attributes',
                             employeesAttribute, alias='employees')
        employeeKind = kind.newItem('employee', view)
        managerAttribute = Attribute('manager', employeeKind, attrKind)
        managerAttribute.otherName = 'employees'
        employeeKind.addValue('attributes', managerAttribute, alias='manager')

        return managerKind, employeeKind
コード例 #6
0
ファイル: TestRefDictAlias.py プロジェクト: vogth/chandler
    def _createBlockKind(self, cardinality):
        view = self.view
        kind = view.findPath("//Schema/Core/Kind")
        itemKind = view.findPath("//Schema/Core/Item")
        attrKind = itemKind.itsParent["Attribute"]

        # blockKind has a 'blocks' reference collection, and an inverse 'blockParent'
        blockKind = kind.newItem("Block", view)
        blocksAttribute = Attribute("blocks", blockKind, attrKind)
        blocksAttribute.cardinality = cardinality
        blocksAttribute.otherName = "blockParent"
        blockKind.addValue("attributes", blocksAttribute, alias="blocks")
        blockParentAttribute = Attribute("blockParent", blockKind, attrKind)
        blockParentAttribute.cardinality = "single"
        blockParentAttribute.otherName = "blocks"
        blockKind.addValue("attributes", blockParentAttribute, alias="blockParent")
        return blockKind
コード例 #7
0
    def _createBlockAndEventKinds(self, cardinality):
        view = self.view
        kind = view.findPath('//Schema/Core/Kind')
        itemKind = view.findPath('//Schema/Core/Item')
        attrKind = itemKind.itsParent['Attribute']

        # blockKind has a 'blocks' reference collection, and an inverse 'blockParent'
        blockKind = kind.newItem('Block', view)
        blocksAttribute = Attribute('blocks', blockKind, attrKind)
        blocksAttribute.cardinality = cardinality
        blocksAttribute.copyPolicy = currentPolicy
        blocksAttribute.otherName = 'blockParent'
        blockKind.addValue('attributes',
                          blocksAttribute, alias='blocks')
        blockParentAttribute = Attribute('blockParent', blockKind, attrKind)
        blockParentAttribute.cardinality = 'single'
        blockParentAttribute.otherName = 'blocks'
        blockParentAttribute.copyPolicy = currentPolicy
        blockKind.addValue('attributes',
                           blockParentAttribute, alias='blockParent')

        # also has an "event" reference that has no inverse
        eventAttribute = Attribute('event', blockKind, attrKind)
        eventAttribute.cardinality = 'single'
        eventAttribute.copyPolicy = currentPolicy
        blockKind.addValue('attributes',
                           eventAttribute, alias='event')

        # create the event kind, which has a pointer to a Block.
        eventKind = kind.newItem('Event', view)
        notifyBlock = Attribute('notify', eventKind, attrKind)
        notifyBlock.cardinality = 'single'
        notifyBlock.copyPolicy = currentPolicy
        eventKind.addValue('attributes',
                          notifyBlock, alias='notify')

        return (blockKind, eventKind)
コード例 #8
0
    def testListMultis(self):
        """Test list valued literal attributes """

        view = self.view

        def verifyItem(i):
            """verify that a list valued literal attribute has the right values"""
            # verify list length
            self.assertEquals(len(i.strings), 4)

            # test to see that there is a key at every position
            self.assert_(i.hasKey('strings', 0))
            self.assert_(i.hasKey('strings', 1))
            self.assert_(i.hasKey('strings', 2))
            self.assert_(i.hasKey('strings', 3))

            # test to see that every value is in the attribute
            self.assert_(i.hasValue('strings', 'Goofy'))
            self.assert_(i.hasValue('strings', 'Donald'))
            self.assert_(i.hasValue('strings', 'Minnie'))
            self.assert_(i.hasValue('strings', 'Mickey'))

            # verify list contents using getValue() method
            self.assertEquals(i.getValue('strings', 0), 'Mickey')
            self.assertEquals(i.getValue('strings', 1), 'Minnie')
            self.assertEquals(i.getValue('strings', 2), 'Donald')
            self.assertEquals(i.getValue('strings', 3), 'Goofy')

            # verify list contents using python list notation
            self.assertEquals(i.strings[0], 'Mickey')
            self.assertEquals(i.strings[1], 'Minnie')
            self.assertEquals(i.strings[2], 'Donald')
            self.assertEquals(i.strings[3], 'Goofy')

        kind = view.findPath('//Schema/Core/Kind')
        itemKind = view.findPath('//Schema/Core/Item')
        myKind = kind.newItem('listKind', view)

        # create an attribute with cardinality list and add to the kind
        attrKind = itemKind.itsParent['Attribute']
        multiAttribute = Attribute('strings', myKind, attrKind)
        multiAttribute.cardinality = 'list'
        myKind.addValue('attributes', multiAttribute, alias='strings')

        # create an item of the new kind
        item = myKind.newItem('item', view)

        # add to the list attribute
        item.setValue('strings', 'Mickey')
        item.addValue('strings', 'Minnie')
        item.addValue('strings', 'Donald')
        item.addValue('strings', 'Goofy')
        verifyItem(item)

        # again set the list attribute
        item.strings = ['Mickey', 'Minnie', 'Donald', 'Goofy']
        verifyItem(item)

        # now write what we've done and read it back
        self._reopenRepository()
        item = view.findPath('//item')
        verifyItem(item)

        #test removeValue by removing values and checking
        #that value is removed and length has decreased
        item.removeValue('strings', key=0)
        self.failIf(item.hasValue('strings', 'Mickey'))
        self.assertEquals(len(item.strings), 3)

        del item.strings[2]
        self.failIf(item.hasValue('strings', 'Goofy'))
        self.assertEquals(len(item.strings), 2)

        del item.strings[1]
        self.failIf(item.hasValue('strings', 'Donald'))
        self.assertEquals(len(item.strings), 1)

        item.removeValue('strings', key=0)
        self.failIf(item.hasValue('strings', 'Minnie'))
        self.assertEquals(len(item.strings), 0)

        # now write what we've done and read it back
        self._reopenRepository()
        item = view.findPath('//item')
        self.failIf(item.hasValue('strings', 'Mickey'))
        self.failIf(item.hasValue('strings', 'Goofy'))
        self.failIf(item.hasValue('strings', 'Donald'))
        self.failIf(item.hasValue('strings', 'Minnie'))
        self.assertEquals(len(item.strings), 0)
コード例 #9
0
    def testDictMultis(self):
        """Test dictionary valued literal attributes"""

        view = self.view

        def verifyItem(i):
            """ verify that a dictionayr value literal attribute contains the right data"""
            self.assertEquals(len(i.strings), 4)

            # test to see that all keys were inserted
            self.assert_(i.hasKey('strings', 'Mickey'))
            self.assert_(i.hasKey('strings', 'Minnie'))
            self.assert_(i.hasKey('strings', 'Donald'))
            self.assert_(i.hasKey('strings', 'Goofy'))

            # test to see that every value is in the attribute
            self.assert_(i.hasValue('strings', 'Mouse'))
            self.assert_(i.hasValue('strings', 'Mouse'))
            self.assert_(i.hasValue('strings', 'Duck'))
            self.assert_(i.hasValue('strings', 'Dog'))

            # verify dict contents using getValue() method
            self.assertEquals(i.getValue('strings', 'Mickey'), 'Mouse')
            self.assertEquals(i.getValue('strings', 'Minnie'), 'Mouse')
            self.assertEquals(i.getValue('strings', 'Donald'), 'Duck')
            self.assertEquals(i.getValue('strings', 'Goofy'), 'Dog')

            # verify dict contents using python dict notation
            self.assertEquals(i.strings['Mickey'], 'Mouse')
            self.assertEquals(i.strings['Minnie'], 'Mouse')
            self.assertEquals(i.strings['Donald'], 'Duck')
            self.assertEquals(i.strings['Goofy'], 'Dog')

        kind = view.findPath('//Schema/Core/Kind')
        itemKind = view.findPath('//Schema/Core/Item')
        myKind = kind.newItem('dictKind', view)

        # create an attribute with cardinality dict and add to the kind
        attrKind = itemKind.itsParent['Attribute']
        multiAttribute = Attribute('strings', myKind, attrKind)
        multiAttribute.cardinality = 'dict'
        myKind.addValue('attributes', multiAttribute, alias='strings')

        # create an item of the new kind
        item = myKind.newItem('item', view)
        item.setValue('strings', 'Mouse', 'Mickey')
        item.addValue('strings', 'Mouse', 'Minnie')
        item.addValue('strings', 'Duck', 'Donald')
        item.addValue('strings', 'Dog', 'Goofy')
        verifyItem(item)

        # set the strings attribute again
        item.strings = {
            'Mickey': 'Mouse',
            'Minnie': 'Mouse',
            'Donald': 'Duck',
            'Goofy': 'Dog'
        }
        verifyItem(item)

        # now write what we've done and read it back
        self._reopenRepository()
        view = self.view
        item = view.findPath('//item')
        verifyItem(item)

        #test removeValue by removing values and checking
        #that value is removed and length has decreased
        item.removeValue('strings', key='Mickey')
        self.assert_(item.hasValue('strings', 'Mouse'))
        self.assertEquals(len(item.strings), 3)

        del item.strings['Goofy']
        self.failIf(item.hasValue('strings', 'Dog'))
        self.assertEquals(len(item.strings), 2)

        del item.strings['Donald']
        self.failIf(item.hasValue('strings', 'Duck'))
        self.assertEquals(len(item.strings), 1)

        item.removeValue('strings', key='Minnie')
        self.failIf(item.hasValue('strings', 'Mouse'))
        self.assertEquals(len(item.strings), 0)

        # now write what we've done and read it back
        self._reopenRepository()
        item = view.findPath('//item')
        self.failIf('Mickey' in item.strings)
        self.failIf('Minnie' in item.strings)
        self.failIf('Goofy' in item.strings)
        self.failIf('Donald' in item.strings)
        self.failIf(item.hasValue('strings', 'Dog'))
        self.failIf(item.hasValue('strings', 'Duck'))
        self.failIf(item.hasValue('strings', 'Mouse'))
        self.assertEquals(len(item.strings), 0)
コード例 #10
0
    def testListMultis(self):
        """Test list valued literal attributes """

        view = self.view

        def verifyItem(i):
            """verify that a list valued literal attribute has the right values"""
            # verify list length
            self.assertEquals(len(i.strings),4)
    
            # test to see that there is a key at every position
            self.assert_(i.hasKey('strings', 0))
            self.assert_(i.hasKey('strings', 1))
            self.assert_(i.hasKey('strings', 2))
            self.assert_(i.hasKey('strings', 3))
                                         
            # test to see that every value is in the attribute
            self.assert_(i.hasValue('strings', 'Goofy'))
            self.assert_(i.hasValue('strings', 'Donald'))
            self.assert_(i.hasValue('strings', 'Minnie'))
            self.assert_(i.hasValue('strings', 'Mickey'))
    
            # verify list contents using getValue() method
            self.assertEquals(i.getValue('strings', 0), 'Mickey')
            self.assertEquals(i.getValue('strings', 1), 'Minnie')
            self.assertEquals(i.getValue('strings', 2), 'Donald')
            self.assertEquals(i.getValue('strings', 3), 'Goofy')
    
            # verify list contents using python list notation
            self.assertEquals(i.strings[0], 'Mickey')
            self.assertEquals(i.strings[1], 'Minnie')
            self.assertEquals(i.strings[2], 'Donald')
            self.assertEquals(i.strings[3], 'Goofy')
            
        
        kind = view.findPath('//Schema/Core/Kind')                
        itemKind = view.findPath('//Schema/Core/Item')            
        myKind = kind.newItem('listKind', view)
                                                                  
        # create an attribute with cardinality list and add to the kind
        attrKind = itemKind.itsParent['Attribute']
        multiAttribute = Attribute('strings', myKind, attrKind)   
        multiAttribute.cardinality = 'list'
        myKind.addValue('attributes', multiAttribute, alias='strings')
                                                                  
        # create an item of the new kind
        item = myKind.newItem('item', view)                   

        # add to the list attribute
        item.setValue('strings', 'Mickey')                         
        item.addValue('strings', 'Minnie')                         
        item.addValue('strings', 'Donald')                         
        item.addValue('strings', 'Goofy')                          
        verifyItem(item)
        
        # again set the list attribute
        item.strings = [ 'Mickey', 'Minnie', 'Donald', 'Goofy' ]
        verifyItem(item)
        
        # now write what we've done and read it back
        self._reopenRepository()
        item = view.findPath('//item')
        verifyItem(item)

        #test removeValue by removing values and checking
        #that value is removed and length has decreased
        item.removeValue('strings', key=0)
        self.failIf(item.hasValue('strings', 'Mickey'))
        self.assertEquals(len(item.strings), 3)

        del item.strings[2]
        self.failIf(item.hasValue('strings', 'Goofy'))
        self.assertEquals(len(item.strings), 2)

        del item.strings[1]
        self.failIf(item.hasValue('strings', 'Donald'))
        self.assertEquals(len(item.strings), 1)

        item.removeValue('strings', key=0)
        self.failIf(item.hasValue('strings', 'Minnie'))
        self.assertEquals(len(item.strings), 0)

        # now write what we've done and read it back
        self._reopenRepository()
        item = view.findPath('//item')
        self.failIf(item.hasValue('strings', 'Mickey'))
        self.failIf(item.hasValue('strings', 'Goofy'))
        self.failIf(item.hasValue('strings', 'Donald'))
        self.failIf(item.hasValue('strings', 'Minnie'))
        self.assertEquals(len(item.strings), 0)
コード例 #11
0
    def testDictMultis(self):
        """Test dictionary valued literal attributes"""

        view = self.view

        def verifyItem(i):
            """ verify that a dictionayr value literal attribute contains the right data"""
            self.assertEquals(len(i.strings), 4)
    
            # test to see that all keys were inserted
            self.assert_(i.hasKey('strings', 'Mickey'))
            self.assert_(i.hasKey('strings', 'Minnie'))
            self.assert_(i.hasKey('strings', 'Donald'))
            self.assert_(i.hasKey('strings', 'Goofy'))
                                         
            # test to see that every value is in the attribute
            self.assert_(i.hasValue('strings', 'Mouse'))
            self.assert_(i.hasValue('strings', 'Mouse'))
            self.assert_(i.hasValue('strings', 'Duck'))
            self.assert_(i.hasValue('strings', 'Dog'))
    
            # verify dict contents using getValue() method
            self.assertEquals(i.getValue('strings', 'Mickey'), 'Mouse')
            self.assertEquals(i.getValue('strings', 'Minnie'), 'Mouse')
            self.assertEquals(i.getValue('strings', 'Donald'), 'Duck')
            self.assertEquals(i.getValue('strings', 'Goofy'),  'Dog')
    
            # verify dict contents using python dict notation
            self.assertEquals(i.strings['Mickey'], 'Mouse')
            self.assertEquals(i.strings['Minnie'], 'Mouse')
            self.assertEquals(i.strings['Donald'], 'Duck')
            self.assertEquals(i.strings['Goofy'], 'Dog')

        
        kind = view.findPath('//Schema/Core/Kind')                
        itemKind = view.findPath('//Schema/Core/Item')            
        myKind = kind.newItem('dictKind', view)
                                                                  
        # create an attribute with cardinality dict and add to the kind
        attrKind = itemKind.itsParent['Attribute']
        multiAttribute = Attribute('strings', myKind, attrKind)
        multiAttribute.cardinality = 'dict'
        myKind.addValue('attributes', multiAttribute, alias='strings')
                                                                  
        # create an item of the new kind
        item = myKind.newItem('item', view)
        item.setValue('strings', 'Mouse', 'Mickey')
        item.addValue('strings', 'Mouse', 'Minnie')
        item.addValue('strings', 'Duck', 'Donald')
        item.addValue('strings', 'Dog', 'Goofy')
        verifyItem(item)

        # set the strings attribute again
        item.strings = { 'Mickey': 'Mouse', 'Minnie': 'Mouse',
                         'Donald': 'Duck', 'Goofy': 'Dog' }
        verifyItem(item)
        
        # now write what we've done and read it back
        self._reopenRepository()
        view = self.view
        item = view.findPath('//item')
        verifyItem(item)

        #test removeValue by removing values and checking
        #that value is removed and length has decreased
        item.removeValue('strings', key='Mickey')
        self.assert_(item.hasValue('strings', 'Mouse'))
        self.assertEquals(len(item.strings), 3)

        del item.strings['Goofy']
        self.failIf(item.hasValue('strings', 'Dog'))
        self.assertEquals(len(item.strings), 2)

        del item.strings['Donald']
        self.failIf(item.hasValue('strings', 'Duck'))
        self.assertEquals(len(item.strings), 1)

        item.removeValue('strings', key='Minnie')
        self.failIf(item.hasValue('strings', 'Mouse'))
        self.assertEquals(len(item.strings), 0)

        # now write what we've done and read it back
        self._reopenRepository()
        item = view.findPath('//item')
        self.failIf('Mickey' in item.strings)
        self.failIf('Minnie' in item.strings)
        self.failIf('Goofy' in item.strings)
        self.failIf('Donald' in item.strings)
        self.failIf(item.hasValue('strings', 'Dog'))
        self.failIf(item.hasValue('strings', 'Duck'))
        self.failIf(item.hasValue('strings', 'Mouse'))
        self.assertEquals(len(item.strings), 0)