[Zope3-checkins] CVS: Zope3/src/zope/app/tests - test_context.py:1.4
Jim Fulton
jim@zope.com
Mon, 2 Jun 2003 15:41:15 -0400
Update of /cvs-repository/Zope3/src/zope/app/tests
In directory cvs.zope.org:/tmp/cvs-serv28399/src/zope/app/tests
Modified Files:
test_context.py
Log Message:
Updated ContextWrapper to choose a wrapper class by getting an adapter
for IZopeContextWrapper.
=== Zope3/src/zope/app/tests/test_context.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/tests/test_context.py:1.3 Mon Jun 2 13:43:02 2003
+++ Zope3/src/zope/app/tests/test_context.py Mon Jun 2 15:41:14 2003
@@ -156,8 +156,7 @@
def test_ContextWrapper_basic():
"""
- >>> from zope.security.checker import ProxyFactory, NamesChecker
- >>> checker = NamesChecker()
+ >>> from zope.security.checker import ProxyFactory
>>> from zope.context import ContainmentIterator
>>> from zope.app.context import ContextWrapper
>>> from zope.context import getWrapperData
@@ -192,6 +191,77 @@
1
>>> getWrapperData(w3)
{'name': 'x'}
+
+ """
+
+def test_ContextWrapper_w_adapter():
+ """
+ >>> from zope.interface import *
+ >>> from zope.app.tests.placelesssetup import setUp, tearDown
+ >>> from zope.security.checker import ProxyFactory, NamesChecker
+ >>> from zope.context import ContainmentIterator
+ >>> from zope.app.context import ContextWrapper
+ >>> from zope.context import getWrapperData
+ >>> from zope.component.adapter import provideAdapter
+ >>> from zope.app.interfaces.context import IZopeContextWrapper
+
+ >>> setUp()
+
+
+ >>> checker = NamesChecker(['x'])
+
+ >>> class I(Interface):
+ ... pass
+
+ >>> class D(Wrapper):
+ ... x=1
+
+ >>> class C:
+ ... implements(I)
+ ... def __init__(self, name): self.name = name
+ ... def __repr__(self): return self.name
+
+
+ >>> c1 = C('c1')
+
+ >>> c2 = C('c2')
+ >>> p2 = ProxyFactory(c2, checker)
+
+ No adapter, so we get the default Wrapper:
+
+ >>> w2 = ContextWrapper(p2, c1, name=2)
+ >>> int(type(w2) is type(p2))
+ 1
+ >>> getWrapperData(w2)
+ {'name': 2}
+
+ which means we don't have an x attr
+
+ >>> getattr(w2, 'x', None)
+
+ No add an adapter:
+
+ >>> provideAdapter(I, IZopeContextWrapper, D)
+
+ >>> c3 = C('c3')
+ >>> p3 = ProxyFactory(c3, checker)
+ >>> w3 = ContextWrapper(p3, w2, name=3)
+ >>> int(type(w3) is type(p3))
+ 1
+ >>> getWrapperData(w3)
+ {'name': 3}
+
+ Now we have an x, because we have D as our wrapper type:
+
+ >>> getattr(w3, 'x', None)
+ 1
+
+ But note that if we get another wrapper around w2, we'll use the
+ same type:
+
+ >>> w = ContextWrapper(w2, C(''))
+
+ >>> getattr(w, 'x', None)
"""