[CMF-checkins] CVS: CMF/CMFDefault/tests - test_Discussions.py:1.10 test_Document.py:1.22 test_Favorite.py:1.3 test_Image.py:1.4 test_Link.py:1.5 test_MetadataTool.py:1.3 test_NewsItem.py:1.5 test_all.py:1.11 test_join.py:1.4 test_utils.py:1.5 utils.py:NONE

Chris Withers chrisw@nipltd.com
Fri, 15 Feb 2002 14:46:05 -0500


Update of /cvs-repository/CMF/CMFDefault/tests
In directory cvs.zope.org:/tmp/cvs-serv10707/CMFDefault/tests

Modified Files:
	test_Discussions.py test_Document.py test_Favorite.py 
	test_Image.py test_Link.py test_MetadataTool.py 
	test_NewsItem.py test_all.py test_join.py test_utils.py 
Removed Files:
	utils.py 
Log Message:
The unit tests hopefully smell better now. Please try and keep them this way. Look in CMFCore/tests/base for commonly used artifacts.

=== CMF/CMFDefault/tests/test_Discussions.py 1.9 => 1.10 ===
-import unittest, string
+from unittest import TestSuite, makeSuite, main
 
-from AccessControl import SecurityManager
-from Acquisition import aq_base, aq_inner
+from Products.CMFCore.tests.base.testcase import \
+     SecurityTest
+
+from Products.CMFCore.tests.base.utils import \
+     has_path
+
+from Products.CMFCore.tests.base.dummy import \
+     DummyFTI
 
 from Products.CMFCore.CatalogTool import CatalogTool
-from Products.CMFCore.TypesTool import TypesTool, FactoryTypeInformation
+from Products.CMFCore.TypesTool import TypesTool
 from Products.CMFCore.WorkflowTool import WorkflowTool
 
-from Products.CMFDefault.DiscussionTool import DiscussionTool\
-                                             , DiscussionNotAllowed
+from Products.CMFDefault.DiscussionTool import \
+     DiscussionTool, DiscussionNotAllowed
 
 from Products.CMFDefault.Document import Document
 from Products.CMFDefault.URLTool import URLTool
 
-class UnitTestSecurityPolicy:
-    """
-        Stub out the existing security policy for unit testing purposes.
-    """
-    #
-    #   Standard SecurityPolicy interface
-    #
-    def validate( self, accessed, container, name, value, context, roles,
-                 *args, **kw ):
-        return 1
-    
-    def checkPermission( self, permission, object, context ) :
-        return 1
-
-
-class DiscussionTests( unittest.TestCase ):
+class DiscussionTests( SecurityTest ):
 
     def setUp( self ):
-        get_transaction().begin()
-        self._policy = UnitTestSecurityPolicy()
-        self._oldPolicy = SecurityManager.setSecurityPolicy(self._policy)
-        self.connection = Zope.DB.open()
-        self.root = root = self.connection.root()[ 'Application' ]
-        self.root._setObject( 'portal_discussion', DiscussionTool() )
-        self.discussion_tool = self.root.portal_discussion
-        self.root._setObject( 'portal_catalog', CatalogTool() )
-        self.catalog_tool = self.root.portal_catalog
-        self.root._setObject( 'portal_url', URLTool() )
-        self.url_tool = self.root.portal_url
-        self.root._setObject( 'portal_workflow', WorkflowTool() ) 
-        self.workflow_tool = self.root.portal_workflow
-        self.root._setObject( 'portal_types', TypesTool() )
-        types_tool = self.types_tool = self.root.portal_types
+        
+        SecurityTest.setUp(self)
+        
+        root = self.root
+        root._setObject( 'portal_discussion', DiscussionTool() )
+        self.discussion_tool = root.portal_discussion
+        root._setObject( 'portal_catalog', CatalogTool() )
+        self.catalog_tool = root.portal_catalog
+        root._setObject( 'portal_url', URLTool() )
+        self.url_tool = root.portal_url
+        root._setObject( 'portal_workflow', WorkflowTool() ) 
+        self.workflow_tool = root.portal_workflow
+        root._setObject( 'portal_types', TypesTool() )
+        types_tool = self.types_tool = root.portal_types
         try: root._delObject('test')
         except AttributeError: pass
         root._setObject( 'test', Document( 'test' ) )
             
