[CMF-checkins] SVN: CMF/trunk/CMFDefault/ - moved 'implements' declarations from exportimport.zcml into the python code

Yvo Schubbe y.2005- at wcm-solutions.de
Tue Nov 8 11:14:01 EST 2005


Log message for revision 39979:
  - moved 'implements' declarations from exportimport.zcml into the python code
  - split off test_File.py from test_Image.py
  - refactored interface tests for content classes

Changed:
  U   CMF/trunk/CMFDefault/Document.py
  U   CMF/trunk/CMFDefault/File.py
  U   CMF/trunk/CMFDefault/Image.py
  U   CMF/trunk/CMFDefault/Link.py
  U   CMF/trunk/CMFDefault/configure.zcml
  D   CMF/trunk/CMFDefault/exportimport.zcml
  A   CMF/trunk/CMFDefault/tests/common.py
  U   CMF/trunk/CMFDefault/tests/test_Document.py
  U   CMF/trunk/CMFDefault/tests/test_Favorite.py
  A   CMF/trunk/CMFDefault/tests/test_File.py
  U   CMF/trunk/CMFDefault/tests/test_Image.py
  U   CMF/trunk/CMFDefault/tests/test_Link.py
  U   CMF/trunk/CMFDefault/tests/test_NewsItem.py

-=-
Modified: CMF/trunk/CMFDefault/Document.py
===================================================================
--- CMF/trunk/CMFDefault/Document.py	2005-11-08 16:12:53 UTC (rev 39978)
+++ CMF/trunk/CMFDefault/Document.py	2005-11-08 16:14:00 UTC (rev 39979)
@@ -25,6 +25,7 @@
 from StructuredText.StructuredText import HTML
 from zope.interface import implements
 
+from Products.CMFCore.interfaces import IDAVAware
 from Products.CMFCore.PortalContent import PortalContent
 from Products.CMFCore.utils import contributorsplitter
 from Products.CMFCore.utils import keywordsplitter
@@ -58,7 +59,7 @@
     """A Document - Handles both StructuredText and HTML.
     """
 
-    implements(IDocument, IMutableDocument)
+    implements(IDocument, IMutableDocument, IDAVAware)
     __implements__ = (z2IDocument, z2IMutableDocument,
                       PortalContent.__implements__,
                       DefaultDublinCoreImpl.__implements__)

Modified: CMF/trunk/CMFDefault/File.py
===================================================================
--- CMF/trunk/CMFDefault/File.py	2005-11-08 16:12:53 UTC (rev 39978)
+++ CMF/trunk/CMFDefault/File.py	2005-11-08 16:14:00 UTC (rev 39979)
@@ -20,7 +20,9 @@
 import OFS.Image
 from Globals import InitializeClass
 from AccessControl import ClassSecurityInfo
+from zope.interface import implements
 
+from Products.CMFCore.interfaces import IDAVAware
 from Products.CMFCore.PortalContent import PortalContent
 
 from DublinCore import DefaultDublinCoreImpl
@@ -67,10 +69,7 @@
     self._getOb(id).manage_upload(file)
 
 
-class File( OFS.Image.File
-          , PortalContent
-          , DefaultDublinCoreImpl
-          ):
+class File(OFS.Image.File, PortalContent, DefaultDublinCoreImpl):
 
     """A Portal-managed File.
     """
@@ -88,6 +87,7 @@
     # this problem altogether. getId is the new way, accessing .id is
     # deprecated.
 
+    implements(IDAVAware)
     __implements__ = ( PortalContent.__implements__
                      , DefaultDublinCoreImpl.__implements__
                      )

Modified: CMF/trunk/CMFDefault/Image.py
===================================================================
--- CMF/trunk/CMFDefault/Image.py	2005-11-08 16:12:53 UTC (rev 39978)
+++ CMF/trunk/CMFDefault/Image.py	2005-11-08 16:14:00 UTC (rev 39979)
@@ -17,9 +17,11 @@
 """
 
 import OFS.Image
+from AccessControl import ClassSecurityInfo
 from Globals import InitializeClass
-from AccessControl import ClassSecurityInfo
+from zope.interface import implements
 
+from Products.CMFCore.interfaces import IDAVAware
 from Products.CMFCore.PortalContent import PortalContent
 
 from DublinCore import DefaultDublinCoreImpl
@@ -65,13 +67,10 @@
     self._getOb(id).manage_upload(file)
 
 
-class Image( OFS.Image.Image
-           , PortalContent
-           , DefaultDublinCoreImpl
-           ):
+class Image(OFS.Image.Image, PortalContent, DefaultDublinCoreImpl):
+
+    """A Portal-managed Image.
     """
-        A Portal-managed Image
-    """
 
     # The order of base classes is very significant in this case.
     # Image.Image does not store it's id in it's 'id' attribute.
