[CMF-checkins] CVS: Products/CMFTopic/tests - common.py:1.1 test_DateC.py:1.14 test_ListC.py:1.12 test_SIC.py:1.12 test_SSC.py:1.11 test_SortC.py:1.7 test_Topic.py:1.16

Yvo Schubbe y.2005- at wcm-solutions.de
Mon Jun 13 13:32:36 EDT 2005


Update of /cvs-repository/Products/CMFTopic/tests
In directory cvs.zope.org:/tmp/cvs-serv26464/CMFTopic/tests

Modified Files:
	test_DateC.py test_ListC.py test_SIC.py test_SSC.py 
	test_SortC.py test_Topic.py 
Added Files:
	common.py 
Log Message:
ported newstyle (Zope 3) interfaces from CMFonFive:
- added ZCML-files that bridge z2 to z3 interfaces
- added conformance tests
- fixed the Criterion interface
- added missing license headers
- cleaned up related tests a bit


=== Added File Products/CMFTopic/tests/common.py ===
##############################################################################
#
# Copyright (c) 2005 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.
#
##############################################################################
""" CMFTopic product:  unit test utilities.

$Id: common.py,v 1.1 2005/06/13 17:32:05 yuppie Exp $
"""

from unittest import TestCase


class CriterionTestCase(TestCase):

    def _makeOne(self, id, *args, **kw):
        return self._getTargetClass()(id, *args, **kw)

    def test_z2interfaces(self):
        from Interface.Verify import verifyClass
        from Products.CMFTopic.interfaces import Criterion as ICriterion

        verifyClass( ICriterion, self._getTargetClass() )

    def test_z3interfaces(self):
        try:
            from zope.interface.verify import verifyClass
        except ImportError:
            # BBB: for Zope 2.7
            return
        from Products.CMFTopic.interfaces import ICriterion

        verifyClass( ICriterion, self._getTargetClass() )


