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

Fred L. Drake, Jr. fred@zope.com
Fri, 2 May 2003 18:06:24 -0400


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

Modified Files:
      Tag: schema-vocabulary-branch
	test_vocabularywidget.py 
Log Message:
- make the tests make more sense, now that the vocabulary widgets do
- test the simple display widget as well as specialized widgets for
  specialized vocabularies


=== Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py 1.1.2.2 => 1.1.2.3 ===
--- Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py:1.1.2.2	Fri May  2 12:47:54 2003
+++ Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py	Fri May  2 18:06:24 2003
@@ -35,8 +35,9 @@
     value = "splat"
     extra = 42
 
-class SampleVocabulary(object):
-    __implements__ = ISampleVocabulary
+
+class BasicVocabulary(object):
+    __implements__ = vocabulary.IVocabulary
 
     def __contains__(self, value):
         return value == "splat"
@@ -49,11 +50,21 @@
             return SampleTerm()
         raise LookupError("%r didn't 'splat'!" % value)
 
+class SampleVocabulary(BasicVocabulary):
+    __implements__ = ISampleVocabulary
+
+
 
-class SampleDisplayWidget(widget.BrowserWidget):
+class SampleDisplayWidget(widget.VocabularyWidgetBase):
     __implements__ = IBrowserWidget
 
-    cssClass = 'vocab-display-widget'
+    def render(self):
+        return "foo"
+
+
+class SampleContent:
+    def __init__(self):
+        self.field = "splat"
 
 
 class VocabularyWidgetTests(PlacelessSetup, unittest.TestCase):
@@ -82,22 +93,37 @@
                     widget.VocabularyMultiFieldEditWidget)
         # The following widget registrations support the specific
         # sample vocabulary we're using:
+        provideView(vocabulary.IVocabulary,
+                    "field-display-widget",
+                    IBrowserPresentation,
+                    widget.VocabularyDisplayWidget)
         provideView(ISampleVocabulary,
                     "field-display-widget",
                     IBrowserPresentation,
                     SampleDisplayWidget)
 
-    def makeFields(self, cls):
-        field = cls(vocabulary=SampleVocabulary())
-        return field, field.bind("Yowza!")
+    def makeFields(self, cls, vocabulary):
+        field = cls(vocabulary=vocabulary, __name__="field")
+        return field, field.bind(SampleContent())
 
     def test_field_indirection(self):
-        field, bound = self.makeFields(vocabulary.VocabularyField)
+        field, bound = self.makeFields(vocabulary.VocabularyField,
+                                       SampleVocabulary())
         w = getView(bound, "display", TestRequest())
+        self.assertEqual(w(), "foo")
 
     def test_multi_field_indirection(self):
-        field, bound = self.makeFields(vocabulary.VocabularyMultiField)
-        # XXX this can be finished once the previous test is working
+        field, bound = self.makeFields(vocabulary.VocabularyMultiField,
+                                       SampleVocabulary())
+        # XXX this can be finished once the previous test is working,
+        # and we figure out the right way to handle multi-selects from
+        # the widgets
+
+    def test_simple_display(self):
+        field, bound = self.makeFields(vocabulary.VocabularyField,
+                                       BasicVocabulary())
+        w = getView(bound, "display", TestRequest())
+        self.assertEqual(w(), "splat")
 
 
 def test_suite():