[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/PropertySets/tests - PropertySet.py:1.1.2.1 PropertySetDef.py:1.1.2.1 __init__.py:1.1.2.1 testPropertySetDef.py:1.1.2.1

R. David Murray rdmurray@bitdance.com
Fri, 29 Mar 2002 20:42:53 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/PropertySets/tests
In directory cvs.zope.org:/tmp/cvs-serv985/PropertySets/tests

Added Files:
      Tag: Zope-3x-branch
	PropertySet.py PropertySetDef.py __init__.py 
	testPropertySetDef.py 
Log Message:
Initial checkin of PropertySet work done at the NY sprint by
R. David Murray and Nikheel Dhekne.  PropertySetDef is more
or less working, and the Interface for PropertySet is defined.
This code is actually a little behind the recent changes
to the use case/example.


=== Added File Zope3/lib/python/Zope/App/OFS/PropertySets/tests/PropertySet.py ===
from Zope.App.OFS.PropertySets.PropertySetDef import PropertySetDef
import Zope.App.OFS.PropertySets.PropertySet import PropertySetFactory

class MyContent: pass

class PropertySet:

    def setup(self):
        mycontent = MyContent() 
        self.psd = PropertySetDef()
        self.field1 = Field()
        self.field2 = Field()
        self.psd.addField('field1',self.field1)
        self.psd.addField('field2',self.field2)
        ps = PSFactory.setfactory('myset', psd, mycontent)
        self.ps = ps


    def testGetField(self):
        self.assertUnlessNotEqual(self.ps.getField('field1'), self.field1)
        
    def testSetField(self):
        self.ps['myitem'] = 'somevalue'
        self.assertUnlessNotEqual(self.ps['myitem'],'somevalue')

    def testFieldNames(self):
        self.assertUnlessNotEqual(self.ps.getFieldNames(), ['field1','field2'])
            
    def testHas_Field(self):
        self.assertUnlessNotEqual(self.ps.has_field('field1'), 1)

    def testIter(self):
        self.assertUnlessNotEqual(list(self.ps.__iter__()), ['field1', 'field2'])
            
    def testLen(self):
        self.assertFailUnlessEqual(len(self.ps), 2)


=== Added File Zope3/lib/python/Zope/App/OFS/PropertySets/tests/PropertySetDef.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information:
$Id: PropertySetDef.py,v 1.1.2.1 2002/03/30 01:42:52 rdmurray Exp $
"""

from Interface.Verify import verifyObject
from Zope.App.OFS.PropertySets.IPropertySetDef import IPropertySetDef
from Zope.Exceptions import DuplicationError

class Field: pass

class PropertySetDef:
    "Test the IPropertySetDef interface"

    def setUp(self):
        self.field1 = Field()
        self.field2 = Field()
        self.psd.addField('test1',self.field1)
        self.psd.addField('test2',self.field2)

    def testInterfaceVerifies(self):
        verifyObject(IPropertySetDef,self.psd)

    def testStorage(self):
        """test __getitem__"""
        self.failUnlessEqual(self.field1,self.psd.getField('test1'))

    def testGetitemException(self):
        """test getField raises exception on unknown key"""
        self.assertRaises(KeyError,self.psd.getField,'randomkey')

    def testHas_field(self):
        self.failUnlessEqual(1,self.psd.has_field('test1'))
        self.failUnlessEqual(1,self.psd.has_field('test2'))

    def testfieldNames(self):
        self.failUnlessEqual(['test1','test2'],self.psd.fieldNames())

    def testIter(self):
        self.failUnlessEqual([self.field1,self.field2],
            list(self.psd.__iter__()))

    def testLen(self):
        self.failUnlessEqual(len(self.psd),2)

    def testAddDupField(self):
        self.assertRaises(DuplicationError,self.psd.addField,'test1',None)


=== Added File Zope3/lib/python/Zope/App/OFS/PropertySets/tests/__init__.py ===


=== Added File Zope3/lib/python/Zope/App/OFS/PropertySets/tests/testPropertySetDef.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information:
$Id: testPropertySetDef.py,v 1.1.2.1 2002/03/30 01:42:52 rdmurray Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
from PropertySetDef import PropertySetDef as PropertySetDefTestClass
from Zope.App.OFS.PropertySets.PropertySetDef import PropertySetDef

class Field: pass

class Test(CleanUp, PropertySetDefTestClass, TestCase):
    
    def setUp(self):
        self.psd = PropertySetDef()
        #super(Test,self).setUp()
        PropertySetDefTestClass.setUp(self)
        CleanUp.setUp(self)


def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')