[Checkins] SVN: Products.CMFTopic/trunk/Products/CMFTopic/ - unit tests: Add a functional testing layer for CMFTopic, and use it.

Jens Vagelpohl jens at dataflake.org
Fri Sep 12 10:05:33 EDT 2008


Log message for revision 91085:
  - unit tests: Add a functional testing layer for CMFTopic, and use it.
  

Changed:
  U   Products.CMFTopic/trunk/Products/CMFTopic/CHANGES.txt
  A   Products.CMFTopic/trunk/Products/CMFTopic/testing.py
  U   Products.CMFTopic/trunk/Products/CMFTopic/tests/test_Topic.py

-=-
Modified: Products.CMFTopic/trunk/Products/CMFTopic/CHANGES.txt
===================================================================
--- Products.CMFTopic/trunk/Products/CMFTopic/CHANGES.txt	2008-09-12 14:01:02 UTC (rev 91084)
+++ Products.CMFTopic/trunk/Products/CMFTopic/CHANGES.txt	2008-09-12 14:05:33 UTC (rev 91085)
@@ -4,6 +4,8 @@
 2.2.0 (unreleased)
 ------------------
 
+- unit tests: Add a functional testing layer for CMFTopic, and use it.
+
 - Topic: 'addTopic' no longer sends add events.
 
 - interfaces: Removed deprecated oldstyle interfaces.

Added: Products.CMFTopic/trunk/Products/CMFTopic/testing.py
===================================================================
--- Products.CMFTopic/trunk/Products/CMFTopic/testing.py	                        (rev 0)
+++ Products.CMFTopic/trunk/Products/CMFTopic/testing.py	2008-09-12 14:05:33 UTC (rev 91085)
@@ -0,0 +1,54 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+""" Unit test layers.
+
+$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 FunctionalLayer(FunctionalZCMLLayer):
+
+    @classmethod
+    def setUp(cls):
+        import Products.CMFTopic
+        import Products.CMFDefault
+        import Products.DCWorkflow
+
+        zcml.load_config('configure.zcml', Products.CMFTopic)
+        zcml.load_config('configure.zcml', Products.CMFDefault)
+        zcml.load_config('configure.zcml', Products.DCWorkflow)
+
+        app = ZopeTestCase.app()
+        addConfiguredSite(app, 'site', 'Products.CMFDefault:default',
+                          snapshot=False,
+                          extension_ids=('Products.CMFTopic:default',))
+        transaction.commit()
+        ZopeTestCase.close(app)
+
+    @classmethod
+    def tearDown(cls):
+        app = ZopeTestCase.app()
+        app._delObject('site')
+        transaction.commit()
+        ZopeTestCase.close(app)
+


Property changes on: Products.CMFTopic/trunk/Products/CMFTopic/testing.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: Products.CMFTopic/trunk/Products/CMFTopic/tests/test_Topic.py
===================================================================
--- Products.CMFTopic/trunk/Products/CMFTopic/tests/test_Topic.py	2008-09-12 14:01:02 UTC (rev 91084)
+++ Products.CMFTopic/trunk/Products/CMFTopic/tests/test_Topic.py	2008-09-12 14:05:33 UTC (rev 91085)
@@ -19,8 +19,11 @@
 from Testing import ZopeTestCase
 ZopeTestCase.installProduct('CMFTopic', 1)
 
+from AccessControl.SecurityManagement import newSecurityManager
+from AccessControl.User import UnrestrictedUser
 from Acquisition import Implicit
 
+from zope.app.component.hooks import setSite
 from zope.component import getSiteManager
 from zope.interface.verify import verifyClass
 
@@ -31,6 +34,7 @@
 from Products.CMFCore.tests.base.testcase import SecurityTest
 from Products.CMFCore.TypesTool import FactoryTypeInformation as FTI
 from Products.CMFCore.TypesTool import TypesTool
+from Products.CMFTopic.testing import FunctionalLayer
 
 
 class FauxBrain( Implicit ):
@@ -194,32 +198,6 @@
         self.assertEqual( query[ 'foo' ], 'bar' )
         self.assertEqual( query[ 'baz' ], 43 )
 
-    def test_Nested( self ):
-        self.site._setObject( 'portal_types', TypesTool() )
-        self.site.portal_types._setObject('Topic', FTI(id='Topic',
-                                      product='CMFTopic', factory='addTopic'))
-        topic = self._makeOne('top')
-        topic._setPortalTypeName('Topic')
-
-        topic.addCriterion( 'foo', 'String Criterion' )
-        topic.getCriterion( 'foo' ).edit( 'bar' )
-
-        topic.addSubtopic( 'qux' )
-        subtopic = topic.qux
-
-        subtopic.addCriterion( 'baz', 'String Criterion' )
-        subtopic.getCriterion( 'baz' ).edit( 'bam' )
-
-        query = subtopic.buildQuery()
-        self.assertEqual( len( query ), 2 )
-        self.assertEqual( query['foo'], 'bar' )
-        self.assertEqual( query['baz'], 'bam' )
-
-        subtopic.acquireCriteria = 0
-        query = subtopic.buildQuery()
-        self.assertEqual( len( query ), 1 )
-        self.assertEqual( query['baz'], 'bam' )
-
     def test_selfIndexing(self):
         # The Topic object is CatalogAware and should be in the catalog
         # after it has beeen instantiated.
@@ -324,6 +302,39 @@
             self.failUnless( object.description in _DOCUMENTS.values() )
 
 
+class TestTopicFunctional(ZopeTestCase.FunctionalTestCase):
+
+    layer = FunctionalLayer
+
+    def afterSetUp(self):
+        setSite(self.app.site)
+        self.app.site.setupCurrentSkin(self.app.REQUEST)
+        newSecurityManager(None, UnrestrictedUser('god', '', ['Manager'], ''))
+
+    def test_Nested( self ):
+        self.app.site.invokeFactory('Topic', 'top')
+        topic = self.app.site.top
+
+        topic.addCriterion( 'foo', 'String Criterion' )
+        topic.getCriterion( 'foo' ).edit( 'bar' )
+
+        topic.addSubtopic( 'qux' )
+        subtopic = topic.qux
+
+        subtopic.addCriterion( 'baz', 'String Criterion' )
+        subtopic.getCriterion( 'baz' ).edit( 'bam' )
+
+        query = subtopic.buildQuery()
+        self.assertEqual( len( query ), 2 )
+        self.assertEqual( query['foo'], 'bar' )
+        self.assertEqual( query['baz'], 'bam' )
+
+        subtopic.acquireCriteria = 0
+        query = subtopic.buildQuery()
+        self.assertEqual( len( query ), 1 )
+        self.assertEqual( query['baz'], 'bam' )
+
+
 _DOCUMENTS = \
 { 'one'     : "something in the way she moves"
 , 'two'     : "I don't know much about history"
@@ -338,6 +349,7 @@
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(TestTopic),
+        unittest.makeSuite(TestTopicFunctional),
         ))
 
 if __name__ == '__main__':



More information about the Checkins mailing list