[CMF-checkins] CVS: CMF/CMFDefault/tests - test_Discussions.py:1.14.44.1 test_Document.py:1.31.2.1 test_Favorite.py:1.7.2.1 test_Image.py:1.4.58.1 test_Link.py:1.9.56.1 test_MembershipTool.py:1.9.4.1 test_NewsItem.py:1.7.58.1

Yvo Schubbe schubbe at web.de
Thu Dec 18 09:07:05 EST 2003


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

Modified Files:
      Tag: yuppie-collector025-branch
	test_Discussions.py test_Document.py test_Favorite.py 
	test_Image.py test_Link.py test_MembershipTool.py 
	test_NewsItem.py 
Log Message:
- added portal_membership to test context of content types
- some related cleanup


=== CMF/CMFDefault/tests/test_Discussions.py 1.14 => 1.14.44.1 ===
--- CMF/CMFDefault/tests/test_Discussions.py:1.14	Mon Jan  6 15:43:10 2003
+++ CMF/CMFDefault/tests/test_Discussions.py	Thu Dec 18 09:07:03 2003
@@ -1,30 +1,30 @@
 from unittest import TestCase, TestSuite, makeSuite, main
 
+import Testing
 import Zope
 try:
+    Zope.startup()
+except AttributeError:
+    # for Zope versions before 2.6.1
+    pass
+try:
     from Interface.Verify import verifyClass
 except ImportError:
     # for Zope versions before 2.6.0
     from Interface import verify_class_implementation as verifyClass
 
-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.tests.base.dummy import DummyContent
-
 from Products.CMFCore.CatalogTool import CatalogTool
+from Products.CMFCore.tests.base.dummy import DummyContent
+from Products.CMFCore.tests.base.dummy import DummyFTI
+from Products.CMFCore.tests.base.dummy import DummySite
+from Products.CMFCore.tests.base.dummy import DummyTool
+from Products.CMFCore.tests.base.testcase import SecurityTest
+from Products.CMFCore.tests.base.utils import has_path
 from Products.CMFCore.TypesTool import TypesTool
-from Products.CMFCore.URLTool import URLTool
-from Products.CMFCore.WorkflowTool import WorkflowTool
-
-from Products.CMFDefault.DiscussionTool import DiscussionTool
-from Products.CMFDefault.DiscussionTool import DiscussionNotAllowed
 from Products.CMFDefault.DiscussionItem import DiscussionItem
 from Products.CMFDefault.DiscussionItem import DiscussionItemContainer
+from Products.CMFDefault.DiscussionTool import DiscussionNotAllowed
+from Products.CMFDefault.DiscussionTool import DiscussionTool
 
 
 class DiscussionItemTests(TestCase):
@@ -36,9 +36,18 @@
                 import Contentish as IContentish
         from Products.CMFCore.interfaces.Discussions \
                 import DiscussionResponse as IDiscussionResponse
+        from Products.CMFCore.interfaces.DublinCore \
+                import DublinCore as IDublinCore
+        from Products.CMFCore.interfaces.DublinCore \
+                import CatalogableDublinCore as ICatalogableDublinCore
+        from Products.CMFCore.interfaces.DublinCore \
+                import MutableDublinCore as IMutableDublinCore
 
         verifyClass(IDynamicType, DiscussionItem)
         verifyClass(IContentish, DiscussionItem)
+        verifyClass(IDublinCore, DiscussionItem)
+        verifyClass(ICatalogableDublinCore, DiscussionItem)
+        verifyClass(IMutableDublinCore, DiscussionItem)
         verifyClass(IDiscussionResponse, DiscussionItem)
 
 
@@ -54,67 +63,51 @@
 class DiscussionTests( SecurityTest ):
 
     def setUp( self ):
-        
         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', DummyContent( 'test', catalog=1 ) )
-            
-    def test_policy( self ):
+        self.site = DummySite('site').__of__(self.root)
+        self.site._setObject( 'portal_discussion', DiscussionTool() )
+        self.site._setObject( 'portal_membership', DummyTool() )
+        self.site._setObject( 'portal_types', TypesTool() )
+
+    def _makeDummyContent(self, id, *args, **kw):
+        return self.site._setObject( id, DummyContent(id, *args, **kw) )
 
-        test = self.root.test
-        self.assertRaises( DiscussionNotAllowed
-                         , self.discussion_tool.getDiscussionFor
-                         , test
-                         )
+    def test_policy( self ):
+        dtool = self.site.portal_discussion
+        ttool = self.site.portal_types
+        test = self._makeDummyContent('test')
+        self.assertRaises(DiscussionNotAllowed, dtool.getDiscussionFor, test)
         assert getattr( test, 'talkback', None ) is None
 
         test.allow_discussion = 1
-        assert self.discussion_tool.getDiscussionFor( test )
+        assert dtool.getDiscussionFor(test)
         assert test.talkback
 
         del test.talkback
         del test.allow_discussion
-        self.types_tool._setObject( 'Dummy Content', DummyFTI )
-        self.assertRaises( DiscussionNotAllowed
-                         , self.discussion_tool.getDiscussionFor
-                         , test
-                         )
+        ttool._setObject( 'Dummy Content', DummyFTI )
+        self.assertRaises(DiscussionNotAllowed, dtool.getDiscussionFor, test)
         assert getattr( test, 'talkback', None ) is None
 
