[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/tests - test_add.py:1.6 test_editview.py:1.4
Tres Seaver
tseaver@zope.com
Sat, 1 Mar 2003 22:34:11 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/form/tests
In directory cvs.zope.org:/tmp/cvs-serv32503/src/zope/app/browser/form/tests
Modified Files:
test_add.py test_editview.py
Log Message:
Adapt context to the EditView's schema, if possible. Since the view
expects to be able to write to the fields defined by the schema, it
is sensible to check that such fields are actually supported. Note
that this change has an additional benefit: the views can be safely
used for objects which do not implement the schema directly, but
for which an adapter to the schema is available. In particular, I
envision using such an adapter to store the schema values in an
annotation, rather than directly in the object's own attributes, which
should make it safe to extend an arbitrary third-party content object
via a combination of an annotaion, and adapter, and an edit view.
XXX This is still problematic for at least the AddView derivative,
whose context is expected to implement IAdding, rather than the schema.
My current workaround is to use 'queryAdapter(context,self.schema)', and
then replace context with the adapter if found. This choice shouldn't
break any existing, working code; a configuration which manages to
bind an EditView to an inappropriate object will happily scribble on
its attributes, however.
=== Zope3/src/zope/app/browser/form/tests/test_add.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/browser/form/tests/test_add.py:1.5 Tue Feb 11 10:59:33 2003
+++ Zope3/src/zope/app/browser/form/tests/test_add.py Sat Mar 1 22:34:05 2003
@@ -46,6 +46,8 @@
class C:
+ __implements__ = ( I, )
+
def __init__(self, *args, **kw):
self.args = args
self.kw = kw
=== Zope3/src/zope/app/browser/form/tests/test_editview.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/browser/form/tests/test_editview.py:1.3 Fri Feb 21 09:53:34 2003
+++ Zope3/src/zope/app/browser/form/tests/test_editview.py Sat Mar 1 22:34:05 2003
@@ -38,12 +38,16 @@
schema = I
class C:
+ __implements__ = ( I, )
foo = u"c foo"
bar = u"c bar"
a = u"c a"
b = u"c b"
baz = u"c baz"
+class NonConforming( C ):
+ __implements__ = ()
+
class Test(PlacelessSetup, TestCase):
def setUp(self):
@@ -77,6 +81,24 @@
def test_apply_update(self):
c = C()
+ request = TestRequest()
+ v = EV(c, request)
+ d = {}
+ d['foo'] = u'd foo'
+ d['bar'] = u'd bar'
+ d['baz'] = u'd baz'
+ self.failIf(v.apply_update(d))
+ self.assertEqual(c.foo, u'd foo')
+ self.assertEqual(c.bar, u'd bar')
+ self.assertEqual(c.a , u'c a')
+ self.assertEqual(c.b , u'c b')
+ self.assertEqual(c.baz, u'd baz')
+ self.failUnless(getEvents(filter=lambda event: event.object == c))
+
+ def test_apply_update_w_non_conforming_context(self):
+ # XXX This feels bogus: why should we be used to edit a context
+ # which doesn't implement our schema?
+ c = NonConforming()
request = TestRequest()
v = EV(c, request)
d = {}