[CMF-checkins] CVS: CMF/CMFCore/tests - test_DirectoryView.py:1.4.4.1 test_FSPageTemplate.py:1.2.4.1 test_FSPythonScript.py:1.3.4.1 test_ActionInformation.py:1.2.10.1 test_ActionProviderBase.py:1.1.2.1 test_ActionsTool.py:1.2.10.1 test_CatalogTool.py:1.1.24.1 test_ContentTypeRegistry.py:1.6.32.1 test_Expression.py:1.2.10.1 test_PortalFolder.py:1.14.24.1 test_TypesTool.py:1.9.4.1 test_all.py:1.8.2.1

Shane Hathaway shane@cvs.zope.org
Wed, 20 Feb 2002 15:15:22 -0500


Update of /cvs-repository/CMF/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv27999/CMFCore/tests

Modified Files:
      Tag: cmf-pre-1_3-branch
	test_ActionInformation.py test_ActionProviderBase.py 
	test_ActionsTool.py test_CatalogTool.py 
	test_ContentTypeRegistry.py test_Expression.py 
	test_PortalFolder.py test_TypesTool.py test_all.py 
Added Files:
      Tag: cmf-pre-1_3-branch
	test_DirectoryView.py test_FSPageTemplate.py 
	test_FSPythonScript.py 
Log Message:
Merged changes from head, with a small change: the types tool does not need
to be extended in such a complex way.  I took out the type_type registry and
the __bobo_traverse__ hook and replaced it with the original code with only
minor mods that give you the same extensibility without all the hacking.
(If anyone actually wants to use the extensibility, which I suspect no one
is actually interested in doing, I will happily provide instructions and
will create a corrected unit test.)


=== Added File CMF/CMFCore/tests/test_DirectoryView.py ===
import Zope
from unittest import TestCase, TestSuite, makeSuite, main

from Products.CMFCore.tests.base.dummy import \
     DummyFolder

from Products.CMFCore.DirectoryView import \
     registerDirectory,addDirectoryViews,DirectoryViewSurrogate
from Globals import package_home, DevelopmentMode

from os import remove, mkdir, rmdir, curdir
from os.path import join, abspath, dirname
from shutil import copy2

try:
    __file__
except NameError:
    # Test was called directly, so no __file__ global exists.
    _prefix = abspath(curdir)
else:
    # Test was called by another test.
    _prefix = abspath(dirname(__file__))

# the path of our fake skin
skin_path_name = join(_prefix, 'fake_skins', 'fake_skin')

class DirectoryViewTests1( TestCase ):

    def test_registerDirectory( self ):
        """ Test registerDirectory  """
        registerDirectory('fake_skins', _prefix)

class DirectoryViewTests2( TestCase ):

    def setUp( self ):
        registerDirectory('fake_skins', _prefix)
        ob = self.ob = DummyFolder()
        addDirectoryViews(ob, 'fake_skins', _prefix)

    def test_addDirectoryViews( self ):
        """ Test addDirectoryViews  """
        pass

    def test_DirectoryViewExists( self ):
        """
        Check DirectoryView added by addDirectoryViews
        appears as a DirectoryViewSurrogate due
        to Acquisition hackery.
        """
        self.failUnless(isinstance(self.ob.fake_skin,DirectoryViewSurrogate))

    def test_DirectoryViewMethod( self ):
        """ Check if DirectoryView method works """
        self.assertEqual(self.ob.fake_skin.test1(),'test1')

test1path = join(skin_path_name,'test1.py')
test2path = join(skin_path_name,'test2.py')
test3path = join(skin_path_name,'test3')

if DevelopmentMode:

  class DebugModeTests( TestCase ):

    def setUp( self ):
        
        # initialise skins
        registerDirectory('fake_skins', _prefix)
        ob = self.ob = DummyFolder()
        addDirectoryViews(ob, 'fake_skins', _prefix)

        # add a method to the fake skin folder
        f = open(test2path,'w')
        f.write("return 'test2'")
        f.close()

        # edit the test1 method
        copy2(test1path,test1path+'.bak')
        f = open(test1path,'w')
        f.write("return 'new test1'")
        f.close()

        # add a new folder
        mkdir(test3path)
        
    def tearDown( self ):
        
        # undo FS changes
        remove(test1path)
        copy2(test1path+'.bak',test1path)
        remove(test1path+'.bak')
        try:        
            remove(test2path)
        except (IOError,OSError):
            # it might be gone already
            pass
        try:
            rmdir(test3path)
        except (IOError,OSError):
            # it might be gone already
            pass
        
    def test_AddNewMethod( self ):
        """
        See if a method added to the skin folder can be found
        """
        self.assertEqual(self.ob.fake_skin.test2(),'test2')

    def test_EditMethod( self ):
        """
        See if an edited method exhibits its new behaviour
        """
        self.assertEqual(self.ob.fake_skin.test1(),'new test1')

    def test_NewFolder( self ):
        """
        See if a new folder shows up
        """
        self.failUnless(isinstance(self.ob.fake_skin.test3,DirectoryViewSurrogate))
        self.ob.fake_skin.test3.objectIds()

    def test_DeleteMethod( self ):
        """
        Make sure a deleted method goes away
        """
        remove(test2path)
        try:
            self.ob.fake_skin.test2
        except AttributeError:
            pass
        else:
            self.fail('test2 still exists')

    def test_DeleteFolder( self ):
        """
        Make sure a deleted folder goes away
        """
        rmdir(test3path)
        try:
            self.ob.fake_skin.test3
        except AttributeError:
            pass
        else:
            self.fail('test3 still exists')

else:

    class DebugModeTests( TestCase ):
        pass

def test_suite():
    return TestSuite((
        makeSuite(DirectoryViewTests1),
        makeSuite(DirectoryViewTests2),
        makeSuite(DebugModeTests),
        ))

if __name__ == '__main__':
    main(defaultTest='test_suite')






=== Added File CMF/CMFCore/tests/test_FSPageTemplate.py ===
import Zope
from unittest import TestCase, TestSuite, makeSuite, main
from Products.CMFCore.FSPageTemplate import FSPageTemplate
from test_DirectoryView import skin_path_name
from os.path import join
from Testing.makerequest import makerequest
from Products.PageTemplates.TALES import Undefined

