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

Garrett Smith garrett at mojave-corp.com
Mon Mar 1 18:33:49 EST 2004


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

Modified Files:
      Tag: garrett-widgets2-branch
	test_vocabularywidget.py 
Log Message:
Reverted changes to vocabulary widgets re widget lookup.


=== Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py 1.28.14.1 => 1.28.14.2 ===
--- Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py:1.28.14.1	Thu Feb 26 00:10:50 2004
+++ Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py	Mon Mar  1 18:33:49 2004
@@ -16,14 +16,13 @@
 
 import unittest
 
-from zope.app import zapi
 from zope.app.tests import ztapi
 from zope.app.browser.form import vocabularywidget
 from zope.app.browser.form.tests import support
-from zope.app.interfaces.form import IEditWidget, IDisplayWidget
 from zope.app.interfaces.browser.form import IBrowserWidget
 from zope.app.interfaces.browser.form import IVocabularyQueryView
 from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.component import getView
 from zope.interface.declarations import implements
 from zope.publisher.browser import TestRequest
 
@@ -33,6 +32,7 @@
 from zope.schema.interfaces import IVocabularyTokenized
 from zope.schema import vocabulary
 
+
 class ISampleVocabulary(IVocabularyTokenized, IVocabulary):
     """Specialized interface so we can hook views onto a vocabulary."""
 
