[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Folder/Views/Browser/tests - __init__.py:1.1.2.1 testFolderAdder.py:1.1.2.1 testFolderContents.py:1.1.2.1 testLoadedFolderContents.py:1.1.2.1
Stephan Richter
srichter@cbu.edu
Fri, 1 Mar 2002 01:37:10 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Folder/Views/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv10334/Folder/Views/Browser/tests
Added Files:
Tag: srichter-OFS_Formulator-branch
__init__.py testFolderAdder.py testFolderContents.py
testLoadedFolderContents.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/Views/Browser/tests/__init__.py ===
=== Added File Zope3/lib/python/Zope/App/OFS/Folder/Views/Browser/tests/testFolderAdder.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: testFolderAdder.py,v 1.1.2.1 2002/03/01 06:37:09 srichter Exp $
"""
import unittest
from Zope.App.OFS.Folder.Views.Browser.FolderAdder import FolderAdder
from Zope.App.OFS.Folder.Views.Browser.FolderAdder import DuplicateIDError
from Zope.App.OFS.Folder.Folder import Folder
from Zope.App.ZMI.provideClass import provideClass
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'
)
def test_suite():
loader = unittest.TestLoader()
suite = unittest.TestSuite()
suite.addTest(loader.loadTestsFromTestCase(RegistryTest))
suite.addTest(loader.loadTestsFromTestCase(AddingTest))
return suite
if __name__=='__main__':
unittest.main()
=== Added File Zope3/lib/python/Zope/App/OFS/Folder/Views/Browser/tests/testFolderContents.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: testFolderContents.py,v 1.1.2.1 2002/03/01 06:37:09 srichter Exp $
"""
import unittest
from Zope.App.OFS.Folder.Views.Browser.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 testAddServiceManager(self):
folder = Folder()
fc = FolderContents(folder)
fc.addServiceManager()
self.failUnless(folder.hasServiceManager())
self.assertRaises('HasServiceManager', fc.addServiceManager)
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase( Test )
if __name__=='__main__':
unittest.main()
=== Added File Zope3/lib/python/Zope/App/OFS/Folder/Views/Browser/tests/testLoadedFolderContents.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: testLoadedFolderContents.py,v 1.1.2.1 2002/03/01 06:37:09 srichter Exp $
"""
import unittest
from Zope.App.OFS.Folder.Views.Browser.LoadedFolderContents import \
LoadedFolderContents
from Zope.App.OFS.Folder.LoadedFolder import LoadedFolder
class Document:
pass
class Test( unittest.TestCase ):
def testInfo( self ):
""" Do we get the correct information back from FolderContents? """
loadedfolder = LoadedFolder()
loadedsubfolder = LoadedFolder()
loadedfolder.setObject( 'loadedsubfolder', loadedsubfolder )
document = Document()
loadedfolder.setObject( 'document', document )
fc = LoadedFolderContents( loadedfolder )
info_list = fc.listContentInfo()
self.assertEquals( len( info_list ), 2 )
ids = map( lambda x: x['id'], info_list )
self.assert_( 'loadedsubfolder' in ids )
objects = map( lambda x: x['object'], info_list )
self.assert_( loadedsubfolder in objects )
titles = map( lambda x: x['title'], info_list )
self.assert_( 'loadedsubfolder' in titles )
urls = map( lambda x: x['url'], info_list )
self.assert_( 'loadedsubfolder' in urls )
self.failIf( filter( None, map( lambda x: x['icon'], info_list ) ) )
def testRemove( self ):
loadedfolder = LoadedFolder()
loadedsubfolder = LoadedFolder()
loadedfolder.setObject( 'loadedsubfolder', loadedsubfolder )
document = Document()
loadedfolder.setObject( 'document', document )
loadedfolder.setObject( 'document2', Document() )
fc = LoadedFolderContents( loadedfolder )
fc.remove( name='document2' )
info_list = fc.listContentInfo()
self.assertEquals( len( info_list ), 2 )
ids = map( lambda x: x['id'], info_list )
self.assert_( 'loadedsubfolder' in ids )
objects = map( lambda x: x['object'], info_list )
self.assert_( loadedsubfolder in objects )
titles = map( lambda x: x['title'], info_list )
self.assert_( 'loadedsubfolder' in titles )
urls = map( lambda x: x['url'], info_list )
self.assert_( 'loadedsubfolder' 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()