class FSPageTemplateTests( TestCase ):

    def test_Call( self ):
        """
        Test calling works
        """
        root = makerequest(Zope.app())
        script = FSPageTemplate('testPT', join(skin_path_name,'testPT.pt'))
        script = script.__of__(root)
        self.assertEqual(script(),'foo\n')

    def test_BadCall( self ):
        """
        Test calling a bad template gives an Undefined exception
        """
        root = makerequest(Zope.app())
        script = FSPageTemplate('testPT', join(skin_path_name,'testPTbad.pt'))
        script = script.__of__(root)
        self.assertRaises(Undefined,script)

def test_suite():
    return TestSuite((
        makeSuite(FSPageTemplateTests),
        ))

if __name__ == '__main__':
    main(defaultTest='test_suite')






=== Added File CMF/CMFCore/tests/test_FSPythonScript.py ===
import Zope
from unittest import TestCase, TestSuite, makeSuite, main
from Products.CMFCore.FSPythonScript import FSPythonScript
from test_DirectoryView import skin_path_name
from os.path import join

script_path = join(skin_path_name,'test1.py')

class FSPythonScriptTests( TestCase ):

    def test_GetSize( self ):
        """ Test get_size returns correct value """
        script = FSPythonScript('test1', script_path)
        self.assertEqual(len(script.read()),script.get_size())

def test_suite():
    return TestSuite((
        makeSuite(FSPythonScriptTests),
        ))

if __name__ == '__main__':
    main(defaultTest='test_suite')






=== CMF/CMFCore/tests/test_ActionInformation.py 1.2 => 1.2.10.1 ===
-from Products.CMFDefault.MembershipTool import *
-from Products.CMFCore.PortalContent import PortalContent
-from Products.CMFCore.ActionInformation import ActionInformation
-from Products.CMFCore.Expression import Expression, createExprContext
+import Zope
+from unittest import TestSuite, makeSuite, main
 
-class DummyMembershipTool:
-    def isAnonymousUser(self):
-        return 1
-  
-class DummyContent(PortalContent, OFS.SimpleItem.Item):
-    """
-    """
-    meta_type = 'Dummy'
-    url = 'foo_url'
+from Products.CMFCore.tests.base.testcase import \
+     TransactionalTest
 
-    def __init__(self, id, url=None):
-       self.url = url
+from Products.CMFCore.tests.base.dummy import \
+     DummyContent, DummyTool as DummyMembershipTool
 
-    def absolute_url(self):
-       return self.url
+from Products.CMFCore.ActionInformation import ActionInformation
+from Products.CMFCore.Expression import Expression, createExprContext
 
-class ActionInformationTests(unittest.TestCase):
+class ActionInformationTests(TransactionalTest):
     
     def setUp( self ):
-        get_transaction().begin()
-        self.connection = Zope.DB.open()
-        root = self.root = self.connection.root()[ 'Application' ]
+
+        TransactionalTest.setUp( self )
+
+        root = self.root
         root._setObject('portal', DummyContent('portal', 'url_portal'))
-        portal = self.portal = self.root.portal
+        portal = self.portal = root.portal
         portal.portal_membership = DummyMembershipTool()
         self.folder = DummyContent('foo', 'url_foo')
         self.object = DummyContent('bar', 'url_bar')
@@ -77,18 +68,10 @@
         ec = createExprContext(folder, portal, object)
         self.failIf(ai.testCondition(ec))
         
-    def tearDown( self ):
-        get_transaction().abort()
-        self.connection.close()
-        
-
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(ActionInformationTests))
-    return suite
-
-def run():
-    unittest.TextTestRunner().run(test_suite())
+    return TestSuite((
+        makeSuite(ActionInformationTests),
+        ))
 
 if __name__ == '__main__':
-    run()
+    main(defaultTest='test_suite')


=== CMF/CMFCore/tests/test_ActionProviderBase.py 1.1 => 1.1.2.1 ===
+import Zope
+from unittest import TestCase, TestSuite, makeSuite, main
 
-class DummyAction:
-    def __init__( self, **kw ):
-        self.__dict__.update( kw )
+from Products.CMFCore.tests.base.dummy import \
+     DummyTool
 
-class ActionProviderBaseTests(unittest.TestCase):
+from Products.CMFCore.ActionProviderBase import ActionProviderBase
+
+class ActionProviderBaseTests(TestCase):
     
     def _makeProvider( self ):
 
-        from Products.CMFCore.ActionProviderBase import ActionProviderBase
         return ActionProviderBase()
 
     def test_addAction( self ):
@@ -28,12 +29,6 @@
 
     def test_changeActions( self ):
 
-        from Products.CMFCore.ActionProviderBase import ActionProviderBase
-
-        class DummyTool( ActionProviderBase ):
-            _actions = [ DummyAction()
-                       , DummyAction()
-                       ]
 
         apb = DummyTool()
         old_actions = apb._actions
@@ -91,12 +86,9 @@
         self.assertEqual( apb._actions, ['1'] )
 
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(ActionProviderBaseTests))
-    return suite
-
-def run():
-    unittest.TextTestRunner().run(test_suite())
+    return TestSuite((
+        makeSuite(ActionProviderBaseTests),
+        ))
 
 if __name__ == '__main__':
-    run()
+    main(defaultTest='test_suite')


=== CMF/CMFCore/tests/test_ActionsTool.py 1.2 => 1.2.10.1 ===
-from Products.CMFCore.ActionsTool import *
-from Products.CMFDefault.URLTool import *
-import ZPublisher.HTTPRequest
+import Zope
+from unittest import TestCase,TestSuite,makeSuite,main
 