-        ti = getattr(self.types_tool, 'Dummy Content')
+        ti = getattr(ttool, 'Dummy Content')
         ti.allow_discussion = 1
-        assert self.discussion_tool.getDiscussionFor( test )
+        assert dtool.getDiscussionFor(test)
         assert test.talkback
 
         del test.talkback
         ti.allow_discussion = 0
-        self.assertRaises( DiscussionNotAllowed
-                         , self.discussion_tool.getDiscussionFor
-                         , test
-                         )
+        self.assertRaises(DiscussionNotAllowed, dtool.getDiscussionFor, test)
         assert getattr( test, 'talkback', None ) is None
 
         test.allow_discussion = 1
-        assert self.discussion_tool.getDiscussionFor( test )
+        assert dtool.getDiscussionFor(test)
         assert test.talkback
-    
+
     def test_nestedReplies( self ):
-        test = self.root.test
+        dtool = self.site.portal_discussion
+        test = self._makeDummyContent('test')
         test.allow_discussion = 1
-        talkback = self.discussion_tool.getDiscussionFor( test )
+        talkback = dtool.getDiscussionFor(test)
         assert talkback._getDiscussable() == test
         assert talkback._getDiscussable( outer=1 ) == test
         assert not talkback.hasReplies( test )
@@ -134,7 +127,7 @@
         assert len( parents ) == 1
         assert test in parents
 
-        talkback1 = self.discussion_tool.getDiscussionFor( reply1 )
+        talkback1 = dtool.getDiscussionFor(reply1)
         assert talkback == talkback1
         assert len( talkback1.getReplies() ) == 0
         assert len( talkback.getReplies() ) == 1
@@ -160,64 +153,69 @@
         assert parents[ 0 ] == reply1
 
     def test_itemCataloguing( self ):
-
-        test = self.root.test
-        catalog = self.catalog_tool._catalog
+        ctool = self.site._setObject( 'portal_catalog', CatalogTool() )
+        dtool = self.site.portal_discussion
+        catalog = ctool._catalog
+        test = self._makeDummyContent('test', catalog=1)
         test.allow_discussion = 1
-        assert len( self.catalog_tool ) == 1
-        assert has_path( catalog, test.getPhysicalPath() )
-        talkback = self.discussion_tool.getDiscussionFor( test )
-        assert talkback.getPhysicalPath() == ( '', 'test', 'talkback' ), \
-            talkback.getPhysicalPath()
+
+        self.assertEqual( len(ctool), 1 )
+        self.failUnless( has_path( catalog, test.getPhysicalPath() ) )
+        talkback = dtool.getDiscussionFor(test)
+        self.assertEqual( talkback.getPhysicalPath(),
+                          ('', 'bar', 'site', 'test', 'talkback') )
         talkback.createReply( title='test'
                             , text='blah'
                             )
-        assert len( self.catalog_tool ) == 2
+        self.assertEqual( len(ctool), 2 )
         for reply in talkback.getReplies():
-            assert has_path( catalog, reply.getPhysicalPath() )
-            assert has_path( catalog
-                           , '/test/talkback/%s' % reply.getId() )
+            self.failUnless( has_path( catalog, reply.getPhysicalPath() ) )
+            self.failUnless( has_path( catalog,
+                              '/bar/site/test/talkback/%s' % reply.getId() ) )
 
         reply1 = talkback.getReplies()[0]
-        talkback1 = self.discussion_tool.getDiscussionFor( reply1 )
+        talkback1 = dtool.getDiscussionFor(reply1)
         talkback1.createReply( title='test2'
                              , text='blah2'
                              )
         for reply in talkback.getReplies():
-            assert has_path( catalog, reply.getPhysicalPath() )
-            assert has_path( catalog
-                           , '/test/talkback/%s' % reply.getId() )
+            self.failUnless( has_path( catalog, reply.getPhysicalPath() ) )
+            self.failUnless( has_path( catalog,
+                              '/bar/site/test/talkback/%s' % reply.getId() ) )
         for reply in talkback1.getReplies():
-            assert has_path( catalog, reply.getPhysicalPath() )
-            assert has_path( catalog
-                           , '/test/talkback/%s' % reply.getId() )
+            self.failUnless( has_path( catalog, reply.getPhysicalPath() ) )
+            self.failUnless( has_path( catalog,
+                              '/bar/site/test/talkback/%s' % reply.getId() ) )
 
     def test_deletePropagation( self ):
-
-        test = self.root.test
-
+        ctool = self.site._setObject( 'portal_catalog', CatalogTool() )
+        dtool = self.site.portal_discussion
+        test = self._makeDummyContent('test', catalog=1)
         test.allow_discussion = 1
-        talkback = self.discussion_tool.getDiscussionFor( test )
+
+        talkback = dtool.getDiscussionFor(test)
         talkback.createReply( title='test'
                             , text='blah'
                             )
-        self.root._delObject( 'test' )
-        assert len( self.catalog_tool ) == 0
+        self.assertEqual( len(ctool), 2 )
+        self.site._delObject('test')
+        self.assertEqual( len(ctool), 0 )
 
     def test_deleteReplies(self):
