[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testRolePermissionMap.py:1.1.2.2

Barry Warsaw barry@wooz.org
Thu, 13 Dec 2001 13:04:11 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv11591/lib/python/Zope/App/Security/tests

Modified Files:
      Tag: Zope-3x-branch
	testRolePermissionMap.py 
Log Message:
Update tests for new RolePermissionMap interface


=== Zope3/lib/python/Zope/App/Security/tests/testRolePermissionMap.py 1.1.2.1 => 1.1.2.2 ===
 import unittest
 
-from Zope.App.Security import PermissionRegistry
-from Zope.App.Security import RoleRegistry
-from Zope.App.Security import RolePermissionMap
+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):
-        from Zope.App.Security.RolePermissionMap import _clear
-        from Zope.App.Security.PermissionRegistry import _clear as _pclear
-        from Zope.App.Security.RoleRegistry import _clear as _rclear
-        _clear()
-        _pclear()
-        _rclear()
+        pregistry._clear()
+        rregistry._clear()
+        map._clear()
         
     def testUnboundRolePermission(self):
-        permission = PermissionRegistry.definePermission('APerm')
-        role = RoleRegistry.defineRole('ARole')
-        self.assertEqual(RolePermissionMap.getRolesForPermission(permission),
-                         [])
-        self.assertEqual(RolePermissionMap.getPermissionsForRole(role),
-                         [])
+        permission = pregistry.definePermission('APerm')
+        role = rregistry.defineRole('ARole')
+        self.assertEqual(map.getRolesForPermission(permission), [])
+        self.assertEqual(map.getPermissionsForRole(role), [])
 
     def testRolePermission(self):
-        permission = PermissionRegistry.definePermission('APerm')
-        role = RoleRegistry.defineRole('ARole')
-        RolePermissionMap.grantPermissionToRole(permission, role)
-        self.assertEqual(RolePermissionMap.getRolesForPermission(permission),
-                         [role])
-        self.assertEqual(RolePermissionMap.getPermissionsForRole(role),
-                         [permission])
+        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 = PermissionRegistry.definePermission('Perm One')
-        perm2 = PermissionRegistry.definePermission('Perm Two')
-        role1 = RoleRegistry.defineRole('Role One')
-        RolePermissionMap.grantPermissionToRole(perm1, role1)
-        RolePermissionMap.grantPermissionToRole(perm2, role1)
-        perms = RolePermissionMap.getPermissionsForRole(role1)
+        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 = PermissionRegistry.definePermission('Perm One')
-        role1 = RoleRegistry.defineRole('Role One')
-        role2 = RoleRegistry.defineRole('Role Two')
-        RolePermissionMap.grantPermissionToRole(perm1, role1)
-        RolePermissionMap.grantPermissionToRole(perm1, role2)
-        roles = RolePermissionMap.getRolesForPermission(perm1)
+        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)