[Zope3-checkins] CVS: Zope3/src/zope/app/component/tests - test_wrapper_hooks.py:1.1.2.2
Steve Alexander
steve@cat-box.net
Wed, 14 May 2003 09:54:42 -0400
Update of /cvs-repository/Zope3/src/zope/app/component/tests
In directory cvs.zope.org:/tmp/cvs-serv32758/src/zope/app/component/tests
Modified Files:
Tag: stevea-decorators-branch
test_wrapper_hooks.py
Log Message:
Wrote tests for ProxyFactory (there were none), and made its semantics
clearer.
Implemented more decorator factory functionality.
=== Zope3/src/zope/app/component/tests/test_wrapper_hooks.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/app/component/tests/test_wrapper_hooks.py:1.1.2.1 Wed May 14 06:40:26 2003
+++ Zope3/src/zope/app/component/tests/test_wrapper_hooks.py Wed May 14 09:54:12 2003
@@ -28,6 +28,7 @@
from zope.security.checker import ProxyFactory, NamesChecker
from zope.exceptions import ForbiddenAttribute
from zope.security.checker import DecoratedChecker
+from zope.security.tests.test_checker import TestMixinDecoratedChecker
__metaclass__ = type
@@ -57,7 +58,15 @@
self.outer = outer
-class TestDecorate(unittest.TestCase):
+class TestDecorate(TestMixinDecoratedChecker, unittest.TestCase):
+
+ def setUp(self):
+ unittest.TestCase.setUp(self)
+ self.decoratedSetUp()
+
+ def tearDown(self):
+ self.decoratedTearDown()
+ unittest.TestCase.tearDown(self)
def test_decorate(self):
from zope.app.component.hooks import decorate
@@ -133,31 +142,22 @@
self.assert_(type(d) is not Proxy)
# checkers should be combined
- spec.permissionMap = {'x': 'perm2'}
- spec.setPermissionMap = {'x': 'perm3'}
+ class SomeOtherObject:
+ __Security_checker__ = self.originalChecker
+
+ spec.permissionMap = self.decorationGetMap
+ spec.setPermissionMap = self.decorationSetMap
+ proxied_ob = ProxyFactory(SomeOtherObject())
d = decorate(spec, proxied_ob, parent, kw)
self.assert_(type(d) is Proxy)
- c = getChecker(d)
- # XXX this horrible piece of code relies on the implementation too much
- self.assert_(type(c) is DecoratedChecker)
- self.assert_(c._original_checker is getChecker(proxied_ob))
- self.assert_(c._permission_func.__self__ is spec.permissionMap)
- self.assert_(c._setattr_permission_func.__self__
- is spec.setPermissionMap)
-
-## c.check_getattr(ob, 'foo')
-## self.assert_(self.policy.checkChecked(['perm1']))
-## self.assertRaises(ForbiddenAttribute, c.check_getattr, ob, 'bar')
-## self.assert_(self.policy.checkChecked([]))
-## c.check_getattr(ob, 'x')
-## self.assert_(self.policy.checkChecked(['perm2']))
-## self.assertRaises(ForbiddenAttribute, c.check_getattr, ob, 'y')
-## self.assert_(self.policy.checkChecked([]))
-## # XXX: test overlap
-
+ self.checkingTestImpl(self.originalChecker, getChecker(d))
- # XXX: test interface spec
+ # The idea is that if the decorator loses its security proxy, the
+ # correct checker can be put in a new proxy.
+ self.assert_(getObject(d).__Security_checker__ is getChecker(d))
+ def test_decorateInterfaceSpec(self):
+ pass
def test_suite():