[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testAttributePrincipalRoleManager.py:1.1.2.1
Steve Spicklemire
steve@spvi.com
Fri, 8 Feb 2002 14:09:27 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv15034
Added Files:
Tag: Zope-3x-branch
testAttributePrincipalRoleManager.py
Log Message:
add tests for AttributePrincipalRoleManager
=== Added File Zope3/lib/python/Zope/App/Security/tests/testAttributePrincipalRoleManager.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
##############################################################################
from Zope.App.Security.AttributePrincipalRoleManager \
import AttributePrincipalRoleManager
from Zope.App.Security.IAttributePrincipalRoleManageable \
import IAttributePrincipalRoleManageable
from Zope.App.Security.RoleRegistry import roleRegistry
from Zope.App.Security.PrincipalRegistry import principalRegistry as pregistry
from Zope.App.Security.Settings import Assign, Remove
import unittest, sys
class Manageable:
__implements__ = IAttributePrincipalRoleManageable
class Test(unittest.TestCase):
def _make_principal(self, id=None, title=None):
pregistry.definePrincipal(
id or 'APrincipal',
title or 'A Principal',
login = id or 'APrincipal')
return id or 'APrincipal'
def setUp(self):
roleRegistry._clear()
pRegistry._clear()
_clear()
roleRegistry.defineRole('peon', 'Poor Slob')
roleRegistry.defineRole('manager', 'Supreme Being')
def testNormal(self):
obj = Manageable()
mgr = AttributePrincipalRoleManager(obj)
principal = self._make_principal()
mgr.assignRoleToPrincipal( 'peon', principal )
mgr.removeRoleFromPrincipal( 'manager', principal )
l = list(mgr.getRolesForPrincipal(principal))
l.sort()
self.assertEqual(l, [ ('manager',Remove), ('peon',Assign)])
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())