[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testPrincipalPermissionManager.py:1.1.2.8 testPrincipalRoleManager.py:1.1.2.8
Anthony Baxter
anthony@interlink.com.au
Fri, 8 Feb 2002 18:00:21 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv22192/tests
Modified Files:
Tag: Zope-3x-branch
testPrincipalPermissionManager.py testPrincipalRoleManager.py
Log Message:
Backing out today's snafu to make the unit tests pass. We'll finish it
up and commit it tomorrow. Apologies for the interruption to service.
=== Zope3/lib/python/Zope/App/Security/tests/testPrincipalPermissionManager.py 1.1.2.7 => 1.1.2.8 ===
from Zope.App.Security.PrincipalPermissionManager \
import principalPermissionManager as manager
-from Zope.App.Security.Settings import Allow, Deny, Unset
class Test(unittest.TestCase):
@@ -33,6 +32,7 @@
title or 'A Principal',
login = id or 'APrincipal')
return id or 'APrincipal'
+
def testUnboundPrincipalPermission(self):
permission = permregistry.definePermission('APerm', 'title')
@@ -43,47 +43,11 @@
def testPrincipalPermission(self):
permission = permregistry.definePermission('APerm', 'title')
principal = self._make_principal()
- # check that an allow permission is saved correctly
manager.grantPermissionToPrincipal(permission, principal)
self.assertEqual(manager.getPrincipalsForPermission(permission),
- [(principal, Allow)])
+ [principal])
self.assertEqual(manager.getPermissionsForPrincipal(principal),
- [(permission, Allow)])
- # check that the allow permission is removed.
- manager.unsetPermissionForPrincipal(permission, principal)
- self.assertEqual(manager.getPrincipalsForPermission(permission), [])
- self.assertEqual(manager.getPermissionsForPrincipal(principal), [])
- # now put a deny in there, check it's set.
- manager.denyPermissionToPrincipal(permission, principal)
- self.assertEqual(manager.getPrincipalsForPermission(permission),
- [(principal, Deny)])
- self.assertEqual(manager.getPermissionsForPrincipal(principal),
- [(permission, Deny)])
- # test for deny followed by allow . The latter should override.
- manager.grantPermissionToPrincipal(permission, principal)
- self.assertEqual(manager.getPrincipalsForPermission(permission),
- [(principal, Allow)])
- self.assertEqual(manager.getPermissionsForPrincipal(principal),
- [(permission, Allow)])
- # check that allow followed by allow is just a single allow.
- manager.grantPermissionToPrincipal(permission, principal)
- self.assertEqual(manager.getPrincipalsForPermission(permission),
- [(principal, Allow)])
- self.assertEqual(manager.getPermissionsForPrincipal(principal),
- [(permission, Allow)])
- # check that two unsets in a row quietly ignores the second one.
- manager.unsetPermissionForPrincipal(permission, principal)
- manager.unsetPermissionForPrincipal(permission, principal)
- self.assertEqual(manager.getPrincipalsForPermission(permission), [])
- self.assertEqual(manager.getPermissionsForPrincipal(principal), [])
- # check the result of getSetting() when it's empty.
- self.assertEqual(manager.getSetting(permission, principal), Unset)
- # check the result of getSetting() when it's allowed.
- manager.grantPermissionToPrincipal(permission, principal)
- self.assertEqual(manager.getSetting(permission, principal), Allow)
- # check the result of getSetting() when it's denied.
- manager.denyPermissionToPrincipal(permission, principal)
- self.assertEqual(manager.getSetting(permission, principal), Deny)
+ [permission])
def testManyPermissionsOnePrincipal(self):
perm1 = permregistry.definePermission('Perm One', 'title')
@@ -93,24 +57,19 @@
manager.grantPermissionToPrincipal(perm2, prin1)
perms = manager.getPermissionsForPrincipal(prin1)
self.assertEqual(len(perms), 2)
- self.failUnless((perm1,Allow) in perms)
- self.failUnless((perm2,Allow) in perms)
- manager.denyPermissionToPrincipal(perm2, prin1)
- perms = manager.getPermissionsForPrincipal(prin1)
- self.assertEqual(len(perms), 2)
- self.failUnless((perm1,Allow) in perms)
- self.failUnless((perm2,Deny) in perms)
+ self.failUnless(perm1 in perms)
+ self.failUnless(perm2 in perms)
def testManyPrincipalsOnePermission(self):
perm1 = permregistry.definePermission('Perm One', 'title').getId()
prin1 = self._make_principal()
prin2 = self._make_principal('Principal 2', 'Principal Two')
manager.grantPermissionToPrincipal(perm1, prin1)
- manager.denyPermissionToPrincipal(perm1, prin2)
+ manager.grantPermissionToPrincipal(perm1, prin2)
principals = manager.getPrincipalsForPermission(perm1)
self.assertEqual(len(principals), 2)
- self.failUnless((prin1,Allow) in principals)
- self.failUnless((prin2,Deny) in principals)
+ self.failUnless(prin1 in principals)
+ self.failUnless(prin2 in principals)
def test_suite():
loader=unittest.TestLoader()
=== Zope3/lib/python/Zope/App/Security/tests/testPrincipalRoleManager.py 1.1.2.7 => 1.1.2.8 ===
from Zope.App.Security.PrincipalRegistry import principalRegistry as pregistry
from Zope.App.Security.PrincipalRoleManager import principalRoleManager
-from Zope.App.Security.Settings import Assign, Remove
class Test(unittest.TestCase):
@@ -40,55 +39,36 @@
self.assertEqual(principalRoleManager.getRolesForPrincipal(principal),
[])
- def testPrincipalRoleAssign(self):
+ def testPrincipalRole(self):
role = rregistry.defineRole('ARole', 'A Role').getId()
principal = self._make_principal()
principalRoleManager.assignRoleToPrincipal(role, principal)
self.assertEqual(principalRoleManager.getPrincipalsForRole(role),
- [(principal,Assign)])
+ [principal])
self.assertEqual(principalRoleManager.getRolesForPrincipal(principal),
- [(role,Assign)])
-
- def testPrincipalRoleRemove(self):
- role = rregistry.defineRole('ARole', 'A Role').getId()
- principal = self._make_principal()
- principalRoleManager.removeRoleFromPrincipal(role, principal)
- self.assertEqual(principalRoleManager.getPrincipalsForRole(role),
- [(principal,Remove)])
- self.assertEqual(principalRoleManager.getRolesForPrincipal(principal),
- [(role,Remove)])
-
- def testPrincipalRoleUnset(self):
- role = rregistry.defineRole('ARole', 'A Role').getId()
- principal = self._make_principal()
- principalRoleManager.removeRoleFromPrincipal(role, principal)
- principalRoleManager.unsetRoleForPrincipal(role, principal)
- self.assertEqual(principalRoleManager.getPrincipalsForRole(role),
- [])
- self.assertEqual(principalRoleManager.getRolesForPrincipal(principal),
- [])
+ [role])
def testManyRolesOnePrincipal(self):
- role1 = rregistry.defineRole('Role One', 'Role #1').getId()
- role2 = rregistry.defineRole('Role Two', 'Role #2').getId()
+ perm1 = rregistry.defineRole('Role One', 'Role #1').getId()
+ perm2 = rregistry.defineRole('Role Two', 'Role #2').getId()
prin1 = self._make_principal()
- principalRoleManager.assignRoleToPrincipal(role1, prin1)
- principalRoleManager.assignRoleToPrincipal(role2, prin1)
- roles = principalRoleManager.getRolesForPrincipal(prin1)
- self.assertEqual(len(roles), 2)
- self.failUnless((role1,Assign) in perms)
- self.failUnless((role2,Assign) in perms)
+ principalRoleManager.assignRoleToPrincipal(perm1, prin1)
+ principalRoleManager.assignRoleToPrincipal(perm2, prin1)
+ perms = principalRoleManager.getRolesForPrincipal(prin1)
+ self.assertEqual(len(perms), 2)
+ self.failUnless(perm1 in perms)
+ self.failUnless(perm2 in perms)
def testManyPrincipalsOneRole(self):
- role1 = rregistry.defineRole('Role One', 'Role #1').getId()
+ perm1 = rregistry.defineRole('Role One', 'Role #1').getId()
prin1 = self._make_principal()
prin2 = self._make_principal('Principal 2', 'Principal Two')
- principalRoleManager.assignRoleToPrincipal(role1, prin1)
- principalRoleManager.assignRoleToPrincipal(role1, prin2)
- principals = principalRoleManager.getPrincipalsForRole(role1)
+ principalRoleManager.assignRoleToPrincipal(perm1, prin1)
+ principalRoleManager.assignRoleToPrincipal(perm1, prin2)
+ principals = principalRoleManager.getPrincipalsForRole(perm1)
self.assertEqual(len(principals), 2)
- self.failUnless((prin1,Assign) in principals)
- self.failUnless((prin2,Assign) in principals)
+ self.failUnless(prin1 in principals)
+ self.failUnless(prin2 in principals)
def test_suite():
loader=unittest.TestLoader()