-        test = self.root.test
+        dtool = self.site.portal_discussion
+        test = self._makeDummyContent('test')
         test.allow_discussion = 1
 
-        talkback = self.discussion_tool.getDiscussionFor(test)
+        talkback = dtool.getDiscussionFor(test)
         id1 = talkback.createReply(title='test1', text='blah')
         reply1 = talkback.getReply(id1)
-        talkback1 = self.discussion_tool.getDiscussionFor(reply1)
+        talkback1 = dtool.getDiscussionFor(reply1)
         id2 = talkback1.createReply(title='test2', text='blah')
         reply2 = talkback1.getReply(id2)
-        talkback2 = self.discussion_tool.getDiscussionFor(reply2)
+        talkback2 = dtool.getDiscussionFor(reply2)
         id3 = talkback2.createReply(title='test3', text='blah')
         reply3 = talkback.getReply(id3)
-        talkback3 = self.discussion_tool.getDiscussionFor(reply3)
+        talkback3 = dtool.getDiscussionFor(reply3)
         self.assertEqual(len(talkback.getReplies()), 1)
         self.assertEqual(len(talkback1.getReplies()), 1)
         self.assertEqual(len(talkback2.getReplies()), 1)
@@ -226,9 +224,10 @@
         talkback.deleteReply(id2)
         self.assertEqual(len(talkback.getReplies()), 1)
         reply1 = talkback.getReply(id1)
-        talkback1 = self.discussion_tool.getDiscussionFor(reply1)
+        talkback1 = dtool.getDiscussionFor(reply1)
         self.assertEqual(len(talkback.getReplies()), 1)
         self.assertEqual(len(talkback1.getReplies()), 0)
+
 
 def test_suite():
     return TestSuite((


=== CMF/CMFDefault/tests/test_Document.py 1.31 => 1.31.2.1 ===
--- CMF/CMFDefault/tests/test_Document.py:1.31	Tue Dec  2 07:49:09 2003
+++ CMF/CMFDefault/tests/test_Document.py	Thu Dec 18 09:07:03 2003
@@ -34,6 +34,7 @@
 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
@@ -42,14 +43,21 @@
 from Products.CMFDefault.Document import Document
 
 
-class DocumentTests(RequestTest):
+class RequestTestBase(RequestTest):
 
     def setUp(self):
         RequestTest.setUp(self)
-        self.d = Document('foo')
+        self.site = DummySite('site').__of__(self.root)
+        self.site._setObject( 'portal_membership', DummyTool() )
+
+    def _makeOne(self, id, *args, **kw):
+        return self.site._setObject( id, Document(id, *args, **kw) )
+
+
+class DocumentTests(RequestTestBase):
 
     def test_Empty(self):
-        d = Document('foo', text_format='structured-text')
+        d = self._makeOne('foo', text_format='structured-text')
         self.assertEqual( d.title, '' )
         self.assertEqual( d.description, '' )
         self.assertEqual( d.text, '' )
@@ -57,7 +65,7 @@
         self.assertEqual( d._stx_level, 1 )
 
     def test_editBasicHTML(self):
-        d = self.d
+        d = self._makeOne('foo')
         d.edit('html', BASIC_HTML)
         self.failUnless( hasattr(d, 'cooked_text') )
         self.assertEqual( d.Format(), 'text/html' )
@@ -70,7 +78,7 @@
         self.assertEqual( d._stx_level, 1 )
 
     def test_editSimpleXHTML(self):
-        d = self.d
+        d = self._makeOne('foo')
         d.edit('html', SIMPLE_XHTML)
         self.failUnless( hasattr(d, 'cooked_text') )
         self.assertEqual( d.Format(), 'text/html' )
@@ -78,7 +86,7 @@
 
     def test_UpperedHtml(self):
         self.REQUEST['BODY'] = BASIC_HTML.upper()
-        d = self.d
+        d = self._makeOne('foo')
         d.PUT(self.REQUEST, self.RESPONSE)
         self.assertEqual( d.Format(), 'text/html' )
         self.assertEqual( d.title, 'TITLE IN TAG' )
@@ -88,25 +96,25 @@
 
     def test_EntityInTitle(self):
         self.REQUEST['BODY'] = ENTITY_IN_TITLE
-        d = self.d
+        d = self._makeOne('foo')
         d.PUT(self.REQUEST, self.RESPONSE)
         self.assertEqual( d.title, '&Auuml;rger' )
 
     def test_HtmlWithDoctype(self):
-        d = self.d
         self.REQUEST['BODY'] = '%s\n%s' % (DOCTYPE, BASIC_HTML)
+        d = self._makeOne('foo')
         d.PUT(self.REQUEST, self.RESPONSE)
         self.assertEqual( d.Description(), 'Describe me' )
 
     def test_HtmlWithoutNewlines(self):
-        d = self.d
         self.REQUEST['BODY'] = ''.join((BASIC_HTML.split('\n')))
+        d = self._makeOne('foo')
         d.PUT(self.REQUEST, self.RESPONSE)
         self.assertEqual( d.Format(), 'text/html' )
         self.assertEqual( d.Description(), 'Describe me' )
 
     def test_EditPlainDocumentWithEmbeddedHTML(self):
-        d = self.d
+        d = self._makeOne('foo')
         d.edit('structured-text', FAUX_HTML_LEADING_TEXT)
         fully_edited = d.cooked_text
         d._edit(FAUX_HTML_LEADING_TEXT, 'structured-text')
@@ -114,7 +122,7 @@
         self.assertEquals(fully_edited, partly_edited)
 
     def test_BigHtml(self):
-        d = self.d
+        d = self._makeOne('foo')
         s = []
         looper = '<li> number %s</li>'
         for i in range(12000): s.append(looper % i)
@@ -125,7 +133,7 @@
         self.assertEqual( d.CookedBody(), body )
 
     def test_BigHtml_via_upload(self):
-        d = self.d
+        d = self._makeOne('foo')
         s = []
         looper = '<li> number %s</li>'
         for i in range(12000): s.append(looper % i)
@@ -138,19 +146,19 @@
 
     def test_plain_text(self):
         """test that plain text forrmat works"""
-        d = self.d
+        d = self._makeOne('foo')
         d.edit(text_format='plain', text='*some plain text*\nwith a newline')
         self.assertEqual( d.CookedBody(), '*some plain text*<br />with a newline')
 
     def test_EditStructuredTextWithHTML(self):
-        d = self.d
+        d = self._makeOne('foo')
         d.edit(text_format='structured-text', text=STX_WITH_HTML)
 
         self.assertEqual( d.Format(), 'text/plain' )
 
     def test_StructuredText(self):
         self.REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
-        d = self.d
+        d = self._makeOne('foo')
         d.PUT(self.REQUEST, self.RESPONSE)
         self.failUnless( hasattr(d, 'cooked_text') )
         self.assertEqual( d.Format(), 'text/plain' )
@@ -175,7 +183,7 @@
                                 ] )
 
     def test_STX_Levels(self):
