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

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


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

Modified Files:
      Tag: SecurityProxy-branch
	test_Proxy.py 
Log Message:
Add and test check_setattr().

=== Zope3/lib/python/Zope/Security/tests/test_Proxy.py 1.1.2.4 => 1.1.2.5 ===
 
 class Checker:
+
     def check_getattr(self, object, name):
-        ##print "check_getattr", (object, name)
         if name != "foo":
             raise RuntimeError
         return "hello"
+
+    def check_setattr(self, object, name):
+        if name != "foo":
+            raise RuntimeError
+
     def proxy(self, value, checked):
-        ##print "proxy", (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]
 
@@ -40,6 +46,14 @@
 
     def testGetAttrFail(self):
         self.assertRaises(RuntimeError, lambda: self.p.bar)
+
+    def testSetAttrOK(self):
+        self.p.foo = 42
+        self.assertEqual(self.p.foo, [42, "hello"])
+
+    def testSetAttrFail(self):
+        def doit(): self.p.bar = 42
+        self.assertRaises(RuntimeError, doit)
 
     def testGetObject(self):
         self.assertEqual(self.x, getObject(self.p))