[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Folder/tests - testFolder.py:1.1.2.3 testFolderAdder.py:1.1.2.8 testFolderContents.py:1.1.2.3
Jim Fulton
jim@zope.com
Mon, 4 Mar 2002 11:55:35 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Folder/tests
In directory cvs.zope.org:/tmp/cvs-serv14494/tests
Modified Files:
Tag: Zope-3x-branch
testFolder.py testFolderAdder.py testFolderContents.py
Log Message:
Refactored Folder (partially) to use Container framework.
Note that we are not reusing the Container content implementation (at
least for now), but we *are* reusing it's test.
=== Zope3/lib/python/Zope/App/OFS/Folder/tests/testFolder.py 1.1.2.2 => 1.1.2.3 ===
import unittest
-from Zope.ComponentArchitecture.tests.testServiceManagerContainer import TestServiceManagerContainer
+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):
-class Test( unittest.TestCase, TestServiceManagerContainer ):
-
-
- def _makeFolder(self):
- """ """
+ def _Test__new(self):
from Zope.App.OFS.Folder.Folder import Folder
-
return Folder()
-
- def _createInstance(self):
- return self._makeFolder()
-
- 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 )
+ return loader.loadTestsFromTestCase(Test)
if __name__=='__main__':
unittest.TextTestRunner().run( test_suite() )
=== Zope3/lib/python/Zope/App/OFS/Folder/tests/testFolderAdder.py 1.1.2.7 => 1.1.2.8 ===
+##############################################################################
+#
+# Copyright (c) 2001, 2002 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.
+# 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
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
+"""
-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.provideClass import provideClass
+Revision information:
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from Zope.App.OFS.Container.Views.Browser.tests.AdderBaseTests \
+ import BaseRegistryTest, BaseAddingTest
from Zope.App.ZMI.Addable import ContentAddables
-from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
-class Foo: pass
-class Bar: pass
-class Baz: pass
-
-AddPermission = []
-
-class RegistryTest(CleanUp, unittest.TestCase):
-
- 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( ContentAddables.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( ContentAddables
- , qualified_name='Zope.App.OFS.tests.testFolderAdd.Foo'
- , _class=Foo
- , permission=AddPermission
- , title='Foo'
- )
- provideClass(ContentAddables
- , qualified_name='Zope.App.OFS.tests.testFolderAdd.Bar'
- , _class=Bar
- , permission=AddPermission
- , title='Bar'
- )
- provideClass(ContentAddables
- , 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(CleanUp, unittest.TestCase ):
-
- def setUp(self):
- provideClass(ContentAddables
- , qualified_name='Zope.App.OFS.Folder'
- , _class=Folder
- , permission=AddPermission
- , title='Folder'
- )
-
- 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'
- )
+class Methods:
+ # Supply the methds needed by the bases.
+
+ def _TestView__newContext(self):
+ from Zope.App.OFS.Folder.Folder import Folder
+ return Folder()
+
+ def _TestView__newView(self, container):
+ from Zope.App.OFS.Folder.FolderAdder import FolderAdder
+ return FolderAdder(container)
+
+ def _TestAdderView__registry(self):
+ return ContentAddables
+
+class RegistryTest(Methods, BaseRegistryTest, TestCase): pass
+class AddingTest(Methods, BaseAddingTest, TestCase): pass
def test_suite():
- loader = unittest.TestLoader()
- suite = unittest.TestSuite()
- suite.addTest(loader.loadTestsFromTestCase(RegistryTest))
- suite.addTest(loader.loadTestsFromTestCase(AddingTest))
- return suite
+ return TestSuite([makeSuite(RegistryTest),
+ makeSuite(AddingTest),
+ ])
if __name__=='__main__':
- unittest.main()
+ main(defaultTest='test_suite')
=== Zope3/lib/python/Zope/App/OFS/Folder/tests/testFolderContents.py 1.1.2.2 => 1.1.2.3 ===
from Zope.App.OFS.Folder.FolderContents import FolderContents
from Zope.App.OFS.Folder.Folder import Folder
+from Zope.App.OFS.Container.Views.Browser.tests.testContents \
+ import BaseTestContentsBrowserView
+class Test(BaseTestContentsBrowserView, unittest.TestCase):
-class Document:
- pass
+ def _TestView__newContext(self):
+ return Folder()
-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 _TestView__newView(self, container):
+ return FolderContents(container)
def testAddServiceManager(self):
folder = Folder()