[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/tests - test_vocabularywidget.py:1.1.2.6
Fred L. Drake, Jr.
fred@zope.com
Mon, 5 May 2003 16:12:26 -0400
Update of /cvs-repository/Zope3/src/zope/app/browser/form/tests
In directory cvs.zope.org:/tmp/cvs-serv21596
Modified Files:
Tag: schema-vocabulary-branch
test_vocabularywidget.py
Log Message:
add tests for the multi-selection vocabulary widget
=== Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py 1.1.2.5 => 1.1.2.6 ===
--- Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py:1.1.2.5 Mon May 5 15:14:09 2003
+++ Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py Mon May 5 16:12:25 2003
@@ -124,6 +124,10 @@
"field-edit-widget",
IBrowserPresentation,
widget.VocabularyEditWidget)
+ provideView(vocabulary.IVocabulary,
+ "field-edit-multi-widget",
+ IBrowserPresentation,
+ widget.VocabularyMultiEditWidget)
# The following widget registrations support the specific
# sample vocabulary we're using:
provideView(ISampleVocabulary,
@@ -187,9 +191,10 @@
'selected="selected"',
'id="field.myfield"',
'name="field.myfield"',
- 'value="splat"',
'class="vocabularyType"',
+ 'value="splat"',
'>splat<',
+ 'value="foobar"',
'>foobar<',
])
s1, s2 = w.renderItems("splat")
@@ -212,6 +217,52 @@
w = getView(bound, "edit", request)
self.assert_(w.haveData())
self.assertEqual(w._showData(), "foobar")
+
+ def test_multi_edit(self):
+ field, bound = self.makeFields(vocabulary.VocabularyMultiField,
+ BasicVocabulary(["splat", "foobar",
+ "frob"]))
+ w = getView(bound, "edit", TestRequest())
+ self.assert_(not w.haveData())
+ self._verifyResult(w(), [
+ 'id="field.myfield"',
+ 'name="field.myfield:list"',
+ 'class="vocabularyType"',
+ 'value="splat"',
+ '>splat<',
+ 'value="foobar"',
+ '>foobar<',
+ 'value="frob"',
+ '>frob<',
+ ])
+ s1, s2, s3 = w.renderItems(w._missing)
+ self._verifyResult(s1, [
+ 'value="splat"',
+ '>splat<',
+ ])
+ self.assert_(s1.find('selected') < 0)
+ self._verifyResult(s2, [
+ 'value="foobar"',
+ '>foobar<',
+ ])
+ self.assert_(s2.find('selected') < 0)
+ self._verifyResult(s3, [
+ 'value="frob"',
+ '>frob<',
+ ])
+ self.assert_(s3.find('selected') < 0)
+
+ def test_multi_edit_with_form_value(self):
+ field, bound = self.makeFields(vocabulary.VocabularyMultiField,
+ BasicVocabulary(["splat", "foobar"]))
+ request = TestRequest(
+ QUERY_STRING='field.myfield:list=foobar&field.myfield:list=splat')
+ request.processInputs()
+ w = getView(bound, "edit", request)
+ self.assert_(w.haveData())
+ L = w._showData()
+ L.sort()
+ self.assertEqual(L, ["foobar", "splat"])
def test_suite():