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

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


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

Modified Files:
      Tag: SecurityProxy-branch
	test_Proxy.py 
Log Message:
Test for check_call.  Make check_str and check_repr explicit, get rid
of generic __getattr__.


=== Zope3/lib/python/Zope/Security/tests/test_Proxy.py 1.1.2.6 => 1.1.2.7 ===
 class Checker:
 
+    call_ok = 1
+
     def check_getattr(self, object, name):
         if name != "foo":
             raise RuntimeError
@@ -23,24 +25,32 @@
             raise RuntimeError
         return "hello"
 
+    def check_call(self, object):
+        if not self.call_ok:
+            raise RuntimeError
+        return "hello"
+
+    def check_str(self, object):
+        return "hello"
+
+    def check_repr(self, object):
+        return "hello"
+
     def proxy(self, value, checked):
         if isinstance(value, str):
             return value
         return [value, checked]
 
-    def __getattr__(self, name):
-        if name.startswith("check_"):
-            return lambda *args: None
-        else:
-            raise AttributeError, name
-
 
 class Something:
-    foo = [1,2,3]
+    def __init__(self):
+        self.foo = [1,2,3]
     def __getitem__(self, key):
         return self.foo[key]
     def __setitem__(self, key, value):
         self.foo[key] = value
+    def __call__(self, arg):
+        return 42
 
 class ProxyTests(unittest.TestCase):
 
@@ -83,6 +93,13 @@
     def testSetItemFail(self):
         def doit(): self.p[10] = 42
         self.assertRaises(RuntimeError, doit)
+
+    def testCallOK(self):
+        self.assertEqual(self.p(None), [42, "hello"])
+
+    def testCallFail(self):
+        self.c.call_ok = 0
+        self.assertRaises(RuntimeError, self.p, None)
 
     def testGetObject(self):
         self.assertEqual(self.x, getObject(self.p))