[CMF-checkins] SVN: CMF/trunk/CMF - renamed CMFDefault's FunctionalZCMLLayer to FunctionalLayer, it now sets up a complete site

Yvo Schubbe y.2006_ at wcm-solutions.de
Tue Nov 7 10:18:05 EST 2006


Log message for revision 71094:
  - renamed CMFDefault's FunctionalZCMLLayer to FunctionalLayer, it now sets up a complete site
  - refactored functional tests using the new FunctionalLayer and ZopeTestCase's FunctionalTestCase

Changed:
  U   CMF/trunk/CMFCalendar/testing.py
  U   CMF/trunk/CMFDefault/testing.py
  U   CMF/trunk/CMFDefault/tests/test_DiscussionReply.py
  U   CMF/trunk/CMFDefault/tests/test_Image.py
  U   CMF/trunk/CMFDefault/tests/test_Portal.py
  U   CMF/trunk/CMFDefault/tests/test_RegistrationTool.py
  U   CMF/trunk/CMFDefault/tests/test_join.py
  U   CMF/trunk/CMFTopic/tests/test_DateC.py

-=-
Modified: CMF/trunk/CMFCalendar/testing.py
===================================================================
--- CMF/trunk/CMFCalendar/testing.py	2006-11-07 13:54:29 UTC (rev 71093)
+++ CMF/trunk/CMFCalendar/testing.py	2006-11-07 15:18:04 UTC (rev 71094)
@@ -22,8 +22,8 @@
 import transaction
 from Products.Five import zcml
 
+from Products.CMFCore.testing import FunctionalZCMLLayer
 from Products.CMFDefault.factory import addConfiguredSite
-from Products.CMFDefault.testing import FunctionalZCMLLayer
 
 
 class FunctionalLayer(FunctionalZCMLLayer):
@@ -31,8 +31,14 @@
     @classmethod
     def setUp(cls):
         import Products.CMFCalendar
+        import Products.CMFDefault
+        import Products.CMFTopic
+        import Products.DCWorkflow
 
         zcml.load_config('configure.zcml', Products.CMFCalendar)
