[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testPrincipalPermissionMap.py:1.1.2.1 testPrincipalRoleMap.py:1.1.2.1
Barry Warsaw
barry@wooz.org
Thu, 13 Dec 2001 13:03:36 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv11086/lib/python/Zope/App/Security/tests
Added Files:
Tag: Zope-3x-branch
testPrincipalPermissionMap.py testPrincipalRoleMap.py
Log Message:
New tests for the new classes/modules
=== Added File Zope3/lib/python/Zope/App/Security/tests/testPrincipalPermissionMap.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 PrincipalPermissionMap module."""
import sys
import unittest
from Zope.App.Security.PermissionRegistry import registry as pregistry
from Zope.App.Security.PrincipalRegistry import globalRegistry as xregistry
from Zope.App.Security.PrincipalPermissionMap import map
class Test(unittest.TestCase):
def tearDown(self):
pregistry._clear()
xregistry.clear()
map._clear()
def _make_principal(self, id=None, title=None):
return xregistry.definePrincipal(
id or 'APrincipal',
title or 'A Principal',
login = id or 'APrincipal')
def testUnboundPrincipalPermission(self):
permission = pregistry.definePermission('APerm')
principal = self._make_principal()
self.assertEqual(map.getPrincipalsForPermission(permission), [])
self.assertEqual(map.getPermissionsForPrincipal(principal), [])
def testPrincipalPermission(self):
permission = pregistry.definePermission('APerm')
principal = self._make_principal()
map.grantPermissionToPrincipal(permission, principal)
self.assertEqual(map.getPrincipalsForPermission(permission),
[principal])
self.assertEqual(map.getPermissionsForPrincipal(principal),
[permission])
def testManyPermissionsOnePrincipal(self):
perm1 = pregistry.definePermission('Perm One')
perm2 = pregistry.definePermission('Perm Two')
prin1 = self._make_principal()
map.grantPermissionToPrincipal(perm1, prin1)
map.grantPermissionToPrincipal(perm2, prin1)
perms = map.getPermissionsForPrincipal(prin1)
self.assertEqual(len(perms), 2)
self.failUnless(perm1 in perms)
self.failUnless(perm2 in perms)
def testManyPrincipalsOnePermission(self):
perm1 = pregistry.definePermission('Perm One')
prin1 = self._make_principal()
prin2 = self._make_principal('Principal 2', 'Principal Two')
map.grantPermissionToPrincipal(perm1, prin1)
map.grantPermissionToPrincipal(perm1, prin2)
principals = map.getPrincipalsForPermission(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())
=== Added File Zope3/lib/python/Zope/App/Security/tests/testPrincipalRoleMap.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 RolePermissionMap module."""
import sys
import unittest
from Zope.App.Security.PermissionRegistry import registry as pregistry
from Zope.App.Security.RoleRegistry import registry as rregistry
from Zope.App.Security.RolePermissionMap import map
class Test(unittest.TestCase):
def tearDown(self):
pregistry._clear()
rregistry._clear()
map._clear()
def testUnboundRolePermission(self):
permission = pregistry.definePermission('APerm')
role = rregistry.defineRole('ARole')
self.assertEqual(map.getRolesForPermission(permission), [])
self.assertEqual(map.getPermissionsForRole(role), [])
def testRolePermission(self):
permission = pregistry.definePermission('APerm')
role = rregistry.defineRole('ARole')
map.grantPermissionToRole(permission, role)
self.assertEqual(map.getRolesForPermission(permission), [role])
self.assertEqual(map.getPermissionsForRole(role), [permission])
def testManyPermissionsOneRole(self):
perm1 = pregistry.definePermission('Perm One')
perm2 = pregistry.definePermission('Perm Two')
role1 = rregistry.defineRole('Role One')
map.grantPermissionToRole(perm1, role1)
map.grantPermissionToRole(perm2, role1)
perms = map.getPermissionsForRole(role1)
self.assertEqual(len(perms), 2)
self.failUnless(perm1 in perms)
self.failUnless(perm2 in perms)
def testManyRolesOnePermission(self):
perm1 = pregistry.definePermission('Perm One')
role1 = rregistry.defineRole('Role One')
role2 = rregistry.defineRole('Role Two')
map.grantPermissionToRole(perm1, role1)
map.grantPermissionToRole(perm1, role2)
roles = map.getRolesForPermission(perm1)
self.assertEqual(len(roles), 2)
self.failUnless(role1 in roles)
self.failUnless(role2 in roles)
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())