-    
-    def tearDown( self ):
-        del self.types_tool
-        del self.workflow_tool
-        del self.url_tool
-        del self.discussion_tool
-        del self.catalog_tool
-        del self.root
-        del self._policy
-        get_transaction().abort()
-        self.connection.close()
-        SecurityManager.setSecurityPolicy( self._oldPolicy )
-
     def test_policy( self ):
 
         test = self.root.test
@@ -79,14 +56,7 @@
 
         del test.talkback
         del test.allow_discussion
-        FTI = FactoryTypeInformation
-        self.types_tool._setObject( 'Document'
-                                  , FTI( 'Document'
-                                       , meta_type=Document.meta_type
-                                       , product='CMFDefault'
-                                       , factory='addDocument'
-                                       )
-                                  )
+        self.types_tool._setObject( 'Document', DummyFTI )
         self.assertRaises( DiscussionNotAllowed
                          , self.discussion_tool.getDiscussionFor
                          , test
@@ -202,25 +172,10 @@
         self.root._delObject( 'test' )
         assert len( self.catalog_tool ) == 0
 
-def has_path( catalog, path ):
-    """
-        Verify that catalog has an object at path.
-    """
-    if type( path ) is type( () ):
-        path = string.join( path, '/' )
-    rids = map( lambda x: x.data_record_id_, catalog.searchResults() )
-    for rid in rids:
-        if catalog.getpath( rid ) == path:
-            return 1
-    return 0
-
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest( unittest.makeSuite( DiscussionTests ) )
-    return suite
-
-def run():
-    unittest.TextTestRunner().run( test_suite() )
+    return TestSuite((
+        makeSuite( DiscussionTests ),
+        ))
 
 if __name__ == '__main__':
-    run()
+    main(defaultTest='test_suite')


=== CMF/CMFDefault/tests/test_Document.py 1.21 => 1.22 === (431/531 lines abridged)
-from Products.CMFDefault.tests.utils import fakeRequest, fakeResponse
-from Products.CMFDefault.Document import Document
-#" 
-DOCTYPE = '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'''
-
-HTML_TEMPLATE = '''\
-<html><head>
- <title>%(title)s</title>
-</head>
-<body bgcolor="#efe843">%(body)s</body>
-</html>
-'''
-
-BASIC_HTML = '''\
-<html>
- <head>
-  <title>Title in tag</title>
-  <meta name="description" content="Describe me">
-  <meta name="contributors" content="foo@bar.com; baz@bam.net;
-    Benotz, Larry J (larry@benotz.stuff)">
-  <meta name="title" content="Title in meta">
-  <meta name="subject" content="content management">
-  <meta name="keywords" content="unit tests, framework; ,zope ">
- </head>
- <body bgcolor="#ffffff">
-  <h1>Not a lot here</h1>
- </body>
-</html>
-'''
-
-SIMPLE_HTML = '''\
-<html>
- <head>
-  <title>Title in tag</title>
-  <meta name="description" content="Describe me">
-  <meta name="contributors" content="foo@bar.com; baz@bam.net;
-    Benotz, Larry J (larry@benotz.stuff)">
-  <meta name="title" content="Title in meta">
-  <meta name="subject" content="content management">
- </head>
- <body bgcolor="#ffffff">
-  <h1>Not a lot here</h1>
- </body>
-</html>
-'''
-
-ENTITY_IN_TITLE = '''\
-<html>
- <head>
-  <title>&Auuml;rger</title>

[-=- -=- -=- 431 lines omitted -=- -=- -=-]

         self.assertEqual( r.status, 204 )
 
     def test_PutHtmlWithDoctype(self):
-        d = Document('foo')
+        
         html = '%s\n\n  \n   %s' % (DOCTYPE, BASIC_HTML)
-        self._request.body = html
-        r = d.PUT(self._request, self._response)
-        self.assertEqual( d.Format(), 'text/html' )
-        self.assertEqual( d.Description(), 'Describe me' )
+        self.REQUEST['BODY'] = html
+        
+        r = self.d.PUT(self.REQUEST, self.RESPONSE)
+        self.assertEqual( self.d.Format(), 'text/html' )
+        self.assertEqual( self.d.Description(), 'Describe me' )
         self.assertEqual( r.status, 204 )
 
     def test_PutHtml(self):
-        d = Document('foo')
-        self._request.body = BASIC_HTML
-        r = d.PUT(self._request, self._response)
-        self.assertEqual( d.Format(), 'text/html' )
-        self.assertEqual( d.Description(), 'Describe me' )
+        
+        self.REQUEST['BODY'] = BASIC_HTML
+        r = self.d.PUT(self.REQUEST, self.RESPONSE)
+        self.assertEqual( self.d.Format(), 'text/html' )
+        self.assertEqual( self.d.Description(), 'Describe me' )
         self.assertEqual( r.status, 204 )
 
 
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(DocumentTests))
-    suite.addTest(unittest.makeSuite(TestFTPGet))
-    suite.addTest(unittest.makeSuite(TestDocumentPUT))
-    return suite
-
-def run():
-    unittest.TextTestRunner().run(test_suite())
+    return TestSuite((
+        makeSuite(DocumentTests),
+        makeSuite(TestFTPGet),
+        makeSuite(TestDocumentPUT),
+        ))
 
 if __name__ == '__main__':
-    run()
+    main(defaultTest='test_suite')
 


=== CMF/CMFDefault/tests/test_Favorite.py 1.2 => 1.3 ===
 """
 __version__ = "$Revision$"[11:-2]
+import Zope
+from unittest import TestCase, TestSuite, makeSuite, main
 
+from Products.CMFCore.tests.base.dummy import \
+     DummyTool as DummyURLTool, \
+     DummyObject as DummySite
 
-import unittest
-import Acquisition
-from Acquisition import aq_inner, aq_parent
+from Products.CMFDefault.Favorite import Favorite
 
-class DummyURLTool( Acquisition.Implicit ):
-
-    root = 'DummyTool'
-
-    def __call__( self ):
-        return self.root
-
-    getPortalPath = __call__
-
-    def getPortalObject( self ):
-        return aq_parent( aq_inner( self ) )
-
-    def getIcon( self, relative=0 ):
-        return 'Tool: %s' % relative
-
-class DummySite( Acquisition.Implicit ):
-
-    def __init__( self, **kw ):
-        self.__dict__.update( kw )
-
-    def restrictedTraverse( self, path ):
-        return path and getattr( self, path ) or self
-
-    def getIcon( self, relative=0 ):
-        return 'Site: %s' % relative
-
-class FavoriteTests( unittest.TestCase ):
+class FavoriteTests( TestCase ):
 
     def setUp( self ):
-
         self.tool = DummyURLTool()
         self.site = DummySite( portal_url=self.tool )
 
     def _makeOne( self, *args, **kw ):
 
-        from Products.CMFDefault.Favorite import Favorite
-
         f = apply( Favorite, args, kw )
         return f.__of__( self.site )
 
@@ -101,13 +75,9 @@
 
 
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest( unittest.makeSuite( FavoriteTests ) )
-    return suite
-
-def run():
-    unittest.TextTestRunner().run(test_suite())
+    return TestSuite((
+        makeSuite( FavoriteTests ),
+        ))
 
 if __name__ == '__main__':
-    run()
-
+    main(defaultTest='test_suite')


=== CMF/CMFDefault/tests/test_Image.py 1.3 => 1.4 ===
+import Zope
+from unittest import TestCase, TestSuite, makeSuite, main
+
+import os, cStringIO
 
 from Products.CMFDefault.Image import Image
 from Products.CMFDefault import tests
@@ -6,14 +9,7 @@
 TESTS_HOME = tests.__path__[0]
 TEST_JPG = os.path.join(TESTS_HOME, 'TestImage.jpg')
 
-
-class TestImageElement(unittest.TestCase):
-
-    def setUp( self ):
-        get_transaction().begin()
-
-    def tearDown( self ):
-        get_transaction().abort()
+class TestImageElement(TestCase):
 
     def test_EditWithEmptyFile(self):
         """ Test handling of empty file uploads """
@@ -34,19 +30,10 @@
         assert image.get_size() == testfilesize
         
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(TestImageElement))
+    return TestSuite((
+        makeSuite(TestImageElement),
+        ))
     return suite
 
-def run():
-    suite = test_suite()
-    return unittest.TextTestRunner().run(suite)
-
 if __name__ == '__main__':
-    import sys
-    result = run()
-    if result.wasSuccessful():
-        sys.exit(0)
-    else:
-        sys.exit(1)
-        
+    main(defaultTest='test_suite')        


=== CMF/CMFDefault/tests/test_Link.py 1.4 => 1.5 ===
+import Zope
+from unittest import TestCase, TestSuite, makeSuite, main
+
+from re import compile
+
 from Products.CMFDefault.Link import Link
 
 BASIC_STRUCTUREDTEXT = '''\
@@ -18,7 +22,7 @@
 http://www.zope.org
 '''
 
-class LinkTests(unittest.TestCase):
+class LinkTests(TestCase):
 
     def test_Empty( self ):
         d = Link( 'foo' )
@@ -42,7 +46,7 @@
 
         d = Link('foo')
         d._writeFromPUT( body=STX_W_CONTINUATION )
-        rnlinesplit = re.compile( r'\r?\n?' )
+        rnlinesplit = compile( r'\r?\n?' )
         desc_lines = rnlinesplit.split( d.Description() )
         
         self.assertEqual( d.Title(), 'Zope Community' )
@@ -67,11 +71,10 @@
         self.assertEqual( d.getRemoteUrl(), 'http://baz.com' )
 
 
-
 def test_suite():
-    return unittest.makeSuite(LinkTests)
-
-def main():
-    unittest.TextTestRunner().run(test_suite())
+    return TestSuite((
+        makeSuite(LinkTests),
+        ))
 
-if __name__=='__main__': main()
+if __name__ == '__main__':
+    main(defaultTest='test_suite')


=== CMF/CMFDefault/tests/test_MetadataTool.py 1.2 => 1.3 ===
 import Zope
-import unittest, string
-from Products.CMFDefault.MetadataTool import *
+from unittest import TestCase, TestSuite, makeSuite, main
+
+from Products.CMFDefault.MetadataTool import \
+     MetadataElementPolicy, MetadataTool, ElementSpec, \
+     DEFAULT_ELEMENT_SPECS, MetadataError
+
 from Products.CMFDefault.DublinCore import DefaultDublinCoreImpl
 
-class TestMetadataElementPolicy( unittest.TestCase ):
+class TestMetadataElementPolicy( TestCase ):
 
     def setUp( self ):
-        get_transaction().begin()
         self.sv_policy = MetadataElementPolicy( 0 )
         self.mv_policy = MetadataElementPolicy( 1 )
 
     def tearDown( self ):
         del self.sv_policy
         del self.mv_policy
-        get_transaction().abort()
 
     def test_emptySV( self ):
         assert not self.sv_policy.isMultiValued()
@@ -52,7 +53,7 @@
         assert 'xxx' in self.mv_policy.allowedVocabulary()
         assert 'yyy' in self.mv_policy.allowedVocabulary()
 
-class TestElementSpec( unittest.TestCase ):
+class TestElementSpec( TestCase ):
 
     def setUp( self ):
         self.sv_spec    = ElementSpec( 0 )
@@ -91,7 +92,7 @@
     def Type( self ):
         return 'Bar'
 
-class TestMetadataTool( unittest.TestCase ):
+class TestMetadataTool( TestCase ):
 
     def setUp( self ):
         self.tool = MetadataTool()
@@ -358,13 +359,11 @@
 
 
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest( unittest.makeSuite( TestMetadataElementPolicy ) )
-    suite.addTest( unittest.makeSuite( TestElementSpec ) )
-    suite.addTest( unittest.makeSuite( TestMetadataTool ) )
-    return suite
-
-def main():
-    unittest.TextTestRunner().run(test_suite())
+    return TestSuite((
+        makeSuite(TestMetadataElementPolicy),
+        makeSuite(TestElementSpec),
+        makeSuite(TestMetadataTool),
+        ))
 
-if __name__=='__main__': main()
+if __name__ == '__main__':
+    main(defaultTest='test_suite')


=== CMF/CMFDefault/tests/test_NewsItem.py 1.4 => 1.5 ===
-from utils import fakeRequest, fakeResponse
+from unittest import makeSuite, main
+
 from Products.CMFDefault.NewsItem import NewsItem
-#" 
-DOCTYPE = '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'''
 
-BASIC_HTML = '''\
-<html>
- <head>
-  <title>Title in tag</title>
-  <meta name="description" content="Describe me">
-  <meta name="contributors" content="foo@bar.com; baz@bam.net">
- </head>
- <body bgcolor="#ffffff">
-  <h1>Not a lot here</h1>
- </body>
-</html>
-'''
-
-ENTITY_IN_TITLE = '''\
-<html>
- <head>
-  <title>&Auuml;rger</title>
- </head>
- <bOdY>
-  <h2>Not a lot here either</h2>
- </bodY>
-</html>
-'''
-
-BASIC_STRUCTUREDTEXT = '''\
-Title: My NewsItem
-Description: A news item by me
-Contributors: foo@bar.com; baz@bam.net; no@yes.maybe
-
-This is the header and it supercedes the title
-
-  Body body body body body
-  body body body.
-
-   o What does this do
-   
-   o if it happens to you?
-'''
+from Products.CMFCore.tests.base.testcase import \
+     RequestTest
 
-class NewsItemTests(unittest.TestCase):
+from Products.CMFCore.tests.base.content import \
+     DOCTYPE, BASIC_HTML, ENTITY_IN_TITLE, BASIC_STRUCTUREDTEXT
 
-    def setUp( self ):
-        get_transaction().begin()
+class NewsItemTests(RequestTest):
 
-    def tearDown( self ):
-        get_transaction().abort()
+    def setUp(self):
+        RequestTest.setUp(self)
+        self.d = NewsItem('foo')
 
     def test_Empty(self):
         d = NewsItem('foo', text_format='structured-text')
@@ -59,91 +22,80 @@
         assert d.text_format == 'structured-text'
 
     def test_BasicHtml(self):
-        REQUEST = fakeRequest()
-        REQUEST['BODY']=BASIC_HTML
-        d = NewsItem('foo')
-        d.PUT(REQUEST, RESPONSE=fakeResponse())
+        self.REQUEST['BODY']=BASIC_HTML
+        d = self.d
+        d.PUT(self.REQUEST, self.RESPONSE)
         assert d.Format() == 'text/html', d.Format()
         assert d.title == 'Title in tag'
-        assert string.find(d.text, '</body>') == -1
+        self.assertEqual(d.text.find('</body>'),-1)
         assert d.Description() == 'Describe me'
-        assert len(d.Contributors()) == 2
+        self.assertEqual(len(d.Contributors()),3)
 
     def test_UpperedHtml(self):
-        REQUEST = fakeRequest()
-        REQUEST['BODY'] = string.upper(BASIC_HTML)
-        d = NewsItem('foo')
-        d.PUT(REQUEST, RESPONSE=fakeResponse())
+        self.REQUEST['BODY'] = BASIC_HTML.upper()
+        d = self.d
+        d.PUT(self.REQUEST, self.RESPONSE)
         assert d.Format() == 'text/html'
         assert d.title == 'TITLE IN TAG'
-        assert string.find(d.text, '</BODY') == -1
+        self.assertEqual( d.text.find('</BODY'),-1)
         assert d.Description() == 'DESCRIBE ME'
-        assert len(d.Contributors()) == 2
+        assert len(d.Contributors()) == 3
 
     def test_EntityInTitle(self):
-        REQUEST = fakeRequest()
-        REQUEST['BODY'] = ENTITY_IN_TITLE
-        d = NewsItem('foo')
-        d.PUT(REQUEST, RESPONSE=fakeResponse())
+        self.REQUEST['BODY'] = ENTITY_IN_TITLE
+        d = self.d
+        d.PUT(self.REQUEST, self.RESPONSE)
         assert d.title == '&Auuml;rger', "Title '%s' being lost" % (
             d.title )
 
     def test_HtmlWithDoctype(self):
-        REQUEST = fakeRequest()
-        d = NewsItem('foo')
-        REQUEST['BODY'] = '%s\n%s' % (DOCTYPE, BASIC_HTML)
-        d.PUT(REQUEST, RESPONSE=fakeResponse())
+        d = self.d
+        self.REQUEST['BODY'] = '%s\n%s' % (DOCTYPE, BASIC_HTML)
+        d.PUT(self.REQUEST, self.RESPONSE)
         assert d.Description() == 'Describe me'
 
     def test_HtmlWithoutNewlines(self):
-        REQUEST = fakeRequest()
-        d = NewsItem('foo')
-        REQUEST['BODY'] = string.join(string.split(BASIC_HTML, '\n'), '')
-        d.PUT(REQUEST, RESPONSE=fakeResponse())
+        d = self.d
+        self.REQUEST['BODY'] = ''.join(BASIC_HTML.split('\n'))
+        d.PUT(self.REQUEST, self.RESPONSE)
         assert d.Format() == 'text/html'
         assert d.Description() == 'Describe me'
 
     def test_StructuredText(self):
-        REQUEST = fakeRequest()
-        REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
-        d = NewsItem('foo')
-        d.PUT(REQUEST, RESPONSE=fakeResponse())
+        self.REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
+        d = self.d
+        d.PUT(self.REQUEST, self.RESPONSE)
         
         assert d.Format() == 'text/plain'
-        assert d.Title() == 'My NewsItem'
-        assert d.Description() == 'A news item by me'
+        self.assertEqual(d.Title(),'My Document')
+        self.assertEqual(d.Description(),'A document by me')
         assert len(d.Contributors()) == 3
-        assert string.find(d.cooked_text, '<p>') >= 0
+        self.failUnless(d.cooked_text.find('<p>') >= 0)
 
     def test_Init(self):
-        REQUEST = fakeRequest()
-        REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
+        self.REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
         d = NewsItem('foo', text='')
-        d.PUT(REQUEST, RESPONSE=fakeResponse())
+        d.PUT(self.REQUEST, self.RESPONSE)
         assert d.Format() == 'text/plain'
-        assert d.Title() == 'My NewsItem', d.Title()
-        assert d.Description() == 'A news item by me'
+        self.assertEqual(d.Title(),'My Document')
+        self.assertEqual(d.Description(),'A document by me')
         assert len(d.Contributors()) == 3
-        assert string.find(d.cooked_text, '<p>') >= 0
+        self.failUnless(d.cooked_text.find('<p>') >= 0)
 
         d = NewsItem('foo', text='')
-        REQUEST['BODY'] = BASIC_HTML
-        d.PUT(REQUEST, RESPONSE=fakeResponse())
+        self.REQUEST['BODY'] = BASIC_HTML
+        d.PUT(self.REQUEST, self.RESPONSE)
         assert d.Format() == 'text/html'
         assert d.Title() == 'Title in tag'
-        assert len(d.Contributors()) == 2
+        assert len(d.Contributors()) == 3
 
         d = NewsItem('foo', text_format='structured-text', title='Foodoc')
         assert d.text == ''
         assert d.title == 'Foodoc'
         assert d.Format() == 'text/plain'
 
-
-
 def test_suite():
-    return unittest.makeSuite(NewsItemTests)
-
-def main():
-    unittest.TextTestRunner().run(test_suite())
+    return makeSuite(NewsItemTests)
 
-if __name__=='__main__': main()
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== CMF/CMFDefault/tests/test_all.py 1.10 => 1.11 ===
-import unittest
-
-from Products.CMFDefault.tests import test_Discussions
-from Products.CMFDefault.tests import test_Document
-from Products.CMFDefault.tests import test_NewsItem
-from Products.CMFDefault.tests import test_Link
-from Products.CMFDefault.tests import test_Favorite
-from Products.CMFDefault.tests import test_Image
-from Products.CMFDefault.tests import test_MetadataTool
-from Products.CMFDefault.tests import test_utils
-# test_join is broken, because it tries to use a shortcut.
-#from Products.CMFDefault.tests import test_join  
+from unittest import main
+from Products.CMFCore.tests.base.utils import build_test_suite
 
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest( test_Discussions.test_suite() )
-    suite.addTest( test_Document.test_suite() )
-    suite.addTest( test_NewsItem.test_suite() )
-    suite.addTest( test_Link.test_suite() )
-    suite.addTest( test_Favorite.test_suite() )
-    suite.addTest( test_Image.test_suite() )
-    suite.addTest( test_MetadataTool.test_suite() )
-    suite.addTest( test_utils.test_suite() )
-    #suite.addTest( test_join.test_suite() )
-    return suite
 
-def run():
-    if hasattr( unittest, 'JUnitTextTestRunner' ):
-        unittest.JUnitTextTestRunner().run( test_suite() )
-    else:
-        unittest.TextTestRunner( verbosity=0 ).run( test_suite() )
+    return build_test_suite('Products.CMFDefault.tests',[
+        'test_Discussions',
+        'test_Document',
+        'test_NewsItem',
+        'test_Link',
+        'test_Favorite',
+        'test_Image',
+        'test_MetadataTool',
+        'test_utils',
+        'test_join',
+        ])
 
 if __name__ == '__main__':
-    run()
+    main(defaultTest='test_suite')


=== CMF/CMFDefault/tests/test_join.py 1.3 => 1.4 ===
-import unittest
-import Products.CMFCore
-import Products.CMFDefault
-
-class MembershipTests( unittest.TestCase ):
-
-    def setUp( self ):
-        get_transaction().begin()
-        self.connection = Zope.DB.open()
-        self.root = self.connection.root()[ 'Application' ]
-
-    def tearDown( self ):
-        get_transaction().abort()
-        self.connection.close()
+from unittest import TestSuite, makeSuite, main
+
+from Products.CMFCore.tests.base.testcase import \
+     TransactionalTest
+
+class MembershipTests( TransactionalTest ):
 
     def test_join( self ):
         self.root.manage_addProduct[ 'CMFDefault' ].manage_addCMFSite( 'site' )
@@ -27,12 +19,9 @@
 
 
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest( unittest.makeSuite( MembershipTests ) )
-    return suite
-
-def run():
-    unittest.TextTestRunner().run(test_suite())
+    return TestSuite((
+        makeSuite(MembershipTests),
+        ))
 
 if __name__ == '__main__':
-    run()
+    main(defaultTest='test_suite')


=== CMF/CMFDefault/tests/test_utils.py 1.4 => 1.5 ===
+from unittest import TestCase,makeSuite,main
+
 from Products.CMFDefault.utils import parseHeadersBody
-from string import split
 
-class DefaultUtilsTests(unittest.TestCase):
+class DefaultUtilsTests(TestCase):
     COMMON_HEADERS = '''Author: Tres Seaver
 Title: Test Products.PTKDemo.utils.parseHeadersBody'''
 
@@ -15,12 +15,6 @@
 Header: value
 '''
 
-    def setUp( self ):
-        get_transaction().begin()
-
-    def tearDown( self ):
-        get_transaction().abort()
-    
     def test_NoBody( self ):
         headers, body = parseHeadersBody( '%s\n\n' % self.COMMON_HEADERS )
         assert( len( headers ) == 2, '%d!' % len( headers ) )
@@ -37,7 +31,7 @@
                                         )
         assert( len( headers ) == 3, '%d!' % len( headers )  )
         assert( 'Description' in headers.keys() )
-        desc_len = len( split( headers[ 'Description' ], '\n' ) )
+        desc_len = len( headers[ 'Description' ].split('\n') )
         assert( desc_len == 2, '%d!' % desc_len )
         assert( len( body ) == 0, '%d!' % len( body ) )
     
@@ -64,8 +58,8 @@
         assert( preloaded[ 'text_format' ] == headers[ 'text_format' ] )
 
 def test_suite():
-    return unittest.makeSuite(DefaultUtilsTests)
+    return makeSuite(DefaultUtilsTests)
 
 if __name__ == '__main__':
-    result = unittest.TextTestRunner().run(test_suite())
+    main(defaultTest='test_suite')
 

=== Removed File CMF/CMFDefault/tests/utils.py ===