[Zope-Checkins] CVS: Zope/lib/python/AccessControl/tests - testZopeGuards.py:1.1.4.3

Jim Fulton jim at zope.com
Fri Jan 16 16:04:57 EST 2004


Update of /cvs-repository/Zope/lib/python/AccessControl/tests
In directory cvs.zope.org:/tmp/cvs-serv16946/lib/python/AccessControl/tests

Modified Files:
      Tag: Zope-2_7-branch
	testZopeGuards.py 
Log Message:
Changed guarded_getattr to use the new strategy.


=== Zope/lib/python/AccessControl/tests/testZopeGuards.py 1.1.4.2 => 1.1.4.3 ===
--- Zope/lib/python/AccessControl/tests/testZopeGuards.py:1.1.4.2	Mon Jan 12 18:56:02 2004
+++ Zope/lib/python/AccessControl/tests/testZopeGuards.py	Fri Jan 16 16:04:54 2004
@@ -78,9 +78,11 @@
         self.args = args
 
 
-class TestGuardedGetattr(GuardTestCase):
+class TestGuardedGetattrPy(GuardTestCase):
 
     def setUp(self):
+        import AccessControl.ImplPython
+        self.guarded_getattr = AccessControl.ImplPython.guarded_getattr
         self.__sm = SecurityManager()
         self.__old = self.setSecurityManager(self.__sm)
 
@@ -88,7 +90,7 @@
         self.setSecurityManager(self.__old)
 
     def test_calls_validate_for_unknown_type(self):
-        guarded_getattr(self, 'test_calls_validate_for_unknown_type')
+        self.guarded_getattr(self, 'test_calls_validate_for_unknown_type')
         self.assert_(self.__sm.calls)
 
     def test_attr_handler_table(self):
@@ -96,20 +98,27 @@
         _dict = type(d)
         old = ContainerAssertions.get(_dict)
 
-        mytable = {'keys': 1,
-                   'values': Method,
-                   }
-        ContainerAssertions[_dict] = mytable
+        def myfactory(name, value):
+            if name == 'values':
+                return Method
+            return 1
+
+        ContainerAssertions[_dict] = myfactory
         try:
-            guarded_getattr(d, 'keys')
+            self.guarded_getattr(d, 'keys')
             self.assertEqual(len(self.__sm.calls), 0)
-            values = guarded_getattr(d, 'values')
+            values = self.guarded_getattr(d, 'values')
             self.assertEqual(values.__class__, Method)
             self.assertEqual(values.args, (d, 'values'))
-            self.assertRaises(Unauthorized, guarded_getattr, d, 'items')
         finally:
             ContainerAssertions[_dict] = old
 
+class TestGuardedGetattrC(TestGuardedGetattrPy):
+
+    def setUp(self):
+        TestGuardedGetattrPy.setUp(self)
+        import AccessControl.ImplC
+        self.guarded_getattr = AccessControl.ImplC.guarded_getattr
 
 class TestDictGuards(GuardTestCase):
 
@@ -433,7 +442,8 @@
 
 def test_suite():
     suite = unittest.TestSuite()
-    for cls in (TestGuardedGetattr,
+    for cls in (TestGuardedGetattrPy,
+                TestGuardedGetattrC,
                 TestDictGuards,
                 TestBuiltinFunctionGuards,
                 TestListGuards,




More information about the Zope-Checkins mailing list