[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testAttributePrincipalPermissionManager.py:1.1.2.3 testAttributePrincipalRoleManager.py:1.1.2.5 testAttributeRolePermissionManager.py:1.1.2.6 testPermissionRegistry.py:1.1.2.11 testPrincipalPermissionManager.py:1.1.2.12 testPrincipalPermissionView.py:1.1.2.4 testPrincipalRegistry.py:1.1.2.6 testPrincipalRoleManager.py:1.1.2.12 testPrincipalRoleView.py:1.1.2.5 testProtectClass.py:1.1.2.6 testPublicClass.py:1.1.2.7 testRolePermissionManager.py:1.1.2.9 testRolePermissionView.py:1.1.2.4 testRoleRegistry.py:1.1.2.6 testSecurityDirectives.py:1.1.2.12 testSecurityManagement.py:1.1.2.8 testSecurityManager.py:1.1.2.6 testZSP.py:1.1.2.10
Jim Fulton
jim@cvs.zope.org
Tue, 19 Feb 2002 11:05:39 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv7148/lib/python/Zope/App/Security/tests
Modified Files:
Tag: Zope-3x-branch
testAttributePrincipalPermissionManager.py
testAttributePrincipalRoleManager.py
testAttributeRolePermissionManager.py
testPermissionRegistry.py testPrincipalPermissionManager.py
testPrincipalPermissionView.py testPrincipalRegistry.py
testPrincipalRoleManager.py testPrincipalRoleView.py
testProtectClass.py testPublicClass.py
testRolePermissionManager.py testRolePermissionView.py
testRoleRegistry.py testSecurityDirectives.py
testSecurityManagement.py testSecurityManager.py testZSP.py
Log Message:
Refactored tests to use a global-data cleanup framework.
This avoids a lot of messy clean-up code needed for tests that
use global registries, such as component services.
It is really important to make sure global registries get registered
with this framework.
See the doc strings in Zope.Testing.CleannUp.
=== Zope3/lib/python/Zope/App/Security/tests/testAttributePrincipalPermissionManager.py 1.1.2.2 => 1.1.2.3 ===
import AttributePrincipalPermissionManager
from Zope.App.Security.Settings import Allow, Deny, Unset
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
class Manageable:
__implements__ = IAttributePrincipalPermissionManageable
-class Test(unittest.TestCase):
-
- def tearDown(self):
- permregistry._clear()
- prinregistry._clear()
+class Test(CleanUp, unittest.TestCase):
def _make_principal(self, id=None, title=None):
p = prinregistry.definePrincipal(
=== Zope3/lib/python/Zope/App/Security/tests/testAttributePrincipalRoleManager.py 1.1.2.4 => 1.1.2.5 ===
import IAttributePrincipalRoleManageable
from Zope.App.Security.Settings import Assign, Remove
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
class Manageable:
__implements__ = IAttributePrincipalRoleManageable
-class Test(unittest.TestCase):
-
- def tearDown(self):
- rregistry._clear()
- pregistry._clear()
-
- setUp=tearDown
+class Test(CleanUp, unittest.TestCase):
def _make_principal(self, id=None, title=None):
p = pregistry.definePrincipal(
=== Zope3/lib/python/Zope/App/Security/tests/testAttributeRolePermissionManager.py 1.1.2.5 => 1.1.2.6 ===
from Zope.App.Security.IAttributeRolePermissionManageable \
import IAttributeRolePermissionManageable
-from Zope.ComponentArchitecture import defineService, provideService, _clear
+from Zope.ComponentArchitecture import defineService, provideService
from Zope.App.Security.IRoleService import IRoleService
from Zope.App.Security.IPermissionService import IPermissionService
from Zope.App.Security.RoleRegistry import roleRegistry
from Zope.App.Security.PermissionRegistry import permissionRegistry
from Zope.App.Security.Settings import Allow, Deny
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
import unittest, sys
class Manageable:
__implements__ = IAttributeRolePermissionManageable
-class Test(unittest.TestCase):
+class Test(CleanUp, unittest.TestCase):
def setUp(self):
- roleRegistry._clear()
- permissionRegistry._clear()
- _clear()
+ CleanUp.setUp(self)
defineService('RoleService', IRoleService)
defineService('PermissionService', IPermissionService)
provideService('RoleService', roleRegistry)
=== Zope3/lib/python/Zope/App/Security/tests/testPermissionRegistry.py 1.1.2.10 => 1.1.2.11 ===
from Zope.App.Security.IPermission import IPermission
from Interface.verify import verify
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
-class Test(unittest.TestCase):
-
- def tearDown(self):
- permissionRegistry._clear()
-
- setUp = tearDown
+class Test(CleanUp, unittest.TestCase):
def testEmptyPermissions(self):
self.assertEqual(None, permissionRegistry.getPermission('Foo'))
=== Zope3/lib/python/Zope/App/Security/tests/testPrincipalPermissionManager.py 1.1.2.11 => 1.1.2.12 ===
import principalPermissionManager as manager
from Zope.App.Security.Settings import Allow, Deny, Unset
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
-class Test(unittest.TestCase):
-
- def tearDown(self):
- permregistry._clear()
- prinregistry._clear()
- manager._clear()
+class Test(CleanUp, unittest.TestCase):
def _make_principal(self, id=None, title=None):
p = prinregistry.definePrincipal(
=== Zope3/lib/python/Zope/App/Security/tests/testPrincipalPermissionView.py 1.1.2.3 => 1.1.2.4 ===
import unittest
-from Zope.ComponentArchitecture import defineService, provideService, _clear
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
+from Zope.ComponentArchitecture import defineService, provideService
from Zope.ComponentArchitecture import provideAdapter
from Zope.App.Security.IAttributePrincipalPermissionManageable \
import IAttributePrincipalPermissionManageable
@@ -126,12 +127,9 @@
return self._title
-class Test(unittest.TestCase):
+class Test(CleanUp, unittest.TestCase):
def setUp(self):
-
- _clear()
-
self._permissions = []
self._permissions.append(DummyObject('qux', 'Qux'))
self._permissions.append(DummyObject('baz', 'Baz'))
@@ -150,9 +148,6 @@
DummyAuthenticationService(principals = self._principals))
provideAdapter(IAttributePrincipalPermissionManageable,
IPrincipalPermissionManager, DummyAdapter)
-
- def tearDown(self):
- _clear()
def _makeOne(self):
from Zope.App.Security.PrincipalPermissionView \
=== Zope3/lib/python/Zope/App/Security/tests/testPrincipalRegistry.py 1.1.2.5 => 1.1.2.6 ===
from Zope.App.Security.PrincipalRegistry import DuplicateLogin, DuplicateId
from Zope.Exceptions import NotFoundError
-from Zope.ComponentArchitecture import _clear as clearCA
from Zope.Publisher.HTTP.IHTTPCredentials import IHTTPCredentials
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
class Request:
@@ -32,10 +32,10 @@
self.challenge = challenge
-class Test(unittest.TestCase):
+class Test(CleanUp, unittest.TestCase):
def setUp(self):
- clearCA()
+ CleanUp.setUp(self)
from Zope.ComponentArchitecture import provideAdapter
from Zope.App.Security.BasicAuthAdapter import BasicAuthAdapter
@@ -48,9 +48,6 @@
'tim', '123')
self.reg.definePrincipal('2', 'Jim Fulton', 'Sir Jim Fulton',
'jim', '456')
-
- def tearDown(self):
- clearCA()
def testRegistered(self):
p = self.reg.getPrincipal('1')
=== Zope3/lib/python/Zope/App/Security/tests/testPrincipalRoleManager.py 1.1.2.11 => 1.1.2.12 ===
from Zope.App.Security.PrincipalRoleManager import principalRoleManager
from Zope.App.Security.Settings import Assign, Remove
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
-class Test(unittest.TestCase):
-
- def tearDown(self):
- rregistry._clear()
- pregistry._clear()
- principalRoleManager._clear()
-
- setUp=tearDown
+class Test(CleanUp, unittest.TestCase):
def _make_principal(self, id=None, title=None):
p = pregistry.definePrincipal(
=== Zope3/lib/python/Zope/App/Security/tests/testPrincipalRoleView.py 1.1.2.4 => 1.1.2.5 ===
import unittest
-from Zope.ComponentArchitecture import defineService, provideService, _clear
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
+from Zope.ComponentArchitecture import defineService, provideService
from Zope.App.Security.IRoleService import IRoleService
from Zope.App.Security.IAuthenticationService import IAuthenticationService
@@ -63,12 +64,9 @@
def getPrincipals( self ):
return self._principals
-class Test( unittest.TestCase ):
+class Test(CleanUp, unittest.TestCase ):
def setUp(self):
-
- _clear()
-
self._roles = []
self._roles.append( DummyObject( 'qux', 'Qux' ) )
self._roles.append( DummyObject( 'baz', 'Baz' ) )
@@ -85,9 +83,6 @@
provideService( 'AuthenticationService',
DummyAuthenticationService( principals = self._principals ) )
-
- def tearDown(self):
- _clear()
def _makeOne( self ):
from Zope.App.Security.PrincipalRoleView import PrincipalRoleView
=== Zope3/lib/python/Zope/App/Security/tests/testProtectClass.py 1.1.2.5 => 1.1.2.6 ===
from Zope.Configuration.xmlconfig import xmlconfig, ZopeXMLConfigurationError
from testmodulehookup import *
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
-xmlconfig(StringIO("""
-<zopeConfigure xmlns='http://namespaces.zope.org/zope'>
- <directive namespace="http://namespaces.zope.org/security"
- name="protectClass"
- attributes="name, permission, interface, method, methods"
- handler="Zope.App.Security.protectClass.">
- <subdirective namespace="http://namespaces.zope.org/security"
- name="protect"
- attributes="permission, interface, method, methods" />
- <subdirective namespace="http://namespaces.zope.org/security"
- name="instances"
- attributes="permission" />
- </directive>
-</zopeConfigure>
-"""))
+def defineDirectives():
+ xmlconfig(StringIO("""
+ <zopeConfigure xmlns='http://namespaces.zope.org/zope'>
+ <directive namespace="http://namespaces.zope.org/security"
+ name="protectClass"
+ attributes="name, permission, interface, method, methods"
+ handler="Zope.App.Security.protectClass.">
+ <subdirective namespace="http://namespaces.zope.org/security"
+ name="protect"
+ attributes="permission, interface, method, methods" />
+ <subdirective namespace="http://namespaces.zope.org/security"
+ name="instances"
+ attributes="permission" />
+ </directive>
+ </zopeConfigure>"""))
NOTSET = []
P1 = "extravagant"
P2 = "paltry"
-class Test(unittest.TestCase):
+class Test(CleanUp, unittest.TestCase):
def setUp(self):
+ defineDirectives()
class C:
__implements__ = I
def m1(self):
@@ -53,6 +55,7 @@
self.assertState()
def tearDown(self):
+ CleanUp.tearDown(self)
testmodule.test_class = None
def assertState(self, instP=NOTSET,
=== Zope3/lib/python/Zope/App/Security/tests/testPublicClass.py 1.1.2.6 => 1.1.2.7 ===
from Zope.App.Security import publicClass
-from Zope.Configuration.meta import _clear as metaclear
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
# So we can use config parser to exercise publicClass stuff.
from cStringIO import StringIO
@@ -26,7 +26,7 @@
PublicPermission = publicClass.PublicPermission
-class Test(unittest.TestCase):
+class Test(CleanUp, unittest.TestCase):
def setUp(self):
xmlconfig(StringIO("""
@@ -50,7 +50,7 @@
self.assertState()
def tearDown(self):
- metaclear()
+ CleanUp.tearDown(self)
testmodule.test_class = None
def assertState(self, instP=NOTSET,
=== Zope3/lib/python/Zope/App/Security/tests/testRolePermissionManager.py 1.1.2.8 => 1.1.2.9 ===
from Zope.App.Security.Settings \
import Allow, Deny, Unset
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
-class Test(unittest.TestCase):
-
- def tearDown(self):
- pregistry._clear()
- rregistry._clear()
- manager._clear()
+class Test(CleanUp, unittest.TestCase):
def testUnboundRolePermission(self):
permission = pregistry.definePermission('APerm', 'aPerm title').getId()
=== Zope3/lib/python/Zope/App/Security/tests/testRolePermissionView.py 1.1.2.3 => 1.1.2.4 ===
import unittest, sys
-from Zope.ComponentArchitecture import defineService, provideService, _clear
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
+from Zope.ComponentArchitecture import defineService, provideService
from Zope.App.Security.IRoleService import IRoleService
from RoleService import RoleService
from PermissionService import PermissionService
@@ -20,10 +21,9 @@
from Zope.App.Security.RolePermissionView import RolePermissionView
from Zope.App.Security.IPermissionService import IPermissionService
-class Test(unittest.TestCase):
+class Test(CleanUp, unittest.TestCase):
def setUp(self):
- _clear()
defineService('RoleService', IRoleService)
provideService('RoleService', RoleService(
manager='Manager', member='Member'))
@@ -31,9 +31,6 @@
provideService('PermissionService', PermissionService(
read='Read', write='Write'))
self.view = RolePermissionView(RolePermissionManager())
-
- def tearDown(self):
- _clear()
def testRoles(self):
roles = list(self.view.roles())
=== Zope3/lib/python/Zope/App/Security/tests/testRoleRegistry.py 1.1.2.5 => 1.1.2.6 ===
from Zope.App.Security.IRole import IRole
from Interface.verify import verify
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
-class Test(unittest.TestCase):
-
- def tearDown(self):
- roleRegistry._clear()
+class Test(CleanUp, unittest.TestCase):
def testEmptyRoles(self):
self.assertEqual(None, roleRegistry.getRole('Foo'))
=== Zope3/lib/python/Zope/App/Security/tests/testSecurityDirectives.py 1.1.2.11 => 1.1.2.12 ===
from Zope.Configuration.xmlconfig import xmlconfig
from StringIO import StringIO
-from Zope.Configuration.meta import _clear as metaclear
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
from Zope.Configuration.xmlconfig import ZopeXMLConfigurationError
from Zope.App.Security.PrincipalRegistry import principalRegistry
from Zope.App.Security.PermissionRegistry \
@@ -100,15 +100,10 @@
"""))
-class TestPrincipalDirective(unittest.TestCase):
+class TestPrincipalDirective(CleanUp, unittest.TestCase):
def setUp(self):
- principalRegistry._clear()
metaConfigure()
- def tearDown(self):
- principalRegistry._clear()
- metaclear()
-
def testRegister(self):
f = configfile("""<security:principal principal_id="1"
title="Sir Tim Peters"
@@ -134,15 +129,10 @@
self.assertEqual(len(reg.getPrincipals('')), 2)
-class TestPermissionDirective(unittest.TestCase):
+class TestPermissionDirective(CleanUp, unittest.TestCase):
def setUp(self):
- pregistry._clear()
metaConfigure()
- def tearDown(self):
- pregistry._clear()
- metaclear()
-
def testRegister(self):
f = configfile("""
<security:definePermission
@@ -174,15 +164,10 @@
#self.assertRaises(AlreadyRegisteredError, xmlconfig, f)
self.assertRaises(ZopeXMLConfigurationError, xmlconfig, f)
-class TestRoleDirective(unittest.TestCase):
+class TestRoleDirective(CleanUp, unittest.TestCase):
def setUp(self):
- rregistry._clear()
metaConfigure()
- def tearDown(self):
- rregistry._clear()
- metaclear()
-
def testRegister(self):
f = configfile("""
<security:defineRole
@@ -215,15 +200,11 @@
#self.assertRaises(AlreadyRegisteredError, xmlconfig, f)
self.assertRaises(ZopeXMLConfigurationError, xmlconfig, f)
-class TestRolePermission( unittest.TestCase ):
+class TestRolePermission(CleanUp, unittest.TestCase):
def setUp( self ):
metaConfigure()
- def tearDown( self ):
- metaclear()
- role_perm_mgr._clear()
-
def testMap( self ):
f = configfile("""
<security:grantPermissionToRole
@@ -242,15 +223,11 @@
self.assertEqual(len( perms ), 1)
self.failUnless(("Foo",Allow) in perms)
-class TestPrincipalPermission( unittest.TestCase ):
+class TestPrincipalPermission(CleanUp, unittest.TestCase):
def setUp( self ):
metaConfigure()
- def tearDown( self ):
- metaclear()
- principal_perm_mgr._clear()
-
def testMap( self ):
f = configfile("""
<security:grantPermissionToPrincipal
@@ -269,14 +246,10 @@
self.assertEqual(len( perms ), 1)
self.failUnless(("Foo", Allow) in perms)
-class TestPrincipalRole( unittest.TestCase ):
+class TestPrincipalRole(CleanUp, unittest.TestCase):
def setUp( self ):
metaConfigure()
-
- def tearDown( self ):
- metaclear()
- principal_role_mgr._clear()
def testMap( self ):
f = configfile("""
=== Zope3/lib/python/Zope/App/Security/tests/testSecurityManagement.py 1.1.2.7 => 1.1.2.8 ===
self.failUnless( mgr.checkPermission( None, None ) )
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())
=== Zope3/lib/python/Zope/App/Security/tests/testSecurityManager.py 1.1.2.5 => 1.1.2.6 ===
mgr.popExecutable( exe1 ) # back to default policy
self.failIf( mgr.checkPermission( None, None ) )
+
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())
=== Zope3/lib/python/Zope/App/Security/tests/testZSP.py 1.1.2.9 => 1.1.2.10 ===
from Zope.App.Security.IPrincipalRoleManager import IPrincipalRoleManager
from Zope.Exceptions import Unauthorized, Forbidden
-
-def _clear():
- permissionRegistry._clear()
- principalRegistry._clear()
- roleRegistry._clear()
- principalPermissionManager._clear()
- rolePermissionManager._clear()
- principalRoleManager._clear()
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
class Context:
def __init__(self, user, stack=[]):
@@ -65,13 +58,9 @@
self.__permission__ = permission
-class Test( unittest.TestCase ):
-
- def tearDown(self):
- _clear()
+class Test(CleanUp, unittest.TestCase):
def setUp(self):
- _clear()
jim = principalRegistry.definePrincipal('jim', 'Jim', 'Jim Fulton',
'jim', '123')
self.jim = jim.getId()