[Zope-Checkins] CVS: Zope3/lib/python/Zope/Security/tests - test_Proxy.py:1.1.2.6

Guido van Rossum guido@python.org
Thu, 18 Apr 2002 14:27:19 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv12232/tests

Modified Files:
      Tag: SecurityProxy-branch
	test_Proxy.py 
Log Message:
Add and test check_{get,set}item().

=== Zope3/lib/python/Zope/Security/tests/test_Proxy.py 1.1.2.5 => 1.1.2.6 ===
             raise RuntimeError
 
+    def check_getitem(self, object, key):
+        if not 0 <= key < 10:
+            raise RuntimeError
+        return "hello"
+
+    def check_setitem(self, object, key):
+        if not 0 <= key < 10:
+            raise RuntimeError
+        return "hello"
+
     def proxy(self, value, checked):
         if isinstance(value, str):
             return value
@@ -27,6 +37,10 @@
 
 class Something:
     foo = [1,2,3]
+    def __getitem__(self, key):
+        return self.foo[key]
+    def __setitem__(self, key, value):
+        self.foo[key] = value
 
 class ProxyTests(unittest.TestCase):
 
@@ -53,6 +67,21 @@
 
     def testSetAttrFail(self):
         def doit(): self.p.bar = 42
+        self.assertRaises(RuntimeError, doit)
+
+    def testGetItemOK(self):
+        self.assertEqual(self.p[0], [1, "hello"])
+
+    def testGetItemFail(self):
+        def doit(): return self.p[10]
+        self.assertRaises(RuntimeError, doit)
+
+    def testSetItemOK(self):
+        self.p[0] = 42
+        self.assertEqual(self.p[0], [42, "hello"])
+
+    def testSetItemFail(self):
+        def doit(): self.p[10] = 42
         self.assertRaises(RuntimeError, doit)
 
     def testGetObject(self):