[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Folder/tests - __init__.py:1.1.2.1 testFolder.py:1.1.2.1 testFolderAdder.py:1.1.2.1 testFolderContents.py:1.1.2.1
Stephan Richter
srichter@cbu.edu
Sat, 19 Jan 2002 23:57:32 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Folder/tests
In directory cvs.zope.org:/tmp/cvs-serv30501/Folder/tests
Added Files:
Tag: Zope-3x-branch
__init__.py testFolder.py testFolderAdder.py
testFolderContents.py
Log Message:
- Restructuring the directory structure in Zope.App.OFS
- Added a simple Image support including two views
NOTE: The ImageData.tag() method does not work yet, since absolute_url is
not implemented yet.
=== Added File Zope3/lib/python/Zope/App/OFS/Folder/tests/__init__.py ===
=== Added File Zope3/lib/python/Zope/App/OFS/Folder/tests/testFolder.py ===
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (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
class Test( unittest.TestCase ):
def _makeFolder(self):
""" """
from Zope.App.OFS.Folder.Folder import Folder
return Folder()
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() )
=== Added File Zope3/lib/python/Zope/App/OFS/Folder/tests/testFolderAdder.py ===
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (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.FolderAdder import FolderAdder
from Zope.App.OFS.Folder.FolderAdder import DuplicateIDError
from Zope.App.OFS.Folder.Folder import Folder
from Zope.App.ZMI.Addable import provideAddable
from Zope.App.ZMI.provideClass import provideClass
class Foo: pass
class Bar: pass
class Baz: pass
AddPermission = []
class RegistryTest( unittest.TestCase ):
def setUp( self ):
pass
def tearDown( self ):
from Zope.App.ZMI.Addable import _clear as clearAddables
from Zope.ComponentArchitecture import _clear as clearRegistry
clearAddables()
clearRegistry()
def testNonesuch( self ):
"""
Do we get the correct information back when no
addables have been registered?
"""
folder = Folder()
fa = FolderAdder( folder )
info_list = fa.listAddableInfo()
self.failIf( info_list )
def testHaveSome( self ):
"""
Do we get the correct information back when no
addables have been registered?
"""
data = [ ( 'foo', 'Foo', 'Foo Thingies' )
, ( 'bar', 'Bar', 'Barflies' )
, ( 'baz', 'Baz', 'Bazzing Around' )
]
for datum in data:
apply( provideAddable, datum, {} )
folder = Folder()
fa = FolderAdder( folder )
info_list = fa.listAddableInfo()
self.assertEquals( len( info_list ), len( data ) )
id_list = map( lambda x: x['id'], info_list )
self.assert_( 'foo' in id_list )
self.assert_( 'bar' in id_list )
self.assert_( 'baz' in id_list )
title_list = map( lambda x: x['title'], info_list )
self.assert_( 'Foo' in title_list )
self.assert_( 'Bar' in title_list )
self.assert_( 'Baz' in title_list )
def testNonesuchAction( self ):
"""
Can we get add an object back when no classes have
been registered?
"""
folder = Folder()
fa = FolderAdder( folder )
self.assertRaises( KeyError, fa.action, type_name='foo', id='foo_123' )
def testHaveSomeAction( self ):
"""
Can we get add an object back when some classes have
been registered?
"""
provideClass( qualified_name='Zope.App.OFS.tests.testFolderAdd.Foo'
, _class=Foo
, permission=AddPermission
, title='Foo'
)
provideClass( qualified_name='Zope.App.OFS.tests.testFolderAdd.Bar'
, _class=Bar
, permission=AddPermission
, title='Bar'
)
provideClass( qualified_name='Zope.App.OFS.tests.testFolderAdd.Baz'
, _class=Baz
, permission=AddPermission
, title='Baz'
)
folder = Folder()
fa = FolderAdder( folder )
info_list = fa.listAddableInfo()
self.assertEquals( len( info_list ), 3 )
class AddingTest( unittest.TestCase ):
def setUp( self ):
provideClass( qualified_name='Zope.App.OFS.Folder'
, _class=Folder
, permission=AddPermission
, title='Folder'
)
def tearDown( self ):
from Zope.App.ZMI.Addable import _clear as clearAddables
from Zope.ComponentArchitecture import _clear as clearRegistry
clearAddables()
clearRegistry()
def testAdding( self ):
"""
Does addition of a new object with the same ID as an existing
object fail?
"""
folder = Folder()
fa = FolderAdder( folder )
fa.action( type_name='Zope.App.OFS.Folder', id='foo' )
self.assertEquals( len( folder.objectIds() ), 1 )
self.assertEquals( folder.objectIds()[0], 'foo' )
self.assertEquals( len( folder.objectValues() ), 1 )
self.assertEquals( folder.objectValues()[0].__class__, Folder )
def testDuplicates( self ):
"""
Does addition of a new object with the same ID as an existing
object fail?
"""
folder = Folder()
fa = FolderAdder( folder )
fa.action( type_name='Zope.App.OFS.Folder', id='foo' )
self.assertRaises( DuplicateIDError
, fa.action
, type_name='Zope.App.OFS.Folder'
, id='foo'
)
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/testFolderContents.py ===
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (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.FolderContents import FolderContents
from Zope.App.OFS.Folder.Folder import Folder
class Document:
pass
class Test( unittest.TestCase ):
def testInfo( self ):
""" Do we get the correct information back from FolderContents? """
folder = Folder()
subfolder = Folder()
folder.setObject( 'subfolder', subfolder )
document = Document()
folder.setObject( 'document', document )
fc = FolderContents( folder )
info_list = fc.listContentInfo()
self.assertEquals( len( info_list ), 2 )
ids = map( lambda x: x['id'], info_list )
self.assert_( 'subfolder' in ids )
objects = map( lambda x: x['object'], info_list )
self.assert_( subfolder in objects )
titles = map( lambda x: x['title'], info_list )
self.assert_( 'subfolder' in titles )
urls = map( lambda x: x['url'], info_list )
self.assert_( 'subfolder' in urls )
self.failIf( filter( None, map( lambda x: x['icon'], info_list ) ) )
def testRemove( self ):
folder = Folder()
subfolder = Folder()
folder.setObject( 'subfolder', subfolder )
document = Document()
folder.setObject( 'document', document )
folder.setObject( 'document2', Document() )
fc = FolderContents( folder )
fc.remove( name='document2' )
info_list = fc.listContentInfo()
self.assertEquals( len( info_list ), 2 )
ids = map( lambda x: x['id'], info_list )
self.assert_( 'subfolder' in ids )
objects = map( lambda x: x['object'], info_list )
self.assert_( subfolder in objects )
titles = map( lambda x: x['title'], info_list )
self.assert_( 'subfolder' in titles )
urls = map( lambda x: x['url'], info_list )
self.assert_( 'subfolder' in urls )
self.assertRaises( KeyError, fc.remove, 'document3' )
fc.remove( 'document3', 1 )
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase( Test )
if __name__=='__main__':
unittest.main()