[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testAttributeRolePermissionManager.py:1.1.2.3.2.1
Jim Fulton
jim@zope.com
Mon, 11 Feb 2002 10:21:51 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv19423
Modified Files:
Tag: Zope-3x-security_defactor-branch
testAttributeRolePermissionManager.py
Log Message:
Changed to follow the rules for ids, which are that you can't
generally count on a registry using the ids you give it.
=== Zope3/lib/python/Zope/App/Security/tests/testAttributeRolePermissionManager.py 1.1.2.3 => 1.1.2.3.2.1 ===
provideService('PermissionService', permissionRegistry)
- permissionRegistry.definePermission('read', 'Read Something')
- permissionRegistry.definePermission('write', 'Write Something')
+ read = permissionRegistry.definePermission('read', 'Read Something')
+ self.read = read.getId()
+
+ write = permissionRegistry.definePermission('write', 'Write Something')
+ self.write = write.getId()
- roleRegistry.defineRole('peon', 'Poor Slob')
- roleRegistry.defineRole('manager', 'Supreme Being')
+ peon = roleRegistry.defineRole('peon', 'Poor Slob')
+ self.peon = peon.getId()
+
+ manager = roleRegistry.defineRole('manager', 'Supreme Being')
+ self.manager = manager.getId()
def testNormal(self):
obj = Manageable()
mgr = AttributeRolePermissionManager(obj)
+ mgr.grantPermissionToRole(self.read,self.manager)
+ mgr.grantPermissionToRole(self.write,self.manager)
+ mgr.grantPermissionToRole(self.write,self.manager)
- mgr.grantPermissionToRole('read','manager')
- mgr.grantPermissionToRole('write','manager')
- mgr.grantPermissionToRole('write','manager')
-
- mgr.grantPermissionToRole('read','peon')
+ mgr.grantPermissionToRole(self.read,self.peon)
- l = list(mgr.getPermissionsForRole('manager'))
- self.failUnless( ('read', Allow) in l )
- self.failUnless( ('write', Allow) in l )
+ l = list(mgr.getPermissionsForRole(self.manager))
+ self.failUnless( (self.read, Allow) in l )
+ self.failUnless( (self.write, Allow) in l )
- l = list(mgr.getPermissionsForRole('peon'))
- self.failUnless( [('read', Allow)] == l )
+ l = list(mgr.getPermissionsForRole(self.peon))
+ self.failUnless( [(self.read, Allow)] == l )
- l = list(mgr.getRolesForPermission('read'))
- self.failUnless( ('manager', Allow) in l )
- self.failUnless( ('peon', Allow) in l )
+ l = list(mgr.getRolesForPermission(self.read))
+ self.failUnless( (self.manager, Allow) in l )
+ self.failUnless( (self.peon, Allow) in l )
- l = list(mgr.getRolesForPermission('write'))
- self.assertEqual(l, [ ('manager', 'Allow') ] )
+ l = list(mgr.getRolesForPermission(self.write))
+ self.assertEqual(l, [ (self.manager, Allow) ] )
- mgr.denyPermissionToRole('read', 'peon')
- l = list(mgr.getPermissionsForRole('peon'))
- self.assertEqual(l, [('read', 'Deny')] )
+ mgr.denyPermissionToRole(self.read, self.peon)
+ l = list(mgr.getPermissionsForRole(self.peon))
+ self.assertEqual(l, [(self.read, Deny)] )
- mgr.unsetPermissionForRole('read', 'peon')
+ mgr.unsetPermissionForRole(self.read, self.peon)
- l = list(mgr.getRolesForPermission('read'))
- self.assertEqual(l, [ ('manager', Allow) ] )
+ l = list(mgr.getRolesForPermission(self.read))
+ self.assertEqual(l, [ (self.manager, Allow) ] )
def test_suite():