@@ -47,9 +47,7 @@
 
     This is not intended to be a useful widget.
     """
-    implements(IBrowserWidget,
-               vocabularywidget.IVocabularyDisplayWidget,
-               vocabularywidget.IVocabularyListDisplayWidget)
+    implements(IBrowserWidget)
 
     def __call__(self):
         return "foo"
@@ -152,36 +150,35 @@
         # This is equivalent to the default configuration for
         # vocabulary field view registration from configure.zcml.
         # Single-selection views only.
-        ztapi.browserViewProviding(
+        ztapi.browserView(
             IVocabularyField,
-            vocabularywidget.VocabularyFieldDisplayWidget,
-            IDisplayWidget)
-        ztapi.browserViewProviding(
+            "display",
+            vocabularywidget.VocabularyFieldDisplayWidget)
+        ztapi.browserView(
             IVocabularyField,
-            vocabularywidget.VocabularyFieldEditWidget,
-            IEditWidget)
+            "edit",
+            vocabularywidget.VocabularyFieldEditWidget)
         # Register the "basic" widgets:
-        ztapi.browserViewProviding(
+        ztapi.browserView(
             IVocabularyTokenized,
-            vocabularywidget.VocabularyDisplayWidget,
-            vocabularywidget.IVocabularyDisplayWidget)
-        ztapi.browserViewProviding(
+            "field-display-widget",
+            vocabularywidget.VocabularyDisplayWidget)
+        ztapi.browserView(
             IVocabularyTokenized,
+            "field-edit-widget",
             # XXX indirect through a derived class to allow
             # testing of multiple concrete widgets
-            self.singleSelectionEditWidget,
-            vocabularywidget.IVocabularyEditWidget)
-        ztapi.browserViewProviding(
+            self.singleSelectionEditWidget)
+        ztapi.browserView(
             IIterableVocabularyQuery,
-            vocabularywidget.IterableVocabularyQueryView,
-            vocabularywidget.IWidgetQueryHelper)
+            "widget-query-helper",
+            vocabularywidget.IterableVocabularyQueryView)
         # The following widget registration supports the specific
         # sample vocabulary we're using, used to demonstrate how to
         # override widget selection based on vocabulary:
-        ztapi.browserViewProviding(
-            ISampleVocabulary,
-            SampleDisplayWidget,
-            vocabularywidget.IVocabularyDisplayWidget)
+        ztapi.browserView(ISampleVocabulary,
+                    "field-display-widget",
+                                        SampleDisplayWidget)
 
 
 class MultiSelectionViews:
@@ -190,34 +187,33 @@
         # This is equivalent to the default configuration for
         # vocabulary field view registration from configure.zcml.
         # Multi-selection views only.
-        ztapi.browserViewProviding(
+        ztapi.browserView(
             IVocabularyListField,
-            vocabularywidget.VocabularyListFieldDisplayWidget,
-            IDisplayWidget)
-        ztapi.browserViewProviding(
+            "display",
+            vocabularywidget.VocabularyListFieldDisplayWidget)
+        ztapi.browserView(
             IVocabularyListField,
-            vocabularywidget.VocabularyListFieldEditWidget,
-            IEditWidget)
+            "edit",
+            vocabularywidget.VocabularyListFieldEditWidget)
         # Bind widgets to the vocabulary fields:
-        ztapi.browserViewProviding(
+        ztapi.browserView(
             IVocabularyTokenized,
-            vocabularywidget.VocabularyListDisplayWidget,
-            vocabularywidget.IVocabularyListDisplayWidget)
-        ztapi.browserViewProviding(
+            "field-display-list-widget",
+            vocabularywidget.VocabularyListDisplayWidget)
+        ztapi.browserView(
             IVocabularyTokenized,
-            vocabularywidget.VocabularyMultiEditWidget,
-            vocabularywidget.IVocabularyMultiEditWidget)
-        ztapi.browserViewProviding(
+            "field-edit-list-widget",
+            vocabularywidget.VocabularyMultiEditWidget)
+        ztapi.browserView(
             IIterableVocabularyQuery,
-            vocabularywidget.IterableVocabularyQueryMultiView,
-            vocabularywidget.IWidgetQueryHelper)
+            "widget-query-list-helper",
+            vocabularywidget.IterableVocabularyQueryMultiView)
         # The following widget registration supports the specific
         # sample vocabulary we're using, used to demonstrate how to
         # override widget selection based on vocabulary:
-        ztapi.browserViewProviding(
-            ISampleVocabulary,
-            SampleDisplayWidget,
-            vocabularywidget.IVocabularyListDisplayWidget)
+        ztapi.browserView(ISampleVocabulary,
+                    "field-display-list-widget",
+                                        SampleDisplayWidget)
 
 
 class SelectionTestBase(VocabularyWidgetTestBase):
@@ -225,7 +221,7 @@
 
     def test_vocabulary_specialization(self):
         bound = self.makeField(SampleVocabulary.fromValues(["frobnication"]))
-        w = zapi.getViewProviding(bound, IDisplayWidget, self.makeRequest())
+        w = getView(bound, "display", self.makeRequest())
         self.assertEqual(w(), "foo")
 
 
@@ -240,19 +236,19 @@
 
     def test_display(self):
         bound = self.makeField()
-        w = zapi.getViewProviding(bound, IDisplayWidget, self.makeRequest())
+        w = getView(bound, "display", self.makeRequest())
         w.setRenderedValue(bound.context.f)
         self.assertEqual(w(), "splat")
 
     def test_display_with_form_value(self):
         bound = self.makeField()
         request = self.makeRequest('field.f=foobar')
-        w = zapi.getViewProviding(bound, IDisplayWidget, request)
+        w = getView(bound, "display", request)
         self.assert_(w.hasInput())
         self.assertEqual(w(), "foobar")
 
     def setup_edit(self, bound):
-        w = zapi.getViewProviding(bound, IEditWidget, self.makeRequest())
+        w = getView(bound, "edit", self.makeRequest())
         w.setRenderedValue(bound.context.f)
         self.assert_(not w.hasInput())
         return w
@@ -311,7 +307,7 @@
     def test_edit_with_form_value(self):
         bound = self.makeField()
         request = self.makeRequest('field.f=foobar')
-        w = zapi.getViewProviding(bound, IEditWidget, request)
+        w = getView(bound, "edit", request)
         self.assert_(w.hasInput())
         self.assertEqual(w.getInputValue(), "foobar")
         self.assert_(isinstance(w, vocabularywidget.VocabularyEditWidget))
@@ -322,7 +318,7 @@
         # report hasInput() properly.
         bound = self.makeField()
         bound.context.f = "splat"
-        w = zapi.getViewProviding(bound, IEditWidget, self.makeRequest(
+        w = getView(bound, "edit", self.makeRequest(
             'field.f-empty-marker='))
         self.assert_(w.hasInput())
         self.assertEqual(w.getInputValue(), None) # XXX might be []...
@@ -342,7 +338,7 @@
     def test_edit_with_form_value(self):
         bound = self.makeField()
         request = self.makeRequest('field.f=foobar')
-        w = zapi.getViewProviding(bound, IEditWidget, request)
+        w = getView(bound, "edit", request)
         self.assert_(w.hasInput())
         self.assertEqual(w.getInputValue(), "foobar")
         self.assert_(isinstance(w, vocabularywidget.RadioWidget))
@@ -422,13 +418,13 @@
     def test_display_without_value(self):
         bound = self.makeField()
         del bound.context.f
-        w = zapi.getViewProviding(bound, IDisplayWidget, self.makeRequest())
+        w = getView(bound, "display", self.makeRequest())
         self.assert_(not w.hasInput())
         self.assertEqual(w(), "")
 
     def test_display_with_value(self):
         bound = self.makeField(value=["foobar", "frob"])
-        w = zapi.getViewProviding(bound, IDisplayWidget, self.makeRequest())
+        w = getView(bound, "display", self.makeRequest())
         w.setRenderedValue(bound.context.f)
         self.assert_(not w.hasInput())
         self.verifyResult(w(), [
@@ -450,7 +446,7 @@
     def test_display_with_form_data(self):
         bound = self.makeField(value=["foobar", "frob"])
         request = self.makeRequest('field.f:list=splat')
-        w = zapi.getViewProviding(bound, IDisplayWidget, request)
+        w = getView(bound, "display", request)
         self.assert_(w.hasInput())
         s = w()
         self.verifyResult(s, [
@@ -467,7 +463,7 @@
 
     def test_edit(self):
         bound = self.makeField()
-        w = zapi.getViewProviding(bound, IEditWidget, self.makeRequest())
+        w = getView(bound, "edit", self.makeRequest())
         self.assert_(not w.hasInput())
         self.verifyResult(w(), [
             'id="field.f"',
@@ -499,7 +495,7 @@
     def test_edit_with_form_value(self):
         bound = self.makeField()
         request = self.makeRequest('field.f:list=foobar&field.f:list=splat')
-        w = zapi.getViewProviding(bound, IEditWidget, request)
+        w = getView(bound, "edit", request)
         self.assert_(w.hasInput())
         L = w.getInputValue()
         L.sort()
@@ -520,7 +516,7 @@
     def test_get_query_helper(self):
         bound = self.makeField()
         request = self.makeRequest()
-        w = zapi.getViewProviding(bound, IEditWidget, request)
+        w = getView(bound, "edit", request)
         self.assert_(isinstance(w.query, MyVocabularyQuery))
         self.assert_(w.queryview.widget is w)
         self.assertEqual(w.queryview.name, w.name + "-query")
@@ -528,7 +524,7 @@
 
     def test_query_input_section(self):
         bound = self.makeField()
-        w = zapi.getViewProviding(bound, IEditWidget, self.makeRequest())
+        w = getView(bound, "edit", self.makeRequest())
         w.setRenderedValue(bound.context.f)
         checks = [
             "this-is-query-input",
@@ -538,7 +534,7 @@
 
     def test_query_output_section_without_results(self):
         bound = self.makeField()
-        w = zapi.getViewProviding(bound, IEditWidget, self.makeRequest())
+        w = getView(bound, "edit", self.makeRequest())
         w.setRenderedValue(bound.context.f)
         checks = [
             "query-results-go-here",
@@ -548,7 +544,7 @@
 
     def test_query_output_section_with_results(self):
         bound = self.makeField()
-        w = zapi.getViewProviding(bound, IEditWidget, self.makeRequest("field.f-query=foo"))
+        w = getView(bound, "edit", self.makeRequest("field.f-query=foo"))
         w.setRenderedValue(bound.context.f)
         checks = [
             "query-results-go-here",
@@ -568,10 +564,9 @@
 
     def registerViews(self):
         SingleSelectionViews.registerViews(self)
-        ztapi.browserViewProviding(
-            IMyVocabularyQuery,
-            MyQueryViewSingle,
-            vocabularywidget.IWidgetQueryHelper)
+        ztapi.browserView(IMyVocabularyQuery,
+                          "widget-query-helper",
+                          MyQueryViewSingle)
 
 
 class MultiSelectionQuerySupportTests(MultiSelectionViews,
@@ -584,10 +579,9 @@
 
     def registerViews(self):
         MultiSelectionViews.registerViews(self)
-        ztapi.browserViewProviding(
-            IMyVocabularyQuery,
-            MyQueryViewMulti,
-            vocabularywidget.IWidgetQueryListHelper)
+        ztapi.browserView(IMyVocabularyQuery,
+                          "widget-query-list-helper",
+                          MyQueryViewMulti)
 
 
 def test_suite():




More information about the Zope3-Checkins mailing list