[Zope3-checkins] CVS: Zope3/src/zope/app/security/tests - test_permissionfield.py:1.9 test_principallogging.py:1.3 test_protectclass.py:1.6 test_protectsubclass.py:1.4 test_securitydirectives.py:1.14 test_settings.py:1.4

Stephan Richter srichter at cosmos.phy.tufts.edu
Mon Mar 8 07:06:34 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/security/tests
In directory cvs.zope.org:/tmp/cvs-serv13053/src/zope/app/security/tests

Modified Files:
	test_permissionfield.py test_principallogging.py 
	test_protectclass.py test_protectsubclass.py 
	test_securitydirectives.py test_settings.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/security/tests/test_permissionfield.py 1.8 => 1.9 ===
--- Zope3/src/zope/app/security/tests/test_permissionfield.py:1.8	Fri Mar  7 16:13:49 2003
+++ Zope3/src/zope/app/security/tests/test_permissionfield.py	Mon Mar  8 07:06:02 2004
@@ -15,35 +15,32 @@
 
 $Id$
 """
-
-from unittest import TestCase, TestSuite, main, makeSuite
-from zope.security.checker import CheckerPublic
-from zope.app.security.permission import PermissionField
+import unittest
 from zope.schema.interfaces import ValidationError
+from zope.security.checker import CheckerPublic
+from zope.app.tests import ztapi
+from zope.app.security.interfaces import IPermission
+from zope.app.security.permission import Permission, PermissionField
 from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.app.security.registries.permissionregistry import permissionRegistry
-from zope.app.interfaces.security import IPermissionService
-from zope.component.service \
-     import serviceManager, defineService
-from zope.app.services.servicenames import Permissions
 
-from zope.app.security.registries.permissionregistry import Permission
 
-class TestPermissionField(PlacelessSetup, TestCase):
+class TestPermissionField(PlacelessSetup, unittest.TestCase):
 
     def test_validate(self):
-        defineService(Permissions, IPermissionService)
-        serviceManager.provideService(Permissions, permissionRegistry)
         dummy = Permission('dummy', 'Dummy', 'Dummy permission')
         field = PermissionField()
         self.assertRaises(ValidationError, field.validate, dummy)
-        permissionRegistry.definePermission('read', 'Read', 'Read something')
-        field.validate(permissionRegistry.getPermission('read').getId())
+        ztapi.provideUtility(IPermission,
+                             Permission('read', 'Read', 'Read something'),
+                             'read')
+        field.validate('read')
         field.validate(CheckerPublic)
 
-def test_suite():
-    return TestSuite((makeSuite(TestPermissionField),))
 
+def test_suite():
+    return unittest.TestSuite((
+        unittest.makeSuite(TestPermissionField),
+        ))
 
 if __name__=='__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')


=== Zope3/src/zope/app/security/tests/test_principallogging.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/security/tests/test_principallogging.py:1.2	Tue Jul 22 11:20:15 2003
+++ Zope3/src/zope/app/security/tests/test_principallogging.py	Mon Mar  8 07:06:02 2004
@@ -15,13 +15,13 @@
 
 $Id$
 """
-
 import unittest
 from zope.interface.verify import verifyObject
 
 class PrincipalStub:
-    def getId(self):
-        return 42
+
+    id = 42
+
 
 class TestPrincipalLogging(unittest.TestCase):
 


=== Zope3/src/zope/app/security/tests/test_protectclass.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/security/tests/test_protectclass.py:1.5	Fri Aug 15 20:44:03 2003
+++ Zope3/src/zope/app/security/tests/test_protectclass.py	Mon Mar  8 07:06:02 2004
@@ -11,53 +11,59 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-""" Test handler for 'protectClass' directive """
+""" Test handler for 'protectClass' directive
 
+$Id$
+"""
 import unittest
+from zope.interface import implements
+from zope.security.checker import selectChecker
+from zope.app.tests import ztapi
+from zope.app.tests.placelesssetup import PlacelessSetup
 
-from zope.app.security.tests.modulehookup import *
-from zope.app.security.registries.permissionregistry import permissionRegistry
-from zope.testing.cleanup import CleanUp # Base class w registry cleanup
+from zope.app.security.permission import Permission
+from zope.app.security.interfaces import IPermission
 from zope.app.security.protectclass import protectName, protectLikeUnto
 from zope.app.security.protectclass import protectSetAttribute
