[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/tests -
test_editview.py:1.17
Dominik Huber
dominik.huber at projekt01.ch
Wed Feb 25 08:22:10 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/browser/form/tests
In directory cvs.zope.org:/tmp/cvs-serv13943
Modified Files:
test_editview.py
Log Message:
BUG FIX: The form framework supports now security-proxied adapters
(adapter invoked via __conform__). '_setUpWidget' method of EditView,
EditWizardView and DisplayView provides a LocationProxy
for all adapters which do not implement ILocation itself.
Involved files:
zope\app\browser\form\editview.py
zope\app\browser\form\editwizard.py
zope\app\browser\form\schemadisplay.py
zope\app\browser\form\tests\test_editview.py:
- add test_update_via_adapter
- add test_setUpWidget_via_conform_adapter
=== Zope3/src/zope/app/browser/form/tests/test_editview.py 1.16 => 1.17 ===
--- Zope3/src/zope/app/browser/form/tests/test_editview.py:1.16 Fri Jan 30 17:20:52 2004
+++ Zope3/src/zope/app/browser/form/tests/test_editview.py Wed Feb 25 08:22:09 2004
@@ -60,21 +60,41 @@
class Foo:
implements(IFoo)
- foo = 'Foo foo'
+ foo = u'Foo foo'
+
+class ConformFoo(object):
+ implements(IFoo)
+
+ foo = u'Foo foo'
+
+ def __conform__(self, interface):
+ # fake proxied adapter (attention only read proxy)
+ from zope.security.checker import InterfaceChecker
+ from zope.security.checker import ProxyFactory
+
+ if interface is IBar:
+ checker = InterfaceChecker(IBar)
+ return ProxyFactory(OtherFooBarAdapter(self), checker)
+
class FooBarAdapter(object):
+ implements(IBar)
+ __used_for__ = IFoo
def __init__(self, context):
self.context = context
- def setbar(self, v):
- self.context.foo = v
+ def getbar(self): return self.context.foo
+ def setbar(self, v): self.context.foo = v
- bar = property(lambda self: self.context.foo,
- setbar)
+ bar = property(getbar, setbar)
+
+class OtherFooBarAdapter(FooBarAdapter):
+ pass
class BarV(EditView):
schema = IBar
+ object_factories = []
class Test(PlacelessSetup, unittest.TestCase):
@@ -148,9 +168,29 @@
self.assertEqual(c.b , u'c b')
self.assertEqual(c.getbaz(), u'c baz')
+ def test_update_via_adapter(self):
+ f = Foo()
+ request = TestRequest()
+ v = BarV(f, request)
+ # check adapter
+ self.assertEqual(f.foo, u'Foo foo')
+ a = ztapi.zapi.getAdapter(f, IBar)
+ self.assertEqual(a.bar, u'Foo foo')
+ # update
+ request.form[Update] = ''
+ request.form['field.bar'] = u'r bar'
+ message = v.update()
+ self.failUnless(message.startswith('Updated '), message)
+ self.assertEqual(a.bar, u'r bar')
+ # wrong update
+ self.failIf(getEvents())
-
-
+ def test_setUpWidget_via_conform_adapter(self):
+
+ f = ConformFoo()
+ request = TestRequest()
+ v = BarV(f, request)
+
def test_suite():
return unittest.makeSuite(Test)
More information about the Zope3-Checkins
mailing list