[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testPrincipalPermissionManager.py:1.1.2.1 testPrincipalPermissionMap.py:NONE
Barry Warsaw
barry@wooz.org
Thu, 13 Dec 2001 15:48:11 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv29394/lib/python/Zope/App/Security/tests
Added Files:
Tag: Zope-3x-branch
testPrincipalPermissionManager.py
Removed Files:
Tag: Zope-3x-branch
testPrincipalPermissionMap.py
Log Message:
test of the new PrincipalPermissionManager
=== Added File Zope3/lib/python/Zope/App/Security/tests/testPrincipalPermissionManager.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 PrincipalPermissionManager 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.PrincipalPermissionManager import manager
class Test(unittest.TestCase):
def tearDown(self):
pregistry._clear()
xregistry.clear()
manager._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(manager.getPrincipalsForPermission(permission), [])
self.assertEqual(manager.getPermissionsForPrincipal(principal), [])
def testPrincipalPermission(self):
permission = pregistry.definePermission('APerm')
principal = self._make_principal()
manager.grantPermissionToPrincipal(permission, principal)
self.assertEqual(manager.getPrincipalsForPermission(permission),
[principal])
self.assertEqual(manager.getPermissionsForPrincipal(principal),
[permission])
def testManyPermissionsOnePrincipal(self):
perm1 = pregistry.definePermission('Perm One')
perm2 = pregistry.definePermission('Perm Two')
prin1 = self._make_principal()
manager.grantPermissionToPrincipal(perm1, prin1)
manager.grantPermissionToPrincipal(perm2, prin1)
perms = manager.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')
manager.grantPermissionToPrincipal(perm1, prin1)
manager.grantPermissionToPrincipal(perm1, prin2)
principals = manager.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())
=== Removed File Zope3/lib/python/Zope/App/Security/tests/testPrincipalPermissionMap.py ===