[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testAttributePrincipalPermissionManager.py:1.1.2.7 testAttributePrincipalRoleManager.py:1.1.2.10 testAttributeRolePermissionManager.py:1.1.2.11 testPrincipalPermissionView.py:1.1.2.9 testZSP.py:1.1.2.16
Steve Alexander
steve@cat-box.net
Sun, 26 May 2002 12:10:29 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv3979/lib/python/Zope/App/Security/tests
Modified Files:
Tag: Zope-3x-branch
testAttributePrincipalPermissionManager.py
testAttributePrincipalRoleManager.py
testAttributeRolePermissionManager.py
testPrincipalPermissionView.py testZSP.py
Log Message:
Changed MementoBag to Annotations as per collector issue 66
http://collector.zope.org/Zope3-dev/66
Note that this will break pre-existing __memobag__ attributes in
persistent objects.
=== Zope3/lib/python/Zope/App/Security/tests/testAttributePrincipalPermissionManager.py 1.1.2.6 => 1.1.2.7 ===
import unittest
-from Zope.App.OFS.Memento.IAttributeMementoStorable \
- import IAttributeMementoStorable
+from Zope.App.OFS.Annotation.IAttributeAnnotatable import IAttributeAnnotatable
from Zope.ComponentArchitecture import getService
-from Zope.App.OFS.Memento.IMementoBag import IMementoBag
-from Zope.App.OFS.Memento.AttributeMementoBag import AttributeMementoBag
+from Zope.App.OFS.Annotation.IAnnotations import IAnnotations
+from Zope.App.OFS.Annotation.AttributeAnnotations import AttributeAnnotations
from Zope.App.Security.PermissionRegistry \
import permissionRegistry as permregistry
from Zope.App.Security.PrincipalRegistry \
@@ -31,15 +30,15 @@
from Zope.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
class Manageable:
- __implements__ = IAttributeMementoStorable
+ __implements__ = IAttributeAnnotatable
class Test(PlacelessSetup, unittest.TestCase):
def setUp(self):
PlacelessSetup.setUp(self)
getService(None,"Adapters").provideAdapter(
- IAttributeMementoStorable, IMementoBag,
- AttributeMementoBag)
+ IAttributeAnnotatable, IAnnotations,
+ AttributeAnnotations)
def _make_principal(self, id=None, title=None):
p = prinregistry.definePrincipal(
@@ -61,44 +60,53 @@
permission = permregistry.definePermission('APerm', 'title')
permission = permission.getId()
principal = self._make_principal()
+
# check that an allow permission is saved correctly
manager.grantPermissionToPrincipal(permission, principal)
self.assertEqual(manager.getPrincipalsForPermission(permission),
[(principal, Allow)])
self.assertEqual(manager.getPermissionsForPrincipal(principal),
[(permission, Allow)])
+
# check that the allow permission is removed.
manager.unsetPermissionForPrincipal(permission, principal)
self.assertEqual(manager.getPrincipalsForPermission(permission), [])
self.assertEqual(manager.getPermissionsForPrincipal(principal), [])
+
# now put a deny in there, check it's set.
manager.denyPermissionToPrincipal(permission, principal)
self.assertEqual(manager.getPrincipalsForPermission(permission),
[(principal, Deny)])
self.assertEqual(manager.getPermissionsForPrincipal(principal),
[(permission, Deny)])
+
# test for deny followed by allow . The latter should override.
manager.grantPermissionToPrincipal(permission, principal)
self.assertEqual(manager.getPrincipalsForPermission(permission),
[(principal, Allow)])
self.assertEqual(manager.getPermissionsForPrincipal(principal),
[(permission, Allow)])
+
# check that allow followed by allow is just a single allow.
manager.grantPermissionToPrincipal(permission, principal)
self.assertEqual(manager.getPrincipalsForPermission(permission),
[(principal, Allow)])
self.assertEqual(manager.getPermissionsForPrincipal(principal),
[(permission, Allow)])
+
# check that two unsets in a row quietly ignores the second one.
manager.unsetPermissionForPrincipal(permission, principal)
manager.unsetPermissionForPrincipal(permission, principal)
self.assertEqual(manager.getPrincipalsForPermission(permission), [])
self.assertEqual(manager.getPermissionsForPrincipal(principal), [])
+
# check the result of getSetting() when it's empty.
self.assertEqual(manager.getSetting(permission, principal), Unset)
+
# check the result of getSetting() when it's allowed.
manager.grantPermissionToPrincipal(permission, principal)
self.assertEqual(manager.getSetting(permission, principal), Allow)
+
# check the result of getSetting() when it's denied.
manager.denyPermissionToPrincipal(permission, principal)
self.assertEqual(manager.getSetting(permission, principal), Deny)
=== Zope3/lib/python/Zope/App/Security/tests/testAttributePrincipalRoleManager.py 1.1.2.9 => 1.1.2.10 ===
import unittest
-from Zope.App.OFS.Memento.IAttributeMementoStorable \
- import IAttributeMementoStorable
+from Zope.App.OFS.Annotation.IAttributeAnnotatable import IAttributeAnnotatable
from Zope.ComponentArchitecture import getService
-from Zope.App.OFS.Memento.IMementoBag import IMementoBag
-from Zope.App.OFS.Memento.AttributeMementoBag import AttributeMementoBag
+from Zope.App.OFS.Annotation.IAnnotations import IAnnotations
+from Zope.App.OFS.Annotation.AttributeAnnotations import AttributeAnnotations
from Zope.App.Security.RoleRegistry import roleRegistry as rregistry
from Zope.App.Security.PrincipalRegistry import principalRegistry as pregistry
from Zope.App.Security.AttributePrincipalRoleManager \
@@ -29,15 +28,15 @@
from Zope.App.OFS.Services.ServiceManager.tests.PlacefulSetup import PlacefulSetup
class Manageable:
- __implements__ = IAttributeMementoStorable
+ __implements__ = IAttributeAnnotatable
class Test(PlacefulSetup, unittest.TestCase):
def setUp(self):
PlacefulSetup.setUp(self)
getService(None,"Adapters").provideAdapter(
- IAttributeMementoStorable, IMementoBag,
- AttributeMementoBag)
+ IAttributeAnnotatable, IAnnotations,
+ AttributeAnnotations)
def _make_principal(self, id=None, title=None):
p = pregistry.definePrincipal(
=== Zope3/lib/python/Zope/App/Security/tests/testAttributeRolePermissionManager.py 1.1.2.10 => 1.1.2.11 ===
from Zope.App.Security.AttributeRolePermissionManager \
import AttributeRolePermissionManager
-from Zope.App.OFS.Memento.IAttributeMementoStorable \
- import IAttributeMementoStorable
-from Zope.App.OFS.Memento.IMementoBag import IMementoBag
-from Zope.App.OFS.Memento.AttributeMementoBag import AttributeMementoBag
+from Zope.App.OFS.Annotation.IAttributeAnnotatable import IAttributeAnnotatable
+from Zope.App.OFS.Annotation.IAnnotations import IAnnotations
+from Zope.App.OFS.Annotation.AttributeAnnotations import AttributeAnnotations
from Zope.ComponentArchitecture \
import getServiceManager, getService
from Zope.App.Security.IRoleService import IRoleService
@@ -30,7 +29,7 @@
import unittest, sys
class Manageable:
- __implements__ = IAttributeMementoStorable
+ __implements__ = IAttributeAnnotatable
class Test(PlacefulSetup, unittest.TestCase):
@@ -43,8 +42,8 @@
provideService('RoleService', roleRegistry)
provideService('PermissionService', permissionRegistry)
provideAdapter=getService(None,"Adapters").provideAdapter
- provideAdapter(IAttributeMementoStorable, IMementoBag,
- AttributeMementoBag)
+ provideAdapter(IAttributeAnnotatable, IAnnotations,
+ AttributeAnnotations)
read = permissionRegistry.definePermission('read', 'Read Something')
self.read = read.getId()
=== Zope3/lib/python/Zope/App/Security/tests/testPrincipalPermissionView.py 1.1.2.8 => 1.1.2.9 ===
from Zope.ComponentArchitecture import getService, getServiceManager
-from Zope.App.OFS.Memento.IAttributeMementoStorable \
- import IAttributeMementoStorable
-from Zope.App.OFS.Memento.IMementoBag import IMementoBag
-from Zope.App.OFS.Memento.AttributeMementoBag import AttributeMementoBag
+from Zope.App.OFS.Annotation.IAttributeAnnotatable import IAttributeAnnotatable
+from Zope.App.OFS.Annotation.IAnnotations import IAnnotations
+from Zope.App.OFS.Annotation.AttributeAnnotations import AttributeAnnotations
from Zope.App.Security.IPermissionService import IPermissionService
from Zope.App.Security.IAuthenticationService import IAuthenticationService
from Zope.App.Security.IPrincipalPermissionManager \
@@ -34,7 +33,7 @@
class DummyContext:
- __implements__ = IAttributeMementoStorable
+ __implements__ = IAttributeAnnotatable
#IPrincipalPermissionManager, IPrincipalPermissionMap
class DummyPermissionService:
@@ -155,10 +154,10 @@
provideService('AuthenticationService',
DummyAuthenticationService(principals = self._principals))
provideAdapter=getService(None,'Adapters').provideAdapter
- provideAdapter(IAttributeMementoStorable,
+ provideAdapter(IAttributeAnnotatable,
IPrincipalPermissionManager, DummyAdapter)
provideAdapter(
- IAttributeMementoStorable, IMementoBag, AttributeMementoBag)
+ IAttributeAnnotatable, IAnnotations, AttributeAnnotations)
def _makeOne(self):
from Zope.App.Security.PrincipalPermissionView \
=== Zope3/lib/python/Zope/App/Security/tests/testZSP.py 1.1.2.15 => 1.1.2.16 ===
from Zope.App.Security.IPrincipalRoleManager import IPrincipalRoleManager
from Zope.Exceptions import Unauthorized, Forbidden
-from Zope.App.OFS.Memento.IAttributeMementoStorable \
- import IAttributeMementoStorable
-from Zope.App.OFS.Memento.IMementoBag import IMementoBag
-from Zope.App.OFS.Memento.AttributeMementoBag import AttributeMementoBag
+from Zope.App.OFS.Annotation.IAttributeAnnotatable import IAttributeAnnotatable
+from Zope.App.OFS.Annotation.IAnnotations import IAnnotations
+from Zope.App.OFS.Annotation.AttributeAnnotations import AttributeAnnotations
from Zope.App.OFS.Services.ServiceManager.tests.PlacefulSetup\
import PlacefulSetup
@@ -66,8 +65,8 @@
def setUp(self):
PlacefulSetup.setUp(self)
getService(None,"Adapters").provideAdapter(
- IAttributeMementoStorable, IMementoBag,
- AttributeMementoBag)
+ IAttributeAnnotatable, IAnnotations,
+ AttributeAnnotations)
jim = principalRegistry.definePrincipal('jim', 'Jim', 'Jim Fulton',
'jim', '123')
self.jim = jim.getId()
@@ -223,7 +222,7 @@
test, self.tim)
-class ITest(IAttributeMementoStorable):
+class ITest(IAttributeAnnotatable):
pass
class TestClass: