def setUp(self): super(TypesTest, self).setUp() self.kind = self._find(self._KIND_KIND) self.itemKind = self._find(self._ITEM_KIND) self.attrKind = self.itemKind.itsParent['Attribute'] self.newKind = self.kind.newItem('newKind', self.rep) self.typeKind = self._find('//Schema/Core/Type') self.typenames=['String', 'Symbol', 'Integer', 'Long', 'Float', 'Complex', 'Boolean', 'UUID', 'SingleRef', '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, self.rep, self.attrKind) classobj = eval('repository.schema.Types.%s' % a) typeItem = self._find('//Schema/Core/%s' % a) self.types[a] = typeItem tempAtt.type = typeItem self.atts[a] = tempAtt self.newKind.addValue('attributes', tempAtt, alias='%sAttribute' % a)
def setUp(self): super(KindTest, self).setUp() self.kind = self._find("//Schema/Core/Kind") self.itemKind = self._find("//Schema/Core/Item") self.attrKind = self.itemKind.itsParent['Attribute'] self.kind1 = self.kind.newItem('kind1', self.rep) self.kind1.addValue('superKinds', self.itemKind) self.kind1Attr1 = Attribute('k1a1', self.rep, 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', self.rep, self.attrKind) self.kind2Attr2.cardinality = 'list' self.kind2.addValue('attributes', self.kind2Attr2, alias='k2a2')
def testSubAttributes(self): """Test attributes which have sub attributes (subAttributes and superAttribute attributes)""" itemKind = self._find('//Schema/Core/Item') self.assert_(itemKind is not None) item = Item('item1', self.rep, itemKind) attrKind = itemKind.itsParent['Attribute'] # subattributes are created by assigning the "parent" attribute # to the superAttribute attribute of the "child" attribute issuesAttr = itemKind.getAttribute('issues') criticalSubAttr = Attribute('critical', issuesAttr, attrKind) criticalSubAttr.superAttribute = issuesAttr self.assert_(criticalSubAttr.superAttribute is issuesAttr) self.assert_(criticalSubAttr in issuesAttr.subAttributes) # now do it by assigning to the subAttributes list to ensure that # the bidirectional ref is getting updated. normalSubAttr = Attribute('normal', issuesAttr, attrKind) issuesAttr.subAttributes.append(normalSubAttr) self.assert_(normalSubAttr.superAttribute is issuesAttr) self.assert_(normalSubAttr in issuesAttr.subAttributes) # now do it by callin addValue on the Attribute item minorSubAttr = Attribute('minor', issuesAttr, attrKind) issuesAttr.addValue('subAttributes', minorSubAttr) self.assert_(minorSubAttr.superAttribute is issuesAttr) self.assert_(minorSubAttr in issuesAttr.subAttributes) # now write what we've done and read it back self._reopenRepository() item = self._find('//item1') itemKind = item.itsKind issuesAttr = itemKind.getAttribute('issues') attMap = {} for i in issuesAttr.subAttributes: attMap[i.itsName] = i criticalSubAttr = attMap['critical'] normalSubAttr = attMap['normal'] minorSubAttr = attMap['minor'] self.assert_(criticalSubAttr.superAttribute is issuesAttr) self.assert_(criticalSubAttr in issuesAttr.subAttributes) self.assert_(normalSubAttr.superAttribute is issuesAttr) self.assert_(normalSubAttr in issuesAttr.subAttributes) self.assert_(minorSubAttr.superAttribute is issuesAttr) self.assert_(minorSubAttr in issuesAttr.subAttributes)
def _createManagerAndEmployeeKinds(self, type): kind = self._find('//Schema/Core/Kind') itemKind = self._find('//Schema/Core/Item') attrKind = itemKind.itsParent['Attribute'] managerKind = kind.newItem('manager', self.rep) employeesAttribute = Attribute('employees',managerKind, attrKind) employeesAttribute.cardinality = type employeesAttribute.otherName = 'manager' managerKind.addValue('attributes', employeesAttribute,alias='employees') employeeKind = kind.newItem('employee', self.rep) managerAttribute = Attribute('manager',employeeKind, attrKind) managerAttribute.otherName = 'employees' employeeKind.addValue('attributes', managerAttribute,alias='manager') return (managerKind, employeeKind)
def setUp(self): super(RedirectAttributeOrderingTest, self).setUp() kind = self._find('//Schema/Core/Kind') itemKind = self._find('//Schema/Core/Item') attrKind = itemKind.itsParent['Attribute'] # noteKind has a 'creator' string, and a 'who' attribute to # redirectTo 'creator' noteKind = kind.newItem('Note', self.rep) creatorAttribute = Attribute('creator', noteKind, attrKind) creatorAttribute.cardinality = 'single' noteKind.addValue('attributes', creatorAttribute, alias='creator') whoAttribute = Attribute('who', noteKind, attrKind) whoAttribute.cardinality = 'single' whoAttribute.redirectTo = 'creator' noteKind.addValue('attributes', whoAttribute, alias='who') # taskMixin has a 'participant' string, and a 'who' attribute to # redirectTo 'participant' taskMixin = kind.newItem('TaskMixin', self.rep) participantAttribute = Attribute('participant', taskMixin, attrKind) participantAttribute.cardinality = 'single' taskMixin.addValue('attributes', participantAttribute, alias='participant') whoAttribute = Attribute('who', taskMixin, attrKind) whoAttribute.cardinality = 'single' whoAttribute.redirectTo = 'participant' taskMixin.addValue('attributes', whoAttribute, alias='who') # taskKind is a Kind with superkinds noteKind and taskMixin taskKind = kind.newItem('Task', self.rep) taskKind.addValue('superKinds', noteKind) taskKind.addValue('superKinds', taskMixin) self.noteKind = noteKind.itsUUID self.taskMixin = taskMixin.itsUUID self.taskKind = taskKind.itsUUID
def _create_schema_item(self, view): if self.owner is None or self.name is None: raise TypeError( "role object used outside of schema.Item subclass" ) if isinstance(self.inverse,ForwardReference): self.inverse = self.inverse.referent() # force resolution now attr = Attribute("tmp_"+self.name, None, itemFor(Attribute, view)) return attr
def _createManagerAndEmployeeKinds(self, type): kind = self._find('//Schema/Core/Kind') itemKind = self._find('//Schema/Core/Item') attrKind = itemKind.itsParent['Attribute'] managerKind = kind.newItem('manager', self.rep) employeesAttribute = Attribute('employees', managerKind, attrKind) employeesAttribute.cardinality = type employeesAttribute.otherName = 'manager' managerKind.addValue('attributes', employeesAttribute, alias='employees') employeeKind = kind.newItem('employee', self.rep) managerAttribute = Attribute('manager', employeeKind, attrKind) managerAttribute.otherName = 'employees' employeeKind.addValue('attributes', managerAttribute, alias='manager') return (managerKind, employeeKind)
def testListMultis(self): """Test list valued literal attributes """ 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 = self._find('//Schema/Core/Kind') itemKind = self._find('//Schema/Core/Item') myKind = kind.newItem('listKind', self.rep) # 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', self.rep) # 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 = self._find('//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 = self._find('//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)
def testDictMultis(self): """Test dictionary valued literal attributes""" 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 = self._find('//Schema/Core/Kind') itemKind = self._find('//Schema/Core/Item') myKind = kind.newItem('dictKind', self.rep) # 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', self.rep) 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() item = self._find('//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 = self._find('//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)
def _createBlockAndEventKinds(self, cardinality): kind = self._find('//Schema/Core/Kind') itemKind = self._find('//Schema/Core/Item') attrKind = itemKind.itsParent['Attribute'] # blockKind has a 'blocks' reference collection, and an inverse 'blockParent' blockKind = kind.newItem('Block', self.rep) 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', self.rep) notifyBlock = Attribute('notify', eventKind, attrKind) notifyBlock.cardinality = 'single' notifyBlock.copyPolicy = currentPolicy eventKind.addValue('attributes', notifyBlock, alias='notify') return (blockKind, eventKind)
def testListMultis(self): """Test list valued literal attributes """ 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 = self._find('//Schema/Core/Kind') itemKind = self._find('//Schema/Core/Item') myKind = kind.newItem('listKind', self.rep) # 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', self.rep) # 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 = self._find('//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 = self._find('//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)