[Zope3-checkins]
CVS: Zope3/src/zope/app/securitypolicy/browser/tests
- test_principalroleview.py:1.2
test_rolepermissionview.py:1.2 roleservice.py:NONE
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Mar 5 13:39:39 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/securitypolicy/browser/tests
In directory cvs.zope.org:/tmp/cvs-serv11332/src/zope/app/securitypolicy/browser/tests
Modified Files:
test_principalroleview.py test_rolepermissionview.py
Removed Files:
roleservice.py
Log Message:
Make all the security code use role utilities and the new fields instead of
the methods.
=== Zope3/src/zope/app/securitypolicy/browser/tests/test_principalroleview.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/securitypolicy/browser/tests/test_principalroleview.py:1.1 Fri Feb 27 07:46:32 2004
+++ Zope3/src/zope/app/securitypolicy/browser/tests/test_principalroleview.py Fri Mar 5 13:39:08 2004
@@ -11,23 +11,25 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""
+"""Principal-Role View Tests
+
$Id$
"""
-
import unittest
-from zope.component import getServiceManager
from zope.interface import implements
from zope.publisher.browser import BrowserView, TestRequest
+from zope.app import zapi
+from zope.app.tests import ztapi
from zope.app.interfaces.security import IAuthenticationService
from zope.app.interfaces.services.service import ISimpleService
from zope.app.services.servicenames import Authentication
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.interfaces import IPrincipalRoleManager
-from zope.app.securitypolicy.interfaces import IRoleService
from zope.app.securitypolicy.browser.principalroleview import \
PrincipalRoleView
@@ -47,15 +49,6 @@
def getSetting(self, role, principal):
return DummySetting('%r:%r' % (role, principal))
-class DummyRoleService:
-
- implements(IRoleService, ISimpleService)
-
- def __init__(self, roles):
- self._roles = roles
-
- def getRoles(self):
- return self._roles
class DummyObject:
def __init__(self, id, title):
@@ -78,19 +71,21 @@
def getPrincipals(self, name):
return self._principals
+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)
- self._roles = []
- self._roles.append(DummyObject('qux', 'Qux'))
- self._roles.append(DummyObject('baz', 'Baz'))
- defineService=getServiceManager(None).defineService
- provideService=getServiceManager(None).provideService
-
- defineService("Roles", IRoleService)
- provideService("Roles"
- , DummyRoleService(roles = self._roles))
+
+ self._roles = [defineRole('qux', 'Qux'), defineRole('baz', 'Baz')]
+
+ defineService = zapi.getServiceManager(None).defineService
+ provideService = zapi.getServiceManager(None).provideService
defineService(Authentication, IAuthenticationService)
@@ -109,17 +104,17 @@
roles = list(view.getAllRoles())
self.assertEqual(len(roles), 2)
- ids = map(lambda x: x.getId(), self._roles)
+ ids = [role.id for role in self._roles]
for role in roles:
- self.failUnless(role.getId() in ids)
+ self.failUnless(role.id in ids)
def testPrincipals(self):
view = self._makeOne()
principals = list(view.getAllPrincipals())
self.assertEqual(len(principals), 2)
- ids = map(lambda x: x.getId(), self._principals)
+ ids = [p.getId() for p in self._principals]
for principal in principals:
self.failUnless(principal.getId() in ids, (principal, ids))
@@ -130,7 +125,7 @@
grid = view.createGrid()
p_ids = [p.getId() for p in view.getAllPrincipals()]
- r_ids = [r.getId() for r in view.getAllRoles()]
+ r_ids = [r.id for r in view.getAllRoles()]
self.failUnless(grid.listAvailableValues())
=== Zope3/src/zope/app/securitypolicy/browser/tests/test_rolepermissionview.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/securitypolicy/browser/tests/test_rolepermissionview.py:1.1 Fri Feb 27 07:46:32 2004
+++ Zope3/src/zope/app/securitypolicy/browser/tests/test_rolepermissionview.py Fri Mar 5 13:39:08 2004
@@ -17,14 +17,15 @@
"""
import unittest
-from zope.component import getServiceManager
from zope.publisher.browser import BrowserView, TestRequest
+from zope.app import zapi
+from zope.app.tests import ztapi
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zope.app.services.servicenames import Permissions
from zope.app.interfaces.security import IPermissionService
-from zope.app.securitypolicy.interfaces import IRoleService
-from zope.app.securitypolicy.browser.tests.roleservice import RoleService
+from zope.app.securitypolicy.role import Role
+from zope.app.securitypolicy.interfaces import IRole
from zope.app.securitypolicy.browser.tests.permissionservice import \
PermissionService
from zope.app.securitypolicy.browser.tests.rolepermissionmanager import \
@@ -35,18 +36,20 @@
class RolePermissionView(RolePermissionView, BrowserView):
"""Adding BrowserView to Utilities; this is usually done by ZCML."""
+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=getServiceManager(None).defineService
- provideService=getServiceManager(None).provideService
- defineService("Roles", IRoleService)
- provideService("Roles", RoleService(
- manager='Manager', member='Member'))
- defineService(Permissions, IPermissionService)
- provideService(Permissions, PermissionService(
+ sm = zapi.getServiceManager(None)
+ defineRole('manager', 'Manager')
+ defineRole('member', 'Member')
+ sm.defineService(Permissions, IPermissionService)
+ sm.provideService(Permissions, PermissionService(
read='Read', write='Write'))
self.view = RolePermissionView(RolePermissionManager(), None)
@@ -55,9 +58,9 @@
ids = ['manager', 'member']
titles = ['Manager', 'Member']
for role in roles:
- i=ids.index(role.getId())
+ i=ids.index(role.id)
self.failIf(i < 0)
- self.assertEqual(role.getTitle(), titles[i])
+ self.assertEqual(role.title, titles[i])
del ids[i]
del titles[i]
@@ -94,7 +97,7 @@
rset = permissionRole.roleSettings()
for ir in range(len(rset)):
setting = rset[ir]
- r = roles[ir].getId()
+ r = roles[ir].id
p = permissions[ip].getId()
if setting == 'Allow':
self.failUnless(r == 'manager' and p == 'read')
@@ -121,7 +124,7 @@
rset = permissionRole.roleSettings()
for ir in range(len(rset)):
setting = rset[ir]
- r = roles[ir].getId()
+ r = roles[ir].id
p = permissions[ip].getId()
if setting == 'Allow':
self.failUnless(r == 'manager' and p == 'write')
=== Removed File Zope3/src/zope/app/securitypolicy/browser/tests/roleservice.py ===
More information about the Zope3-Checkins
mailing list