[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testPrincipalRoleManager.py:1.1.2.1 testPrincipalRoleMap.py:NONE
Barry Warsaw
barry@wooz.org
Thu, 13 Dec 2001 16:04:27 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv1491/lib/python/Zope/App/Security/tests
Added Files:
Tag: Zope-3x-branch
testPrincipalRoleManager.py
Removed Files:
Tag: Zope-3x-branch
testPrincipalRoleMap.py
Log Message:
Updates tests for PrincipalRoleMap -> PrincipalRoleManager
=== Added File Zope3/lib/python/Zope/App/Security/tests/testPrincipalRoleManager.py ===
# Copyright (c) 2001 Zope Coporation and Contributors. All Rights Reserved.
#
# 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
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
"""Test handler for PrincipalRoleManager module."""
import sys
import unittest
from Zope.App.Security.RoleRegistry import registry as rregistry
from Zope.App.Security.PrincipalRegistry import globalRegistry as pregistry
from Zope.App.Security.PrincipalRoleManager import manager
class Test(unittest.TestCase):
def tearDown(self):
rregistry._clear()
pregistry.clear()
manager._clear()
def _make_principal(self, id=None, title=None):
return pregistry.definePrincipal(
id or 'APrincipal',
title or 'A Principal',
login = id or 'APrincipal')
def testUnboundPrincipalRole(self):
role = rregistry.defineRole('ARole')
principal = self._make_principal()
self.assertEqual(manager.getPrincipalsForRole(role), [])
self.assertEqual(manager.getRolesForPrincipal(principal), [])
def testPrincipalRole(self):
role = rregistry.defineRole('ARole')
principal = self._make_principal()
manager.assignRoleToPrincipal(role, principal)
self.assertEqual(manager.getPrincipalsForRole(role),
[principal])
self.assertEqual(manager.getRolesForPrincipal(principal),
[role])
def testManyRolesOnePrincipal(self):
perm1 = rregistry.defineRole('Role One')
perm2 = rregistry.defineRole('Role Two')
prin1 = self._make_principal()
manager.assignRoleToPrincipal(perm1, prin1)
manager.assignRoleToPrincipal(perm2, prin1)
perms = manager.getRolesForPrincipal(prin1)
self.assertEqual(len(perms), 2)
self.failUnless(perm1 in perms)
self.failUnless(perm2 in perms)
def testManyPrincipalsOneRole(self):
perm1 = rregistry.defineRole('Role One')
prin1 = self._make_principal()
prin2 = self._make_principal('Principal 2', 'Principal Two')
manager.assignRoleToPrincipal(perm1, prin1)
manager.assignRoleToPrincipal(perm1, prin2)
principals = manager.getPrincipalsForRole(perm1)
self.assertEqual(len(principals), 2)
self.failUnless(prin1 in principals)
self.failUnless(prin2 in principals)
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())
=== Removed File Zope3/lib/python/Zope/App/Security/tests/testPrincipalRoleMap.py ===