+        zcml.load_config('configure.zcml', Products.CMFDefault)
+        zcml.load_config('configure.zcml', Products.CMFTopic)
+        zcml.load_config('configure.zcml', Products.DCWorkflow)
 
         app = ZopeTestCase.app()
         addConfiguredSite(app, 'site', 'Products.CMFDefault:default',

Modified: CMF/trunk/CMFDefault/testing.py
===================================================================
--- CMF/trunk/CMFDefault/testing.py	2006-11-07 13:54:29 UTC (rev 71093)
+++ CMF/trunk/CMFDefault/testing.py	2006-11-07 15:18:04 UTC (rev 71094)
@@ -15,12 +15,18 @@
 $Id$
 """
 
+from Testing import ZopeTestCase
+ZopeTestCase.installProduct('ZCTextIndex', 1)
+ZopeTestCase.installProduct('CMFCore', 1)
+
+import transaction
 from Products.Five import zcml
 
 from Products.CMFCore.testing import FunctionalZCMLLayer
+from Products.CMFDefault.factory import addConfiguredSite
 
 
-class FunctionalZCMLLayer(FunctionalZCMLLayer):
+class FunctionalLayer(FunctionalZCMLLayer):
 
     @classmethod
     def setUp(cls):
@@ -32,6 +38,15 @@
         zcml.load_config('configure.zcml', Products.CMFTopic)
         zcml.load_config('configure.zcml', Products.DCWorkflow)
 
+        app = ZopeTestCase.app()
+        addConfiguredSite(app, 'site', 'Products.CMFDefault:default',
+                          snapshot=False)
+        transaction.commit()
+        ZopeTestCase.close(app)
+
     @classmethod
     def tearDown(cls):
-        pass
+        app = ZopeTestCase.app()
+        app._delObject('site')
+        transaction.commit()
+        ZopeTestCase.close(app)

Modified: CMF/trunk/CMFDefault/tests/test_DiscussionReply.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_DiscussionReply.py	2006-11-07 13:54:29 UTC (rev 71093)
+++ CMF/trunk/CMFDefault/tests/test_DiscussionReply.py	2006-11-07 15:18:04 UTC (rev 71094)
@@ -17,47 +17,31 @@
 
 import unittest
 from Testing import ZopeTestCase
-ZopeTestCase.installProduct('ZCTextIndex', 1)
-ZopeTestCase.installProduct('CMFCore', 1)
 
 from AccessControl.SecurityManagement import newSecurityManager
-from AccessControl.SecurityManagement import noSecurityManager
 
-from Products.CMFCore.tests.base.testcase import RequestTest
-from Products.CMFDefault.factory import addConfiguredSite
-from Products.CMFDefault.testing import FunctionalZCMLLayer
+from Products.CMFDefault.testing import FunctionalLayer
 
 
-class DiscussionReplyTest(RequestTest):
+class DiscussionReplyTest(ZopeTestCase.FunctionalTestCase):
 
-    layer = FunctionalZCMLLayer
+    layer = FunctionalLayer
 
-    def setUp(self):
-        RequestTest.setUp(self)
-        try:
-            addConfiguredSite(self.root, 'cmf', 'Products.CMFDefault:default',
-                              snapshot=False)
-            self.portal = self.root.cmf
-            # Become a Manager
-            self.uf = self.portal.acl_users
-            self.uf.userFolderAddUser('manager', '', ['Manager'], [])
-            self.login('manager')
-            # Make a document
-            self.discussion = self.portal.portal_discussion
-            self.portal.invokeFactory('Document', id='doc')
-            self.discussion.overrideDiscussionFor(self.portal.doc, 1)
-            # Publish it
-            self.workflow = self.portal.portal_workflow
-            self.workflow.doActionFor(self.portal.doc, 'publish')
-        except:
-            self.tearDown()
-            raise
+    def afterSetUp(self):
+        self.portal = self.app.site
+        # Become a Manager
+        self.uf = self.portal.acl_users
+        self.uf.userFolderAddUser('manager', '', ['Manager'], [])
+        self.site_login('manager')
+        # Make a document
+        self.discussion = self.portal.portal_discussion
+        self.portal.invokeFactory('Document', id='doc')
+        self.discussion.overrideDiscussionFor(self.portal.doc, 1)
+        # Publish it
+        self.workflow = self.portal.portal_workflow
+        self.workflow.doActionFor(self.portal.doc, 'publish')
 
-    def tearDown(self):
-        noSecurityManager()
-        RequestTest.tearDown(self)
-
-    def login(self, name):
+    def site_login(self, name):
         user = self.uf.getUserById(name)
         user = user.__of__(self.uf)
         newSecurityManager(None, user)
@@ -75,14 +59,10 @@
     # Run the test again as another Member, i.e. reply to someone
     # else's document.
 
-    def setUp(self):
-        DiscussionReplyTest.setUp(self)
-        try:
-            self.uf.userFolderAddUser('member', '', ['Member'], [])
-            self.login('member')
-        except:
-            self.tearDown()
-            raise
+    def afterSetUp(self):
+        DiscussionReplyTest.afterSetUp(self)
+        self.uf.userFolderAddUser('member', '', ['Member'], [])
+        self.site_login('member')
 
 
 def test_suite():

Modified: CMF/trunk/CMFDefault/tests/test_Image.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_Image.py	2006-11-07 13:54:29 UTC (rev 71093)
+++ CMF/trunk/CMFDefault/tests/test_Image.py	2006-11-07 15:18:04 UTC (rev 71094)
@@ -17,27 +17,22 @@
 
 import unittest
 from Testing import ZopeTestCase
-ZopeTestCase.installProduct('ZCTextIndex', 1)
-ZopeTestCase.installProduct('CMFCore', 1)
 
 from os.path import join as path_join
 from cStringIO import StringIO
 
 import transaction
 from AccessControl.SecurityManagement import newSecurityManager
-from AccessControl.SecurityManagement import noSecurityManager
+from AccessControl.User import UnrestrictedUser
 
 from Products.CMFCore.testing import ConformsToContent
 from Products.CMFCore.tests.base.dummy import DummyCachingManager
 from Products.CMFCore.tests.base.dummy import DummyCachingManagerWithPolicy
 from Products.CMFCore.tests.base.dummy import DummySite
 from Products.CMFCore.tests.base.dummy import DummyTool
-from Products.CMFCore.tests.base.security import OmnipotentUser
 from Products.CMFCore.tests.base.testcase import RequestTest
-from Products.CMFCore.tests.base.testcase import SecurityRequestTest
 from Products.CMFDefault import tests
-from Products.CMFDefault.factory import addConfiguredSite
-from Products.CMFDefault.testing import FunctionalZCMLLayer
+from Products.CMFDefault.testing import FunctionalLayer
 
 TESTS_HOME = tests.__path__[0]
 TEST_JPG = path_join(TESTS_HOME, 'TestImage.jpg')
@@ -104,35 +99,25 @@
         self.assertEqual(image.content_type, 'image/jpeg')
 
 
-class TestImageCopyPaste(SecurityRequestTest):
+class TestImageCopyPaste(ZopeTestCase.FunctionalTestCase):
 
     # Tests related to http://www.zope.org/Collectors/CMF/176
     # Copy/pasting an image (or file) should reset the object's workflow state.
 
-    layer = FunctionalZCMLLayer
+    layer = FunctionalLayer
 
-    def setUp(self):
-        SecurityRequestTest.setUp(self)
-        try:
-            addConfiguredSite(self.root, 'cmf', 'Products.CMFDefault:default',
-                              snapshot=False)
-            self.site = self.root.cmf
-            newSecurityManager(None, OmnipotentUser().__of__(self.site))
-            self.site.invokeFactory('File', id='file')
-            self.site.portal_workflow.doActionFor(self.site.file, 'publish')
-            self.site.invokeFactory('Image', id='image')
-            self.site.portal_workflow.doActionFor(self.site.image, 'publish')
-            self.site.invokeFactory('Folder', id='subfolder')
-            self.subfolder = self.site.subfolder
-            self.workflow = self.site.portal_workflow
-            transaction.savepoint(optimistic=True) # Make sure we have _p_jars
-        except:
-            self.tearDown()
-            raise
+    def afterSetUp(self):
+        newSecurityManager(None, UnrestrictedUser('god', '', ['Manager'], ''))
 
-    def tearDown(self):
-        noSecurityManager()
-        SecurityRequestTest.tearDown(self)
+        self.site = self.app.site
+        self.site.invokeFactory('File', id='file')
+        self.site.portal_workflow.doActionFor(self.site.file, 'publish')
+        self.site.invokeFactory('Image', id='image')
+        self.site.portal_workflow.doActionFor(self.site.image, 'publish')
+        self.site.invokeFactory('Folder', id='subfolder')
+        self.subfolder = self.site.subfolder
+        self.workflow = self.site.portal_workflow
+        transaction.commit() # Make sure we have _p_jars
 
     def test_File_CopyPasteResetsWorkflowState(self):
         # Copy/pasting a File should reset wf state to private
@@ -186,6 +171,7 @@
         review_state = self.workflow.getInfoFor(self.site.image2, 'review_state')
         self.assertEqual(review_state, 'published')
 
+
 class TestCaching(RequestTest):
 
     def _extractFile( self ):
@@ -274,7 +260,6 @@
 
         self.root.image = self._makeOne( 'test_image', 'test_image.gif' )
         image = self.root.image
-        import transaction
         transaction.savepoint(optimistic=True)
 
         mod_time = image.modified()

Modified: CMF/trunk/CMFDefault/tests/test_Portal.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_Portal.py	2006-11-07 13:54:29 UTC (rev 71093)
+++ CMF/trunk/CMFDefault/tests/test_Portal.py	2006-11-07 15:18:04 UTC (rev 71094)
@@ -17,28 +17,20 @@
 
 import unittest
 from Testing import ZopeTestCase
-ZopeTestCase.installProduct('ZCTextIndex', 1)
-ZopeTestCase.installProduct('CMFCore', 1)
 
+from AccessControl.SecurityManagement import newSecurityManager
+from AccessControl.User import UnrestrictedUser
 from Acquisition import aq_base
 
-from Products.CMFCore.tests.base.testcase import SecurityRequestTest
-from Products.CMFDefault.testing import FunctionalZCMLLayer
+from Products.CMFDefault.testing import FunctionalLayer
 
 
-class CMFSiteTests(SecurityRequestTest):
+class CMFSiteTests(ZopeTestCase.FunctionalTestCase):
 
-    layer = FunctionalZCMLLayer
+    layer = FunctionalLayer
 
-    def _makeSite( self, id='testsite' ):
-
-        from Products.CMFDefault.factory import addConfiguredSite
-
-        addConfiguredSite(self.root, id, 'Products.CMFDefault:default',
-                          snapshot=False)
-        return getattr( self.root, id )
-
     def _makeContent( self, site, portal_type, id='document', **kw ):
+        newSecurityManager(None, UnrestrictedUser('god', '', ['Manager'], ''))
 
         site.invokeFactory( type_name=portal_type, id=id )
         content = getattr( site, id )
@@ -49,13 +41,12 @@
         return content
 
     def test_new( self ):
+        site = self.app.site
 
-        site = self._makeSite()
         self.assertEqual( len( site.portal_catalog ), 0 )
 
     def test_MetadataCataloguing( self ):
-
-        site = self._makeSite()
+        site = self.app.site
         catalog = site.portal_catalog
         site.portal_membership.memberareaCreationFlag = 0
         uid_handler = getattr(site, 'portal_uidhandler', None)
@@ -104,8 +95,7 @@
             self.assertEqual( len( catalog ), 0 )
 
     def test_DocumentEditCataloguing( self ):
-
-        site = self._makeSite()
+        site = self.app.site
         catalog = site.portal_catalog
 
         doc = self._makeContent( site
@@ -123,8 +113,7 @@
         self.assertEqual( _getMetadata( catalog, rid ), 'Bar' )
 
     def test_ImageEditCataloguing( self ):
-
-        site = self._makeSite()
+        site = self.app.site
         catalog = site.portal_catalog
 
         doc = self._makeContent( site
@@ -140,8 +129,7 @@
         self.assertEqual( _getMetadata( catalog, rid ), 'Bar' )
 
     def test_FileEditCataloguing( self ):
-
-        site = self._makeSite()
+        site = self.app.site
         catalog = site.portal_catalog
 
         doc = self._makeContent( site
@@ -157,8 +145,7 @@
         self.assertEqual( _getMetadata( catalog, rid ), 'Bar' )
 
     def test_LinkEditCataloguing( self ):
-
-        site = self._makeSite()
+        site = self.app.site
         catalog = site.portal_catalog
 
         doc = self._makeContent( site
@@ -174,8 +161,7 @@
         self.assertEqual( _getMetadata( catalog, rid ), 'Bar' )
 
     def test_NewsItemEditCataloguing( self ):
-
-        site = self._makeSite()
+        site = self.app.site
         catalog = site.portal_catalog
 
         doc = self._makeContent( site

Modified: CMF/trunk/CMFDefault/tests/test_RegistrationTool.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_RegistrationTool.py	2006-11-07 13:54:29 UTC (rev 71093)
+++ CMF/trunk/CMFDefault/tests/test_RegistrationTool.py	2006-11-07 15:18:04 UTC (rev 71094)
@@ -16,11 +16,10 @@
 """
 
 import unittest
-import Testing
-from zope.testing import doctest
+from Testing import ZopeTestCase
 
 from Products.CMFCore.tests.base.testcase import RequestTest
-from Products.CMFDefault.testing import FunctionalZCMLLayer
+from Products.CMFDefault.testing import FunctionalLayer
 
 
 class FauxMembershipTool:
@@ -83,9 +82,8 @@
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(RegistrationToolTests))
-    s = doctest.DocFileSuite('RegistrationTool.txt',
-                optionflags=(doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE))
-    s.layer = FunctionalZCMLLayer
+    s = ZopeTestCase.FunctionalDocFileSuite('RegistrationTool.txt')
+    s.layer = FunctionalLayer
     suite.addTest(s)
     return suite
 