=== Products/CMFTopic/tests/test_DateC.py 1.13 => 1.14 ===
--- Products/CMFTopic/tests/test_DateC.py:1.13	Thu Aug 12 11:07:43 2004
+++ Products/CMFTopic/tests/test_DateC.py	Mon Jun 13 13:32:05 2005
@@ -10,22 +10,22 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-""" Unit tests for DateCriterion module.
+""" Unit tests for DateCriteria module.
 
 $Id$
 """
 
-from unittest import TestCase, TestSuite, makeSuite, main
+from unittest import TestSuite, makeSuite, main
 import Testing
 import Zope
 Zope.startup()
 
 from DateTime.DateTime import DateTime
 
-from Products.CMFTopic.DateCriteria import FriendlyDateCriterion
+from common import CriterionTestCase
 
 
-class FriendlyDateCriterionTests(TestCase):
+class FriendlyDateCriterionTests(CriterionTestCase):
 
     lessThanFiveDaysOld = { 'value': 4
                           , 'operation': 'min'
@@ -41,13 +41,13 @@
             , 'daterange': 'ahead'
             }
 
-    def test_Interface( self ):
-        from Products.CMFTopic.interfaces import Criterion
-        self.failUnless(
-            Criterion.isImplementedByInstancesOf( FriendlyDateCriterion ) )
+    def _getTargetClass(self):
+        from Products.CMFTopic.DateCriteria import FriendlyDateCriterion
+
+        return FriendlyDateCriterion
 
     def test_Empty( self ):
-        friendly = FriendlyDateCriterion( 'foo', 'foofield' )
+        friendly = self._makeOne('foo', 'foofield')
 
         self.assertEqual( friendly.getId(), 'foo' )
         self.assertEqual( friendly.field, 'foofield' )
@@ -57,7 +57,7 @@
         self.assertEqual( len( friendly.getCriteriaItems() ), 0 )
 
     def test_ListOfDefaultDates( self ):
-        friendly = FriendlyDateCriterion( 'foo', 'foofield' )
+        friendly = self._makeOne('foo', 'foofield')
 
         d = friendly.defaultDateOptions()
         self.assertEqual( d[0][0], 0 )
@@ -65,7 +65,7 @@
         self.assertEqual( d[2][0], 2 )
 
     def test_Clear( self ):
-        friendly = FriendlyDateCriterion( 'foo', 'foofield' )
+        friendly = self._makeOne('foo', 'foofield')
 
         friendly.edit( value=None )
         self.assertEqual( friendly.value, None )
@@ -73,7 +73,7 @@
         self.assertEqual( friendly.daterange, 'old' )
 
     def test_Basic( self ):
-        friendly = FriendlyDateCriterion( 'foo', 'foofield' )
+        friendly = self._makeOne('foo', 'foofield')
 
         friendly.apply( self.lessThanFiveDaysOld )
         self.assertEqual( friendly.value, 4 )
@@ -81,7 +81,7 @@
         self.assertEqual( friendly.daterange, 'old' )
 
     def test_BadInput( self ):
-        friendly = FriendlyDateCriterion( 'foo', 'foofield' )
+        friendly = self._makeOne('foo', 'foofield')
 
         # Bogus value
         self.assertRaises( ValueError, friendly.edit, 'blah' )
@@ -93,7 +93,7 @@
         self.assertRaises( ValueError, friendly.edit, 4, 'max', 'new' )
 
     def test_StringAsValue( self ):
-        friendly = FriendlyDateCriterion( 'foo', 'foofield' )
+        friendly = self._makeOne('foo', 'foofield')
 
         friendly.edit( '4' )
         self.assertEqual( friendly.value, 4 )
@@ -105,7 +105,7 @@
         self.assertEqual( friendly.value, None )
 
     def test_Today( self ):
-        friendly = FriendlyDateCriterion( 'foo', 'foofield' )
+        friendly = self._makeOne('foo', 'foofield')
 
         friendly.apply( self.today )
         self.assertEqual( friendly.daterange, 'ahead' )
@@ -120,7 +120,7 @@
         self.assertEqual( result[0][1]['range'], 'min:max' )
 
     def test_FiveDaysOld( self ):
-        friendly = FriendlyDateCriterion( 'foo', 'foofield' )
+        friendly = self._makeOne('foo', 'foofield')
 
         friendly.apply( self.lessThanFiveDaysOld )
         self.assertEqual( friendly.daterange, 'old' )
@@ -133,7 +133,7 @@
         self.assertEqual( result[0][1]['range'], 'min' )
 
     def test_OneMonthAhead( self ):
-        friendly = FriendlyDateCriterion( 'foo', 'foofield' )
+        friendly = self._makeOne('foo', 'foofield')
 
         friendly.apply( self.lessThanOneMonthAhead )
         self.assertEqual( friendly.daterange, 'ahead' )


=== Products/CMFTopic/tests/test_ListC.py 1.11 => 1.12 ===
--- Products/CMFTopic/tests/test_ListC.py:1.11	Thu Aug 12 11:07:43 2004
+++ Products/CMFTopic/tests/test_ListC.py	Mon Jun 13 13:32:05 2005
@@ -15,24 +15,23 @@
 $Id$
 """
 
-from unittest import TestCase, TestSuite, makeSuite, main
+from unittest import TestSuite, makeSuite, main
 import Testing
 import Zope
 Zope.startup()
 
+from common import CriterionTestCase
 
-class ListCriterionTests(TestCase):
 
-    def test_Interface( self ):
-        from Products.CMFTopic.interfaces import Criterion
+class ListCriterionTests(CriterionTestCase):
+
+    def _getTargetClass(self):
         from Products.CMFTopic.ListCriterion import ListCriterion
-        self.failUnless(
-            Criterion.isImplementedByInstancesOf( ListCriterion ) )
 
-    def test_Empty( self ):
+        return ListCriterion
 
-        from Products.CMFTopic.ListCriterion import ListCriterion
-        listc = ListCriterion('foo', 'foofield')
+    def test_Empty( self ):
+        listc = self._makeOne('foo', 'foofield')
 
         self.assertEqual( listc.getId(), 'foo' )
         self.assertEqual( listc.field, 'foofield' )
@@ -40,9 +39,7 @@
         self.assertEqual( len(listc.getCriteriaItems()), 0 )
 
     def test_Edit_withString( self ):
-
-        from Products.CMFTopic.ListCriterion import ListCriterion
-        listc = ListCriterion( 'foo', 'foofield' )
+        listc = self._makeOne('foo', 'foofield')
 
         listc.edit('bar\nbaz')
         self.assertEqual( listc.getId(), 'foo' )
@@ -56,9 +53,7 @@
         self.assertEqual( items[0][1], ( 'bar', 'baz' ) )
 
     def test_Edit_withList( self ):