-from zope.interface import implements
+from zope.app.security.tests.modulehookup import *
 
 NOTSET = []
 
 P1 = "extravagant"
 P2 = "paltry"
 
-class Test(CleanUp, unittest.TestCase):
+class Test(PlacelessSetup, unittest.TestCase):
 
     def setUp(self):
-        permissionRegistry.definePermission(P1, P1)
-        permissionRegistry.definePermission(P2, P2)
+        super(Test, self).setUp()
+
+        ztapi.provideUtility(IPermission, Permission(P1), P1)
+        ztapi.provideUtility(IPermission, Permission(P2), P2)
 
         class B:
             def m1(self):
                 return "m1"
             def m2(self):
                 return "m2"
+
         class C(B):
             implements(I)
             def m3(self):
                 return "m3"
             def m4(self):
                 return "m4"
+
         TestModule.test_base = B
         TestModule.test_class = C
         TestModule.test_instance = C()
         self.assertState()
 
     def tearDown(self):
-        CleanUp.tearDown(self)
+        super(Test, self).tearDown()
         TestModule.test_class = None
 
     def assertState(self, m1P=NOTSET, m2P=NOTSET, m3P=NOTSET):
         "Verify that class, instance, and methods have expected permissions."
-
-        from zope.security.checker import selectChecker
-
         checker = selectChecker(TestModule.test_instance)
         self.assertEqual(checker.permission_id('m1'), (m1P or None))
         self.assertEqual(checker.permission_id('m2'), (m2P or None))
@@ -65,9 +71,6 @@
 
     def assertSetattrState(self, m1P=NOTSET, m2P=NOTSET, m3P=NOTSET):
         "Verify that class, instance, and methods have expected permissions."
-
-        from zope.security.checker import selectChecker
-
         checker = selectChecker(TestModule.test_instance)
         self.assertEqual(checker.setattr_permission_id('m1'), (m1P or None))
         self.assertEqual(checker.setattr_permission_id('m2'), (m2P or None))
@@ -93,9 +96,6 @@
 
     def assertSetattrState(self, m1P=NOTSET, m2P=NOTSET, m3P=NOTSET):
         "Verify that class, instance, and methods have expected permissions."
-
-        from zope.security.checker import selectChecker
-
         checker = selectChecker(TestModule.test_instance)
         self.assertEqual(checker.setattr_permission_id('m1'), (m1P or None))
         self.assertEqual(checker.setattr_permission_id('m2'), (m2P or None))


=== Zope3/src/zope/app/security/tests/test_protectsubclass.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/security/tests/test_protectsubclass.py:1.3	Thu May  1 15:35:34 2003
+++ Zope3/src/zope/app/security/tests/test_protectsubclass.py	Mon Mar  8 07:06:02 2004
@@ -13,17 +13,18 @@
 ##############################################################################
 """Test proper protection of inherited methods
 
-Revision information:
 $Id$
 """
+import unittest
+from zope.security.checker import selectChecker
+from zope.app.tests import ztapi
+from zope.app.tests.placelesssetup import PlacelessSetup
 
-from unittest import TestCase, main, makeSuite
-from zope.testing.cleanup import CleanUp # Base class w registry cleanup
+from zope.app.security.interfaces import IPermission
+from zope.app.security.permission import Permission
 from zope.app.security.protectclass import protectName
-from zope.app.security.registries.permissionregistry import permissionRegistry
-from zope.security.checker import selectChecker
 
-class Test(CleanUp, TestCase):
+class Test(PlacelessSetup, unittest.TestCase):
 
     def testInherited(self):
 
@@ -36,8 +37,8 @@
         class S(B1, B2):
             pass
 
-        permissionRegistry.definePermission('B1', '')
-        permissionRegistry.definePermission('S', '')
+        ztapi.provideUtility(IPermission, Permission('B1', ''), 'B1')
+        ztapi.provideUtility(IPermission, Permission('S', ''), 'S')
         protectName(B1, 'g', 'B1')
         protectName(S, 'g', 'S')
         protectName(S, 'h', 'S')