-class ActionsToolTests( unittest.TestCase ):
+from Products.CMFCore.tests.base.testcase import \
+     SecurityRequestTest
+
+from Products.CMFCore.ActionsTool import ActionsTool
+from Products.CMFCore.TypesTool import TypesTool
+from Products.CMFCore.PortalFolder import PortalFolder
+from Products.CMFDefault.URLTool import URLTool
+from Products.CMFDefault.RegistrationTool import RegistrationTool
+from Products.CMFDefault.MembershipTool import MembershipTool
+
+class ActionsToolTests( SecurityRequestTest ):
 
     def setUp( self ):
-        get_transaction().begin()
-        self.connection = Zope.DB.open()
-        root = self.root = self.connection.root()[ 'Application' ]
-
-        env = { 'SERVER_NAME' : 'http://localhost'
-              , 'SERVER_PORT' : '80'
-              }
-        root.REQUEST = ZPublisher.HTTPRequest.HTTPRequest( None, env, None )
         
+        SecurityRequestTest.setUp(self)
+        
+        root = self.root
         root._setObject( 'portal_actions', ActionsTool() )
         root._setObject('foo', URLTool() )
         self.tool = root.portal_actions
@@ -37,17 +40,55 @@
         self.assertEqual(tool.listActionProviders(),
                           ('portal_actions',))
 
-    def tearDown( self ):
-        get_transaction().abort()
-        self.connection.close()
+    def test_listActionInformationActions(self):
+        """
+        Check that listFilteredActionsFor works for objects
+        that return ActionInformation objects
+        """
+        root = self.root
+        tool = self.tool
+        root._setObject('portal_registration', RegistrationTool())
+        root._setObject('portal_membership', MembershipTool())
+        root._setObject('portal_types', TypesTool())
+        self.tool.action_providers = ('portal_actions','portal_registration')
+        self.assertEqual(tool.listFilteredActionsFor(root.portal_registration),
+                         {'workflow': [],
+                          'user': [],
+                          'object': [{'permissions': ('List folder contents',),
+                                      'id': 'folderContents',
+                                      'url': ' http://foo/folder_contents',
+                                      'name': 'Folder contents',
+                                      'visible': 1,
+                                      'category': 'object'}],
+                          'folder': [],
+                          'global': []})
+        
+    def test_listDictionaryActions(self):
+        """
+        Check that listFilteredActionsFor works for objects
+        that return dictionaries
+        """
+        root = self.root
+        tool = self.tool
+        root._setObject('donkey', PortalFolder('donkey'))
+        root._setObject('portal_membership', MembershipTool())
+        root._setObject('portal_types', TypesTool())
+        self.assertEqual(tool.listFilteredActionsFor(root.donkey),
+                         {'workflow': [],
+                          'user': [],
+                          'object': [],
+                          'folder': [{'permissions': ('List folder contents',),
+                                      'id': 'folderContents',
+                                      'url': ' http://foo/donkey/folder_contents',
+                                      'name': 'Folder contents',
+                                      'visible': 1,
+                                      'category': 'folder'}],
+                          'global': []})
 
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(ActionsToolTests))
-    return suite
-
-def run():
-    unittest.TextTestRunner().run(test_suite())
+    return TestSuite((
+        makeSuite(ActionsToolTests),
+        ))
 
 if __name__ == '__main__':
-    run()
+    main(defaultTest='test_suite')


=== CMF/CMFCore/tests/test_CatalogTool.py 1.1 => 1.1.24.1 ===
-import unittest
-import OFS.Folder, OFS.SimpleItem
-import Acquisition
-from Products.CMFCore.CatalogTool import *
-from Products.CMFCore.PortalContent import PortalContent
-
-
-class DummyContent( PortalContent, OFS.SimpleItem.Item ):
-    """
-    """
-    meta_type = 'Dummy'
-
-class CatalogToolTests( unittest.TestCase ):
-
-    def setUp( self ):
-        get_transaction().begin()
-    
-    def tearDown( self ):
-        get_transaction().abort()
+from unittest import TestCase, TestSuite, makeSuite, main
+
+from Products.CMFCore.tests.base.dummy import \
+     DummyContent
+
+from Products.CMFCore.CatalogTool import CatalogTool
+
+class CatalogToolTests( TestCase ):
 
     def test_processActions( self ):
         """
@@ -25,18 +14,15 @@
             argument, 'idxs', to 'catalog_object'.
         """
         tool = CatalogTool()
-        dummy = DummyContent()
+        dummy = DummyContent(catalog=1)
 
         tool.catalog_object( dummy, '/dummy' )
         tool.catalog_object( dummy, '/dummy', [ 'SearchableText' ] )
 
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest( unittest.makeSuite( CatalogToolTests ) )
-    return suite
-
-def run():
-    unittest.TextTestRunner().run(test_suite())
+    return TestSuite((
+        makeSuite( CatalogToolTests ),
+        ))
 
 if __name__ == '__main__':
-    run()
+    main(defaultTest='test_suite')


=== CMF/CMFCore/tests/test_ContentTypeRegistry.py 1.6 => 1.6.32.1 ===
-import unittest
-import re
-from Products.CMFCore.ContentTypeRegistry import *
+from unittest import TestCase, TestSuite, makeSuite, main
 
-class MajorMinorPredicateTests( unittest.TestCase ):
 
-    def setUp( self ):
-        get_transaction().begin()
+from Products.CMFCore.ContentTypeRegistry import ContentTypeRegistry
+from Products.CMFCore.ContentTypeRegistry import MajorMinorPredicate
+from Products.CMFCore.ContentTypeRegistry import ExtensionPredicate
+from Products.CMFCore.ContentTypeRegistry import NameRegexPredicate
+from Products.CMFCore.ContentTypeRegistry import MimeTypeRegexPredicate
 
-    def tearDown( self ):
-        get_transaction().abort()
+class MajorMinorPredicateTests( TestCase ):
 
     def test_empty( self ):
         pred = MajorMinorPredicate( 'empty' )
@@ -43,13 +42,7 @@
         assert pred( 'foo', 'text/html', 'asdfljksadf' )
         assert not pred( 'foo', 'image/png', 'asdfljksadf' )
 
-class ExtensionPredicateTests( unittest.TestCase ):
-
-    def setUp( self ):
-        get_transaction().begin()
-
-    def tearDown( self ):
-        get_transaction().abort()
+class ExtensionPredicateTests( TestCase ):
 
     def test_empty( self ):
         pred = ExtensionPredicate( 'empty' )
