[Zope3-checkins] CVS: Zope3/src/zope/app/component/tests - test_wrapper_hooks.py:1.1.2.4
Steve Alexander
steve@cat-box.net
Fri, 16 May 2003 09:02:07 -0400
Update of /cvs-repository/Zope3/src/zope/app/component/tests
In directory cvs.zope.org:/tmp/cvs-serv4848/src/zope/app/component/tests
Modified Files:
Tag: stevea-decorators-branch
test_wrapper_hooks.py
Log Message:
Added BasicTypes_examples to checkers, to help with tests that need to
check that BasicTypes are handled a particular way.
Added test of ContextWrapper_hook.
=== Zope3/src/zope/app/component/tests/test_wrapper_hooks.py 1.1.2.3 => 1.1.2.4 ===
--- Zope3/src/zope/app/component/tests/test_wrapper_hooks.py:1.1.2.3 Wed May 14 10:14:16 2003
+++ Zope3/src/zope/app/component/tests/test_wrapper_hooks.py Fri May 16 09:01:37 2003
@@ -22,7 +22,7 @@
from zope.interface import Interface, implements, InterfaceSpecification
from zope.interface import directlyProvides
from zope.security.proxy import Proxy, getObject, getChecker
-from zope.proxy.context.wrapper import getobject, getcontext, getdict
+from zope.proxy.context.wrapper import getobject, getcontext, getdict, Wrapper
from zope.proxy.context.decorator import Decorator
from zope.proxy.context.decorator import getmixinfactory, getnames
from zope.proxy.context.decorator import getmixincreate
@@ -30,6 +30,10 @@
from zope.exceptions import ForbiddenAttribute
from zope.security.checker import DecoratedChecker
from zope.security.tests.test_checker import TestMixinDecoratedChecker
+from zope.app.component.decoratorservice import registerDecorator
+from zope.app.component.decoratorservice import registerDecoratorForClass
+
+from zope.testing.cleanup import CleanUp
__metaclass__ = type
@@ -108,7 +112,8 @@
self.assert_(type(unproxied_d) is Decorator)
self.assert_(getmixincreate(unproxied_d).inner is ob)
- # when the mixin is untrusted but ob has no proxy, it is left unproxied
+ # when the mixin is untrusted but ob has no proxy, it is left
+ # unproxied
spec.mixinIsTrusted = False
d = decorate(spec, ob, parent, kw)
self.assert_(getmixincreate(d).inner is ob)
@@ -197,10 +202,54 @@
self.assert_(IBar.isImplementedBy(d))
self.assert_(IBaz.isImplementedBy(d))
+class TestContextWrapperHook(CleanUp, unittest.TestCase):
+ def setUp(self):
+ CleanUp.setUp(self)
+
+ def test_BasicTypes(self):
+ from zope.app.component.hooks import ContextWrapper_hook
+
+ # Test that basic types don't get wrapped
+ from zope.security.checker import BasicTypes_examples
+ for tp, obj in BasicTypes_examples.items():
+ self.assert_(ContextWrapper_hook(obj, None) is obj)
+
+ def test_decoration(self):
+ from zope.app.component.hooks import ContextWrapper_hook
+ class Foo:
+ pass
+ spec = DecoratorSpecStub(True, Mixin, None, (), {}, {})
+ registerDecorator('some.decorator.id', spec)
+ registerDecoratorForClass(Foo, 'some.decorator.id', 'context')
+ self.assert_(type(ContextWrapper_hook(Foo(), None)) is Decorator)
+
+ def test_regularObject(self):
+ from zope.app.component.hooks import ContextWrapper_hook
+ class Foo:
+ pass
+ obj = Foo()
+ w = ContextWrapper_hook(obj, None)
+ self.assert_(type(w) is Wrapper)
+
+ def test_proxiedObject(self):
+ from zope.app.component.hooks import ContextWrapper_hook
+ class Foo:
+ pass
+ obj = Foo()
+ proxied_obj = ProxyFactory(obj)
+ self.assert_(type(proxied_obj) is Proxy)
+ w = ContextWrapper_hook(proxied_obj, None)
+ self.assert_(type(w) is Proxy)
+ self.assert_(getChecker(w) is getChecker(proxied_obj))
+ self.assert_(type(getObject(w)) is Wrapper)
+ # Confusingly, getobject is to unwrap Wrappers and getObject is to
+ # unwrap Proxies.
+ self.assert_(getobject(getObject(w)) is obj)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestDecorate))
+ suite.addTest(unittest.makeSuite(TestContextWrapperHook))
return suite