Beispiel #1
0
    def testLiteralAttributes(self):
        """Test basic features of literal attributes"""
        kind = self._find('//Schema/Core/Kind')
        itemKind = self._find('//Schema/Core/Item')
        self.assert_(itemKind is not None)

        kind1 = Item('kind1', self.rep, kind)
        self.assert_(kind1 is not None)

        item1 = Item('item1', self.rep, itemKind)
        self.assert_(item1 is not None)

        #Test hasAttributeAspect and getAttributeAspect
        self.assert_(
            kind1.hasAttributeAspect('attributes', 'cardinality') and
            kind1.getAttributeAspect('attributes', 'cardinality') == 'list')

        self.assert_(
            kind1.hasAttributeAspect('superKinds', 'cardinality') and
            kind1.getAttributeAspect('superKinds', 'cardinality') == 'list')

        self.assert_(
            kind1.hasAttributeAspect('classes', 'cardinality')
            and kind1.getAttributeAspect('classes', 'cardinality') == 'dict')

        # up to here displayName is an unset Chandler attribute
        self.failUnlessRaises(AttributeError, lambda: item1.displayName)
        # now set the attribute
        item1.setAttributeValue('displayName', 'myName')
        self.assertEquals(item1.displayName, 'myName')
        #test __getattr__ and getAttributeValue() access
        self.assertEquals(item1.displayName,
                          item1.getAttributeValue('displayName'))
        # now remove attribute value
        item1.removeAttributeValue('displayName')
        self.failUnlessRaises(AttributeError, lambda: item1.displayName)
        #TODO need a test for list valued literal attribute

        # test dict valued literal attribute
        self.assert_(kind.classes['python'] is not None)
    def testLiteralAttributes(self):
        """Test basic features of literal attributes"""
        kind = self._find('//Schema/Core/Kind')
        itemKind = self._find('//Schema/Core/Item')
        self.assert_(itemKind is not None)

        kind1 = Item('kind1', self.rep, kind)
        self.assert_(kind1 is not None)

        item1 = Item('item1', self.rep, itemKind)
        self.assert_(item1 is not None)

        #Test hasAttributeAspect and getAttributeAspect
        self.assert_(kind1.hasAttributeAspect('attributes','cardinality') and
                     kind1.getAttributeAspect('attributes','cardinality') == 'list')

        self.assert_(kind1.hasAttributeAspect('superKinds','cardinality') and
                     kind1.getAttributeAspect('superKinds','cardinality') == 'list')

        self.assert_(kind1.hasAttributeAspect('classes','cardinality') and
                     kind1.getAttributeAspect('classes','cardinality') == 'dict')

        # up to here displayName is an unset Chandler attribute
        self.failUnlessRaises(AttributeError, lambda: item1.displayName)
        # now set the attribute
        item1.setAttributeValue('displayName', 'myName')
        self.assertEquals(item1.displayName, 'myName')
        #test __getattr__ and getAttributeValue() access
        self.assertEquals(item1.displayName, item1.getAttributeValue('displayName'))
        # now remove attribute value
        item1.removeAttributeValue('displayName')
        self.failUnlessRaises(AttributeError, lambda: item1.displayName)
        #TODO need a test for list valued literal attribute

        # test dict valued literal attribute
        self.assert_(kind.classes['python'] is not None)