@@ -86,6 +85,7 @@
     # this problem altogether. getId is the new way, accessing .id is
     # deprecated.
 
+    implements(IDAVAware)
     __implements__ = ( PortalContent.__implements__
                      , DefaultDublinCoreImpl.__implements__
                      )

Modified: CMF/trunk/CMFDefault/Link.py
===================================================================
--- CMF/trunk/CMFDefault/Link.py	2005-11-08 16:12:53 UTC (rev 39978)
+++ CMF/trunk/CMFDefault/Link.py	2005-11-08 16:14:00 UTC (rev 39979)
@@ -21,7 +21,9 @@
 from AccessControl import ClassSecurityInfo
 from Globals import DTMLFile
 from Globals import InitializeClass
+from zope.interface import implements
 
+from Products.CMFCore.interfaces import IDAVAware
 from Products.CMFCore.PortalContent import PortalContent
 from Products.CMFCore.utils import contributorsplitter
 from Products.CMFCore.utils import keywordsplitter
@@ -52,6 +54,7 @@
     """A Link.
     """
 
+    implements(IDAVAware)
     __implements__ = ( PortalContent.__implements__
                      , DefaultDublinCoreImpl.__implements__
                      )

Modified: CMF/trunk/CMFDefault/configure.zcml
===================================================================
--- CMF/trunk/CMFDefault/configure.zcml	2005-11-08 16:12:53 UTC (rev 39978)
+++ CMF/trunk/CMFDefault/configure.zcml	2005-11-08 16:14:00 UTC (rev 39979)
@@ -6,8 +6,4 @@
     package=".skin"
     />
 
-  <include
-    file="exportimport.zcml"
-    />
-
 </configure>

Deleted: CMF/trunk/CMFDefault/exportimport.zcml
===================================================================
--- CMF/trunk/CMFDefault/exportimport.zcml	2005-11-08 16:12:53 UTC (rev 39978)
+++ CMF/trunk/CMFDefault/exportimport.zcml	2005-11-08 16:14:00 UTC (rev 39979)
@@ -1,38 +0,0 @@
-<configure
-    xmlns="http://namespaces.zope.org/zope"
-    xmlns:five="http://namespaces.zope.org/five"
-    i18n_domain="cmf"
-    >
-
-  <five:implements
-    class=".Portal.CMFSite"
-    interface="Products.CMFCore.interfaces.ISiteRoot"
-    />
-
-  <five:implements
-    class=".Document.Document"
-    interface="Products.CMFCore.interfaces.IDAVAware"
-    />
-
-  <five:implements
-    class=".File.File"
-    interface="Products.CMFCore.interfaces.IDAVAware"
-    />
-
-  <five:implements
-    class=".Image.Image"
-    interface="Products.CMFCore.interfaces.IDAVAware"
-    />
-
-  <five:implements
-    class=".Link.Link"
-    interface="Products.CMFCore.interfaces.IDAVAware"
-    />
-
-  <five:implements
-    class=".NewsItem.NewsItem"
-    interface="Products.CMFCore.interfaces.IDAVAware"
-    />
-
-</configure>
-

