[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/tests - test_vocabularywidget.py:1.1.2.5

Fred L. Drake, Jr. fred@zope.com
Mon, 5 May 2003 15:14:10 -0400


Update of /cvs-repository/Zope3/src/zope/app/browser/form/tests
In directory cvs.zope.org:/tmp/cvs-serv13069

Modified Files:
      Tag: schema-vocabulary-branch
	test_vocabularywidget.py 
Log Message:
- reflect refactoring of "get the value" and "render the value"
- add tests for proper haveData() behavior and use


=== Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py 1.1.2.4 => 1.1.2.5 ===
--- Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py:1.1.2.4	Mon May  5 13:56:55 2003
+++ Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py	Mon May  5 15:14:09 2003
@@ -76,7 +76,7 @@
 class SampleDisplayWidget(widget.VocabularyWidgetBase):
     __implements__ = IBrowserWidget
 
-    def render(self):
+    def render(self, value):
         return "foo"
 
 
@@ -159,10 +159,20 @@
         w = getView(bound, "display", TestRequest())
         self.assertEqual(w(), "foobar")
 
+    def test_simple_display_with_form_value(self):
+        field, bound = self.makeFields(vocabulary.VocabularyField,
+                                       BasicVocabulary(["splat", "foobar"]))
+        request = TestRequest(QUERY_STRING='field.myfield=foobar')
+        request.processInputs()
+        w = getView(bound, "display", request)
+        self.assert_(w.haveData())
+        self.assertEqual(w(), "foobar")
+
     def test_simple_edit(self):
         vocab = BasicVocabulary(["splat", "foobar"])
         field, bound = self.makeFields(vocabulary.VocabularyField, vocab)
         w = getView(bound, "edit", TestRequest())
+        self.assert_(not w.haveData())
         self._verifyResult(w(), [
             'selected="selected"',
             'id="field.myfield"',
@@ -172,6 +182,7 @@
         field, bound = self.makeFields(vocabulary.VocabularyField, vocab,
                                        "foobar")
         w = getView(bound, "edit", TestRequest())
+        self.assert_(not w.haveData())
         self._verifyResult(w(), [
             'selected="selected"',
             'id="field.myfield"',
@@ -192,6 +203,15 @@
             '>foobar<',
             ])
         self.assert_(s2.find('selected') < 0)
+
+    def test_simple_edit_with_form_value(self):
+        field, bound = self.makeFields(vocabulary.VocabularyField,
+                                       BasicVocabulary(["splat", "foobar"]))
+        request = TestRequest(QUERY_STRING='field.myfield=foobar')
+        request.processInputs()
+        w = getView(bound, "edit", request)
+        self.assert_(w.haveData())
+        self.assertEqual(w._showData(), "foobar")
 
 
 def test_suite():