[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/tests - test_vocabularywidget.py:1.2
Fred L. Drake, Jr.
fred@zope.com
Tue, 20 May 2003 12:10:59 -0400
Update of /cvs-repository/Zope3/src/zope/app/browser/form/tests
In directory cvs.zope.org:/tmp/cvs-serv24680/src/zope/app/browser/form/tests
Added Files:
test_vocabularywidget.py
Log Message:
Merge schema-vocabulary-branch into the trunk.
Preliminary documentation on vocabularies and schema vocabulary fields
can be found at http://dev.zope.org/Zope3/VocabularyFields.
=== Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py 1.1 => 1.2 === (431/531 lines abridged)
--- /dev/null Tue May 20 12:10:59 2003
+++ Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py Tue May 20 12:10:28 2003
@@ -0,0 +1,528 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+"""Tests of the vocabulary field widget machinery."""
+
+import unittest
+
+from zope.app.browser.form import vocabularywidget
+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.component.view import provideView
+from zope.publisher.browser import TestRequest
+from zope.publisher.interfaces.browser import IBrowserPresentation
+
+from zope.schema.interfaces import IVocabulary, ITerm, IVocabularyQuery
+from zope.schema.interfaces import IVocabularyField, IVocabularyMultiField
+from zope.schema import vocabulary
+
+
+class ISampleVocabulary(IVocabulary):
+ """Specialized interface so we can hook views onto a vocabulary."""
+
+class SampleTerm(object):
+ """Trivial ITerm implementation."""
+ __implements__ = ITerm
+
+ def __init__(self, value):
+ self.value = value
+
+
+class BasicVocabulary(object):
+ """Simple vocabulary that uses terms from a passed-in list of values."""
+ __implements__ = IVocabulary
+
[-=- -=- -=- 431 lines omitted -=- -=- -=-]
+ bound = self.makeField(self.queryableVocabulary)
+ w = getView(bound, "edit", self.makeRequest("field.f-query=foo"))
+ checks = [
+ "query-results-go-here",
+ ]
+ self.verifyResult(w.queryview.renderResults([]), checks)
+ self.verifyResult(w(), checks + ['class="queryresults"'])
+
+
+class SingleSelectionQuerySupportTests(SingleSelectionViews,
+ QuerySupportTestBase):
+ """Query support tests for single-selection widgets."""
+
+ defaultFieldValue = "splat"
+ fieldClass = vocabulary.VocabularyField
+ queryViewLabel = "single"
+
+ def registerViews(self):
+ SingleSelectionViews.registerViews(self)
+ provideView(IMyVocabularyQuery,
+ "widget-query-helper",
+ IBrowserPresentation,
+ MyQueryViewSingle)
+
+
+class MultiSelectionQuerySupportTests(MultiSelectionViews,
+ QuerySupportTestBase):
+ """Query support tests for multi-selection widgets."""
+
+ defaultFieldValue = ["splat"]
+ fieldClass = vocabulary.VocabularyMultiField
+ queryViewLabel = "multi"
+
+ def registerViews(self):
+ MultiSelectionViews.registerViews(self)
+ provideView(IMyVocabularyQuery,
+ "widget-query-multi-helper",
+ IBrowserPresentation,
+ MyQueryViewMulti)
+
+
+def test_suite():
+ suite = unittest.makeSuite(SingleSelectionTests)
+ suite.addTest(unittest.makeSuite(MultiSelectionTests))
+ suite.addTest(unittest.makeSuite(SingleSelectionQuerySupportTests))
+ suite.addTest(unittest.makeSuite(MultiSelectionQuerySupportTests))
+ return suite
+
+if __name__ == '__main__':
+ unittest.main()