[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testPrincipalRoleManager.py:1.1.2.5
Steve Spicklemire
steve@spvi.com
Fri, 8 Feb 2002 13:20:57 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv2601/tests
Modified Files:
Tag: Zope-3x-branch
testPrincipalRoleManager.py
Log Message:
adding IAttributePrincipalRole stuff
=== Zope3/lib/python/Zope/App/Security/tests/testPrincipalRoleManager.py 1.1.2.4 => 1.1.2.5 ===
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):
@@ -39,25 +40,44 @@
self.assertEqual(principalRoleManager.getRolesForPrincipal(principal),
[])
- def testPrincipalRole(self):
+ def testPrincipalRoleAssign(self):
role = rregistry.defineRole('ARole', 'A Role').getId()
principal = self._make_principal()
principalRoleManager.assignRoleToPrincipal(role, principal)
self.assertEqual(principalRoleManager.getPrincipalsForRole(role),
- [principal])
+ [(principal,Assign)])
self.assertEqual(principalRoleManager.getRolesForPrincipal(principal),
- [role])
+ [(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.usetRoleFromPrincipal(role, principal)
+ self.assertEqual(principalRoleManager.getPrincipalsForRole(role),
+ [])
+ self.assertEqual(principalRoleManager.getRolesForPrincipal(principal),
+ [])
def testManyRolesOnePrincipal(self):
- perm1 = rregistry.defineRole('Role One', 'Role #1').getId()
- perm2 = rregistry.defineRole('Role Two', 'Role #2').getId()
+ role1 = rregistry.defineRole('Role One', 'Role #1').getId()
+ role2 = rregistry.defineRole('Role Two', 'Role #2').getId()
prin1 = self._make_principal()
- 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)
+ 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)
def testManyPrincipalsOneRole(self):
perm1 = rregistry.defineRole('Role One', 'Role #1').getId()