Added: CMF/trunk/CMFDefault/tests/common.py
===================================================================
--- CMF/trunk/CMFDefault/tests/common.py	2005-11-08 16:12:53 UTC (rev 39978)
+++ CMF/trunk/CMFDefault/tests/common.py	2005-11-08 16:14:00 UTC (rev 39979)
@@ -0,0 +1,53 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+""" Unit tests mixin classes.
+
+$Id$
+"""
+
+class ConformsToContent:
+
+    def test_content_z2interfaces(self):
+        from Interface.Verify import verifyClass
+        from Products.CMFCore.interfaces.Contentish \
+                import Contentish as IContentish
+        from Products.CMFCore.interfaces.DublinCore \
+                import CatalogableDublinCore as ICatalogableDublinCore
+        from Products.CMFCore.interfaces.DublinCore \
+                import DublinCore as IDublinCore
+        from Products.CMFCore.interfaces.DublinCore \
+                import MutableDublinCore as IMutableDublinCore
+        from Products.CMFCore.interfaces.Dynamic \
+                import DynamicType as IDynamicType
+
+        verifyClass(ICatalogableDublinCore, self._getTargetClass())
+        verifyClass(IContentish, self._getTargetClass())
+        verifyClass(IDublinCore, self._getTargetClass())
+        verifyClass(IDynamicType, self._getTargetClass())
+        verifyClass(IMutableDublinCore, self._getTargetClass())
+
+    def test_content_z3interfaces(self):
+        from zope.interface.verify import verifyClass
+        from Products.CMFCore.interfaces import ICatalogableDublinCore
+        from Products.CMFCore.interfaces import IContentish
+        from Products.CMFCore.interfaces import IDAVAware
+        from Products.CMFCore.interfaces import IDublinCore
+        from Products.CMFCore.interfaces import IDynamicType
+        from Products.CMFCore.interfaces import IMutableDublinCore
+
+        verifyClass(ICatalogableDublinCore, self._getTargetClass())
+        verifyClass(IContentish, self._getTargetClass())
+        verifyClass(IDAVAware, self._getTargetClass())
+        verifyClass(IDublinCore, self._getTargetClass())
+        verifyClass(IDynamicType, self._getTargetClass())
+        verifyClass(IMutableDublinCore, self._getTargetClass())