-        d = self.d
+        d = self._makeOne('foo')
         d.edit(text_format='structured-text', text=BASIC_STRUCTUREDTEXT)
         self.assertEqual( d._stx_level, 1 )
 
@@ -200,7 +208,7 @@
 
     def test_Init(self):
         self.REQUEST['BODY']=BASIC_STRUCTUREDTEXT
-        d = self.d
+        d = self._makeOne('foo')
         d.PUT(self.REQUEST, self.RESPONSE)
         self.assertEqual( d.Format(), 'text/plain' )
         self.assertEqual( d.Title(), 'My Document' )
@@ -208,28 +216,30 @@
         self.assertEqual( len(d.Contributors()), 3 )
         self.failUnless( d.cooked_text.find('<p>') >= 0 )
 
-        d = Document('foo', text='')
+        d = self._makeOne('foo', text='')
         self.REQUEST['BODY']=BASIC_HTML
         d.PUT(self.REQUEST, self.RESPONSE)
         self.assertEqual( d.Format(), 'text/html' )
         self.assertEqual( d.Title(), 'Title in tag' )
         self.assertEqual( len(d.Contributors()), 3 )
 
-        d = Document('foo', text_format='structured-text', title='Foodoc')
+        d = self._makeOne('foo', text_format='structured-text',
+                          title='Foodoc')
         self.assertEqual( d.text, '' )
         self.failIf( d.CookedBody() )
         self.assertEqual( d.title, 'Foodoc' )
         self.assertEqual( d.Format(), 'text/plain' )
 
         # Tracker issue 435:  initial text is not cooked.
-        d = Document('foo', text_format='structured-text', text=STX_NO_HEADERS)
+        d = self._makeOne('foo', text_format='structured-text',
+                          text=STX_NO_HEADERS)
         self.assertEqual( d.EditableBody(), STX_NO_HEADERS )
         self.failUnless( d.CookedBody() )
         self.assertEqual( d.Format(), 'text/plain' )
 
     def test_STX_NoHeaders( self ):
         self.REQUEST['BODY']=STX_NO_HEADERS
