[Zope3-checkins] CVS: Zope3/src/zope/app/form/tests - test_utility.py:1.5
R. David Murray
bitz@bitdance.com
Mon, 27 Jan 2003 22:40:12 -0500
Update of /cvs-repository/Zope3/src/zope/app/form/tests
In directory cvs.zope.org:/tmp/cvs-serv13589/zope/app/form/tests
Modified Files:
test_utility.py
Log Message:
setUpWidgets did not have any unit tests for the code path where the names
argument was passed. I added some. There was also what I believe is
a bug in that code path: if a name was specified that existed in the
Interface but was not a Field, it was silently ignored. I rewrote
setUpWidgets to use schema's getFieldNamesInOrder instead of doing the
introspection itself, and the altered code will now generate an error
in the above case. What happens is that setUpWidget tries to bind
the thing that isn't a field and an AttributeError is thrown. Perhaps
setUpWidgets should check names-specified Interface names to make sure
they are Fields and throw a KeyError if they are not. That seems a
little like lying, though, so I'm leaving it the way it is for now
(the resulting error message is clear enough, as it refers to the
'Method' object, which is obviously not a Field). I put a comment
in the test to explain why the AttributeError occurs.
=== Zope3/src/zope/app/form/tests/test_utility.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/form/tests/test_utility.py:1.4 Mon Jan 27 21:56:43 2003
+++ Zope3/src/zope/app/form/tests/test_utility.py Mon Jan 27 22:40:10 2003
@@ -41,6 +41,8 @@
title = Text(title=u"Title", required = False)
description = Text(title=u"Description",
default = u'No description', required = False)
+ def foo():
+ """Does foo things"""
class I2(Interface):
title = Text(title = u"Title", required = True)
@@ -178,6 +180,24 @@
setUpWidgets(view, I)
self.assertEqual(view.title(), u'title: ')
self.assertEqual(view.description(), u'description: ')
+
+ def test_setupWidgets_only_some_fields(self):
+ c = C()
+ request = TestRequest()
+ view = BrowserView(c, request)
+ setUpWidgets(view, I, names=['title'])
+ self.assertEqual(view.title(), u'title: ')
+ self.failIf(hasattr(view, 'description'))
+
+ def test_setupWidgets_bad_field_name(self):
+ c = C()
+ request = TestRequest()
+ view = BrowserView(c, request)
+ self.assertRaises(KeyError, setUpWidgets, view, I, names=['bar'])
+ #This AttributeError occurs when setUpWidget tries to call
+ #bind on the non-Field (Method) object. The point is that
+ #that *some* error should occur, not necessarily this specific one.
+ self.assertRaises(AttributeError, setUpWidgets, view, I, names=['foo'])
def test_setupWidgets_w_prefix(self):
c = C()