Property changes on: CMF/trunk/CMFDefault/tests/common.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: CMF/trunk/CMFDefault/tests/test_Document.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_Document.py	2005-11-08 16:12:53 UTC (rev 39978)
+++ CMF/trunk/CMFDefault/tests/test_Document.py	2005-11-08 16:14:00 UTC (rev 39979)
@@ -15,10 +15,8 @@
 $Id$
 """
 
-from unittest import TestSuite, makeSuite, main
+import unittest
 import Testing
-import Zope2
-Zope2.startup()
 
 from os.path import abspath
 from os.path import dirname
@@ -42,71 +40,43 @@
 from Products.CMFCore.tests.base.content import STX_NO_HEADERS_BUT_COLON
 from Products.CMFCore.tests.base.content import STX_WITH_HTML
 from Products.CMFCore.tests.base.dummy import DummySite
-from Products.CMFCore.tests.base.dummy import DummyTool
 from Products.CMFCore.tests.base.testcase import RequestTest
 from Products.CMFCore.tests.base.tidata import FTIDATA_CMF15
 from Products.CMFCore.TypesTool import FactoryTypeInformation as FTI
 from Products.CMFCore.TypesTool import TypesTool
 from Products.CMFDefault import utils
 
+from common import ConformsToContent
 
+
 class RequestTestBase(RequestTest):
 
-    def setUp(self):
-        RequestTest.setUp(self)
-        self.site = DummySite('site').__of__(self.root)
-        self.site._setObject( 'portal_membership', DummyTool() )
-
-    def _makeOne(self, id, *args, **kw):
+    def _getTargetClass(self):
         from Products.CMFDefault.Document import Document
 
-        return self.site._setObject( id, Document(id, *args, **kw) )
+        return Document
 
+    def _makeOne(self, *args, **kw):
+        return self._getTargetClass()(*args, **kw)
 
-class DocumentTests(RequestTestBase):
 
+class DocumentTests(ConformsToContent, RequestTestBase):
+
     def test_z2interfaces(self):
         from Interface.Verify import verifyClass
-        from Products.CMFCore.interfaces.Contentish \
-                import Contentish as IContentish
-        from Products.CMFCore.interfaces.DublinCore \
-                import CatalogableDublinCore as ICatalogableDublinCore
-        from Products.CMFCore.interfaces.DublinCore \
-                import DublinCore as IDublinCore
-        from Products.CMFCore.interfaces.DublinCore \
-                import MutableDublinCore as IMutableDublinCore
-        from Products.CMFCore.interfaces.Dynamic \
-                import DynamicType as IDynamicType
-        from Products.CMFDefault.Document import Document
         from Products.CMFDefault.interfaces.Document import IDocument
         from Products.CMFDefault.interfaces.Document import IMutableDocument
 
-        verifyClass(ICatalogableDublinCore, Document)
-        verifyClass(IContentish, Document)
-        verifyClass(IDocument, Document)
-        verifyClass(IDublinCore, Document)
-        verifyClass(IDynamicType, Document)
-        verifyClass(IMutableDocument, Document)
-        verifyClass(IMutableDublinCore, Document)
+        verifyClass(IDocument, self._getTargetClass())
+        verifyClass(IMutableDocument, self._getTargetClass())
 
     def test_z3interfaces(self):
         from zope.interface.verify import verifyClass
-        from Products.CMFCore.interfaces import ICatalogableDublinCore
-        from Products.CMFCore.interfaces import IContentish
-        from Products.CMFCore.interfaces import IDublinCore
-        from Products.CMFCore.interfaces import IDynamicType
-        from Products.CMFCore.interfaces import IMutableDublinCore
-        from Products.CMFDefault.Document import Document
         from Products.CMFDefault.interfaces import IDocument
         from Products.CMFDefault.interfaces import IMutableDocument
 
-        verifyClass(ICatalogableDublinCore, Document)
-        verifyClass(IContentish, Document)
-        verifyClass(IDocument, Document)
-        verifyClass(IDublinCore, Document)
-        verifyClass(IDynamicType, Document)
-        verifyClass(IMutableDocument, Document)
-        verifyClass(IMutableDublinCore, Document)
+        verifyClass(IDocument, self._getTargetClass())
+        verifyClass(IMutableDocument, self._getTargetClass())
 
     def test_Empty(self):
         d = self._makeOne('foo', text_format='structured-text')
@@ -405,6 +375,10 @@
 
 class DocumentFTPGetTests(RequestTestBase):
 
+    def setUp(self):
+        RequestTest.setUp(self)
+        self.site = DummySite('site').__of__(self.root)
+
     def testHTML( self ):
         self.REQUEST['BODY']=BASIC_HTML
 
@@ -499,14 +473,8 @@
             self.failUnless( header in get_headers )
 
 
-class DocumentPUTTests(RequestTest):
+class DocumentPUTTests(RequestTestBase):
 
-    def _makeOne(self, id, *args, **kw):
-        from Products.CMFDefault.Document import Document
-
-        # NullResource.PUT calls the PUT method on the bare object!
-        return Document(id, *args, **kw)
-
     def test_PUTBasicHTML(self):
         self.REQUEST['BODY'] = BASIC_HTML
         d = self._makeOne('foo')
@@ -588,11 +556,11 @@
 
 
 def test_suite():
-    return TestSuite((
-        makeSuite(DocumentTests),
-        makeSuite(DocumentFTPGetTests),
-        makeSuite(DocumentPUTTests),
+    return unittest.TestSuite((
+        unittest.makeSuite(DocumentTests),
+        unittest.makeSuite(DocumentFTPGetTests),
+        unittest.makeSuite(DocumentPUTTests),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')

Modified: CMF/trunk/CMFDefault/tests/test_Favorite.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_Favorite.py	2005-11-08 16:12:53 UTC (rev 39978)
+++ CMF/trunk/CMFDefault/tests/test_Favorite.py	2005-11-08 16:14:00 UTC (rev 39979)
@@ -15,29 +15,33 @@
 $Id$
 """
 
-from unittest import TestCase, TestSuite, makeSuite, main
+import unittest
 import Testing
-import Zope2
-Zope2.startup()
 
 from Products.CMFCore.tests.base.dummy import DummySite
 from Products.CMFCore.tests.base.dummy import DummyTool
-from Products.CMFDefault.Favorite import Favorite
 
+from common import ConformsToContent
 
-class FavoriteTests( TestCase ):
 
-    def setUp( self ):
+class FavoriteTests(ConformsToContent, unittest.TestCase):
+
+    def _getTargetClass(self):
+        from Products.CMFDefault.Favorite import Favorite
+
+        return Favorite
+
+    def _makeOne(self, *args, **kw):
+        return self._getTargetClass()(*args, **kw)
+
+    def setUp(self):
         self.site = DummySite('site')
         self.site._setObject( 'portal_membership', DummyTool() )
         self.site._setObject( 'portal_url', DummyTool() )
 
-    def _makeOne(self, id, *args, **kw):
-        return self.site._setObject( id, Favorite(id, *args, **kw) )
-
     def test_Empty( self ):
         utool = self.site.portal_url