-        d = self.d
+        d = self._makeOne('foo')
         d.editMetadata( title="Plain STX"
                        , description="Look, Ma, no headers!"
                        , subject=( "plain", "STX" )
@@ -251,7 +261,7 @@
         self.failUnless( 'STX' in d.Subject() )
 
     def test_STX_NoHeaders_but_colon( self ):
-        d = self.d
+        d = self._makeOne('foo')
         d.editMetadata( title="Plain STX"
                        , description="Look, Ma, no headers!"
                        , subject=( "plain", "STX" )
@@ -261,7 +271,7 @@
         self.assertEqual( d.EditableBody(), STX_NO_HEADERS_BUT_COLON )
 
     def test_ZMI_edit( self ):
-        d = self.d
+        d = self._makeOne('foo')
         d.editMetadata( title="Plain STX"
                        , description="Look, Ma, no headers!"
                        , subject=( "plain", "STX" )
@@ -272,7 +282,7 @@
         self.assertEqual( d.EditableBody(), STX_NO_HEADERS_BUT_COLON )
 
     def test_Format_methods(self):
-        d = self.d
+        d = self._makeOne('foo')
         d.setFormat('plain')
         self.assertEqual( d.text_format, 'plain' )
         self.assertEqual( d.Format(), 'text/plain' )
@@ -310,29 +320,27 @@
         verifyClass(IContentish, Document)
         verifyClass(IDublinCore, Document)
         verifyClass(ICatalogableDublinCore, Document)
-        # XXX: verifyClass doesn't work with WorkflowMethod wrappers.
-        # verifyClass(IMutableDublinCore, Document)
+        verifyClass(IMutableDublinCore, Document)
 
 
-class DocumentFTPGetTests(RequestTest):
+class DocumentFTPGetTests(RequestTestBase):
 
     def testHTML( self ):
         self.REQUEST['BODY']=BASIC_HTML
 
-        site = DummySite('site').__of__(self.root)
-        ttool = site._setObject( 'portal_types', TypesTool() )
+        ttool = self.site._setObject( 'portal_types', TypesTool() )
         fti = FTIDATA_CMF15[0].copy()
         del fti['id']
         ttool._setObject( 'Document', FTI('Document', **fti) )
 
-        zpt = site._setObject( 'source_html',
-                               ZopePageTemplate('source_html') )
+        zpt = self.site._setObject( 'source_html',
+                                    ZopePageTemplate('source_html') )
         dir = abspath( dirname(utils.__file__) )
         _file = path_join(dir, 'skins', 'zpt_content', 'source_html.pt')
         data = open(_file, 'r').read()
         zpt.write(data)
 
-        d = site._setObject( 'foo', Document('foo') )
+        d = self._makeOne('foo')
         d._setPortalTypeName('Document')
         d.PUT(self.REQUEST, self.RESPONSE)
 
@@ -385,7 +393,7 @@
 
     def testSTX( self ):
         self.REQUEST['BODY']=SIMPLE_STRUCTUREDTEXT
-        d = Document( 'foo' )
+        d = self._makeOne('foo')
         d.PUT(self.REQUEST, self.RESPONSE)
 
         rnlinesplit = compile( r'\r?\n?' )
@@ -411,15 +419,11 @@
             self.failUnless( header in get_headers )
 
 
-class DocumentPUTTests(RequestTest):
-
-    def setUp(self):
-        RequestTest.setUp(self)
-        self.d = Document('foo')
+class DocumentPUTTests(RequestTestBase):
 
     def test_PUTBasicHTML(self):
         self.REQUEST['BODY'] = BASIC_HTML
-        d = self.d
+        d = self._makeOne('foo')
         r = d.PUT(self.REQUEST, self.RESPONSE)
         self.failUnless( hasattr(d, 'cooked_text') )
         self.assertEqual( d.Format(), 'text/html' )
@@ -443,7 +447,7 @@
 
     def test_PUTSimpleXHTML(self):
         self.REQUEST['BODY'] = SIMPLE_XHTML
-        d = self.d
+        d = self._makeOne('foo')
         r = d.PUT(self.REQUEST, self.RESPONSE)
         self.failUnless( hasattr(d, 'cooked_text') )
         self.assertEqual( d.Format(), 'text/html' )
@@ -452,29 +456,26 @@
         self.assertEqual( r.status, 204 )
 
     def test_PutStructuredTextWithHTML(self):
-
         self.REQUEST['BODY'] = STX_WITH_HTML
-
-        r = self.d.PUT(self.REQUEST, self.RESPONSE)
-        self.assertEqual( self.d.Format(), 'text/plain' )
+        d = self._makeOne('foo')
+        r = d.PUT(self.REQUEST, self.RESPONSE)
+        self.assertEqual( d.Format(), 'text/plain' )
         self.assertEqual( r.status, 204 )
 
     def test_PutStructuredText(self):
-
         self.REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
-
-        r = self.d.PUT(self.REQUEST, self.RESPONSE)
-        self.assertEqual( self.d.Format(), 'text/plain' )
+        d = self._makeOne('foo')
+        r = d.PUT(self.REQUEST, self.RESPONSE)
+        self.assertEqual( d.Format(), 'text/plain' )
         self.assertEqual( r.status, 204 )
 
     def test_PutHtmlWithDoctype(self):
-
         html = '%s\n\n  \n   %s' % (DOCTYPE, BASIC_HTML)
         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' )
+        d = self._makeOne('foo')
+        r = d.PUT(self.REQUEST, self.RESPONSE)
+        self.assertEqual( d.Format(), 'text/html' )
+        self.assertEqual( d.Description(), 'Describe me' )
         self.assertEqual( r.status, 204 )
 
 


=== CMF/CMFDefault/tests/test_Favorite.py 1.7 => 1.7.2.1 ===
--- CMF/CMFDefault/tests/test_Favorite.py:1.7	Mon Dec  1 08:55:45 2003
+++ CMF/CMFDefault/tests/test_Favorite.py	Thu Dec 18 09:07:03 2003
@@ -25,35 +25,35 @@
     # for Zope versions before 2.6.1
     pass
 
-from Products.CMFCore.tests.base.dummy import DummyObject as DummySite
-from Products.CMFCore.tests.base.dummy import DummyTool as DummyURLTool
+from Products.CMFCore.tests.base.dummy import DummySite
+from Products.CMFCore.tests.base.dummy import DummyTool
 from Products.CMFDefault.Favorite import Favorite
 
 
 class FavoriteTests( TestCase ):
 
     def setUp( self ):
-        self.tool = DummyURLTool()
-        self.site = DummySite( portal_url=self.tool )
+        self.site = DummySite('site')
+        self.site._setObject( 'portal_membership', DummyTool() )
+        self.site._setObject( 'portal_url', DummyTool() )
 
-    def _makeOne(self, *args, **kw):
-        f = Favorite(*args, **kw)
-        return f.__of__( self.site )
+    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' )
 
         self.assertEqual( f.getId(), 'foo' )
         self.assertEqual( f.Title(), '' )
         self.assertEqual( f.Description(), '' )
-        self.assertEqual( f.getRemoteUrl(), self.tool.root )
+        self.assertEqual( f.getRemoteUrl(), utool.root )
         self.assertEqual( f.getObject(), self.site )
         self.assertEqual( f.getIcon(), self.site.getIcon() )
         self.assertEqual( f.getIcon(1), self.site.getIcon(1) )
 
     def test_CtorArgs( self ):
-
+        utool = self.site.portal_url
         self.assertEqual( self._makeOne( 'foo'
                                        , title='Title'
                                        ).Title(), 'Title' )
@@ -63,26 +63,26 @@
                                        ).Description(), 'Description' )
 
         baz = self._makeOne( 'baz', remote_url='portal_url' )
-        self.assertEqual( baz.getObject(), self.tool )
+        self.assertEqual( baz.getObject(), utool )
         self.assertEqual( baz.getRemoteUrl()
-                        , '%s/portal_url' % self.tool.root )
-        self.assertEqual( baz.getIcon(), self.tool.getIcon() )
+                        , '%s/portal_url' % utool.root )
+        self.assertEqual( baz.getIcon(), utool.getIcon() )
 
     def test_edit( self ):
