[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testPermissionRegistry.py:1.1.2.4
Tres Seaver
tseaver@zope.com
Wed, 28 Nov 2001 14:02:29 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv2992/tests
Modified Files:
Tag: Zope-3x-branch
testPermissionRegistry.py
Log Message:
- Add role registration, including assignment of permissions to roles.
=== Zope3/lib/python/Zope/App/Security/tests/testPermissionRegistry.py 1.1.2.3 => 1.1.2.4 ===
+#
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
@@ -12,17 +14,54 @@
class Test(unittest.TestCase):
def tearDown(self):
- from Zope.App.Security.PermissionRegistry import _clearPermissions
- _clearPermissions()
+ from Zope.App.Security.PermissionRegistry import _clear
+ _clear()
- def testDefine(self):
+ def testDefinePermission(self):
from Zope.App.Security.PermissionRegistry import definePermission
from Zope.App.Security.PermissionRegistry import definedPermission
+ from Zope.App.Security.PermissionRegistry import rolesForPermission
- self.failIf(definedPermission('Manage Contacts'))
- definePermission('Manage Contacts')
- self.failUnless(definedPermission('Manage Contacts'))
+ self.assertRaises( LookupError, rolesForPermission, 'Foo' )
+
+ self.failIf(definedPermission('Foo'))
+ definePermission('Foo')
+ self.failUnless(definedPermission('Foo'))
+
+ roles = rolesForPermission( 'Foo' )
+ self.assertEquals( len( roles ), 0 )
+
+ def testDefineRole( self ):
+ from Zope.App.Security.PermissionRegistry import defineRole
+ from Zope.App.Security.PermissionRegistry import definedRole
+
+ role = defineRole( 'Everyman' )
+ self.failUnless( definedRole( 'Everyman' ) )
+
+ def testIncludeNonesuchPermission( self ):
+ from Zope.App.Security.PermissionRegistry import defineRole
+ from Zope.App.Security.PermissionRegistry import definedRole
+ from Zope.App.Security.PermissionRegistry import definePermission
+ role = defineRole( 'Everyman' )
+ self.assertRaises( LookupError, role.includePermission, 'Foo' )
+
+ def testIncludePermission( self ):
+ from Zope.App.Security.PermissionRegistry import defineRole
+ from Zope.App.Security.PermissionRegistry import definedRole
+ from Zope.App.Security.PermissionRegistry import definePermission
+ from Zope.App.Security.PermissionRegistry import rolesForPermission
+
+ definePermission( 'Foo' )
+ role = defineRole( 'Everyman' )
+
+ role.includePermission( 'Foo' )
+ self.failUnless( role.hasPermission( 'Foo' ) )
+
+ roles = rolesForPermission( 'Foo' )
+ self.assertEquals( len( roles ), 1 )
+
+ self.assertRaises( LookupError, role.includePermission, 'Foo' )
def test_suite():