@@ -52,7 +53,7 @@
 
 
 def test_suite():
-    return makeSuite(Test)
+    return unittest.makeSuite(Test)
 
 if __name__=='__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')


=== Zope3/src/zope/app/security/tests/test_securitydirectives.py 1.13 => 1.14 ===
--- Zope3/src/zope/app/security/tests/test_securitydirectives.py:1.13	Wed Jan 14 17:55:27 2004
+++ Zope3/src/zope/app/security/tests/test_securitydirectives.py	Mon Mar  8 07:06:02 2004
@@ -16,30 +16,25 @@
 $Id$
 """
 import unittest
-
-from zope.component.service import serviceManager as services
-from zope.app.services.servicenames import Permissions, Authentication
-from zope.app.interfaces.security import IPermissionService
-from zope.app.interfaces.security import IAuthenticationService
-
 from zope.configuration.config import ConfigurationConflictError
 from zope.configuration import xmlconfig
 
-from zope.testing.cleanup import CleanUp # Base class w registry cleanup
-
-import zope.app.security.tests
+from zope.app import zapi
+from zope.app.tests import ztapi
+from zope.app.tests.placelesssetup import PlacelessSetup
+
+from zope.app.services.servicenames import Authentication
+from zope.app.security.interfaces import IAuthenticationService, IPermission
+from zope.app.security.principalregistry import principalRegistry
 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
+import zope.app.security.tests
 
-class TestBase(CleanUp):
 
-    def setUp(self):
-        CleanUp.setUp(self)
+class TestBase(PlacelessSetup):
 
-        services.defineService(Permissions, IPermissionService)
-        services.provideService(Permissions, pregistry)
+    def setUp(self):
+        super(TestBase, self).setUp()
+        services = zapi.getServiceManager(None)
 
         services.defineService(Authentication, IAuthenticationService)
         services.provideService(Authentication, principalRegistry)
@@ -52,13 +47,13 @@
         reg=principalRegistry
 
         p = reg.getPrincipal('zope.p1')
-        self.assertEqual(p.getId(), 'zope.p1')
-        self.assertEqual(p.getTitle(), 'Sir Tim Peters')
-        self.assertEqual(p.getDescription(), 'Tim Peters')
+        self.assertEqual(p.id, 'zope.p1')
+        self.assertEqual(p.title, 'Sir Tim Peters')
+        self.assertEqual(p.description, 'Tim Peters')
         p = reg.getPrincipal('zope.p2')
-        self.assertEqual(p.getId(), 'zope.p2')
-        self.assertEqual(p.getTitle(), 'Sir Jim Fulton')
-        self.assertEqual(p.getDescription(), 'Jim Fulton')
+        self.assertEqual(p.id, 'zope.p2')
+        self.assertEqual(p.title, 'Sir Jim Fulton')
+        self.assertEqual(p.description, 'Jim Fulton')
 
         self.assertEqual(len(reg.getPrincipals('')), 2)
 
@@ -67,10 +62,10 @@
 
     def testRegister(self):
         context = xmlconfig.file("perm.zcml", zope.app.security.tests)
-        perm = pregistry.getPermission("Can.Do.It")
-        self.failUnless(perm.getId().endswith('Can.Do.It'))
-        self.assertEqual(perm.getTitle(), 'A Permissive Permission')
-        self.assertEqual(perm.getDescription(),
+        perm = zapi.getUtility(None, IPermission, "Can.Do.It")
+        self.failUnless(perm.id.endswith('Can.Do.It'))
+        self.assertEqual(perm.title, 'A Permissive Permission')
+        self.assertEqual(perm.description,
                          'This permission lets you do anything')
 
     def testDuplicationRegistration(self):


=== Zope3/src/zope/app/security/tests/test_settings.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/security/tests/test_settings.py:1.3	Thu May  1 15:35:34 2003
+++ Zope3/src/zope/app/security/tests/test_settings.py	Mon Mar  8 07:06:02 2004
@@ -11,6 +11,10 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
+"""Security Settings Tests
+
+$Id$
+"""
 import unittest
 
 from zope.app.security.settings import Allow




More information about the Zope3-Checkins mailing list