-
+        utool = self.site.portal_url
         f = self._makeOne( 'foo' )
         f.edit( 'portal_url' )
-        self.assertEqual( f.getObject(), self.tool )
+        self.assertEqual( f.getObject(), utool )
         self.assertEqual( f.getRemoteUrl()
-                        , '%s/portal_url' % self.tool.root )
-        self.assertEqual( f.getIcon(), self.tool.getIcon() )
+                        , '%s/portal_url' % utool.root )
+        self.assertEqual( f.getIcon(), utool.getIcon() )
 
     def test_editEmpty( self ):
-
+        utool = self.site.portal_url
         f = self._makeOne( 'gnnn' )
         f.edit( '' )
         self.assertEqual( f.getObject(), self.site )
-        self.assertEqual( f.getRemoteUrl(), self.tool.root )
+        self.assertEqual( f.getRemoteUrl(), utool.root )
         self.assertEqual( f.getIcon(), self.site.getIcon() )
 
 


=== CMF/CMFDefault/tests/test_Image.py 1.4 => 1.4.58.1 ===
--- CMF/CMFDefault/tests/test_Image.py:1.4	Fri Feb 15 14:45:34 2002
+++ CMF/CMFDefault/tests/test_Image.py	Thu Dec 18 09:07:03 2003
@@ -1,19 +1,33 @@
-import Zope
 from unittest import TestCase, TestSuite, makeSuite, main
 
+import Testing
+import Zope
+try:
+    Zope.startup()
+except AttributeError:
+    # for Zope versions before 2.6.1
+    pass
+
 import os, cStringIO
 
-from Products.CMFDefault.Image import Image
+from Products.CMFCore.tests.base.dummy import DummySite
+from Products.CMFCore.tests.base.dummy import DummyTool
 from Products.CMFDefault import tests
+from Products.CMFDefault.Image import Image
 
 TESTS_HOME = tests.__path__[0]
 TEST_JPG = os.path.join(TESTS_HOME, 'TestImage.jpg')
 
+
 class TestImageElement(TestCase):
 
+    def setUp(self):
+        self.site = DummySite('site')
+        self.site._setObject( 'portal_membership', DummyTool() )
+
     def test_EditWithEmptyFile(self):
-        """ Test handling of empty file uploads """
-        image = Image('testimage')
+        # Test handling of empty file uploads
+        image = self.site._setObject( 'testimage', Image('testimage') )
 
         testfile = open(TEST_JPG, 'rb')
         image.edit(file=testfile)
@@ -28,7 +42,8 @@
 
         assert image.get_size() > 0
         assert image.get_size() == testfilesize
