[Zope3-checkins] CVS: Zope3/src/zope/app/securitypolicy/tests -
test_annotationprincipalpermissionmanager.py:1.3
test_annotationprincipalrolemanager.py:1.3
test_annotationrolepermissionmanager.py:1.3
test_principalpermissionmanager.py:1.3
test_principalrolemanager.py:1.3 test_rolepermissionmanager.py:1.3
test_securitydirectives.py:1.3 test_zopepolicy.py:1.3
Stephan Richter
srichter at cosmos.phy.tufts.edu
Mon Mar 8 07:06:41 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/securitypolicy/tests
In directory cvs.zope.org:/tmp/cvs-serv13053/src/zope/app/securitypolicy/tests
Modified Files:
test_annotationprincipalpermissionmanager.py
test_annotationprincipalrolemanager.py
test_annotationrolepermissionmanager.py
test_principalpermissionmanager.py
test_principalrolemanager.py test_rolepermissionmanager.py
test_securitydirectives.py test_zopepolicy.py
Log Message:
Adjusted code to use the new APIs for permissions and principals. Also, use
the utility service instead of the permission registry to look up permissions.
=== Zope3/src/zope/app/securitypolicy/tests/test_annotationprincipalpermissionmanager.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/securitypolicy/tests/test_annotationprincipalpermissionmanager.py:1.2 Fri Mar 5 13:39:09 2004
+++ Zope3/src/zope/app/securitypolicy/tests/test_annotationprincipalpermissionmanager.py Mon Mar 8 07:06:09 2004
@@ -11,7 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Test handler for AnnotationPrincipalPermissionManager module.
+"""Test handler for Annotation Principal Permission Manager module.
$Id$
"""
@@ -21,15 +21,13 @@
from zope.app.tests import ztapi
from zope.app.attributeannotations import AttributeAnnotations
-from zope.app.interfaces.annotation import IAttributeAnnotatable
-from zope.app.interfaces.annotation import IAnnotations
-from zope.app.security.registries.permissionregistry import \
- permissionRegistry as permregistry
-from zope.app.security.registries.principalregistry import \
- principalRegistry as prinregistry
+from zope.app.interfaces.annotation import IAttributeAnnotatable, IAnnotations
+from zope.app.security.principalregistry import principalRegistry
from zope.app.security.settings import Allow, Deny, Unset
from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.app.security.interfaces import IPermission
+from zope.app.security.permission import Permission
from zope.app.securitypolicy.principalpermission \
import AnnotationPrincipalPermissionManager
@@ -45,24 +43,24 @@
AttributeAnnotations)
def _make_principal(self, id=None, title=None):
- p = prinregistry.definePrincipal(
+ p = principalRegistry.definePrincipal(
id or 'APrincipal',
title or 'A Principal',
login = id or 'APrincipal')
- return p.getId()
+ return p.id
def testUnboundPrincipalPermission(self):
manager = AnnotationPrincipalPermissionManager(Manageable())
- permission = permregistry.definePermission('APerm', 'title')
- permission = permission.getId()
+ ztapi.provideUtility(IPermission, Permission('APerm', 'title'), 'APerm')
+ permission = 'APerm'
principal = self._make_principal()
self.assertEqual(manager.getPrincipalsForPermission(permission), [])
self.assertEqual(manager.getPermissionsForPrincipal(principal), [])
def testPrincipalPermission(self):
manager = AnnotationPrincipalPermissionManager(Manageable())
- permission = permregistry.definePermission('APerm', 'title')
- permission = permission.getId()
+ ztapi.provideUtility(IPermission, Permission('APerm', 'title'), 'APerm')
+ permission = 'APerm'
principal = self._make_principal()
# check that an allow permission is saved correctly
@@ -117,32 +115,38 @@
def testManyPermissionsOnePrincipal(self):
manager = AnnotationPrincipalPermissionManager(Manageable())
- perm1 = permregistry.definePermission('Perm One', 'title').getId()
- perm2 = permregistry.definePermission('Perm Two', 'title').getId()
+ ztapi.provideUtility(
+ IPermission, Permission('Perm One', 'title'), 'Perm One')
+ perm1 = 'Perm One'
+ ztapi.provideUtility(
+ IPermission, Permission('Perm Two', 'title'), 'Perm Two')
+ perm2 = '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,Allow) in perms)
- self.failUnless((perm2,Allow) in perms)
+ self.failUnless((perm1, Allow) in perms)
+ self.failUnless((perm2, Allow) in perms)
manager.denyPermissionToPrincipal(perm2, prin1)
perms = manager.getPermissionsForPrincipal(prin1)
self.assertEqual(len(perms), 2)
- self.failUnless((perm1,Allow) in perms)
- self.failUnless((perm2,Deny) in perms)
+ self.failUnless((perm1, Allow) in perms)
+ self.failUnless((perm2, Deny) in perms)
def testManyPrincipalsOnePermission(self):
manager = AnnotationPrincipalPermissionManager(Manageable())
- perm1 = permregistry.definePermission('Perm One', 'title').getId()
+ ztapi.provideUtility(
+ IPermission, Permission('Perm One', 'title'), 'Perm One')
+ perm1 = 'Perm One'
prin1 = self._make_principal()
prin2 = self._make_principal('Principal 2', 'Principal Two')
manager.grantPermissionToPrincipal(perm1, prin1)
manager.denyPermissionToPrincipal(perm1, prin2)
principals = manager.getPrincipalsForPermission(perm1)
self.assertEqual(len(principals), 2)
- self.failUnless((prin1,Allow) in principals)
- self.failUnless((prin2,Deny) in principals)
+ self.failUnless((prin1, Allow) in principals)
+ self.failUnless((prin2, Deny) in principals)
def test_suite():
loader=unittest.TestLoader()
=== Zope3/src/zope/app/securitypolicy/tests/test_annotationprincipalrolemanager.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/securitypolicy/tests/test_annotationprincipalrolemanager.py:1.2 Fri Mar 5 13:39:09 2004
+++ Zope3/src/zope/app/securitypolicy/tests/test_annotationprincipalrolemanager.py Mon Mar 8 07:06:09 2004
@@ -17,22 +17,18 @@
"""
import unittest
from zope.interface import implements
-from zope.component import getService
+from zope.app import zapi
from zope.app.tests import ztapi
from zope.app.attributeannotations import AttributeAnnotations
-from zope.app.interfaces.annotation import IAttributeAnnotatable
-from zope.app.interfaces.annotation import IAnnotations
-from zope.app.services.servicenames import Adapters
-from zope.app.security.registries.principalregistry import \
- principalRegistry as pregistry
+from zope.app.interfaces.annotation import IAttributeAnnotatable, IAnnotations
+from zope.app.security.principalregistry import principalRegistry
from zope.app.security.settings import Allow, Deny
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zope.app.securitypolicy.role import Role
from zope.app.securitypolicy.interfaces import IRole
-from zope.app.securitypolicy.principalrole import \
- AnnotationPrincipalRoleManager
+from zope.app.securitypolicy.principalrole import AnnotationPrincipalRoleManager
class Manageable:
implements(IAttributeAnnotatable)
@@ -51,11 +47,11 @@
AttributeAnnotations)
def _make_principal(self, id=None, title=None):
- p = pregistry.definePrincipal(
+ p = principalRegistry.definePrincipal(
id or 'APrincipal',
title or 'A Principal',
login = id or 'APrincipal')
- return p.getId()
+ return p.id
def _make_roleManager(self, obj=None):
if obj is None:
=== Zope3/src/zope/app/securitypolicy/tests/test_annotationrolepermissionmanager.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/securitypolicy/tests/test_annotationrolepermissionmanager.py:1.2 Fri Mar 5 13:39:09 2004
+++ Zope3/src/zope/app/securitypolicy/tests/test_annotationrolepermissionmanager.py Mon Mar 8 07:06:09 2004
@@ -18,15 +18,12 @@
import unittest
from zope.interface import implements
-from zope.app import zapi
from zope.app.tests import ztapi
from zope.app.attributeannotations import AttributeAnnotations
-from zope.app.interfaces.annotation import IAttributeAnnotatable
-from zope.app.interfaces.annotation import IAnnotations
-from zope.app.interfaces.security import IPermissionService
-from zope.app.security.registries.permissionregistry import permissionRegistry
+from zope.app.interfaces.annotation import IAttributeAnnotatable, IAnnotations
+from zope.app.security.interfaces import IPermission
+from zope.app.security.permission import Permission
from zope.app.security.settings import Allow, Deny
-from zope.app.services.servicenames import Permissions, Adapters
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zope.app.securitypolicy.role import Role
@@ -37,32 +34,27 @@
class Manageable:
implements(IAttributeAnnotatable)
-def defineRole(id, title=None, description=None):
- role = Role(id, title, description)
- ztapi.provideUtility(IRole, role, name=role.id)
- return role
-
class Test(PlacefulSetup, unittest.TestCase):
def setUp(self):
PlacefulSetup.setUp(self)
- defineService = zapi.getServiceManager(None).defineService
- provideService = zapi.getServiceManager(None).provideService
- defineService(Permissions, IPermissionService)
- provideService(Permissions, permissionRegistry)
ztapi.provideAdapter(IAttributeAnnotatable, IAnnotations,
AttributeAnnotations)
- read = permissionRegistry.definePermission('read', 'Read Something')
- self.read = read.getId()
-
- write = permissionRegistry.definePermission('write', 'Write Something')
- self.write = write.getId()
+ read = Permission('read', 'Read Something')
+ ztapi.provideUtility(IPermission, read, name=read.id)
+ self.read = read.id
+
+ write = Permission('write', 'Write Something')
+ ztapi.provideUtility(IPermission, write, name=write.id)
+ self.write = write.id
- peon = defineRole('peon', 'Poor Slob')
+ peon = Role('peon', 'Poor Slob')
+ ztapi.provideUtility(IRole, peon, name=peon.id)
self.peon = peon.id
- manager = defineRole('manager', 'Supreme Being')
+ manager = Role('manager', 'Supreme Being')
+ ztapi.provideUtility(IRole, manager, name=manager.id)
self.manager = manager.id
def testNormal(self):
=== Zope3/src/zope/app/securitypolicy/tests/test_principalpermissionmanager.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/securitypolicy/tests/test_principalpermissionmanager.py:1.2 Fri Mar 5 13:39:09 2004
+++ Zope3/src/zope/app/securitypolicy/tests/test_principalpermissionmanager.py Mon Mar 8 07:06:09 2004
@@ -17,43 +17,45 @@
"""
import unittest
-from zope.component.service import serviceManager as services
-from zope.testing.cleanup import CleanUp
+from zope.app import zapi
+from zope.app.tests import ztapi
+from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.app.interfaces.security import IPermissionService
-from zope.app.interfaces.security import IAuthenticationService
+from zope.app.security.interfaces import IAuthenticationService, IPermission
+from zope.app.security.permission import Permission
-from zope.app.services.servicenames import Permissions, Authentication
-from zope.app.security.registries.permissionregistry \
- import permissionRegistry as permregistry
-from zope.app.security.registries.principalregistry \
- import principalRegistry as prinregistry
+from zope.app.services.servicenames import Authentication
from zope.app.security.settings import Allow, Deny, Unset
+from zope.app.security.principalregistry import principalRegistry
from zope.app.securitypolicy.principalpermission \
import principalPermissionManager as manager
-class Test(CleanUp, unittest.TestCase):
- def setUp(self):
- CleanUp.setUp(self)
+def definePermission(id, title=None, description=None):
+ perm = Permission(id, title, description)
+ ztapi.provideUtility(IPermission, perm, name=perm.id)
+ return perm
+
+class Test(PlacelessSetup, unittest.TestCase):
- services.defineService(Permissions, IPermissionService)
- services.provideService(Permissions, permregistry)
+ def setUp(self):
+ super(Test, self).setUp()
+ services = zapi.getServiceManager(None)
services.defineService(Authentication, IAuthenticationService)
- services.provideService(Authentication, prinregistry)
+ services.provideService(Authentication, principalRegistry)
def _make_principal(self, id=None, title=None):
- p = prinregistry.definePrincipal(
+ p = principalRegistry.definePrincipal(
id or 'APrincipal',
title or 'A Principal',
login = id or 'APrincipal')
- return p.getId()
+ return p.id
def testUnboundPrincipalPermission(self):
- permission = permregistry.definePermission('APerm', 'title').getId()
+ permission = definePermission('APerm', 'title').id
principal = self._make_principal()
self.assertEqual(manager.getPrincipalsForPermission(permission), [])
self.assertEqual(manager.getPermissionsForPrincipal(principal), [])
@@ -69,14 +71,14 @@
'permission', principal)
def test_invalidPrincipal(self):
- permission = permregistry.definePermission('APerm', 'title').getId()
+ permission = definePermission('APerm', 'title').id
self.assertRaises(ValueError,
manager.grantPermissionToPrincipal,
permission, 'principal')
def testPrincipalPermission(self):
- permission = permregistry.definePermission('APerm', 'title').getId()
+ permission = definePermission('APerm', 'title').id
principal = self._make_principal()
# check that an allow permission is saved correctly
manager.grantPermissionToPrincipal(permission, principal)
@@ -121,8 +123,8 @@
self.assertEqual(manager.getSetting(permission, principal), Deny)
def testManyPermissionsOnePrincipal(self):
- perm1 = permregistry.definePermission('Perm One', 'title').getId()
- perm2 = permregistry.definePermission('Perm Two', 'title').getId()
+ perm1 = definePermission('Perm One', 'title').id
+ perm2 = definePermission('Perm Two', 'title').id
prin1 = self._make_principal()
manager.grantPermissionToPrincipal(perm1, prin1)
manager.grantPermissionToPrincipal(perm2, prin1)
@@ -140,7 +142,7 @@
self.failUnless((perm2,prin1,Deny) in perms)
def testManyPrincipalsOnePermission(self):
- perm1 = permregistry.definePermission('Perm One', 'title').getId()
+ perm1 = definePermission('Perm One', 'title').id
prin1 = self._make_principal()
prin2 = self._make_principal('Principal 2', 'Principal Two')
manager.grantPermissionToPrincipal(perm1, prin1)
=== Zope3/src/zope/app/securitypolicy/tests/test_principalrolemanager.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/securitypolicy/tests/test_principalrolemanager.py:1.2 Fri Mar 5 13:39:09 2004
+++ Zope3/src/zope/app/securitypolicy/tests/test_principalrolemanager.py Mon Mar 8 07:06:09 2004
@@ -20,12 +20,11 @@
from zope.app import zapi
from zope.app.tests import ztapi
from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.app.interfaces.security import IAuthenticationService
from zope.app.services.servicenames import Authentication
+from zope.app.security.interfaces import IAuthenticationService
from zope.app.security.settings import Allow, Deny
-from zope.app.security.registries.principalregistry \
- import principalRegistry as pregistry
+from zope.app.security.principalregistry import principalRegistry
from zope.app.securitypolicy.role import Role
from zope.app.securitypolicy.interfaces import IRole
@@ -43,15 +42,15 @@
services = zapi.getServiceManager(None)
services.defineService(Authentication, IAuthenticationService)
- services.provideService(Authentication, pregistry)
+ services.provideService(Authentication, principalRegistry)
def _make_principal(self, id=None, title=None):
- p = pregistry.definePrincipal(
+ p = principalRegistry.definePrincipal(
id or 'APrincipal',
title or 'A Principal',
login = id or 'APrincipal')
- return p.getId()
-
+ return p.id
+
def testUnboundPrincipalRole(self):
role = defineRole('ARole', 'A Role').id
principal = self._make_principal()
=== Zope3/src/zope/app/securitypolicy/tests/test_rolepermissionmanager.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/securitypolicy/tests/test_rolepermissionmanager.py:1.2 Fri Mar 5 13:39:09 2004
+++ Zope3/src/zope/app/securitypolicy/tests/test_rolepermissionmanager.py Mon Mar 8 07:06:09 2004
@@ -21,11 +21,9 @@
from zope.app import zapi
from zope.app.tests import ztapi
-from zope.app.services.servicenames import Permissions
-from zope.app.interfaces.security import IPermissionService
-from zope.app.security.registries.permissionregistry \
- import permissionRegistry as pregistry
+from zope.app.security.interfaces import IPermission
+from zope.app.security.permission import Permission
from zope.app.security.settings import Allow, Deny
from zope.app.securitypolicy.role import Role
@@ -38,23 +36,21 @@
ztapi.provideUtility(IRole, role, name=role.id)
return role
-class Test(PlacelessSetup, unittest.TestCase):
-
- def setUp(self):
- super(Test, self).setUp()
- services = zapi.getServiceManager(None)
+def definePermission(id, title=None, description=None):
+ perm = Permission(id, title, description)
+ ztapi.provideUtility(IPermission, perm, name=perm.id)
+ return perm
- services.defineService(Permissions, IPermissionService)
- services.provideService(Permissions, pregistry)
+class Test(PlacelessSetup, unittest.TestCase):
def testUnboundRolePermission(self):
- permission = pregistry.definePermission('APerm', 'aPerm title').getId()
+ permission = definePermission('APerm', 'aPerm title').id
role = defineRole('ARole', 'A Role').id
self.assertEqual(manager.getRolesForPermission(permission), [])
self.assertEqual(manager.getPermissionsForRole(role), [])
def testRolePermission(self):
- permission = pregistry.definePermission('APerm', 'aPerm title').getId()
+ permission = definePermission('APerm', 'aPerm title').id
role = defineRole('ARole', 'A Role').id
manager.grantPermissionToRole(permission, role)
self.assertEqual(manager.getRolesForPermission(permission),
@@ -63,9 +59,9 @@
[(permission,Allow)])
def testManyPermissionsOneRole(self):
- perm1 = pregistry.definePermission('Perm One', 'P1').getId()
- perm2 = pregistry.definePermission('Perm Two', 'P2').getId()
- perm3 = pregistry.definePermission('Perm Three', 'P3').getId()
+ perm1 = definePermission('Perm One', 'P1').id
+ perm2 = definePermission('Perm Two', 'P2').id
+ perm3 = definePermission('Perm Three', 'P3').id
role1 = defineRole('Role One', 'Role #1').id
perms = manager.getPermissionsForRole(role1)
self.assertEqual(len(perms), 0)
@@ -84,7 +80,7 @@
self.failUnless((perm2,Allow) in perms)
def testManyRolesOnePermission(self):
- perm1 = pregistry.definePermission('Perm One', 'title').getId()
+ perm1 = definePermission('Perm One', 'title').id
role1 = defineRole('Role One', 'Role #1').id
role2 = defineRole('Role Two', 'Role #2').id
roles = manager.getRolesForPermission(perm1)
@@ -107,7 +103,7 @@
self.assertRaises(ValueError,
manager.grantPermissionToRole, 'perm1', 'role1'
)
- perm1 = pregistry.definePermission('Perm One', 'title').getId()
+ perm1 = definePermission('Perm One', 'title').id
self.assertRaises(ValueError,
manager.grantPermissionToRole, perm1, 'role1'
)
=== Zope3/src/zope/app/securitypolicy/tests/test_securitydirectives.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/securitypolicy/tests/test_securitydirectives.py:1.2 Fri Mar 5 13:39:09 2004
+++ Zope3/src/zope/app/securitypolicy/tests/test_securitydirectives.py Mon Mar 8 07:06:09 2004
@@ -19,20 +19,17 @@
from zope.app import zapi
from zope.app.tests import ztapi
-from zope.app.services.servicenames import Permissions, Authentication
-from zope.app.interfaces.security import IPermissionService
-from zope.app.interfaces.security import IAuthenticationService
+from zope.app.services.servicenames import Authentication
+from zope.app.security.interfaces import IAuthenticationService
from zope.configuration.config import ConfigurationConflictError
from zope.configuration import xmlconfig
from zope.app.tests.placelesssetup import PlacelessSetup
-import zope.app.securitypolicy.tests
-import zope.app.securitypolicy.tests
+from zope.app.security.interfaces import IPermission
+from zope.app.security.permission import Permission
from zope.app.security.settings import Allow
-from zope.app.security.registries.principalregistry import principalRegistry
-from zope.app.security.registries.permissionregistry \
- import permissionRegistry as pregistry
+from zope.app.security.principalregistry import principalRegistry
from zope.app.securitypolicy.role import Role
from zope.app.securitypolicy.interfaces import IRole
@@ -42,6 +39,7 @@
import principalPermissionManager as principal_perm_mgr
from zope.app.securitypolicy.principalrole \
import principalRoleManager as principal_role_mgr
+import zope.app.securitypolicy.tests
def defineRole(id, title=None, description=None):
@@ -56,9 +54,6 @@
super(TestBase, self).setUp()
services = zapi.getServiceManager(None)
- services.defineService(Permissions, IPermissionService)
- services.provideService(Permissions, pregistry)
-
services.defineService(Authentication, IAuthenticationService)
services.provideService(Authentication, principalRegistry)
@@ -85,7 +80,8 @@
def setUp(self):
super(TestSecurityMapping, self).setUp()
- pregistry.definePermission("zope.Foo", '', '')
+ ztapi.provideUtility(IPermission, Permission('zope.Foo', ''),
+ name='zope.Foo')
defineRole("zope.Bar", '', '')
principalRegistry.definePrincipal("zope.Blah", '', '')
self.context = xmlconfig.file("mapping.zcml",
=== Zope3/src/zope/app/securitypolicy/tests/test_zopepolicy.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/securitypolicy/tests/test_zopepolicy.py:1.2 Fri Mar 5 13:39:09 2004
+++ Zope3/src/zope/app/securitypolicy/tests/test_zopepolicy.py Mon Mar 8 07:06:09 2004
@@ -16,20 +16,14 @@
$Id$
"""
import unittest
-
from zope.interface import implements
-from zope.app.interfaces.security import IPermissionService
-from zope.app.interfaces.security import IAuthenticationService
-
from zope.app import zapi
from zope.app.attributeannotations import AttributeAnnotations
-from zope.app.interfaces.annotation import IAttributeAnnotatable
-from zope.app.interfaces.annotation import IAnnotations
-from zope.app.security.registries.permissionregistry import permissionRegistry
-from zope.app.security.registries.principalregistry import principalRegistry
-from zope.app.security.registries.principalregistry import PrincipalBase
-from zope.app.services.servicenames import Permissions, Adapters
+from zope.app.interfaces.annotation import IAttributeAnnotatable, IAnnotations
+from zope.app.security.principalregistry import principalRegistry, PrincipalBase
+from zope.app.security.interfaces import IPermission, IAuthenticationService
+from zope.app.security.permission import Permission
from zope.app.services.servicenames import Authentication
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zope.app.tests import ztapi
@@ -68,6 +62,11 @@
ztapi.provideUtility(IRole, role, name=role.id)
return role
+def definePermission(id, title=None, description=None):
+ perm = Permission(id, title, description)
+ ztapi.provideUtility(IPermission, perm, name=perm.id)
+ return perm
+
class Test(PlacefulSetup, unittest.TestCase):
@@ -75,9 +74,6 @@
PlacefulSetup.setUp(self)
services = zapi.getServiceManager(None)
- services.defineService(Permissions, IPermissionService)
- services.provideService(Permissions, permissionRegistry)
-
services.defineService(Authentication, IAuthenticationService)
services.provideService(Authentication, principalRegistry)
@@ -96,36 +92,31 @@
'Unknown', 'Nothing is known about this principal')
# set up some permissions
- read = permissionRegistry.definePermission('read', 'Read',
- 'Read something')
- self.read = read.getId()
- write = permissionRegistry.definePermission('write', 'Write',
- 'Write something')
- self.write = write.getId()
- create = permissionRegistry.definePermission('create', 'Create',
- 'Create something')
- self.create = create.getId()
- update = permissionRegistry.definePermission('update', 'Update',
- 'Update something')
- self.update = update.getId()
+ self.read = definePermission('read', 'Read', 'Read something').id
+
+ self.write = definePermission('write', 'Write', 'Write something').id
+
+ self.create = definePermission('create', 'Create',
+ 'Create something').id
+
+ self.update = definePermission('update', 'Update',
+ 'Update something').id
# ... and some roles...
defineRole("zope.Anonymous", "Everybody",
"All users have this role implicitly")
- peon = defineRole('Peon', 'Site Peon')
- self.peon = peon.id
- manager = defineRole('Manager', 'Site Manager')
- self.manager = manager.id
+ self.peon = defineRole('Peon', 'Site Peon').id
+
+ self.manager = defineRole('Manager', 'Site Manager').id
- arole = defineRole('Another', 'Another Role')
- self.arole = arole.id
+ self.arole = defineRole('Another', 'Another Role').id
# grant and deny some permissions to a principal
- principalPermissionManager.grantPermissionToPrincipal(self.create,
- self.jim.getId())
- principalPermissionManager.denyPermissionToPrincipal(self.update,
- self.jim.getId())
+ principalPermissionManager.grantPermissionToPrincipal(
+ self.create, self.jim.id)
+ principalPermissionManager.denyPermissionToPrincipal(
+ self.update, self.jim.id)
# grant and deny some permissions to the roles
rolePermissionManager.grantPermissionToRole(self.read, self.peon)
@@ -134,24 +125,27 @@
rolePermissionManager.grantPermissionToRole(self.write, self.manager)
# ... and assign roles to principals
- principalRoleManager.assignRoleToPrincipal(self.peon, self.jim.getId())
- principalRoleManager.assignRoleToPrincipal(self.manager,
- self.tim.getId())
+ principalRoleManager.assignRoleToPrincipal(self.peon, self.jim.id)
+ principalRoleManager.assignRoleToPrincipal(self.manager, self.tim.id)
self.policy = self._makePolicy()
+
def _makePolicy(self):
from zope.app.securitypolicy.zopepolicy import ZopeSecurityPolicy
return ZopeSecurityPolicy()
+
def __assertPermissions(self, user, expected, object=None):
permissions = list(permissionsOfPrincipal(user, object))
permissions.sort()
self.assertEqual(permissions, expected)
+
def testImport(self):
from zope.app.securitypolicy.zopepolicy import ZopeSecurityPolicy
+
def testGlobalCheckPermission(self):
self.failUnless(
self.policy.checkPermission(self.read, None, Context(self.jim)))
@@ -183,7 +177,7 @@
self.__assertPermissions(self.unknown, ['read'])
principalPermissionManager.grantPermissionToPrincipal(
- self.write, self.jim.getId())
+ self.write, self.jim.id)
self.failUnless(
self.policy.checkPermission(self.write, None, Context(self.jim)))
@@ -193,11 +187,11 @@
self.failIf(self.policy.checkPermission(
self.write, None, Context(self.jim)))
principalRoleManager.assignRoleToPrincipal(
- self.manager, self.jim.getId())
+ self.manager, self.jim.id)
self.failUnless(self.policy.checkPermission(
self.write, None, Context(self.jim)))
principalRoleManager.removeRoleFromPrincipal(
- self.manager, self.jim.getId())
+ self.manager, self.jim.id)
self.failIf(self.policy.checkPermission(
self.write, None, Context(self.jim)))
@@ -213,11 +207,11 @@
self.failIf(self.policy.checkPermission(
self.write, ob3, Context(self.jim)))
AnnotationPrincipalRoleManager(ob3).assignRoleToPrincipal(
- self.manager, self.jim.getId())
+ self.manager, self.jim.id)
self.failUnless(self.policy.checkPermission(
self.write, ob3, Context(self.jim)))
AnnotationPrincipalRoleManager(ob3).removeRoleFromPrincipal(
- self.manager, self.jim.getId())
+ self.manager, self.jim.id)
self.failIf(self.policy.checkPermission(
self.write, ob3, Context(self.jim)))
@@ -226,8 +220,8 @@
ARPM = AnnotationRolePermissionManager
ztapi.provideAdapter(ITest,
IRolePermissionManager, ARPM)
- test = permissionRegistry.definePermission('test', 'Test', '')
- test = test.getId()
+ test = definePermission('test', 'Test', '')
+ test = test.id
ob1 = TestClass()
ob2 = TestClass(); ob2.__parent__ = ob1
@@ -253,13 +247,13 @@
principalPermissionManager.denyPermissionToPrincipal(
- test, self.jim.getId())
+ test, self.jim.id)
self.failIf(self.policy.checkPermission(
test, ob3, Context(self.jim)))
self.__assertPermissions(self.jim, ['create', 'read'], ob3)
principalPermissionManager.unsetPermissionForPrincipal(
- test, self.jim.getId())
+ test, self.jim.id)
# Make sure multiple conflicting role permissions resolve correctly
ARPM(ob2).grantPermissionToRole(test, 'zope.Anonymous')
@@ -268,11 +262,11 @@
new = principalRegistry.definePrincipal('new', 'Newbie',
'Newbie User', 'new', '098')
- principalRoleManager.assignRoleToPrincipal(self.arole, new.getId())
+ principalRoleManager.assignRoleToPrincipal(self.arole, new.id)
self.failUnless(self.policy.checkPermission(test, ob3, Context(new)))
self.__assertPermissions(new, ['test'], ob3)
- principalRoleManager.assignRoleToPrincipal(self.peon, new.getId())
+ principalRoleManager.assignRoleToPrincipal(self.peon, new.id)
self.failIf(self.policy.checkPermission(test, ob3, Context(new)))
self.__assertPermissions(new, ['read'], ob3)
@@ -285,41 +279,40 @@
ob2 = TestClass(); ob2.__parent__ = ob1
ob3 = TestClass(); ob3.__parent__ = ob2
- test = permissionRegistry.definePermission('test', 'Test', '')
- test = test.getId()
+ test = definePermission('test', 'Test', '').id
self.failIf(self.policy.checkPermission(test, ob3, Context(self.tim)))
self.__assertPermissions(self.tim, ['read', 'write'], ob3)
- APPM(ob2).grantPermissionToPrincipal(test, self.tim.getId())
- self.failUnless(self.policy.checkPermission(test, ob3,
- Context(self.tim)))
+ APPM(ob2).grantPermissionToPrincipal(test, self.tim.id)
+ self.failUnless(self.policy.checkPermission(
+ test, ob3, Context(self.tim)))
self.__assertPermissions(self.tim, ['read', 'test', 'write'], ob3)
- APPM(ob3).denyPermissionToPrincipal(test, self.tim.getId())
- self.failIf(self.policy.checkPermission(test, ob3,
- Context(self.tim)))
+ APPM(ob3).denyPermissionToPrincipal(test, self.tim.id)
+ self.failIf(self.policy.checkPermission(
+ test, ob3, Context(self.tim)))
self.__assertPermissions(self.tim, ['read', 'write'], ob3)
- APPM(ob1).denyPermissionToPrincipal(test, self.jim.getId())
- APPM(ob3).grantPermissionToPrincipal(test, self.jim.getId())
- self.failUnless(self.policy.checkPermission(test, ob3,
- Context(self.jim)))
+ APPM(ob1).denyPermissionToPrincipal(test, self.jim.id)
+ APPM(ob3).grantPermissionToPrincipal(test, self.jim.id)
+ self.failUnless(self.policy.checkPermission(
+ test, ob3, Context(self.jim)))
self.__assertPermissions(self.jim, ['create', 'read', 'test'], ob3)
- APPM(ob3).unsetPermissionForPrincipal(test, self.jim.getId())
- self.failIf(self.policy.checkPermission(test, ob3,
- Context(self.jim)))
+ APPM(ob3).unsetPermissionForPrincipal(test, self.jim.id)
+ self.failIf(self.policy.checkPermission(
+ test, ob3, Context(self.jim)))
self.__assertPermissions(self.jim, ['create', 'read'], ob3)
# make sure placeless principal permissions override placeful ones
- APPM(ob3).grantPermissionToPrincipal(test, self.tim.getId())
+ APPM(ob3).grantPermissionToPrincipal(test, self.tim.id)
principalPermissionManager.denyPermissionToPrincipal(
- test, self.tim.getId())
- self.failIf(self.policy.checkPermission(test, ob3,
- Context(self.tim)))
+ test, self.tim.id)
+ self.failIf(self.policy.checkPermission(
+ test, ob3, Context(self.tim)))
self.__assertPermissions(self.tim, ['read', 'write'], ob3)
More information about the Zope3-Checkins
mailing list