[CMF-checkins] CVS: CMF/CMFCore/tests - test_MembershipTool.py:1.5 test_PortalFolder.py:1.22 test_TypesTool.py:1.22 test_URLTool.py:1.4

Yvo Schubbe schubbe@web.de
Wed, 11 Jun 2003 07:11:20 -0400


Update of /cvs-repository/CMF/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv2261/CMFCore/tests

Modified Files:
	test_MembershipTool.py test_PortalFolder.py test_TypesTool.py 
	test_URLTool.py 
Log Message:
Merged yuppie-collector165-branch:
- Fixed ownership of STI constructor scripts. (Collector #165)
- Added and refactored tests.

=== CMF/CMFCore/tests/test_MembershipTool.py 1.4 => 1.5 ===
--- CMF/CMFCore/tests/test_MembershipTool.py:1.4	Mon Jun  2 12:18:48 2003
+++ CMF/CMFCore/tests/test_MembershipTool.py	Wed Jun 11 07:11:19 2003
@@ -14,7 +14,7 @@
 from AccessControl.SecurityManagement import newSecurityManager
 
 from Products.CMFCore.PortalFolder import PortalFolder
-from Products.CMFCore.tests.base.dummy import DummyFolder as DummyFolderBase
+from Products.CMFCore.tests.base.dummy import DummySite
 from Products.CMFCore.tests.base.dummy import DummyTool
 from Products.CMFCore.tests.base.dummy import DummyUserFolder
 from Products.CMFCore.tests.base.testcase import SecurityTest
@@ -22,15 +22,6 @@
 from Products.CMFCore.MembershipTool import MembershipTool
 
 
-class DummyFolder(DummyFolderBase):
-    def _getProductRegistryData(self, name):
-        return ()
-    def getPhysicalRoot(self):
-        return self
-    def unrestrictedTraverse(self, path, default=None, restricted=0):
-        return self.acl_users
-
-
 class MembershipToolTests(TestCase):
 
     def test_interface(self):
@@ -47,8 +38,7 @@
 
     def setUp(self):
         SecurityTest.setUp(self)
-        self.site = DummyFolder()
-        self.site.id = 'testSite'
+        self.site = DummySite('site').__of__(self.root)
         self.mtool = MembershipTool().__of__(self.site)
 
     def test_createMemberarea(self):


=== CMF/CMFCore/tests/test_PortalFolder.py 1.21 => 1.22 ===
--- CMF/CMFCore/tests/test_PortalFolder.py:1.21	Tue Apr 15 12:08:02 2003
+++ CMF/CMFCore/tests/test_PortalFolder.py	Wed Jun 11 07:11:19 2003
@@ -1,9 +1,16 @@
 from unittest import TestCase, TestSuite, makeSuite, main
+
 import Zope
+try:
+    Zope.startup()
+except AttributeError:
+    # for Zope versions before 2.6.1
+    pass
 
 from DateTime import DateTime
 
 from Products.CMFCore.tests.base.dummy import DummyContent
+from Products.CMFCore.tests.base.dummy import DummyFactory
 from Products.CMFCore.tests.base.dummy import DummyFTI
 from Products.CMFCore.tests.base.testcase import SecurityTest
 from Products.CMFCore.tests.base.testcase import newSecurityManager
@@ -19,6 +26,7 @@
 def extra_meta_types():
     return [  { 'name' : 'Dummy', 'action' : 'manage_addFolder' } ]
 
+
 class PortalFolderFactoryTests( SecurityTest ):
 
     def setUp( self ):
@@ -46,6 +54,7 @@
 
         self.failIf( 'foo' in f.objectIds() )
 
+        f.manage_addProduct = { 'FooProduct' : DummyFactory(f) }
         f.invokeFactory( type_name='Dummy Content', id='foo' )
 
         self.failUnless( 'foo' in f.objectIds() )


=== CMF/CMFCore/tests/test_TypesTool.py 1.21 => 1.22 ===
--- CMF/CMFCore/tests/test_TypesTool.py:1.21	Fri May  9 17:40:23 2003
+++ CMF/CMFCore/tests/test_TypesTool.py	Wed Jun 11 07:11:19 2003
@@ -12,47 +12,64 @@
     # for Zope versions before 2.6.0
     from Interface import verify_class_implementation as verifyClass
 
-from Acquisition import aq_base
+from AccessControl import Unauthorized
 from AccessControl.SecurityManagement import newSecurityManager
 from AccessControl.SecurityManagement import noSecurityManager
+from AccessControl.SecurityManager import setSecurityPolicy
+from Acquisition import aq_base
 from webdav.NullResource import NullResource
-
+from Products.PythonScripts.PythonScript import PythonScript
 from Products.PythonScripts.standard import url_quote
 
 from Products.CMFCore.TypesTool import FactoryTypeInformation as FTI
 from Products.CMFCore.TypesTool import ScriptableTypeInformation as STI
 from Products.CMFCore.TypesTool import TypesTool
-from Products.CMFCore.TypesTool import Unauthorized
-
 from Products.CMFCore.PortalFolder import PortalFolder
 from Products.CMFCore.utils import _getViewFor
 
-from Products.CMFCore.tests.base.testcase import SecurityRequestTest
 from Products.CMFCore.tests.base.security import OmnipotentUser
 from Products.CMFCore.tests.base.security import UserWithRoles
-from Products.CMFCore.tests.base.dummy import DummyObject
-from Products.CMFCore.tests.base.dummy import addDummy
-from Products.CMFCore.tests.base.dummy import DummyTypeInfo
+from Products.CMFCore.tests.base.dummy import DummyFactory
 from Products.CMFCore.tests.base.dummy import DummyFolder
 from Products.CMFCore.tests.base.dummy import DummyFTI
+from Products.CMFCore.tests.base.dummy import DummyObject
+from Products.CMFCore.tests.base.dummy import DummySite
+from Products.CMFCore.tests.base.dummy import DummyUserFolder
+from Products.CMFCore.tests.base.testcase import SecurityTest
+
+STI_SCRIPT = """\
+## Script (Python) "addBaz"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=container, id
+##title=
+##
+product = container.manage_addProduct['FooProduct']
+product.addFoo(id)
+item = getattr(container, id)
+return item
+"""
 
-class TypesToolTests( SecurityRequestTest ):
+
+class TypesToolTests(SecurityTest):
 
     def setUp( self ):
-        SecurityRequestTest.setUp(self)
-        root = self.root
-        root.addDummy = addDummy
-
-        root._setObject( 'portal_types', TypesTool() )
-        tool = root.portal_types
-        tool._setObject( 'Dummy Content', DummyFTI ) 
+        SecurityTest.setUp(self)
+        self.site = DummySite('site').__of__(self.root)
+        self.acl_users = self.site._setObject( 'acl_users', DummyUserFolder() )
+        self.ttool = self.site._setObject( 'portal_types', TypesTool() )
+        self.ttool._setObject( 'Dummy Content', DummyFTI ) 
  
     def test_processActions( self ):
         """
         Are the correct, permitted methods returned for actions?
         """
-        self.root._setObject( 'portal', PortalFolder( 'portal', '' ) )
-        portal = self.root.portal
+        site = self.site
+        portal = site._setObject( 'portal', PortalFolder(id='portal') )
+        portal.manage_addProduct = { 'FooProduct' : DummyFactory(portal) }
         portal.invokeFactory( 'Dummy Content', 'actions_dummy' )
         dummy = portal._getOb( 'actions_dummy' )
 
@@ -75,7 +92,7 @@
         Test that everything returned by allMetaTypes can be
         traversed to.
         """
-        tool = self.root.portal_types
+        tool = self.ttool
         meta_types={}
         # Seems we get NullResource if the method couldn't be traverse to
         # so we check for that. If we've got it, something is b0rked.
@@ -90,7 +107,34 @@
         self.failUnless(meta_types.has_key('Scriptable Type Information'))
         self.failUnless(meta_types.has_key('Factory-based Type Information'))
 
-    def test_interface(self):
+    def test_constructContent(self):
+        site = self.site
+        acl_users = self.acl_users
+        ttool = self.ttool
+        setSecurityPolicy(self._oldPolicy)
+        newSecurityManager(None, acl_users.all_powerful_Oz)
+        self.site._owner = (['acl_users'], 'all_powerful_Oz')
+        sti_baz = STI('Baz',
+                      permission='Add portal content',
+                      constructor_path='addBaz')
+        ttool._setObject('Baz', sti_baz)
+        ttool._setObject( 'addBaz',  PythonScript('addBaz') )
+        s = ttool.addBaz
+        s.write(STI_SCRIPT)
+
+        f = site._setObject( 'folder', PortalFolder(id='folder') )
+        f.manage_addProduct = { 'FooProduct' : DummyFactory(f) }
+        f._owner = (['acl_users'], 'user_foo')
+        self.assertEqual( f.getOwner(), acl_users.user_foo )
+
+        ttool.constructContent('Dummy Content', container=f, id='page1')
+        try:
+            ttool.constructContent('Baz', container=f, id='page2')
+        except Unauthorized:
+            self.fail('CMF Collector issue #165 (Ownership bug): '
+                      'Unauthorized raised' )
+
+def test_interface(self):
         from Products.CMFCore.interfaces.portal_types \
                 import portal_types as ITypesTool
         from Products.CMFCore.interfaces.portal_actions \


=== CMF/CMFCore/tests/test_URLTool.py 1.3 => 1.4 ===
--- CMF/CMFCore/tests/test_URLTool.py:1.3	Mon Jan  6 15:41:20 2003
+++ CMF/CMFCore/tests/test_URLTool.py	Wed Jun 11 07:11:19 2003
@@ -2,40 +2,21 @@
 
 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.dummy import DummyFolder as BaseDummyFolder
 from Products.CMFCore.tests.base.dummy import DummyContent
+from Products.CMFCore.tests.base.dummy import DummyFolder
+from Products.CMFCore.tests.base.dummy import DummySite
 
 from Products.CMFCore.URLTool import URLTool
-
-
-class DummyFolder(BaseDummyFolder):
-
-    def __init__(self, id='', fake_product=0, prefix=''):
-        BaseDummyFolder.__init__(self, fake_product, prefix)
-        self._id = id
-
-    def getId(self):
-        return self._id
-
-    def getPhysicalPath(self):
-        return self.aq_inner.aq_parent.getPhysicalPath() + ( self._id, )
-
-
-class DummySite(DummyFolder):
-
-    _domain = 'http://www.foobar.com'
-    _path = 'bar'
-
-    def absolute_url(self, relative=0):
-        return '/'.join( (self._domain, self._path, self._id) )
-
-    def getPhysicalPath(self):
-        return ('', self._path, self._id)
 
 
 class URLToolTests(TestCase):