[Zope-Checkins] CVS: Zope3/lib/python/Zope/Security/tests - testRestrictedInterpreter.py:1.1.2.4 test_Proxy.py:1.1.2.9
Guido van Rossum
guido@python.org
Thu, 18 Apr 2002 15:45:17 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv26218/tests
Modified Files:
Tag: SecurityProxy-branch
testRestrictedInterpreter.py test_Proxy.py
Log Message:
The 'checked' argument to the checker.proxy() method is no more.
=== Zope3/lib/python/Zope/Security/tests/testRestrictedInterpreter.py 1.1.2.3 => 1.1.2.4 ===
def check_getattr(self, object, name):
pass
- def proxy(self, value, checked):
+ def proxy(self, value):
return Proxy(value, self)
def __getattr__(self, name):
if name.startswith("check_"):
=== Zope3/lib/python/Zope/Security/tests/test_Proxy.py 1.1.2.8 => 1.1.2.9 ===
class Checker:
- call_ok = 1
- getitem_ok = 1
- setitem_ok = 1
+ ok = 1
def check_getattr(self, object, name):
if name != "foo":
@@ -18,17 +16,17 @@
raise RuntimeError
def check_getitem(self, object):
- if not self.getitem_ok:
+ if not self.ok:
raise RuntimeError
return "hello"
def check_setitem(self, object):
- if not self.setitem_ok:
+ if not self.ok:
raise RuntimeError
return "hello"
def check_call(self, object):
- if not self.call_ok:
+ if not self.ok:
raise RuntimeError
return "hello"
@@ -38,10 +36,15 @@
def check_repr(self, object):
return "hello"
- def proxy(self, value, checked):
+ def check_richcompare(self, object):
+ if not self.ok:
+ raise RuntimeError
+ return "hello"
+
+ def proxy(self, value):
if isinstance(value, str):
return value
- return [value, checked]
+ return [value, "hello"]
class Something:
@@ -53,6 +56,8 @@
self.foo[key] = value
def __call__(self, arg):
return 42
+ def __eq__(self, other):
+ return self is other
class ProxyTests(unittest.TestCase):
@@ -85,7 +90,7 @@
self.assertEqual(self.p[0], [1, "hello"])
def testGetItemFail(self):
- self.c.getitem_ok = 0
+ self.c.ok = 0
def doit(): return self.p[10]
self.assertRaises(RuntimeError, doit)
@@ -94,7 +99,7 @@
self.assertEqual(self.p[0], [42, "hello"])
def testSetItemFail(self):
- self.c.setitem_ok = 0
+ self.c.ok = 0
def doit(): self.p[10] = 42
self.assertRaises(RuntimeError, doit)
@@ -102,8 +107,15 @@
self.assertEqual(self.p(None), [42, "hello"])
def testCallFail(self):
- self.c.call_ok = 0
+ self.c.ok = 0
self.assertRaises(RuntimeError, self.p, None)
+
+ def testRichCompareOK(self):
+ self.assertEqual(self.p == self.x, [1, "hello"])
+
+ def testRichCompareFail(self):
+ self.c.ok = 0
+ self.assertRaises(RuntimeError, lambda: self.p == self.x)
def testGetObject(self):
self.assertEqual(self.x, getObject(self.p))