[CMF-checkins] CVS: CMF/CMFDefault/tests - test_MembershipTool.py:1.6

Yvo Schubbe schubbe@web.de
Wed, 28 May 2003 06:57:43 -0400


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

Modified Files:
	test_MembershipTool.py 
Log Message:
Merged yuppie-collector162-branch:
- Fixed member area Ownership and Roles. (Collector #162)

=== CMF/CMFDefault/tests/test_MembershipTool.py 1.5 => 1.6 ===
--- CMF/CMFDefault/tests/test_MembershipTool.py:1.5	Fri Mar 14 14:28:50 2003
+++ CMF/CMFDefault/tests/test_MembershipTool.py	Wed May 28 06:57:42 2003
@@ -2,13 +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.PortalFolder import PortalFolder
 from Products.CMFCore.tests.base.dummy import DummyFolder as DummyFolderBase
-from Products.CMFCore.tests.base.dummy import DummyObject
+from Products.CMFCore.tests.base.dummy import DummyTool
+from Products.CMFCore.tests.base.dummy import DummyUserFolder
+from Products.CMFCore.tests.base.testcase import SecurityTest
 
 from Products.CMFDefault.MembershipTool import MembershipTool
 
@@ -20,17 +28,10 @@
         pass
     def manage_setLocalRoles(self, userid, roles):
         pass
-
-class DummyUserFolder(DummyFolderBase):
-    def getUsers(self):
-        pass
-    def getUser(self, name):
-        return DummyObject()
-
-class DummyWorkflowTool:
-    def notifyCreated(self, ob):
-        pass
-
+    def getPhysicalRoot(self):
+        return self
+    def unrestrictedTraverse(self, path, default=None, restricted=0):
+        return self.acl_users
 
 class MembershipToolTests(TestCase):
 
@@ -42,14 +43,13 @@
         mtool = self.mtool
         self.site._setObject( 'Members', DummyFolder() )
         self.site._setObject( 'acl_users', DummyUserFolder() )
-        self.site._setObject( 'portal_workflow', DummyWorkflowTool() )
-        self.site.bar = 'test attribute'
-        mtool.createMemberarea('foo')
-        self.failUnless( hasattr(self.site.Members.aq_self, 'foo') )
-        mtool.createMemberarea('bar')
-        self.failUnless( hasattr(self.site.Members.aq_self, 'bar'),
-                         'CMF Collector issue #102'  )
-
+        self.site._setObject( 'portal_workflow', DummyTool() )
+        self.site.user_bar = 'test attribute'
+        mtool.createMemberarea('user_foo')
+        self.failUnless( hasattr(self.site.Members.aq_self, 'user_foo') )
+        mtool.createMemberarea('user_bar')
+        self.failUnless( hasattr(self.site.Members.aq_self, 'user_bar'),
+                         'CMF Collector issue #102 (acquisition bug)' )
 
     def test_MembersFolder_methods(self):
         mtool = self.mtool
@@ -73,9 +73,40 @@
         verifyClass(IActionProvider, MembershipTool)
 
 
+class MembershipToolSecurityTests(SecurityTest):
+
+    def setUp(self):
+        SecurityTest.setUp(self)
+        self.site = DummyFolder()
+        self.site.id = 'testSite'
+        self.mtool = MembershipTool().__of__(self.site)
+
+    def test_createMemberarea(self):
+        mtool = self.mtool
+        self.site._setObject( 'Members', PortalFolder('Members') )
+        self.site._setObject( 'acl_users', DummyUserFolder() )
+        self.site._setObject( 'portal_workflow', DummyTool() )
+        mtool.createMemberarea('user_foo')
+
+        f = self.site.Members.user_foo
+        ownership = self.site.acl_users.user_foo
+        localroles = ( ( 'user_foo', ('Owner',) ), )
+        self.assertEqual( f.getOwner(), ownership )
+        self.assertEqual( f.get_local_roles(), localroles,
+                          'CMF Collector issue #162 (LocalRoles broken): %s'
+                          % str( f.get_local_roles() ) )
+        self.assertEqual( f.index_html.getOwner(), ownership,
+                          'CMF Collector issue #162 (Ownership broken): %s'
+                          % str( f.index_html.getOwner() ) )
+        self.assertEqual( f.index_html.get_local_roles(), localroles,
+                          'CMF Collector issue #162 (LocalRoles broken): %s'
+                          % str( f.index_html.get_local_roles() ) )
+
+
 def test_suite():
     return TestSuite((
         makeSuite( MembershipToolTests ),
+        makeSuite( MembershipToolSecurityTests )
         ))
 
 if __name__ == '__main__':