@@ -77,13 +70,7 @@
         assert pred( 'foo.htm', 'text/plain', 'asdfljksadf' )
         assert not pred( 'foo.bar', 'text/html', 'asdfljksadf' )
 
-class MimeTypeRegexPredicateTests( unittest.TestCase ):
-
-    def setUp( self ):
-        get_transaction().begin()
-
-    def tearDown( self ):
-        get_transaction().abort()
+class MimeTypeRegexPredicateTests( TestCase ):
 
     def test_empty( self ):
         pred = MimeTypeRegexPredicate( 'empty' )
@@ -105,13 +92,7 @@
         assert pred( 'foo', 'text/html', 'asdfljksadf' )
         assert not pred( 'foo', 'image/png', 'asdfljksadf' )
     
-class NameRegexPredicateTests( unittest.TestCase ):
-
-    def setUp( self ):
-        get_transaction().begin()
-
-    def tearDown( self ):
-        get_transaction().abort()
+class NameRegexPredicateTests( TestCase ):
 
     def test_empty( self ):
         pred = NameRegexPredicate( 'empty' )
@@ -134,16 +115,13 @@
         assert pred( 'fargo', 'text/plain', 'asdfljksadf' )
         assert not pred( 'bar', 'text/plain', 'asdfljksadf' )
     
-class ContentTypeRegistryTests( unittest.TestCase ):
+class ContentTypeRegistryTests( TestCase ):
 
     def setUp( self ):
-        get_transaction().begin()
-
-    def tearDown( self ):
-        get_transaction().abort()
+        self.reg = ContentTypeRegistry()
 
     def test_empty( self ):
-        reg = ContentTypeRegistry()
+        reg=self.reg
         assert reg.findTypeName( 'foo', 'text/plain', 'asdfljksadf' ) is None
         assert reg.findTypeName( 'fargo', 'text/plain', 'asdfljksadf' ) is None
         assert reg.findTypeName( 'bar', 'text/plain', 'asdfljksadf' ) is None
@@ -151,7 +129,7 @@
         self.assertRaises( KeyError, reg.removePredicate, 'xyzzy' )
     
     def test_reorder( self ):
-        reg = ContentTypeRegistry()
+        reg=self.reg
         predIDs = ( 'foo', 'bar', 'baz', 'qux' )
         for predID in predIDs:
             reg.addPredicate( predID, 'name_regex' )
@@ -162,7 +140,7 @@
         assert ids == ( 'foo', 'baz', 'qux', 'bar' )
 
     def test_lookup( self ):
-        reg = ContentTypeRegistry()
+        reg=self.reg
         reg.addPredicate( 'image', 'major_minor' )
         reg.getPredicate( 'image' ).edit( 'image', '' )
         reg.addPredicate( 'onlyfoo', 'name_regex' )
@@ -175,16 +153,13 @@
         assert reg.findTypeName( 'foo', None, None ) == 'Foo'
 
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest( unittest.makeSuite( MajorMinorPredicateTests ) )
-    suite.addTest( unittest.makeSuite( ExtensionPredicateTests ) )
-    suite.addTest( unittest.makeSuite( MimeTypeRegexPredicateTests ) )
-    suite.addTest( unittest.makeSuite( NameRegexPredicateTests ) )
-    suite.addTest( unittest.makeSuite( ContentTypeRegistryTests ) )
-    return suite
-
-def run():
-    unittest.TextTestRunner().run(test_suite())
+    return TestSuite((
+        makeSuite( MajorMinorPredicateTests ),
+        makeSuite( ExtensionPredicateTests ),
+        makeSuite( MimeTypeRegexPredicateTests ),
+        makeSuite( NameRegexPredicateTests ),
+        makeSuite( ContentTypeRegistryTests ),
+        ))
 
 if __name__ == '__main__':
-    run()
+    main(defaultTest='test_suite')


=== CMF/CMFCore/tests/test_Expression.py 1.2 => 1.2.10.1 ===
-from AccessControl.SecurityManagement import newSecurityManager
-from AccessControl.SecurityManagement import noSecurityManager
-from AccessControl import SecurityManager
-from Products.CMFCore.ActionsTool import *
-from Products.CMFCore.ActionInformation import ActionInformation
-from Products.CMFCore.PortalContent import PortalContent
-from Products.CMFCore.Expression import Expression, createExprContext
-import ZPublisher.HTTPRequest
+import Zope
+from unittest import TestSuite, makeSuite, main
+
+from Products.CMFCore.tests.base.testcase import \
+     SecurityTest
 
-class PermissiveSecurityPolicy:
-    """
-        Stub out the existing security policy for unit testing purposes.
-    """
-    #
-    #   Standard SecurityPolicy interface
-    #
-    def validate( self
-                , accessed=None
-                , container=None
-                , name=None
-                , value=None
-                , context=None
-                , roles=None
-                , *args
-                , **kw):
-        return 1
-    
-    def checkPermission( self, permission, object, context) :
-        if permission == 'forbidden permission':
-            return 0
-        return 1
-
-class UnitTestUser( Acquisition.Implicit ):
-    """
-        Stubbed out manager for unit testing purposes.
-    """
-    def getId( self ):
-        return 'unit_tester'
-    
-    getUserName = getId
-
-    def allowed( self, object, object_roles=None ):
-        # for testing permissions on actions
-        if object.getId() == 'actions_dummy':
-            if 'Anonymous' in object_roles:
-                return 1
-            else:
-                return 0
-        return 1
-
-class DummyMembershipTool:
-    def __init__(self, anon=1):
-        self.anon = anon 
-
-    def isAnonymousUser(self):
-        return self.anon 
-
-    def getAuthenticatedMember(self):
-        return "member"
-  
-class DummyContent(PortalContent, OFS.SimpleItem.Item):
-    """
-    """
-    meta_type = 'Dummy'
-    url = 'foo_url'
-
-    def __init__(self, id, url=None):
-       self.id = id
-       self.url = url
+from Products.CMFCore.tests.base.dummy import \
+     DummyContent, DummyTool as DummyMembershipTool
 