-
-        from Products.CMFTopic.ListCriterion import ListCriterion
-        listc = ListCriterion( 'foo', 'foofield' )
+        listc = self._makeOne('foo', 'foofield')
 
         abc = [ 'a', 'b', 'c' ]
         listc.edit( abc )
@@ -68,9 +63,7 @@
         self.failUnless( tuple( abc ) in map( lambda x: x[1], items ) )
 
     def test_operator( self ):
-
-        from Products.CMFTopic.ListCriterion import ListCriterion
-        listc = ListCriterion( 'foo', 'foofield' )
+        listc = self._makeOne('foo', 'foofield')
 
         abc = [ 'a', 'b', 'c' ]
 


=== Products/CMFTopic/tests/test_SIC.py 1.11 => 1.12 ===
--- Products/CMFTopic/tests/test_SIC.py:1.11	Thu Aug 12 11:07:43 2004
+++ Products/CMFTopic/tests/test_SIC.py	Mon Jun 13 13:32:05 2005
@@ -15,23 +15,23 @@
 $Id$
 """
 
-from unittest import TestCase, TestSuite, makeSuite, main
+from unittest import TestSuite, makeSuite, main
 import Testing
 import Zope
 Zope.startup()
 
-from Products.CMFTopic.SimpleIntCriterion import SimpleIntCriterion
+from common import CriterionTestCase
 
 
-class SimpleIntCriterionTests(TestCase):
+class SimpleIntCriterionTests(CriterionTestCase):
 
-    def test_Interface( self ):
-        from Products.CMFTopic.interfaces import Criterion
-        self.failUnless(
-            Criterion.isImplementedByInstancesOf( SimpleIntCriterion ) )
+    def _getTargetClass(self):
+        from Products.CMFTopic.SimpleIntCriterion import SimpleIntCriterion
+
+        return SimpleIntCriterion
 
     def test_Empty( self ):
-        sic = SimpleIntCriterion( 'foo', 'foofield' )
+        sic = self._makeOne('foo', 'foofield')
         self.assertEqual( sic.getId(), 'foo' )
         self.assertEqual( sic.field, 'foofield' )
         self.assertEqual( sic.value, None )
@@ -39,7 +39,7 @@
         self.assertEqual( len(sic.getCriteriaItems() ), 0 )
 
     def test_EditWithString( self ):
-        sic = SimpleIntCriterion('foo', 'foofield')
+        sic = self._makeOne('foo', 'foofield')
         sic.edit('0')
         self.assertEqual( sic.value, 0 )
         self.assertEqual( sic.getValueString(), '0' )
@@ -51,7 +51,7 @@
         self.assertEqual( items[0][1], 0 )
 
     def test_EditWithInt( self ):
-        sic = SimpleIntCriterion( 'foo', 'foofield' )
+        sic = self._makeOne('foo', 'foofield')
         sic.edit( 32 )
         self.assertEqual( sic.value, 32 )
         self.assertEqual( sic.getValueString(), '32' )
@@ -62,8 +62,8 @@
         self.assertEqual( items[0][1], 32 )
 
     def test_RangeMin( self ):
-        sic = SimpleIntCriterion( 'foo', 'foofield' )
-        sic.edit( '32', SimpleIntCriterion.MINIMUM )
+        sic = self._makeOne('foo', 'foofield')
+        sic.edit( '32', self._getTargetClass().MINIMUM )
 
         self.assertEqual( sic.value, 32 )
         self.assertEqual( sic.getValueString(), '32' )
@@ -76,8 +76,8 @@
         self.assertEqual( items[0][1]['range'], 'min' )
 
     def test_RangeMin_withInt( self ):
-        sic = SimpleIntCriterion( 'foo', 'foofield' )
-        sic.edit( 32, SimpleIntCriterion.MINIMUM )
+        sic = self._makeOne('foo', 'foofield')
+        sic.edit( 32, self._getTargetClass().MINIMUM )
 
         self.assertEqual( sic.value, 32 )
         self.assertEqual( sic.getValueString(), '32' )
@@ -90,8 +90,8 @@
         self.assertEqual( items[0][1]['range'], 'min' )
 
     def test_RangeMax( self ):
-        sic = SimpleIntCriterion( 'foo', 'foofield' )
-        sic.edit( '32', SimpleIntCriterion.MAXIMUM )
+        sic = self._makeOne('foo', 'foofield')
+        sic.edit( '32', self._getTargetClass().MAXIMUM )
 
         self.assertEqual( sic.value, 32 )
         self.assertEqual( sic.getValueString(), '32' )
@@ -104,8 +104,8 @@
         self.assertEqual( items[0][1]['range'], 'max' )
 
     def test_RangeMax_withInt( self ):
-        sic = SimpleIntCriterion( 'foo', 'foofield' )
-        sic.edit( 32, SimpleIntCriterion.MAXIMUM )
+        sic = self._makeOne('foo', 'foofield')
+        sic.edit( 32, self._getTargetClass().MAXIMUM )
 
         self.assertEqual( sic.value, 32 )
         self.assertEqual( sic.getValueString(), '32' )
@@ -118,8 +118,8 @@
         self.assertEqual( items[0][1]['range'], 'max' )
 
     def test_RangeMinMax( self ):
-        sic = SimpleIntCriterion( 'foo', 'foofield' )
-        sic.edit( '32 34', SimpleIntCriterion.MINMAX )
+        sic = self._makeOne('foo', 'foofield')
+        sic.edit( '32 34', self._getTargetClass().MINMAX )
 
         self.assertEqual( sic.value, ( 32, 34 ) )
         self.assertEqual( sic.getValueString(), '32 34' )
@@ -132,8 +132,8 @@
         self.assertEqual( items[0][1]['range'], 'min:max' )
 
     def test_RangeMinMax_withTuple( self ):
-        sic = SimpleIntCriterion( 'foo', 'foofield' )
-        sic.edit( ( 32, 34 ), SimpleIntCriterion.MINMAX )
+        sic = self._makeOne('foo', 'foofield')
+        sic.edit( ( 32, 34 ), self._getTargetClass().MINMAX )
 
         self.assertEqual( sic.value, ( 32, 34 ) )
         self.assertEqual( sic.getValueString(), '32 34' )


=== Products/CMFTopic/tests/test_SSC.py 1.10 => 1.11 ===
--- Products/CMFTopic/tests/test_SSC.py:1.10	Thu Aug 12 11:07:43 2004
+++ Products/CMFTopic/tests/test_SSC.py	Mon Jun 13 13:32:05 2005
@@ -15,27 +15,24 @@
 $Id$
 """
 
