[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Folder/tests - testLoadedFolder.py:1.1.2.1
Stephan Richter
srichter@cbu.edu
Fri, 1 Mar 2002 02:10:53 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Folder/tests
In directory cvs.zope.org:/tmp/cvs-serv25834/Folder/tests
Added Files:
Tag: srichter-OFS_Formulator-branch
testLoadedFolder.py
Log Message:
Okay, I am finally ready to check this stuff in:
- Reorganized the internal directory structure of every content object. For
each content object you have now a Views directory that contains further
directories for different protocols, such as Browser (HTML), XUL, FTP ...
Note: None of the directories is file-type, but functionality-based. It
is a bad idea to create directories for a particular file type, as
it was common in Zope 2.
- Made Folder, File and Image forms Formulator-based. This allows us now to
create forms for new protocols. such as XUL very quickly (often just a
few lines of code). More to Formulator when it is being checked in.
- Cleaned up most files. Almost all files should have now the correct
license disclaimer.
- A new object called LoadedFolder was added. LoadedFolder currently
provides two new functionalities to folders:
1. Ordering. You can change the order of the objects. This idea was
taking from the Zope 2 product OrderedFolders.
2. Limit. You can specify the maximal amount of items the folder is
allowed to store. This idea was also taken from OrderedFolders.
Note: Due to much rearranging during this development, there are no tests
yet written for this. This needs to be done, before we merge with
the Zoep-3x-branch again.
- Started XUL implementation of screens.
- Fixed some bugs I found lying around.
=== 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.2.1 2002/03/01 07:10:51 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() )