-    def absolute_url(self):
-       return self.url
+from Products.CMFCore.ActionInformation import ActionInformation
+from Products.CMFCore.Expression import Expression, createExprContext
 
-class ExpressionTests( unittest.TestCase ):
+class ExpressionTests( SecurityTest ):
 
     def setUp( self ):
-        get_transaction().begin()
-        self._policy = PermissiveSecurityPolicy()
-        self._oldPolicy = SecurityManager.setSecurityPolicy(self._policy)
-        self.connection = Zope.DB.open()
-        root = self.root = self.connection.root()[ 'Application' ]
-        newSecurityManager(None, UnitTestUser().__of__( self.root ))
-        root._setObject('portal', DummyContent('portal', 'url_portal'))
-        portal = self.portal = self.root.portal
-        self.folder = DummyContent('foo', 'url_foo')
-        self.object = DummyContent('bar', 'url_bar')
+        
+        SecurityTest.setUp(self)
+        root = self.root
+        root._setObject('portal', DummyContent('portal', url='url_portal'))
+        portal = self.portal = root.portal
+        self.folder = DummyContent('foo', url='url_foo')
+        self.object = DummyContent('bar', url='url_bar')
         self.ai = ActionInformation(id='view'
                                   , title='View'
                                   , action=Expression(
@@ -123,21 +58,10 @@
         self.assertEqual(folder.id, 'foo')
         self.assertEqual(folder.absolute_url(), 'url_foo')
         
-
-
-    def tearDown( self ):
-        get_transaction().abort()
-        self.connection.close()
-        noSecurityManager()
-        SecurityManager.setSecurityPolicy(self._oldPolicy)
-
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(ExpressionTests))
-    return suite
-
-def run():
-    unittest.TextTestRunner().run(test_suite())
+    return TestSuite((
+        makeSuite(ExpressionTests),
+        ))
 
 if __name__ == '__main__':
-    run()
+    main(defaultTest='test_suite')


=== CMF/CMFCore/tests/test_PortalFolder.py 1.14 => 1.14.24.1 === (451/551 lines abridged)
-import unittest
-import re, new
-import OFS.Folder, OFS.SimpleItem
-from AccessControl import SecurityManager
-from AccessControl.SecurityManagement import newSecurityManager
-import Acquisition
-from DateTime import DateTime
-from Products.CMFCore.TypesTool import TypesTool, FactoryTypeInformation
-from Products.CMFCore.CatalogTool import CatalogTool
-from Products.CMFCore.PortalContent import PortalContent
-from Products.CMFCore.PortalFolder import *
-
-class UnitTestSecurityPolicy:
-    """
-        Stub out the existing security policy for unit testing purposes.
-    """
-    #
-    #   Standard SecurityPolicy interface
-    #
-    def validate( self
-                , accessed=None
-                , container=None
-                , name=None
-                , value=None
-                , context=None
-                , roles=None
-                , *args
-                , **kw):
-        return 1
-    
-    def checkPermission( self, permission, object, context) :
-        return 1
-
-class UnitTestUser( Acquisition.Implicit ):
-    """
-        Stubbed out manager for unit testing purposes.
-    """
-    def getId( self ):
-        return 'unit_tester'
-    
-    getUserName = getId
-
-    def allowed( self, object, object_roles=None ):
-        return 1
+from unittest import TestCase, TestSuite, makeSuite, main
 
-class DummyContent( PortalContent, OFS.SimpleItem.Item ):
-    """
-    """
-    meta_type = 'Dummy'

[-=- -=- -=- 451 lines omitted -=- -=- -=-]

+                               , modified_usage='range:max' )        
+        dummy = self.dummy
         assert not cfilter( dummy )
         dummy.modified_date = DateTime( '2000/12/31' )
         assert cfilter( dummy )
@@ -627,7 +472,7 @@
         dummy.modified_date = DateTime( '2001/01/01' )
         assert cfilter( dummy )
         desc = str( cfilter )
-        lines = string.split( desc, '; ' )
+        lines = desc.split('; ')
         assert len( lines ) == 1
         assert lines[0] == 'Modified before: 2001/01/01'
  
@@ -637,7 +482,7 @@
                                , Title='foo'
                                )
 
-        dummy = DummyContentWithMetadata( 'Dummy' )
+        dummy = self.dummy
         assert not cfilter( dummy )
         dummy.created_date = DateTime( '2000/12/31' )
         assert not cfilter( dummy )
@@ -657,20 +502,16 @@
         assert cfilter( dummy )
 
         desc = str( cfilter )
-        lines = string.split( desc, '; ' )
+        lines = desc.split('; ')
         assert len( lines ) == 2, lines
         assert 'Created before: 2001/01/01' in lines
         assert 'Title: foo' in lines
 
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest( unittest.makeSuite( PortalFolderTests ) )
-    suite.addTest( unittest.makeSuite( PortalFolderPermissionTests ) )
-    suite.addTest( unittest.makeSuite( ContentFilterTests ) )
-    return suite
-
-def run():
-    unittest.TextTestRunner().run(test_suite())
+    return TestSuite((
+        makeSuite( PortalFolderTests ),
+        makeSuite( ContentFilterTests ),
+        ))
 
 if __name__ == '__main__':
-    run()
+    main(defaultTest='test_suite')


