[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Content/Folder/tests - __init__.py:1.2 testFolder.py:1.2 testFolderLimit.py:1.2 testLoadedFolder.py:1.2
Jim Fulton
jim@zope.com
Mon, 10 Jun 2002 19:28:33 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Content/Folder/tests
In directory cvs.zope.org:/tmp/cvs-serv17445/lib/python/Zope/App/OFS/Content/Folder/tests
Added Files:
__init__.py testFolder.py testFolderLimit.py
testLoadedFolder.py
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.
=== Zope3/lib/python/Zope/App/OFS/Content/Folder/tests/__init__.py 1.1 => 1.2 ===
+#
+# 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.
+#
+##############################################################################
=== Zope3/lib/python/Zope/App/OFS/Content/Folder/tests/testFolder.py 1.1 => 1.2 ===
+#
+# 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.
+#
+##############################################################################
+import unittest
+from unittest import TestCase
+from Zope.ComponentArchitecture.tests.testServiceManagerContainer \
+ import BaseTestServiceManagerContainer
+from Zope.App.OFS.Container.tests.testIContainer import BaseTestIContainer
+
+class Test(BaseTestIContainer, BaseTestServiceManagerContainer, TestCase):
+
+ def _Test__new(self):
+ from Zope.App.OFS.Content.Folder.Folder import Folder
+ return Folder()
+
+def test_suite():
+ loader = unittest.TestLoader()
+ return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run( test_suite() )
=== Zope3/lib/python/Zope/App/OFS/Content/Folder/tests/testFolderLimit.py 1.1 => 1.2 ===
+#
+# 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.
+#
+##############################################################################
+import unittest
+
+from Zope.App.OFS.Content.Folder.LoadedFolder import LoadedFolder
+from Zope.App.OFS.Content.Folder.FolderLimit import FolderLimitExceededError
+
+class Object:
+ """Object stub"""
+
+
+class Test( unittest.TestCase ):
+
+
+ def testSetLimit( self ):
+ """ """
+ loadedfolder = LoadedFolder()
+
+ loadedfolder.setLimit(5)
+ self.assertEquals( loadedfolder._limit, 5 )
+
+
+ def testGetLimit( self ):
+ """ """
+ loadedfolder = LoadedFolder()
+
+ loadedfolder._limit = 5
+ self.assertEquals( loadedfolder.getLimit(), 5 )
+
+
+ def testLimitReach(self):
+ """ """
+ loadedfolder = LoadedFolder()
+ loadedfolder.setObject('object1', Object())
+ loadedfolder._limit = 2
+
+ # A second one should fit in
+ loadedfolder.setObject('object2', Object())
+
+ # But with 3 go on strike
+ self.assertRaises( FolderLimitExceededError,
+ loadedfolder.setObject,
+ 'object3', Object() )
+
+
+
+
+def test_suite():
+ loader = unittest.TestLoader()
+ return loader.loadTestsFromTestCase( Test )
+
+if __name__=='__main__':
+ unittest.main()
=== Zope3/lib/python/Zope/App/OFS/Content/Folder/tests/testLoadedFolder.py 1.1 => 1.2 ===
+#
+# 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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+
+import unittest
+
+
+class Test( unittest.TestCase ):
+
+
+ def _makeFolder( self ):
+ """ """
+ from Zope.App.OFS.Content.Folder.LoadedFolder import LoadedFolder
+
+ return LoadedFolder()
+
+
+
+ def testEmpty( self ):
+
+ folder = self._makeFolder()
+ self.failIf( folder.keys() )
+ self.failIf( folder.values() )
+ self.failIf( folder.items() )
+ self.failIf( len(folder) )
+ self.failIf( 'foo' in folder)
+
+ self.assertEquals( folder.get( 'foo', None ), None )
+ self.assertRaises( KeyError, folder.__getitem__, 'foo' )
+
+ self.assertRaises( KeyError, folder.__delitem__, 'foo' )
+
+ def testOneItem( self ):
+
+ folder = self._makeFolder()
+ foo = []
+ folder.setObject( 'foo', foo )
+
+ self.assertEquals( len( folder.keys() ), 1 )
+ self.assertEquals( folder.keys()[0], 'foo' )
+ self.assertEquals( len( folder.values() ), 1 )
+ self.assertEquals( folder.values()[0], foo )
+ self.assertEquals( len( folder.items() ), 1 )
+ self.assertEquals( folder.items()[0], ( 'foo', foo ) )
+ self.assertEquals( len(folder), 1 )
+
+ self.failUnless('foo' in folder)
+ self.failIf('bar' in folder)
+
+ self.assertEquals( folder.get( 'foo', None ), foo )
+ self.assertEquals( folder['foo'], foo )
+
+ self.assertRaises( KeyError, folder.__getitem__, 'qux' )
+
+ foo2 = []
+ folder.setObject( 'foo', foo )
+
+ self.assertEquals( len( folder.keys() ), 1 )
+ self.assertEquals( folder.keys()[0], 'foo' )
+ self.assertEquals( len( folder.values() ), 1 )
+ self.assertEquals( folder.values()[0], foo2 )
+ self.assertEquals( len( folder.items() ), 1 )
+ self.assertEquals( folder.items()[0], ( 'foo', foo2 ) )
+ self.assertEquals( len(folder), 1 )
+
+ del folder['foo']
+
+ self.failIf( folder.keys() )
+ self.failIf( folder.values() )
+ self.failIf( folder.items() )
+ self.failIf( len(folder) )
+ self.failIf('foo' in folder)
+
+ self.assertRaises( KeyError, folder.__getitem__, 'foo' )
+ self.assertEquals( folder.get( 'foo', None ), None )
+ self.assertRaises( KeyError, folder.__delitem__, 'foo' )
+
+ def testManyItems( self ):
+
+ folder = self._makeFolder()
+ objects = [ [0], [1], [2], [3] ]
+ folder.setObject( 'foo', objects[0] )
+ folder.setObject( 'bar', objects[1] )
+ folder.setObject( 'baz', objects[2] )
+ folder.setObject( 'bam', objects[3] )
+
+ self.assertEquals( len( folder.keys() ), len( objects ) )
+ self.failUnless( 'foo' in folder.keys() )
+ self.failUnless( 'bar' in folder.keys() )
+ self.failUnless( 'baz' in folder.keys() )
+ self.failUnless( 'bam' in folder.keys() )
+
+ self.assertEquals( len( folder.values() ), len( objects ) )
+ self.failUnless( objects[0] in folder.values() )
+ self.failUnless( objects[1] in folder.values() )
+ self.failUnless( objects[2] in folder.values() )
+ self.failUnless( objects[3] in folder.values() )
+
+ self.assertEquals( len( folder.items() ), len( objects ) )
+ self.failUnless( ( 'foo', objects[0] ) in folder.items() )
+ self.failUnless( ( 'bar', objects[1] ) in folder.items() )
+ self.failUnless( ( 'baz', objects[2] ) in folder.items() )
+ self.failUnless( ( 'bam', objects[3] ) in folder.items() )
+
+ self.assertEquals( len(folder), len( objects ) )
+
+ self.failUnless('foo' in folder)
+ self.failUnless('bar' in folder)
+ self.failUnless('baz' in folder)
+ self.failUnless('bam' in folder)
+ self.failIf('qux' in folder)
+
+ self.assertEquals( folder.get( 'foo', None ), objects[0] )
+ self.assertEquals( folder['foo'], objects[0] )
+ self.assertEquals( folder.get( 'bar', None ), objects[1] )
+ self.assertEquals( folder['bar'], objects[1] )
+ self.assertEquals( folder.get( 'baz', None ), objects[2] )
+ self.assertEquals( folder['baz'], objects[2] )
+ self.assertEquals( folder.get( 'bam', None ), objects[3] )
+ self.assertEquals( folder['bam'], objects[3] )
+
+ self.assertEquals( folder.get( 'qux', None ), None )
+ self.assertRaises( KeyError, folder.__getitem__, 'qux' )
+
+ del folder['foo']
+ self.assertEquals( len(folder), len( objects ) - 1 )
+ self.failIf( 'foo' in folder)
+ self.failIf( 'foo' in folder.keys() )
+
+ self.failIf( objects[0] in folder.values() )
+ self.failIf( ( 'foo', objects[0] ) in folder.items() )
+
+ self.assertEquals( folder.get( 'foo', None ), None )
+ self.assertRaises( KeyError, folder.__getitem__, 'foo' )
+
+ self.assertRaises( KeyError, folder.__delitem__, 'foo' )
+
+ del folder['bar']
+ del folder['baz']
+ del folder['bam']
+
+ self.failIf( folder.keys() )
+ self.failIf( folder.values() )
+ self.failIf( folder.items() )
+ self.failIf( len(folder) )
+ self.failIf('foo' in folder)
+ self.failIf('bar' in folder)
+ self.failIf('baz' in folder)
+ self.failIf('bam' in folder)
+
+
+
+def test_suite():
+ loader = unittest.TestLoader()
+ return loader.loadTestsFromTestCase( Test )
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run( test_suite() )