[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testZSP.py:1.1.2.1 .testinfo:1.1.2.2
Tres Seaver
tseaver@zope.com
Wed, 28 Nov 2001 14:03:17 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv3487/tests
Modified Files:
Tag: Zope-3x-branch
.testinfo
Added Files:
Tag: Zope-3x-branch
testZSP.py
Log Message:
- Implement ZSP based on '__permission__' (partial on public methods).
=== Added File Zope3/lib/python/Zope/App/Security/tests/testZSP.py ===
import unittest
class Unprotected:
pass
class Protected:
def __init__( self, permission ):
self.__permission__ = permission
class WhiteboxTest( unittest.TestCase ):
"""
Test helper functions.
"""
def _makePolicy( self ):
from Zope.App.Security.ZopeSecurityPolicy import ZopeSecurityPolicy
return ZopeSecurityPolicy()
def testImport( self ):
from Zope.App.Security.ZopeSecurityPolicy import ZopeSecurityPolicy
def testAllowName( self ):
policy = self._makePolicy()
self.failUnless( policy._allowName( 'a' ) )
self.failUnless( policy._allowName( '_a' ) )
self.failIf( policy._allowName( '' ) )
self.failIf( policy._allowName( ' ' ) )
self.failIf( policy._allowName( () ) )
self.failIf( policy._allowName( ('a', 'b') ) )
self.failIf( policy._allowName( [] ) )
self.failIf( policy._allowName( ['a', 'b'] ) )
def testFindPermission( self ):
policy = self._makePolicy()
foo = Protected( 'foo' )
bar = Unprotected()
self.assertEqual( policy._findPermission( foo ), 'foo' )
self.assertEqual( policy._findPermission( bar ), None )
self.assertEqual( policy._findPermission( None ), None )
def testListRolesFor( self ):
policy = self._makePolicy()
foo = Protected( 'foo' )
bar = Unprotected()
self.assertEqual( policy._listRolesFor( 'foo', foo ), () )
self.assertEqual( policy._listRolesFor( 'foo', bar ), () )
# TODO: test placeful role-permission mappings.
def testAggregatedRolesFor( self ):
from Zope.App.Security.PermissionRegistry import definePermission
policy = self._makePolicy()
definePermission( 'foo' )
foo = Protected( 'foo' )
bar = Unprotected()
self.assertEqual( policy._listAggregatedRolesFor( 'foo', foo ), () )
=== Zope3/lib/python/Zope/App/Security/tests/.testinfo 1.1.2.1 => 1.1.2.2 ===
+testZSP.py