-        
+
+
 def test_suite():
     return TestSuite((
         makeSuite(TestImageElement),
@@ -36,4 +51,4 @@
     return suite
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')        
+    main(defaultTest='test_suite')


=== CMF/CMFDefault/tests/test_Link.py 1.9 => 1.9.56.1 ===
--- CMF/CMFDefault/tests/test_Link.py:1.9	Mon Jul  1 12:24:21 2002
+++ CMF/CMFDefault/tests/test_Link.py	Thu Dec 18 09:07:03 2003
@@ -1,36 +1,38 @@
-import Zope
 from unittest import TestCase, TestSuite, makeSuite, main
 
+import Testing
+import Zope
+try:
+    Zope.startup()
+except AttributeError:
+    # for Zope versions before 2.6.1
+    pass
+
 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
 
-BASIC_STRUCTUREDTEXT = '''\
-Title: Zope Community
-Description: Link to the Zope Community website.
-Subject: open source; Zope; community
-
-http://www.zope.org
-'''
-
-STX_W_CONTINUATION = '''\
-Title: Zope Community
-Description: Link to the Zope Community website,
-  including hundreds of contributed Zope products.
-Subject: open source; Zope; community
-
-http://www.zope.org
-'''
 
 class LinkTests(TestCase):
 
+    def setUp(self):
+        self.site = DummySite('site')
+        mtool = self.site._setObject( 'portal_membership', DummyTool() )
+
+    def _makeOne(self, id, *args, **kw):
+        return self.site._setObject( id, Link(id, *args, **kw) )
+
     def canonTest(self, table):
         for orig, wanted in table.items():
             # test with constructor
-            d = Link('foo', remote_url=orig)
+            d = self._makeOne('foo', remote_url=orig)
             self.assertEqual(d.getRemoteUrl(), wanted)
             # test with edit method too
-            d = Link('bar')
+            d = self._makeOne('bar')
             d.edit(orig)
             self.assertEqual(d.getRemoteUrl(), wanted)
 
@@ -42,33 +44,32 @@
         self.assertEqual( d.format, 'text/url' )
         self.assertEqual( d.URL_FORMAT, 'text/url')
 
-        d = Link('foo', remote_url='bar')
+        d = self._makeOne('foo', remote_url='bar')
         d.edit('')
         self.assertEqual(d.getRemoteUrl(), '')
 
-        d = Link('foo', remote_url='http://')
+        d = self._makeOne('foo', remote_url='http://')
         self.assertEqual(d.getRemoteUrl(), '')
 
-        d = Link('foo', remote_url='http:')
+        d = self._makeOne('foo', remote_url='http:')
         self.assertEqual(d.getRemoteUrl(), '')
 
-    def test_StructuredText( self ):
-        d = Link('foo')
-        d._writeFromPUT( body=BASIC_STRUCTUREDTEXT )
-        
+    def test_RFC822(self):
+        d = self._makeOne('foo')
+        d._writeFromPUT( body=BASIC_RFC822 )
+
         self.assertEqual( d.Title(), 'Zope Community' )
         self.assertEqual( d.Description()
                         , 'Link to the Zope Community website.' )
         self.assertEqual( len(d.Subject()), 3 )
         self.assertEqual( d.getRemoteUrl(), 'http://www.zope.org' )
 
-    def test_StructuredText_w_Continuation( self ):
-
-        d = Link('foo')
-        d._writeFromPUT( body=STX_W_CONTINUATION )
+    def test_RFC822_w_Continuation(self):
+        d = self._makeOne('foo')
+        d._writeFromPUT( body=RFC822_W_CONTINUATION )
         rnlinesplit = compile( r'\r?\n?' )
         desc_lines = rnlinesplit.split( d.Description() )
-        
+
         self.assertEqual( d.Title(), 'Zope Community' )
         self.assertEqual( desc_lines[0]
                         , 'Link to the Zope Community website,' )


=== CMF/CMFDefault/tests/test_MembershipTool.py 1.9 => 1.9.4.1 ===
--- CMF/CMFDefault/tests/test_MembershipTool.py:1.9	Wed Sep 24 06:02:19 2003
+++ CMF/CMFDefault/tests/test_MembershipTool.py	Thu Dec 18 09:07:03 2003
@@ -1,5 +1,6 @@
 from unittest import TestCase, TestSuite, makeSuite, main
 
+import Testing
 import Zope
 try:
     Zope.startup()
@@ -34,6 +35,7 @@
     def unrestrictedTraverse(self, path, default=None, restricted=0):
         return self.acl_users
 
+
 class MembershipToolTests(TestCase):
 
     def setUp(self):
@@ -68,10 +70,10 @@
         SecurityTest.setUp(self)
         self.site = DummyFolder()
         self.site.id = 'testSite'
-        self.mtool = MembershipTool().__of__(self.site)
+        self.site._setObject( 'portal_membership', MembershipTool() )
 
     def test_createMemberArea(self):
-        mtool = self.mtool
+        mtool = self.site.portal_membership
         members = self.site._setObject( 'Members', PortalFolder('Members') )
         acl_users = self.site._setObject( 'acl_users', DummyUserFolder() )
         wtool = self.site._setObject( 'portal_workflow', DummyTool() )


=== CMF/CMFDefault/tests/test_NewsItem.py 1.7 => 1.7.58.1 ===
--- CMF/CMFDefault/tests/test_NewsItem.py:1.7	Mon Apr  1 17:11:21 2002
+++ CMF/CMFDefault/tests/test_NewsItem.py	Thu Dec 18 09:07:03 2003
@@ -1,19 +1,35 @@
-from unittest import makeSuite, main
+from unittest import TestSuite, makeSuite, main
 
-from Products.CMFDefault.NewsItem import NewsItem
-
-from Products.CMFCore.tests.base.testcase import RequestTest
+import Testing
+import Zope
+try:
+    Zope.startup()
+except AttributeError:
+    # for Zope versions before 2.6.1
+    pass
 
 from Products.CMFCore.tests.base.content import DOCTYPE
 from Products.CMFCore.tests.base.content import BASIC_HTML
 from Products.CMFCore.tests.base.content import ENTITY_IN_TITLE
 from Products.CMFCore.tests.base.content import BASIC_STRUCTUREDTEXT
+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.CMFDefault.NewsItem import NewsItem
+
 
 class NewsItemTests(RequestTest):
 
-    def test_Empty_html(self):
+    def setUp(self):
+        RequestTest.setUp(self)
+        self.site = DummySite('site').__of__(self.root)
+        self.site._setObject( 'portal_membership', DummyTool() )
 
-        d = NewsItem( 'empty', text_format='html' )
+    def _makeOne(self, id, *args, **kw):
+        return self.site._setObject( id, NewsItem(id, *args, **kw) )
+
+    def test_Empty_html(self):
+        d = self._makeOne('empty', text_format='html')
 
         self.assertEqual( d.Title(), '' )
         self.assertEqual( d.Description(), '' )
@@ -22,8 +38,7 @@
         self.assertEqual( d.text, '' )
 
     def test_Empty_stx(self):
-
-        d = NewsItem('foo', text_format='structured-text')
+        d = self._makeOne('foo', text_format='structured-text')
 
         self.assertEqual( d.Title(), '' )
         self.assertEqual( d.Description(), '' )
@@ -32,9 +47,8 @@
         self.assertEqual( d.text, '' )
 
     def test_PUT_basic_html(self):
-
         self.REQUEST['BODY']=BASIC_HTML
-        d = NewsItem('foo')
+        d = self._makeOne('foo')
         d.PUT(self.REQUEST, self.RESPONSE)
 
         self.assertEqual( d.Title(), 'Title in tag' )
@@ -45,9 +59,8 @@
         self.assertEqual( len(d.Contributors()), 3 )
 
     def test_PUT_uppered_html(self):
-
         self.REQUEST['BODY'] = BASIC_HTML.upper()
-        d = NewsItem('foo')
+        d = self._makeOne('foo')
         d.PUT(self.REQUEST, self.RESPONSE)
 
         self.assertEqual( d.Title(), 'TITLE IN TAG' )
@@ -58,25 +71,22 @@
         self.assertEqual( len(d.Contributors()), 3 )
 
     def test_PUT_entity_in_title(self):
-
         self.REQUEST['BODY'] = ENTITY_IN_TITLE
-        d = NewsItem('foo')
+        d = self._makeOne('foo')
         d.PUT(self.REQUEST, self.RESPONSE)
 
         self.assertEqual( d.Title(), '&Auuml;rger' )
 
     def test_PUT_html_with_doctype(self):
-
-        d = NewsItem('foo')
         self.REQUEST['BODY'] = '%s\n%s' % (DOCTYPE, BASIC_HTML)
+        d = self._makeOne('foo')
         d.PUT(self.REQUEST, self.RESPONSE)
 
         self.assertEqual( d.Description(), 'Describe me' )
 
     def test_PUT_html_without_newlines(self):
-
-        d = NewsItem('foo')
         self.REQUEST['BODY'] = ''.join(BASIC_HTML.split('\n'))
+        d = self._makeOne('foo')
         d.PUT(self.REQUEST, self.RESPONSE)
 
         self.assertEqual( d.Title(), 'Title in tag' )
@@ -87,11 +97,10 @@
         self.assertEqual( len(d.Contributors()), 3 )
 
     def test_PUT_structured_text(self):
-
         self.REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
-        d = NewsItem('foo')
+        d = self._makeOne('foo')
         d.PUT( self.REQUEST, self.RESPONSE )
-        
+
         self.assertEqual( d.Title(), 'My Document')
         self.assertEqual( d.Description(), 'A document by me')
         self.assertEqual( d.Format(), 'text/plain' )
@@ -100,9 +109,8 @@
         self.failUnless( d.cooked_text.find('<p>') >= 0 )
 
     def test_Init(self):
-
         self.REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
-        d = NewsItem('foo', text='')
+        d = self._makeOne('foo', text='')
         d.PUT(self.REQUEST, self.RESPONSE)
 
         self.assertEqual( d.Title(), 'My Document' )
@@ -113,8 +121,8 @@
         self.failUnless( d.cooked_text.find('<p>') >= 0 )
 
     def test_Init_with_stx( self ):
-
-        d = NewsItem('foo', text_format='structured-text', title='Foodoc')
+        d = self._makeOne('foo', text_format='structured-text',
+                          title='Foodoc')
 
         self.assertEqual( d.Title(), 'Foodoc' )
         self.assertEqual( d.Description(), '' )
@@ -122,8 +130,11 @@
         self.assertEqual( d.text_format, 'structured-text' )
         self.assertEqual( d.text, '' )
 
+
 def test_suite():
-    return makeSuite(NewsItemTests)
+    return TestSuite((
+        makeSuite(NewsItemTests),
+        ))
 
-if __name__=='__main__':
+if __name__ == '__main__':
     main(defaultTest='test_suite')




More information about the CMF-checkins mailing list