-        f = self._makeOne( 'foo' )
+        f = self.site._setObject('foo', self._makeOne('foo'))
 
         self.assertEqual( f.getId(), 'foo' )
         self.assertEqual( f.Title(), '' )
@@ -57,7 +61,8 @@
                                        , description='Description'
                                        ).Description(), 'Description' )
 
-        baz = self._makeOne( 'baz', remote_url='portal_url' )
+        baz = self.site._setObject('foo',
+                                self._makeOne('baz', remote_url='portal_url'))
         self.assertEqual( baz.getObject(), utool )
         self.assertEqual( baz.getRemoteUrl()
                         , '%s/portal_url' % utool.root )
@@ -65,7 +70,7 @@
 
     def test_edit( self ):
         utool = self.site.portal_url
-        f = self._makeOne( 'foo' )
+        f = self.site._setObject('foo', self._makeOne('foo'))
         f.edit( 'portal_url' )
         self.assertEqual( f.getObject(), utool )
         self.assertEqual( f.getRemoteUrl()
@@ -74,7 +79,7 @@
 
     def test_editEmpty( self ):
         utool = self.site.portal_url
-        f = self._makeOne( 'gnnn' )
+        f = self.site._setObject('gnnn', self._makeOne('gnnn'))
         f.edit( '' )
         self.assertEqual( f.getObject(), self.site )
         self.assertEqual( f.getRemoteUrl(), utool.root )
@@ -82,9 +87,9 @@
 
 
 def test_suite():
-    return TestSuite((
-        makeSuite( FavoriteTests ),
+    return unittest.TestSuite((
+        unittest.makeSuite(FavoriteTests),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')

Added: CMF/trunk/CMFDefault/tests/test_File.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_File.py	2005-11-08 16:12:53 UTC (rev 39978)
+++ CMF/trunk/CMFDefault/tests/test_File.py	2005-11-08 16:14:00 UTC (rev 39979)
@@ -0,0 +1,69 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+""" Unit tests for File module.
+
+$Id$
+"""
+
+import unittest
+import Testing
+
+from os.path import join as path_join
+
+from Products.CMFDefault import tests
+
+from common import ConformsToContent
+
+TESTS_HOME = tests.__path__[0]
+TEST_JPG = path_join(TESTS_HOME, 'TestImage.jpg')
+
+
+class FileTests(ConformsToContent, unittest.TestCase):
+
+    def _getTargetClass(self):
+        from Products.CMFDefault.File import File
+
+        return File
+
+    def _makeOne(self, *args, **kw):
+        return self._getTargetClass()(*args, **kw)
+
+    def test_File_setFormat(self):
+        # Setting the DC.format must also set the content_type property
+        file = self._makeOne('testfile', format='image/jpeg')
+        self.assertEqual(file.Format(), 'image/jpeg')
+        self.assertEqual(file.content_type, 'image/jpeg')
+        file.setFormat('image/gif')
+        self.assertEqual(file.Format(), 'image/gif')
+        self.assertEqual(file.content_type, 'image/gif')
+
+    def test_FileContentTypeUponConstruction(self):
+        # Test the content type after calling the constructor with the
+        # file object being passed in (http://www.zope.org/Collectors/CMF/370)
+        testfile = open(TEST_JPG, 'rb')
+        # Notice the cheat? File objects lack the extra intelligence that
+        # picks content types from the actual file data, so it needs to be
+        # helped along with a file extension...
+        file = self._makeOne('testfile.jpg', file=testfile)
+        testfile.close()
+        self.assertEqual(file.Format(), 'image/jpeg')
+        self.assertEqual(file.content_type, 'image/jpeg')
+
+
+def test_suite():
+    return unittest.TestSuite((
+        unittest.makeSuite(FileTests),
+        ))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')


Property changes on: CMF/trunk/CMFDefault/tests/test_File.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: CMF/trunk/CMFDefault/tests/test_Image.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_Image.py	2005-11-08 16:12:53 UTC (rev 39978)
+++ CMF/trunk/CMFDefault/tests/test_Image.py	2005-11-08 16:14:00 UTC (rev 39979)
@@ -33,22 +33,30 @@
 from Products.CMFCore.tests.base.testcase import PlacelessSetup
 from Products.CMFCore.tests.base.testcase import RequestTest
 from Products.CMFDefault import tests
-from Products.CMFDefault.File import File
-from Products.CMFDefault.Image import Image
 
+from common import ConformsToContent
+
 TESTS_HOME = tests.__path__[0]
 TEST_JPG = path_join(TESTS_HOME, 'TestImage.jpg')
 
 
-class TestImageElement(unittest.TestCase):
+class TestImageElement(ConformsToContent, unittest.TestCase):
 
+    def _getTargetClass(self):
+        from Products.CMFDefault.Image import Image
+
+        return Image
+
+    def _makeOne(self, *args, **kw):
+        return self._getTargetClass()(*args, **kw)
+
     def setUp(self):
         self.site = DummySite('site')
         self.site._setObject( 'portal_membership', DummyTool() )
 
     def test_EditWithEmptyFile(self):
         # Test handling of empty file uploads
-        image = self.site._setObject( 'testimage', Image('testimage') )
+        image = self.site._setObject('testimage', self._makeOne('testimage'))
 
         testfile = open(TEST_JPG, 'rb')
         image.edit(file=testfile)
@@ -64,18 +72,9 @@
         assert image.get_size() > 0
         assert image.get_size() == testfilesize
 
-    def test_File_setFormat(self):
-        # Setting the DC.format must also set the content_type property
-        file = File('testfile', format='image/jpeg')
-        self.assertEqual(file.Format(), 'image/jpeg')
-        self.assertEqual(file.content_type, 'image/jpeg')
-        file.setFormat('image/gif')
-        self.assertEqual(file.Format(), 'image/gif')
-        self.assertEqual(file.content_type, 'image/gif')
- 
     def test_Image_setFormat(self):
         # Setting the DC.format must also set the content_type property
-        image = Image('testimage', format='image/jpeg')
+        image = self._makeOne('testimage', format='image/jpeg')
         self.assertEqual(image.Format(), 'image/jpeg')
         self.assertEqual(image.content_type, 'image/jpeg')
         image.setFormat('image/gif')
@@ -86,24 +85,12 @@
         # Test the content type after calling the constructor with the
         # file object being passed in (http://www.zope.org/Collectors/CMF/370)
         testfile = open(TEST_JPG, 'rb')
-        image = Image('testimage', file=testfile)
+        image = self._makeOne('testimage', file=testfile)
         testfile.close()
         self.assertEqual(image.Format(), 'image/jpeg')
         self.assertEqual(image.content_type, 'image/jpeg')
 
-    def test_FileContentTypeUponConstruction(self):
-        # Test the content type after calling the constructor with the
-        # file object being passed in (http://www.zope.org/Collectors/CMF/370)
-        testfile = open(TEST_JPG, 'rb')
-        # Notice the cheat? File objects lack the extra intelligence that
-        # picks content types from the actual file data, so it needs to be
-        # helped along with a file extension...
-        file = File('testfile.jpg', file=testfile)
-        testfile.close()
-        self.assertEqual(file.Format(), 'image/jpeg')
-        self.assertEqual(file.content_type, 'image/jpeg')
 
-
 class TestImageCopyPaste(PlacelessSetup, RequestTest):
 
     # Tests related to http://www.zope.org/Collectors/CMF/176

Modified: CMF/trunk/CMFDefault/tests/test_Link.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_Link.py	2005-11-08 16:12:53 UTC (rev 39978)
+++ CMF/trunk/CMFDefault/tests/test_Link.py	2005-11-08 16:14:00 UTC (rev 39979)
@@ -14,29 +14,28 @@
 
 $Id$
 """
-from unittest import TestCase, TestSuite, makeSuite, main
+
+import unittest
 import Testing
-import Zope2
-Zope2.startup()
 
 from re import compile
 
 from Products.CMFCore.tests.base.content import BASIC_RFC822
 from Products.CMFCore.tests.base.content import RFC822_W_CONTINUATION
-from Products.CMFCore.tests.base.dummy import DummySite
-from Products.CMFCore.tests.base.dummy import DummyTool
-from Products.CMFDefault.Link import Link
 
+from common import ConformsToContent
 
-class LinkTests(TestCase):
 
-    def setUp(self):
-        self.site = DummySite('site')
-        mtool = self.site._setObject( 'portal_membership', DummyTool() )
+class LinkTests(ConformsToContent, unittest.TestCase):
 
-    def _makeOne(self, id, *args, **kw):
-        return self.site._setObject( id, Link(id, *args, **kw) )
+    def _getTargetClass(self):
+        from Products.CMFDefault.Link import Link
 
+        return Link
+
+    def _makeOne(self, *args, **kw):
+        return self._getTargetClass()(*args, **kw)
+
     def canonTest(self, table):
         for orig, wanted in table.items():
             # test with constructor
@@ -48,7 +47,7 @@
             self.assertEqual(d.getRemoteUrl(), wanted)
 
     def test_Empty( self ):
-        d = Link( 'foo' )
+        d = self._makeOne('foo')
         self.assertEqual( d.Title(), '' )
         self.assertEqual( d.Description(), '' )
         self.assertEqual( d.getRemoteUrl(), '' )
@@ -135,9 +134,9 @@
 
 
 def test_suite():
-    return TestSuite((
-        makeSuite(LinkTests),
+    return unittest.TestSuite((
+        unittest.makeSuite(LinkTests),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')

Modified: CMF/trunk/CMFDefault/tests/test_NewsItem.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_NewsItem.py	2005-11-08 16:12:53 UTC (rev 39978)
+++ CMF/trunk/CMFDefault/tests/test_NewsItem.py	2005-11-08 16:14:00 UTC (rev 39979)
@@ -24,49 +24,19 @@
 from Products.CMFCore.tests.base.content import ENTITY_IN_TITLE
 from Products.CMFCore.tests.base.testcase import RequestTest
 
+from common import ConformsToContent
 
-class NewsItemTests(unittest.TestCase):
 
-    def _makeOne(self, id, *args, **kw):
-        from Products.CMFDefault.NewsItem import NewsItem
+class NewsItemTests(ConformsToContent, unittest.TestCase):
 
-        return NewsItem(id, *args, **kw)
-
-    def test_z2interfaces(self):
-        from Interface.Verify import verifyClass
-        from Products.CMFCore.interfaces.Contentish \
-                import Contentish as IContentish
-        from Products.CMFCore.interfaces.DublinCore \
-                import CatalogableDublinCore as ICatalogableDublinCore
-        from Products.CMFCore.interfaces.DublinCore \
-                import DublinCore as IDublinCore
-        from Products.CMFCore.interfaces.DublinCore \
-                import MutableDublinCore as IMutableDublinCore
-        from Products.CMFCore.interfaces.Dynamic \
-                import DynamicType as IDynamicType
+    def _getTargetClass(self):
         from Products.CMFDefault.NewsItem import NewsItem
 
-        verifyClass(ICatalogableDublinCore, NewsItem)
-        verifyClass(IContentish, NewsItem)
-        verifyClass(IDublinCore, NewsItem)
-        verifyClass(IDynamicType, NewsItem)
-        verifyClass(IMutableDublinCore, NewsItem)
+        return NewsItem
 
-    def test_z3interfaces(self):
-        from zope.interface.verify import verifyClass
-        from Products.CMFCore.interfaces import ICatalogableDublinCore
-        from Products.CMFCore.interfaces import IContentish
-        from Products.CMFCore.interfaces import IDublinCore
-        from Products.CMFCore.interfaces import IDynamicType
-        from Products.CMFCore.interfaces import IMutableDublinCore
-        from Products.CMFDefault.NewsItem import NewsItem
+    def _makeOne(self, *args, **kw):
+        return self._getTargetClass()(*args, **kw)
 
-        verifyClass(ICatalogableDublinCore, NewsItem)
-        verifyClass(IContentish, NewsItem)
-        verifyClass(IDublinCore, NewsItem)
-        verifyClass(IDynamicType, NewsItem)
-        verifyClass(IMutableDublinCore, NewsItem)
-
     def test_Empty_html(self):
         d = self._makeOne('empty', text_format='html')
 
@@ -104,12 +74,14 @@
 
 class NewsItemPUTTests(RequestTest):
 
-    def _makeOne(self, id, *args, **kw):
+    def _getTargetClass(self):
         from Products.CMFDefault.NewsItem import NewsItem
 
-        # NullResource.PUT calls the PUT method on the bare object!
-        return NewsItem(id, *args, **kw)
+        return NewsItem
 
+    def _makeOne(self, *args, **kw):
+        return self._getTargetClass()(*args, **kw)
+
     def test_Init(self):
         self.REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
         d = self._makeOne('foo', text='')



More information about the CMF-checkins mailing list