=== CMF/CMFCore/tests/test_TypesTool.py 1.9 => 1.9.4.1 ===
-import unittest
-import OFS.Folder, OFS.SimpleItem
-import Acquisition
-from AccessControl.SecurityManagement import newSecurityManager
-from AccessControl.SecurityManagement import noSecurityManager
-from AccessControl import SecurityManager
-from Products.CMFCore.TypesTool import *
-from Products.CMFCore.PortalContent import PortalContent
-from Products.CMFCore.CMFCorePermissions import AddPortalContent
-from Products.CMFCore.CMFCorePermissions import ModifyPortalContent
-from Products.CMFCore.PortalFolder import *
-from Products.CMFCore import utils
-import ZPublisher.HTTPRequest
-
-class PermissiveSecurityPolicy:
-    """
-        Stub out the existing security policy for unit testing purposes.
-    """
-    #
-    #   Standard SecurityPolicy interface
-    #
-    def validate( self
-                , accessed=None
-                , container=None
-                , name=None
-                , value=None
-                , context=None
-                , roles=None
-                , *args
-                , **kw):
-        return 1
-    
-    def checkPermission( self, permission, object, context) :
-        if permission == 'forbidden permission':
-            return 0
-        return 1
-
-class OmnipotentUser( Acquisition.Implicit ):
-    """
-        Stubbed out manager for unit testing purposes.
-    """
-    def getId( self ):
-        return 'all_powerful_Oz'
-    
-    getUserName = getId
-
-    def allowed( self, object, object_roles=None ):
-        return 1
+from unittest import TestCase, TestSuite, makeSuite, main
 
-class UserWithRoles( Acquisition.Implicit ):
-    """
-        Stubbed out manager for unit testing purposes.
-    """
-    def __init__( self, *roles ):
-        self._roles = roles
+from Products.CMFCore.TypesTool import\
+     FactoryTypeInformation as FTI,\
+     ScriptableTypeInformation as STI,\
+     TypesTool,Unauthorized
+
+from Products.CMFCore.PortalFolder import PortalFolder
+from Products.CMFCore.utils import _getViewFor
+
+from Products.CMFCore.tests.base.testcase import \
+     SecurityRequestTest
+from Products.CMFCore.tests.base.security import \
+     OmnipotentUser, UserWithRoles
+from Products.CMFCore.tests.base.dummy import \
+     DummyObject, addDummy, DummyTypeInfo,\
+     DummyFolder, DummyFTI
 
-    def getId( self ):
-        return 'high_roller'
-    
-    getUserName = getId
-
-    def allowed( self, object, object_roles=None ):
-        for orole in object_roles:
-            if orole in self._roles:
-                return 1
-        return 0
-
-class UnitTestUser( Acquisition.Implicit ):
-    """
-        Stubbed out manager for unit testing purposes.
-    """
-    def getId( self ):
-        return 'unit_tester'
-    
-    getUserName = getId
+from AccessControl.SecurityManagement import newSecurityManager
+from AccessControl.SecurityManagement import noSecurityManager
 
-    def has_permission(self, permission, obj):
-        # For types tool tests dealing with filtered_meta_types
-        return 1
-
-    def allowed( self, object, object_roles=None ):
-        # for testing permissions on actions
-        if object.getId() == 'actions_dummy':
-            if 'Anonymous' in object_roles:
-                return 1
-            else:
-                return 0
-        return 1
-
-class DummyMethod:
-    def __init__(self, name):
-        self.name = name
-    def __str__(self):
-        return self.name
-    def __call__(self):
-        return self.name
-
-class DummyContent( PortalContent, OFS.SimpleItem.Item ):
-    """
-    """
-    meta_type = 'Dummy'
-
-def addDummy( self, id ):
-    """
-    """
-    self._setObject( id, DummyContent() )
-
-def extra_meta_types():
-    return (  { 'name' : 'Dummy', 'action' : 'manage_addFolder' }, )
-
-class DummyTypeInfo(TypeInformation):
-    """ new class of type info object """
-    meta_type = "Dummy Test Type Info"
+from Products.PythonScripts.standard import url_quote
+from webdav.NullResource import NullResource
+from Acquisition import aq_base
 
-class TypesToolTests( unittest.TestCase ):
+class TypesToolTests( SecurityRequestTest ):
 
     def setUp( self ):
-        get_transaction().begin()
-        self._policy = PermissiveSecurityPolicy()
-        self._oldPolicy = SecurityManager.setSecurityPolicy(self._policy)
-        self.connection = Zope.DB.open()
-        root = self.root = self.connection.root()[ 'Application' ]
-        newSecurityManager( None, UnitTestUser().__of__( self.root ) )
-
-        env = { 'SERVER_NAME' : 'http://localhost'
-              , 'SERVER_PORT' : '80'
-              }
-        root.REQUEST = ZPublisher.HTTPRequest.HTTPRequest( None, env, None )
-        
+        SecurityRequestTest.setUp(self)
+        root = self.root
         root.addDummy = addDummy
 
         root._setObject( 'portal_types', TypesTool() )
         tool = root.portal_types
-        FTI = FactoryTypeInformation
-        tool._setObject( 'Dummy'
-                       , FTI( 'Dummy'
-                            , meta_type=DummyContent.meta_type
-                            , product='CMFDefault'
-                            , factory='addDocument'
-                            , actions= ( { 'name'          : 'View'
-                                           , 'action'        : 'view'
-                                           , 'permissions'   : ('View', ) },
-                                         { 'name'          : 'View2'
-                                           , 'action'        : 'view2'
-                                           , 'permissions'   : ('View', ) },
-                                         { 'name'          : 'Edit'
-                                           , 'action'        : 'edit'
-                                           , 'permissions'   : ('forbidden permission',)
-                                           }
-                                         )
-                              )
-                         )
+        tool._setObject( 'Dummy', DummyFTI ) 
     
