Back to index

plone3  3.1.7
test_MembershipTool.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Unit tests for MembershipTool module.
00014 
00015 $Id: test_MembershipTool.py 77004 2007-06-24 08:57:54Z yuppie $
00016 """
00017 
00018 import unittest
00019 import Testing
00020 
00021 from AccessControl.SecurityManagement import newSecurityManager
00022 from zope.testing.cleanup import cleanUp
00023 
00024 from Products.CMFCore.PortalFolder import PortalFolder
00025 from Products.CMFCore.tests.base.dummy import DummyFolder
00026 from Products.CMFCore.tests.base.dummy import DummySite
00027 from Products.CMFCore.tests.base.dummy import DummyTool
00028 from Products.CMFCore.tests.base.dummy import DummyUserFolder
00029 from Products.CMFCore.tests.base.testcase import SecurityTest
00030 
00031 
00032 class MembershipToolTests(unittest.TestCase):
00033 
00034     def _makeOne(self, *args, **kw):
00035         from Products.CMFDefault.MembershipTool import MembershipTool
00036 
00037         return MembershipTool(*args, **kw)
00038 
00039     def setUp(self):
00040         self.site = DummySite('site')
00041         self.site._setObject( 'portal_membership', self._makeOne() )
00042 
00043     def test_z2interfaces(self):
00044         from Interface.Verify import verifyClass
00045         from Products.CMFDefault.interfaces.portal_membership \
00046                 import portal_membership as IMembershipTool
00047         from Products.CMFDefault.MembershipTool import MembershipTool
00048 
00049         verifyClass(IMembershipTool, MembershipTool)
00050 
00051     def test_z3interfaces(self):
00052         from zope.interface.verify import verifyClass
00053         from Products.CMFDefault.interfaces import IMembershipTool
00054         from Products.CMFDefault.MembershipTool import MembershipTool
00055 
00056         verifyClass(IMembershipTool, MembershipTool)
00057 
00058     def test_MembersFolder_methods(self):
00059         mtool = self.site.portal_membership
00060         self.assertEqual( mtool.getMembersFolder(), None )
00061         self.site._setObject( 'Members', DummyFolder() )
00062         self.assertEqual( mtool.getMembersFolder(), self.site.Members )
00063         mtool.setMembersFolderById(id='foo')
00064         self.assertEqual( mtool.getMembersFolder(), None )
00065         self.site._setObject( 'foo', DummyFolder() )
00066         self.assertEqual( mtool.getMembersFolder(), self.site.foo )
00067         mtool.setMembersFolderById()
00068         self.assertEqual( mtool.getMembersFolder(), None )
00069 
00070 
00071 class MembershipToolSecurityTests(SecurityTest):
00072 
00073     def _makeOne(self, *args, **kw):
00074         from Products.CMFDefault.MembershipTool import MembershipTool
00075 
00076         return MembershipTool(*args, **kw)
00077 
00078     def setUp(self):
00079         SecurityTest.setUp(self)
00080         self.site = DummySite('site').__of__(self.root)
00081         self.site._setObject( 'portal_membership', self._makeOne() )
00082 
00083     def tearDown(self):
00084         cleanUp()
00085         SecurityTest.tearDown(self)
00086 
00087     def test_createMemberArea(self):
00088         mtool = self.site.portal_membership
00089         members = self.site._setObject( 'Members', PortalFolder('Members') )
00090         acl_users = self.site._setObject( 'acl_users', DummyUserFolder() )
00091         wtool = self.site._setObject( 'portal_workflow', DummyTool() )
00092 
00093         # permission
00094         mtool.createMemberArea('user_foo')
00095         self.failIf( hasattr(members.aq_self, 'user_foo') )
00096         newSecurityManager(None, acl_users.user_bar)
00097         mtool.createMemberArea('user_foo')
00098         self.failIf( hasattr(members.aq_self, 'user_foo') )
00099         newSecurityManager(None, acl_users.user_foo)
00100         mtool.setMemberareaCreationFlag()
00101         mtool.createMemberArea('user_foo')
00102         self.failIf( hasattr(members.aq_self, 'user_foo') )
00103         newSecurityManager(None, acl_users.all_powerful_Oz)
00104         mtool.setMemberareaCreationFlag()
00105         mtool.createMemberArea('user_foo')
00106         self.failUnless( hasattr(members.aq_self, 'user_foo') )
00107 
00108         # default content
00109         f = members.user_foo
00110         ownership = acl_users.user_foo
00111         localroles = ( ( 'user_foo', ('Owner',) ), )
00112         self.assertEqual( f.Title(), "user_foo's Home" )
00113         self.assertEqual( f.getOwner(), ownership )
00114         self.assertEqual( f.get_local_roles(), localroles,
00115                           'CMF Collector issue #162 (LocalRoles broken): %s'
00116                           % str( f.get_local_roles() ) )
00117         self.assertEqual( f.index_html.getOwner(), ownership,
00118                           'CMF Collector issue #162 (Ownership broken): %s'
00119                           % str( f.index_html.getOwner() ) )
00120         self.assertEqual( f.index_html.get_local_roles(), localroles,
00121                           'CMF Collector issue #162 (LocalRoles broken): %s'
00122                           % str( f.index_html.get_local_roles() ) )
00123         self.assertEqual( wtool.test_notified, f.index_html )
00124 
00125         # acquisition
00126         self.site.user_bar = 'test attribute'
00127         newSecurityManager(None, acl_users.user_bar)
00128         mtool.createMemberArea('user_bar')
00129         self.failUnless( hasattr(members.aq_self, 'user_bar'),
00130                          'CMF Collector issue #102 (acquisition bug)' )
00131 
00132 
00133 def test_suite():
00134     return unittest.TestSuite((
00135         unittest.makeSuite(MembershipToolTests),
00136         unittest.makeSuite(MembershipToolSecurityTests),
00137         ))
00138 
00139 if __name__ == '__main__':
00140     unittest.main(defaultTest='test_suite')