Modified: CMF/trunk/CMFDefault/tests/test_join.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_join.py	2006-11-07 13:54:29 UTC (rev 71093)
+++ CMF/trunk/CMFDefault/tests/test_join.py	2006-11-07 15:18:04 UTC (rev 71094)
@@ -17,26 +17,16 @@
 
 import unittest
 from Testing import ZopeTestCase
-ZopeTestCase.installProduct('ZCTextIndex', 1)
-ZopeTestCase.installProduct('CMFCore', 1)
 
-from Products.CMFCore.tests.base.testcase import TransactionalTest
-from Products.CMFDefault.factory import addConfiguredSite
-from Products.CMFDefault.testing import FunctionalZCMLLayer
+from Products.CMFDefault.testing import FunctionalLayer
 
 
-class MembershipTests(TransactionalTest):
+class MembershipTests(ZopeTestCase.FunctionalTestCase):
 
-    layer = FunctionalZCMLLayer
+    layer = FunctionalLayer
 
-    def _makePortal(self):
-        # Create a portal instance suitable for testing
-        addConfiguredSite(self.root, 'site', 'Products.CMFDefault:default',
-                          snapshot=False)
-        return self.root.site
-
     def test_join( self ):
-        site = self._makePortal()
+        site = self.app.site
         member_id = 'test_user'
 
         site.portal_registration.addMember( member_id
@@ -51,7 +41,7 @@
     def test_join_memberproperties(self):
         # Make sure the member data wrapper carries correct properties
         # after joining
-        site = self._makePortal()
+        site = self.app.site
         member_id = 'test_user'
 
         site.portal_registration.addMember( member_id
@@ -67,7 +57,7 @@
         self.assertEqual(m.getRoles(), ('Member', 'Authenticated'))
 
     def test_join_without_email( self ):
-        site = self._makePortal()
+        site = self.app.site
 
         self.assertRaises(ValueError,
                           site.portal_registration.addMember,
@@ -77,7 +67,7 @@
                           )
 
     def test_join_with_variable_id_policies( self ):
-        site = self._makePortal()
+        site = self.app.site
         member_id = 'test.user'
 
         # Test with the default policy: Names with "." should fail

Modified: CMF/trunk/CMFTopic/tests/test_DateC.py
===================================================================
--- CMF/trunk/CMFTopic/tests/test_DateC.py	2006-11-07 13:54:29 UTC (rev 71093)
+++ CMF/trunk/CMFTopic/tests/test_DateC.py	2006-11-07 15:18:04 UTC (rev 71094)
@@ -17,15 +17,11 @@
 
 import unittest
 from Testing import ZopeTestCase
-ZopeTestCase.installProduct('ZCTextIndex', 1)
-ZopeTestCase.installProduct('CMFCore', 1)
 
 from DateTime.DateTime import DateTime
 
-from Products.CMFCore.tests.base.testcase import RequestTest
 from Products.CMFCore.tests.base.dummy import DummyContent
-from Products.CMFDefault.factory import addConfiguredSite
-from Products.CMFDefault.testing import FunctionalZCMLLayer
+from Products.CMFDefault.testing import FunctionalLayer
 from Products.CMFTopic.Topic import Topic
 
 from common import CriterionTestCase
@@ -153,9 +149,9 @@
         self.assertEqual( result[0][1]['range'], 'min:max' )
 
 
-class FriendlyDateCriterionFunctionalTests(RequestTest):
+class FriendlyDateCriterionFunctionalTests(ZopeTestCase.FunctionalTestCase):
 
-    layer = FunctionalZCMLLayer
+    layer = FunctionalLayer
 
     # Test the date criterion using a "real CMF" with catalog etc.
     selectable_diffs = [0, 1, 2, 5, 7, 14, 31, 93, 186, 365, 730]
@@ -163,12 +159,8 @@
     day_diffs = [-730, -365, -186, -93, -31, -14, -7, -5, -2, -1]
     day_diffs.extend(selectable_diffs)
 
-    def setUp(self):
-        RequestTest.setUp(self)
-
-        addConfiguredSite(self.root, 'site', 'Products.CMFDefault:default',
-                          snapshot=False)
-        self.site = self.root.site
+    def afterSetUp(self):
+        self.site = self.app.site
         self.site._setObject( 'topic', Topic('topic') )
         self.topic = self.site.topic
         self.topic.addCriterion('modified', 'Friendly Date Criterion')



More information about the CMF-checkins mailing list