-    def tearDown( self ):
-        get_transaction().abort()
-        self.connection.close()
-        noSecurityManager()
-        SecurityManager.setSecurityPolicy(self._oldPolicy)
-
-    def off_test_otherFolderTypes( self ):
-        """
-            Does 'invokeFactory' work when invoked from non-PortalFolder?
-            Currently tests a bug which hasn't been fixed (remove 'off_'
-            from name to activate)            
-        """
-        self.root._setObject( 'portal', PortalFolder( 'portal', '' ) )
-        portal = self.root.portal
-        portal._setObject( 'normal', OFS.Folder.Folder( 'normal', '' ) )
-        normal = portal.normal
-        normal.invokeFactory( 'Dummy', 'dummy' )
-        assert 'dummy' not in portal.objectIds()
-        assert 'dummy' in normal.objectIds()
-
     def test_processActions( self ):
         """
         Are the correct, permitted methods returned for actions?
@@ -182,44 +45,39 @@
         dummy = portal._getOb( 'actions_dummy' )
 
         # so we can traverse to it:
-        dummy.view = DummyMethod("view")
-        dummy.view2 = DummyMethod("view2")
-        dummy.edit = DummyMethod("edit")
+        dummy.view = DummyObject("view")
+        dummy.view2 = DummyObject("view2")
+        dummy.edit = DummyObject("edit")
 
         default_view = dummy()
-        custom_view = utils._getViewFor( dummy, view='view2' )()
-        unpermitted_view = utils._getViewFor( dummy, view='edit' )()
+        custom_view = _getViewFor( dummy, view='view2' )()
+        unpermitted_view = _getViewFor( dummy, view='edit' )()
 
         self.failUnlessEqual(default_view, 'view')
         self.failUnlessEqual(custom_view, 'view2')
         self.failIf(unpermitted_view == 'edit')
         self.failUnlessEqual(unpermitted_view, 'view')
 
-    def test_AddingOtherTypeInfos(self):
-        addTypeFactory(DummyTypeInfo)
+    def test_allMetaTypes(self):
+        """
+        Test that everything returned by allMetaTypes can be
+        traversed to.
+        """
         tool = self.root.portal_types
-        type_type = DummyTypeInfo.meta_type
-
-        fmt = [ mt['name'] for mt in tool.filtered_meta_types() ]
-        self.failUnless(DummyTypeInfo.meta_type in fmt,
-                        "Subfactory meta type not registered")
-
-        atif = tool.manage_addTypeInfoForm(self.root.REQUEST,
-                                           type_type=type_type)
-        self.failUnless(atif.find(type_type) > -1,
-                        "'%s' not found in type info form" % type_type)
-
-        tool.manage_addTypeInformation(id='foo_default', type_type=None)
-        fd = tool.foo_default
-        self.failUnless(isinstance(fd, FactoryTypeInformation))
-        self.failIf(isinstance(fd, DummyTypeInfo))
-
-        tool.manage_addTypeInformation(id='foo_sub', type_type=type_type)
-        fs = tool.foo_sub
-        self.failUnless(isinstance(fs, DummyTypeInfo), fs.__class__)
-        
+        meta_types={}
+        # Seems we get NullResource if the method couldn't be traverse to
+        # so we check for that. If we've got it, something is b0rked.
+        for factype in tool.all_meta_types():
+            meta_types[factype['name']]=1
+            # The url_quote below is necessary 'cos of the one in
+            # main.dtml. Could be removed once that is gone.
+            self.failIf(type(aq_base(tool.unrestrictedTraverse(url_quote(factype['action'])))) is NullResource)
+
+        # Check the ones we're expecting are there
+        self.failUnless(meta_types.has_key('Scriptable Type Information'))
+        self.failUnless(meta_types.has_key('Factory-based Type Information'))
 
-class TypeInfoTests( unittest.TestCase ):
+class TypeInfoTests( TestCase ):
     
     def test_construction( self ):
         ti = self._makeInstance( 'Foo'
@@ -239,16 +97,46 @@
                                )
         self.assertEqual( ti.immediate_view, 'foo_view' )
 
+    def _makeAndSetInstance( self,id,**kw ):
+        tool = self.tool
+        t = apply( self._makeInstance, (id,), kw )
+        tool._setObject(id,t)
+        return tool[id]
+              
     def test_allowType( self ):
-        ti = self._makeInstance( 'Foo' )
+        self.tool = TypesTool()        
+        ti = self._makeAndSetInstance( 'Foo' )
         self.failIf( ti.allowType( 'Foo' ) )
         self.failIf( ti.allowType( 'Bar' ) )
 
-        ti = self._makeInstance( 'Foo', allowed_content_types=( 'Bar', ) )
+        ti = self._makeAndSetInstance( 'Foo2', allowed_content_types=( 'Bar', ) )
         self.failUnless( ti.allowType( 'Bar' ) )
 
-        ti = self._makeInstance( 'Foo', filter_content_types=0 )
-        self.failUnless( ti.allowType( 'Foo' ) )
+        ti = self._makeAndSetInstance( 'Foo3', filter_content_types=0 )
+        self.failUnless( ti.allowType( 'Foo3' ) )
+
+    
+    def test_GlobalHide( self ):
+        self.tool = TypesTool()        
+        tnf = self._makeAndSetInstance( 'Folder', filter_content_types=0)
+        taf = self._makeAndSetInstance( 'Allowing Folder',
+                                  allowed_content_types=('Hidden','Not Hidden'))
+        tih = self._makeAndSetInstance( 'Hidden'     ,global_allow=0)
+        tnh = self._makeAndSetInstance( 'Not Hidden')
+        # make sure we're normally hidden but everything else is visible
+        self.failIf     ( tnf.allowType( 'Hidden' ) )
+        self.failUnless ( tnf.allowType( 'Not Hidden') )
+        # make sure we're available where we should be
+        self.failUnless ( taf.allowType( 'Hidden' ) )
+        self.failUnless ( taf.allowType( 'Not Hidden') )
+        # make sure we're available in a non-content-type-filtered type
+        # where we have been explicitly allowed
+        taf2 = self._makeAndSetInstance( 'Allowing Folder2',
+                                   allowed_content_types=('Hidden','Not Hidden'),
+                                   filter_content_types=0)
+        self.failUnless ( taf2.allowType( 'Hidden' ) )
+        self.failUnless ( taf2.allowType( 'Not Hidden') )
+        
 
     def test_allowDiscussion( self ):
         ti = self._makeInstance( 'Foo' )
@@ -343,12 +231,12 @@
         
         action = ti.getActionById( 'slot' )
         self.assertEqual( action, 'foo_slot' )
-
+        
 
 class FTIDataTests( TypeInfoTests ):
 
     def _makeInstance( self, id, **kw ):
-        return apply( FactoryTypeInformation, ( id, ), kw )
+        return apply( FTI, ( id, ), kw )
 
     def test_properties( self ):
         ti = self._makeInstance( 'Foo' )
@@ -366,7 +254,7 @@
 class STIDataTests( TypeInfoTests ):
 
     def _makeInstance( self, id, **kw ):
-        return apply( ScriptableTypeInformation, ( id, ), kw )
+        return apply( STI, ( id, ), kw )
 
     def test_properties( self ):
         ti = self._makeInstance( 'Foo' )
@@ -380,63 +268,16 @@
         self.assertEqual( ti.permission, 'Add Foos' )
         self.assertEqual( ti.constructor_path, 'foo_add' )
 
-
-class Foo:
-    """
-        Shim content object.
-    """
-    def __init__( self, id, *args, **kw ):
-        self.id = id
-        self._args = args
-        self._kw = {}
-        self._kw.update( kw )
-
-class FauxFactory:
-    """
-        Shim product factory.
-    """
-    def __init__( self, folder ):
-        self._folder = folder
-
-    def addFoo( self, id, *args, **kw ):
-        if self._folder._prefix:
-            id = '%s_%s' % ( self._folder._prefix, id )
-        foo = apply( Foo, ( id, ) + args, kw )
-        self._folder._setOb( id, foo )
-        if self._folder._prefix:
-            return id
-
-    __roles__ = ( 'FooAdder', )
-    __allow_access_to_unprotected_subobjects__ = { 'addFoo' : 1 }
-
-class FauxFolder( Acquisition.Implicit ):
-    """
-        Shim container
-    """
-    def __init__( self, fake_product=0, prefix='' ):
-        self._prefix = prefix
-
-        if fake_product:
-            self.manage_addProduct = { 'FooProduct' : FauxFactory( self ) }
-
-        self._objects = {}
-
-    def _setOb( self, id, obj ):
-        self._objects[id] = obj
-
-    def _getOb( self, id ):
-        return self._objects[id]
-
-class FTIConstructionTests( unittest.TestCase ):
+class FTIConstructionTests( TestCase ):
 
     def setUp( self ):
         noSecurityManager()
 
     def _makeInstance( self, id, **kw ):
-        return apply( FactoryTypeInformation, ( id, ), kw )
+        return apply( FTI, ( id, ), kw )
 
     def _makeFolder( self, fake_product=0 ):
-        return FauxFolder( fake_product )
+        return DummyFolder( fake_product )
 
     def test_isConstructionAllowed_wo_Container( self ):
 
@@ -478,18 +319,18 @@
         self.assertRaises( Unauthorized, ti.isConstructionAllowed
                          , folder, raise_exc=1 )
 
-class FTIConstructionTests_w_Roles( unittest.TestCase ):
+class FTIConstructionTests_w_Roles( TestCase ):
 
     def tearDown( self ):
         noSecurityManager()
 
     def _makeStuff( self, prefix='' ):
 
-        ti = FactoryTypeInformation( 'Foo'
-                                   , product='FooProduct'
-                                   , factory='addFoo'
-                                   )
-        folder = FauxFolder( fake_product=1, prefix=prefix )
+        ti = FTI( 'Foo'
+                  , product='FooProduct'
+                  , factory='addFoo'
+                  )
+        folder = DummyFolder( fake_product=1,prefix=prefix )
         
         return ti, folder
 
@@ -573,18 +414,14 @@
         self.assertEqual( majyk_dust.id, 'majyk_dust' )
 
 
-
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest( unittest.makeSuite( TypesToolTests ) )
-    suite.addTest( unittest.makeSuite( FTIDataTests ) )
-    suite.addTest( unittest.makeSuite( STIDataTests ) )
-    suite.addTest( unittest.makeSuite( FTIConstructionTests ) )
-    suite.addTest( unittest.makeSuite( FTIConstructionTests_w_Roles ) )
-    return suite
-
-def run():
-    unittest.TextTestRunner().run(test_suite())
+    return TestSuite((
+        makeSuite(TypesToolTests),
+        makeSuite(FTIDataTests),
+        makeSuite(STIDataTests),
+        makeSuite(FTIConstructionTests),
+        makeSuite(FTIConstructionTests_w_Roles),
+        ))
 
 if __name__ == '__main__':
-    run()
+    main(defaultTest='test_suite')


=== CMF/CMFCore/tests/test_all.py 1.8 => 1.8.2.1 ===
-import unittest
-from Products.CMFCore.tests import test_ContentTypeRegistry
-from Products.CMFCore.tests import test_PortalFolder
-from Products.CMFCore.tests import test_TypesTool
-from Products.CMFCore.tests import test_ActionsTool
-from Products.CMFCore.tests import test_ActionInformation
-from Products.CMFCore.tests import test_ActionProviderBase
-from Products.CMFCore.tests import test_Expression
-from Products.CMFCore.tests import test_CatalogTool
+from unittest import main
+from Products.CMFCore.tests.base.utils import build_test_suite
 
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest( test_ContentTypeRegistry.test_suite() )
-    suite.addTest( test_PortalFolder.test_suite() )
-    suite.addTest( test_TypesTool.test_suite() )
-    suite.addTest( test_ActionsTool.test_suite()  )
-    suite.addTest( test_ActionInformation.test_suite() )
-    suite.addTest( test_ActionProviderBase.test_suite() )
-    suite.addTest( test_Expression.test_suite() )
-    suite.addTest( test_CatalogTool.test_suite() )
-    return suite
 
-def run():
-    if hasattr( unittest, 'JUnitTextTestRunner' ):
-        unittest.JUnitTextTestRunner().run( test_suite() )
-    else:
-        unittest.TextTestRunner( verbosity=1 ).run( test_suite() )
+    return build_test_suite('Products.CMFCore.tests',[
+        'test_ContentTypeRegistry',
+        'test_PortalFolder',
+        'test_TypesTool',
+        'test_ActionsTool',
+        'test_ActionInformation',
+        'test_ActionProviderBase',
+        'test_Expression',
+        'test_CatalogTool',
+        'test_DirectoryView',
+        'test_FSPythonScript',
+        'test_FSPageTemplate'
+        ])
 
 if __name__ == '__main__':
-    run()
+    main(defaultTest='test_suite')