-from unittest import TestCase, TestSuite, makeSuite, main
+from unittest import TestSuite, makeSuite, main
 import Testing
 import Zope
 Zope.startup()
 
+from common import CriterionTestCase
 
-class SimpleStringCriterionTests(TestCase):
 
-    def test_Interface( self ):
-        from Products.CMFTopic.interfaces import Criterion
-        from Products.CMFTopic.SimpleStringCriterion \
-            import SimpleStringCriterion
-        self.failUnless(
-            Criterion.isImplementedByInstancesOf( SimpleStringCriterion ) )
-
-    def test_Empty( self ):
+class SimpleStringCriterionTests(CriterionTestCase):
 
+    def _getTargetClass(self):
         from Products.CMFTopic.SimpleStringCriterion \
-            import SimpleStringCriterion
+                import SimpleStringCriterion
+
+        return SimpleStringCriterion
 
-        ssc = SimpleStringCriterion( 'foo', 'foofield' )
+    def test_Empty( self ):
+        ssc = self._makeOne('foo', 'foofield')
 
         self.assertEqual( ssc.getId(), 'foo' )
         self.assertEqual( ssc.field, 'foofield' )
@@ -43,11 +40,7 @@
         self.assertEqual( len( ssc.getCriteriaItems() ), 0 )
 
     def test_Nonempty( self ):
-
-        from Products.CMFTopic.SimpleStringCriterion \
-            import SimpleStringCriterion
-
-        ssc = SimpleStringCriterion( 'foo', 'foofield' )
+        ssc = self._makeOne('foo', 'foofield')
         ssc.edit( 'bar' )
 
         self.assertEqual( ssc.getId(), 'foo' )


