[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/tests - testFolderAdder.py:1.1.2.1

Tres Seaver tseaver@zope.com
Tue, 20 Nov 2001 17:54:45 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/tests
In directory cvs.zope.org:/tmp/cvs-serv2541/lib/python/Zope/App/OFS/tests

Added Files:
      Tag: Zope-3x-branch
	testFolderAdder.py 
Log Message:
 - Yeehaw!  FolderAdder works!

=== Added File Zope3/lib/python/Zope/App/OFS/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.FolderAdder import FolderAdder
from Zope.App.OFS.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 Test( 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 )



def test_suite():
    loader = unittest.TestLoader()
    return loader.loadTestsFromTestCase( Test )

if __name__=='__main__':
    unittest.main()