[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testSecurityDirectives.py:1.1.2.2
Tres Seaver
tseaver@zope.com
Thu, 13 Dec 2001 17:28:47 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv22025/tests
Modified Files:
Tag: Zope-3x-branch
testSecurityDirectives.py
Log Message:
- Add and test directives for principal-role map, principal-permission
map, and role-permission-map.
=== Zope3/lib/python/Zope/App/Security/tests/testSecurityDirectives.py 1.1.2.1 => 1.1.2.2 ===
from Zope.Configuration.xmlconfig import xmlconfig
from StringIO import StringIO
+from Zope.Configuration.meta import _clear as metaclear
+from Zope.Configuration.xmlconfig import ZopeXMLConfigurationError
from Zope.App.Security.PrincipalRegistry import globalRegistry
from Zope.App.Security.PermissionRegistry import registry as pregistry
from Zope.App.Security.RoleRegistry import registry as rregistry
from Zope.App.Security.metaConfigure import metaConfigure
-from Zope.Configuration.meta import _clear as metaclear
-from Zope.Configuration.xmlconfig import ZopeXMLConfigurationError
-#from Zope.App.Security.Registry import AlreadyRegisteredError
+from Zope.App.Security.RolePermissionManager import manager as role_perm_mgr
+from Zope.App.Security.PrincipalPermissionManager \
+ import manager as principal_perm_mgr
+from Zope.App.Security.PrincipalRoleManager \
+ import manager as principal_role_mgr
def configfile(s):
return StringIO("""<zopeConfigure
@@ -145,12 +149,96 @@
#self.assertRaises(AlreadyRegisteredError, xmlconfig, f)
self.assertRaises(ZopeXMLConfigurationError, xmlconfig, f)
+class TestRolePermission( unittest.TestCase ):
+
+ def setUp( self ):
+ metaConfigure()
+
+ def tearDown( self ):
+ metaclear()
+ role_perm_mgr._clear()
+
+ def testMap( self ):
+ f = configfile("""
+ <security:grantPermissionToRole
+ permission="Foo"
+ role="Bar" />
+ """)
+
+ xmlconfig(f)
+
+ roles = role_perm_mgr.getRolesForPermission("Foo")
+ perms = role_perm_mgr.getPermissionsForRole("Bar")
+
+ self.assertEqual(len( roles ), 1)
+ self.failUnless("Bar" in roles)
+
+ self.assertEqual(len( perms ), 1)
+ self.failUnless("Foo" in perms)
+
+class TestPrincipalPermission( unittest.TestCase ):
+
+ def setUp( self ):
+ metaConfigure()
+
+ def tearDown( self ):
+ metaclear()
+ principal_perm_mgr._clear()
+
+ def testMap( self ):
+ f = configfile("""
+ <security:grantPermissionToPrincipal
+ permission="Foo"
+ principal="Bar" />
+ """)
+
+ xmlconfig(f)
+
+ principals = principal_perm_mgr.getPrincipalsForPermission("Foo")
+ perms = principal_perm_mgr.getPermissionsForPrincipal("Bar")
+
+ self.assertEqual(len( principals ), 1)
+ self.failUnless("Bar" in principals)
+
+ self.assertEqual(len( perms ), 1)
+ self.failUnless("Foo" in perms)
+
+class TestPrincipalRole( unittest.TestCase ):
+
+ def setUp( self ):
+ metaConfigure()
+
+ def tearDown( self ):
+ metaclear()
+ principal_role_mgr._clear()
+
+ def testMap( self ):
+ f = configfile("""
+ <security:assignRoleToPrincipal
+ role="Foo"
+ principal="Bar" />
+ """)
+
+ xmlconfig(f)
+
+ principals = principal_role_mgr.getPrincipalsForRole("Foo")
+ roles = principal_role_mgr.getRolesForPrincipal("Bar")
+
+ self.assertEqual(len( principals ), 1)
+ self.failUnless("Bar" in principals)
+
+ self.assertEqual(len( roles ), 1)
+ self.failUnless("Foo" in roles)
+
def test_suite():
suite = unittest.TestSuite()
loader = unittest.TestLoader()
suite.addTest(loader.loadTestsFromTestCase(TestPrincipalDirective))
suite.addTest(loader.loadTestsFromTestCase(TestPermissionDirective))
suite.addTest(loader.loadTestsFromTestCase(TestRoleDirective))
+ suite.addTest(loader.loadTestsFromTestCase(TestRolePermission))
+ suite.addTest(loader.loadTestsFromTestCase(TestPrincipalPermission))
+ suite.addTest(loader.loadTestsFromTestCase(TestPrincipalRole))
return suite