[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Folder/tests - testFolderLimit.py:1.1.4.1 testLoadedFolder.py:1.1.4.1
Stephan Richter
srichter@cbu.edu
Wed, 27 Mar 2002 10:54:46 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Folder/tests
In directory cvs.zope.org:/tmp/cvs-serv12282/Folder/tests
Added Files:
Tag: Zope-3x-branch
testFolderLimit.py testLoadedFolder.py
Log Message:
New Content Objects:
- NaiveFile --> all the data is stored in one string
- File --> Uses a BTree to store the data in chunks (more efficient)
- Image --> Can store and display an image a la Z2 (based on File)
- ZPTPage --> A simple version of ZPT for the content space to allow some
dynamics data (please do not use this for scripting)
Also:
- Expansion of supported views
- all edit screens are Formulator supported
=== Added File Zope3/lib/python/Zope/App/OFS/Folder/tests/testFolderLimit.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
#
##############################################################################
import unittest
from Zope.App.OFS.Folder.LoadedFolder import LoadedFolder
from Zope.App.OFS.Folder.FolderLimit import FolderLimitExeededError
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
self.failIf(loadedfolder.setObject('object2', Object()))
# But with 3 go on strike
self.assertRaises( FolderLimitExeededError,
loadedfolder.setObject,
'object3', Object() )
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase( Test )
if __name__=='__main__':
unittest.main()
=== Added File Zope3/lib/python/Zope/App/OFS/Folder/tests/testLoadedFolder.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
#
##############################################################################
"""
$Id: testLoadedFolder.py,v 1.1.4.1 2002/03/27 15:54:45 srichter Exp $
"""
import unittest
class Test( unittest.TestCase ):
def _makeFolder( self ):
""" """
from Zope.App.OFS.Folder.LoadedFolder import LoadedFolder
return LoadedFolder()
def testEmpty( self ):
folder = self._makeFolder()
self.failIf( folder.objectIds() )
self.failIf( folder.objectValues() )
self.failIf( folder.objectItems() )
self.failIf( folder.objectCount() )
self.failIf( folder.hasObject( 'foo' ) )
self.assertEquals( folder.getObject( 'foo', None ), None )
self.assertRaises( KeyError, folder.getObject, 'foo' )
self.assertRaises( KeyError, folder.delObject, 'foo' )
def testOneItem( self ):
folder = self._makeFolder()
foo = []
folder.setObject( 'foo', foo )
self.assertEquals( len( folder.objectIds() ), 1 )
self.assertEquals( folder.objectIds()[0], 'foo' )
self.assertEquals( len( folder.objectValues() ), 1 )
self.assertEquals( folder.objectValues()[0], foo )
self.assertEquals( len( folder.objectItems() ), 1 )
self.assertEquals( folder.objectItems()[0], ( 'foo', foo ) )
self.assertEquals( folder.objectCount(), 1 )
self.failUnless( folder.hasObject( 'foo' ) )
self.failIf( folder.hasObject( 'bar' ) )
self.assertEquals( folder.getObject( 'foo', None ), foo )
self.assertEquals( folder.getObject( 'foo' ), foo )
self.assertRaises( KeyError, folder.getObject, 'qux' )
foo2 = []
folder.setObject( 'foo', foo )
self.assertEquals( len( folder.objectIds() ), 1 )
self.assertEquals( folder.objectIds()[0], 'foo' )
self.assertEquals( len( folder.objectValues() ), 1 )
self.assertEquals( folder.objectValues()[0], foo2 )
self.assertEquals( len( folder.objectItems() ), 1 )
self.assertEquals( folder.objectItems()[0], ( 'foo', foo2 ) )
self.assertEquals( folder.objectCount(), 1 )
folder.delObject( 'foo' )
self.failIf( folder.objectIds() )
self.failIf( folder.objectValues() )
self.failIf( folder.objectItems() )
self.failIf( folder.objectCount() )
self.failIf( folder.hasObject( 'foo' ) )
self.assertRaises( KeyError, folder.getObject, 'foo' )
self.assertEquals( folder.getObject( 'foo', None ), None )
self.assertRaises( KeyError, folder.delObject, '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.objectIds() ), len( objects ) )
self.failUnless( 'foo' in folder.objectIds() )
self.failUnless( 'bar' in folder.objectIds() )
self.failUnless( 'baz' in folder.objectIds() )
self.failUnless( 'bam' in folder.objectIds() )
self.assertEquals( len( folder.objectValues() ), len( objects ) )
self.failUnless( objects[0] in folder.objectValues() )
self.failUnless( objects[1] in folder.objectValues() )
self.failUnless( objects[2] in folder.objectValues() )
self.failUnless( objects[3] in folder.objectValues() )
self.assertEquals( len( folder.objectItems() ), len( objects ) )
self.failUnless( ( 'foo', objects[0] ) in folder.objectItems() )
self.failUnless( ( 'bar', objects[1] ) in folder.objectItems() )
self.failUnless( ( 'baz', objects[2] ) in folder.objectItems() )
self.failUnless( ( 'bam', objects[3] ) in folder.objectItems() )
self.assertEquals( folder.objectCount(), len( objects ) )
self.failUnless( folder.hasObject( 'foo' ) )
self.failUnless( folder.hasObject( 'bar' ) )
self.failUnless( folder.hasObject( 'baz' ) )
self.failUnless( folder.hasObject( 'bam' ) )
self.failIf( folder.hasObject( 'qux' ) )
self.assertEquals( folder.getObject( 'foo', None ), objects[0] )
self.assertEquals( folder.getObject( 'foo' ), objects[0] )
self.assertEquals( folder.getObject( 'bar', None ), objects[1] )
self.assertEquals( folder.getObject( 'bar' ), objects[1] )
self.assertEquals( folder.getObject( 'baz', None ), objects[2] )
self.assertEquals( folder.getObject( 'baz' ), objects[2] )
self.assertEquals( folder.getObject( 'bam', None ), objects[3] )
self.assertEquals( folder.getObject( 'bam' ), objects[3] )
self.assertEquals( folder.getObject( 'qux', None ), None )
self.assertRaises( KeyError, folder.getObject, 'qux' )
folder.delObject( 'foo' )
self.assertEquals( folder.objectCount(), len( objects ) - 1 )
self.failIf( folder.hasObject( 'foo' ) )
self.failIf( 'foo' in folder.objectIds() )
self.failIf( objects[0] in folder.objectValues() )
self.failIf( ( 'foo', objects[0] ) in folder.objectItems() )
self.assertEquals( folder.getObject( 'foo', None ), None )
self.assertRaises( KeyError, folder.getObject, 'foo' )
self.assertRaises( KeyError, folder.delObject, 'foo' )
folder.delObject( 'bar' )
folder.delObject( 'baz' )
folder.delObject( 'bam' )
self.failIf( folder.objectIds() )
self.failIf( folder.objectValues() )
self.failIf( folder.objectItems() )
self.failIf( folder.objectCount() )
self.failIf( folder.hasObject( 'foo' ) )
self.failIf( folder.hasObject( 'bar' ) )
self.failIf( folder.hasObject( 'baz' ) )
self.failIf( folder.hasObject( 'bam' ) )
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase( Test )
if __name__=='__main__':
unittest.TextTestRunner().run( test_suite() )