=== Products/CMFTopic/tests/test_SortC.py 1.6 => 1.7 ===
--- Products/CMFTopic/tests/test_SortC.py:1.6	Thu Aug 12 11:07:43 2004
+++ Products/CMFTopic/tests/test_SortC.py	Mon Jun 13 13:32:05 2005
@@ -15,24 +15,23 @@
 $Id$
 """
 
-from unittest import TestCase, TestSuite, makeSuite, main
+from unittest import TestSuite, makeSuite, main
 import Testing
 import Zope
 Zope.startup()
 
+from common import CriterionTestCase
 
-class SortCriterionTests(TestCase):
 
-    def test_Interface( self ):
-        from Products.CMFTopic.interfaces import Criterion
+class SortCriterionTests(CriterionTestCase):
+
+    def _getTargetClass(self):
         from Products.CMFTopic.SortCriterion import SortCriterion
-        self.failUnless(
-            Criterion.isImplementedByInstancesOf( SortCriterion ) )
 
-    def test_Empty( self ):
+        return SortCriterion
 
-        from Products.CMFTopic.SortCriterion import SortCriterion
-        ssc = SortCriterion( 'foo', 'foofield' )
+    def test_Empty( self ):
+        ssc = self._makeOne('foo', 'foofield')
 
         self.assertEqual( ssc.getId(), 'foo' )
         self.assertEqual( ssc.field, None )
@@ -46,9 +45,7 @@
         self.assertEqual( items[0][1], 'foofield' )
 
     def test_Nonempty( self ):
-
-        from Products.CMFTopic.SortCriterion import SortCriterion
-        ssc = SortCriterion( 'foo', 'foofield' )
+        ssc = self._makeOne('foo', 'foofield')
 
         ssc.edit( 1 )
 


=== Products/CMFTopic/tests/test_Topic.py 1.15 => 1.16 ===
--- Products/CMFTopic/tests/test_Topic.py:1.15	Thu Aug 12 11:07:43 2004
+++ Products/CMFTopic/tests/test_Topic.py	Mon Jun 13 13:32:05 2005
@@ -27,7 +27,7 @@
 from Products.CMFCore.TypesTool import FactoryTypeInformation as FTI
 from Products.CMFCore.TypesTool import TypesTool
 from Products.CMFTopic.Topic import factory_type_information as FTIDATA_TOPIC
-from Products.CMFTopic.Topic import Topic
+
 
 class FauxBrain( Implicit ):
 
@@ -39,6 +39,7 @@
 
         return self._object
 
+
 class DummyDocument( Implicit ):
 
     def __init__( self, id ):
@@ -119,8 +120,7 @@
 
 
 class TestTopic(SecurityTest):
-    """
-        Test all the general Topic cases
+    """ Test all the general Topic cases.
     """
 
     def setUp(self):
@@ -128,6 +128,8 @@
         self.site = DummySite('site').__of__(self.root)
 
     def _makeOne(self, id, *args, **kw):
+        from Products.CMFTopic.Topic import Topic
+
         return self.site._setObject( id, Topic(id, *args, **kw) )
 
     def _initSite( self, max_items=15, index_ids=() ):
@@ -145,6 +147,34 @@
             self.site._setObject( k, v )
             self.site.portal_catalog._index( document )
 
+    def test_z2interfaces(self):
+        from Interface.Verify import verifyClass
+        from OFS.IOrderSupport import IOrderedContainer
+        from webdav.WriteLockInterface import WriteLockInterface
+        from Products.CMFCore.interfaces.Dynamic \
+                import DynamicType as IDynamicType
+        from Products.CMFCore.interfaces.Folderish \
+                import Folderish as IFolderish
+        from Products.CMFTopic.Topic import Topic
+
+        verifyClass(IDynamicType, Topic)
+        verifyClass(IFolderish, Topic)
+        verifyClass(IOrderedContainer, Topic)
+        verifyClass(WriteLockInterface, Topic)
+
+    def test_z3interfaces(self):
+        try:
+            from zope.interface.verify import verifyClass
+        except ImportError:
+            # BBB: for Zope 2.7
+            return
+        from Products.CMFCore.interfaces import IDynamicType
+        from Products.CMFCore.interfaces import IFolderish
+        from Products.CMFTopic.Topic import Topic
+
+        verifyClass(IDynamicType, Topic)
+        verifyClass(IFolderish, Topic)
+
     def test_Empty( self ):
         topic = self._makeOne('top')
 
@@ -277,6 +307,7 @@
 , 'six'     : "gonna wash that man right out of my hair"
 , 'seven'   : "I'm so much in love"
 }
+
 
 def test_suite():
     return TestSuite((



More information about the CMF-checkins mailing list