[Zope3-checkins] CVS: Zope3/src/zope/app/form/browser/tests - test_choicecollections.py:1.1 test_choicewidget.py:1.2 test_itemswidget.py:1.2 test_multicheckboxwidget.py:1.4 test_registrations.py:1.2 test_selectwidget.py:1.2 test_sequencewidget.py:1.4 test_vocabularyquery.py:1.2 test_choicesequencetest.py:NONE

Gary Poster gary at zope.com
Thu May 6 12:14:12 EDT 2004


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

Modified Files:
	test_choicewidget.py test_itemswidget.py 
	test_multicheckboxwidget.py test_registrations.py 
	test_selectwidget.py test_sequencewidget.py 
	test_vocabularyquery.py 
Added Files:
	test_choicecollections.py 
Removed Files:
	test_choicesequencetest.py 
Log Message:
Convert the field collection behavior as described in 
http://mail.zope.org/pipermail/zope3-dev/2004-May/010797.html

The Sequence field is removed.  As I spoke with Stephan, it may be acceptable to add the Sequence field back in if it actually means something.  Sequence did mean it was iterable but container access API was not described.  It should be described.  IPythonSequence might describe this API.  A Sequence widget should require specification of the factory.

Set now specifies a sets.Set.

IChoiceSequence was removed.




=== Added File Zope3/src/zope/app/form/browser/tests/test_choicecollections.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
"""Test the choice collections widgets (function).

$Id: test_choicecollections.py,v 1.1 2004/05/06 16:13:41 poster Exp $
"""
import unittest
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.publisher.browser import TestRequest
from zope.schema.interfaces import IList, IChoice, IIterableVocabulary
from zope.schema import Choice, List

from zope.app import zapi
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.app.form.interfaces import IInputWidget, IDisplayWidget
from zope.app.form.browser import CollectionDisplayWidget
from zope.app.form.browser import CollectionInputWidget
from zope.app.form.browser import ChoiceCollectionDisplayWidget
from zope.app.form.browser import ChoiceCollectionInputWidget
from zope.app.form.browser import ItemsMultiDisplayWidget, SelectWidget


def provideMultiView(for_, factory, providing, name='', layer="default"):
    s = zapi.getService(None, zapi.servicenames.Presentation)
    return s.provideAdapter(IBrowserRequest, factory, name, for_,
                            providing, layer)


class ListOfChoicesWidgetTest(PlacelessSetup, unittest.TestCase):

    def test_ListOfChoicesDisplayWidget(self):
        provideMultiView((IList, IChoice),
                         ChoiceCollectionDisplayWidget, IDisplayWidget)
        provideMultiView((IList, IIterableVocabulary),
                         ItemsMultiDisplayWidget, IDisplayWidget)
        field = List(value_type=Choice(values=[1, 2, 3]))
        bound = field.bind(object())
        widget = CollectionDisplayWidget(bound, TestRequest())
        self.assert_(isinstance(widget, ItemsMultiDisplayWidget))
        self.assertEqual(widget.context, bound)
        self.assertEqual(widget.vocabulary, bound.value_type.vocabulary)


    def test_ChoiceSequenceEditWidget(self):
        provideMultiView((IList, IChoice),
                         ChoiceCollectionInputWidget, IInputWidget)
        provideMultiView((IList, IIterableVocabulary),
                         SelectWidget, IInputWidget)
        field = List(value_type=Choice(values=[1, 2, 3]))
        bound = field.bind(object())
        widget = CollectionInputWidget(bound, TestRequest())
        self.assert_(isinstance(widget, SelectWidget))
        self.assertEqual(widget.context, bound)
        self.assertEqual(widget.vocabulary, bound.value_type.vocabulary)
        


def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(ListOfChoicesWidgetTest),
        ))

if __name__=='__main__':
    unittest.main(defaultTest='test_suite')


=== Zope3/src/zope/app/form/browser/tests/test_choicewidget.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/form/browser/tests/test_choicewidget.py:1.1	Sat Apr 24 19:19:07 2004
+++ Zope3/src/zope/app/form/browser/tests/test_choicewidget.py	Thu May  6 12:13:41 2004
@@ -24,7 +24,7 @@
 from zope.app import zapi
 from zope.app.tests.placelesssetup import PlacelessSetup
 from zope.app.form.interfaces import IInputWidget, IDisplayWidget
-from zope.app.form.browser import ChoiceDisplayWidget, ChoiceEditWidget
+from zope.app.form.browser import ChoiceDisplayWidget, ChoiceInputWidget
 from zope.app.form.browser import ItemDisplayWidget, DropdownWidget
 
 
@@ -47,12 +47,12 @@
         self.assertEqual(widget.vocabulary, bound.vocabulary)
 
 
-    def test_ChoiceEditWidget(self):
+    def test_ChoiceInputWidget(self):
         provideMultiView((IChoice, IIterableVocabulary),
                          DropdownWidget, IInputWidget)
         field = Choice(values=[1, 2, 3])
         bound = field.bind(object())
-        widget = ChoiceEditWidget(bound, TestRequest())
+        widget = ChoiceInputWidget(bound, TestRequest())
         self.assert_(isinstance(widget, DropdownWidget))
         self.assertEqual(widget.context, bound)
         self.assertEqual(widget.vocabulary, bound.vocabulary)


=== Zope3/src/zope/app/form/browser/tests/test_itemswidget.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/form/browser/tests/test_itemswidget.py:1.1	Sat Apr 24 19:19:07 2004
+++ Zope3/src/zope/app/form/browser/tests/test_itemswidget.py	Thu May  6 12:13:41 2004
@@ -18,7 +18,7 @@
 import unittest
 
 from zope.interface import Interface, implements
-from zope.schema import Choice, Sequence
+from zope.schema import Choice, List
 from zope.publisher.browser import TestRequest
 
 from zope.app.form.interfaces import WidgetInputError
@@ -43,7 +43,7 @@
         values=['one', 'two', 'three'],
         required=True)
 
-    numbers = Sequence(
+    numbers = List(
         title=u"Numbers",
         description=u"The Numbers",
         value_type=choice,


=== Zope3/src/zope/app/form/browser/tests/test_multicheckboxwidget.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/form/browser/tests/test_multicheckboxwidget.py:1.3	Sat Apr 24 19:19:43 2004
+++ Zope3/src/zope/app/form/browser/tests/test_multicheckboxwidget.py	Thu May  6 12:13:41 2004
@@ -17,7 +17,7 @@
 import unittest, doctest
 from zope.interface import Interface, implements
 from zope.publisher.browser import TestRequest
-from zope.schema import Choice, Sequence
+from zope.schema import Choice, List
 
 from zope.app.form.interfaces import IInputWidget
 from zope.app.form.browser import MultiCheckBoxWidget
@@ -32,7 +32,7 @@
     """
 
     _WidgetFactory = MultiCheckBoxWidget
-    _FieldFactory = Sequence
+    _FieldFactory = List
 
     def setUpContent(self, desc=u''):
         class ITestContent(Interface):


=== Zope3/src/zope/app/form/browser/tests/test_registrations.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/form/browser/tests/test_registrations.py:1.1	Sat Apr 24 19:19:07 2004
+++ Zope3/src/zope/app/form/browser/tests/test_registrations.py	Thu May  6 12:13:41 2004
@@ -37,14 +37,14 @@
 
 class ISampleObject(interfaces.IField):
     pass
-    
+
 class SampleObject:
     implements(ISampleObject)
-    
+
 class ISampleVocabulary(
     interfaces.IVocabularyTokenized, interfaces.IVocabulary):
     pass
-    
+
 class SampleVocabularyQuery:
     implements(interfaces.IIterableVocabularyQuery)
     def __init__(self, vocabulary):
@@ -54,8 +54,7 @@
     implements(ISampleVocabulary)
     def getQuery(self):
         return SampleVocabularyQuery(self)
-    
-    
+
 request = TestRequest()
 sample = SampleObject()
 vocab = SampleVocabulary([])
@@ -64,7 +63,6 @@
     setup.placelessSetUp()
     context = xmlconfig.file("tests/registerWidgets.zcml",
                              zope.app.form.browser)
-    
 
 class Tests:
     """Documents and tests widgets registration for specific field types.
@@ -160,14 +158,14 @@
         
     ITuple, IInputWidget -> TupleSequenceWidget
     
-        >>> field = fields.Tuple()
+        >>> field = fields.Tuple(value_type=fields.Int())
         >>> widget = zapi.getViewProviding(field, IInputWidget, request)
         >>> isinstance(widget, TupleSequenceWidget)
         True
 
     IList, IInputWidget -> ListSequenceWidget
     
-        >>> field = fields.List()
+        >>> field = fields.List(value_type=fields.Int())
         >>> widget = zapi.getViewProviding(field, IInputWidget, request)
         >>> isinstance(widget, ListSequenceWidget)
         True
@@ -195,17 +193,17 @@
         >>> isinstance(widget, DropdownWidget)
         True
 
-    IChoiceSequence, IDisplayWidget -> ItemsMultiDisplayWidget
+    IList with IChoice value_type, IDisplayWidget -> ItemsMultiDisplayWidget
     
-        >>> field = fields.Sequence(value_type=fields.Choice(vocabulary=vocab))
+        >>> field = fields.List(value_type=fields.Choice(vocabulary=vocab))
         >>> field = field.bind(sample)
         >>> widget = zapi.getViewProviding(field, IDisplayWidget, request)
         >>> isinstance(widget, ItemsMultiDisplayWidget)
         True
                 
-    IChoiceSequence, IInputWidget -> MultiSelectWidget
+    IList with IChoice value_type, IInputWidget -> MultiSelectWidget
     
-        >>> field = fields.Sequence(value_type=fields.Choice(vocabulary=vocab))
+        >>> field = fields.List(value_type=fields.Choice(vocabulary=vocab))
         >>> field = field.bind(sample)
         >>> widget = zapi.getViewProviding(field, IInputWidget, request)
         >>> isinstance(widget, MultiSelectWidget)


=== Zope3/src/zope/app/form/browser/tests/test_selectwidget.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/form/browser/tests/test_selectwidget.py:1.1	Sat Apr 24 19:19:07 2004
+++ Zope3/src/zope/app/form/browser/tests/test_selectwidget.py	Thu May  6 12:13:41 2004
@@ -17,7 +17,7 @@
 """
 import unittest
 
-from zope.schema import Choice, Sequence
+from zope.schema import Choice, List
 from zope.app.form.browser import SelectWidget
 
 choice = Choice(
@@ -25,7 +25,7 @@
     description=u"The Number",
     values=[1, 2, 3])
 
-sequence = Sequence(
+sequence = List(
     title=u"Numbers",
     description=u"The Numbers",
     value_type=choice)


=== Zope3/src/zope/app/form/browser/tests/test_sequencewidget.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/form/browser/tests/test_sequencewidget.py:1.3	Sat Apr 24 19:19:43 2004
+++ Zope3/src/zope/app/form/browser/tests/test_sequencewidget.py	Thu May  6 12:13:41 2004
@@ -20,6 +20,7 @@
 from zope.schema import Tuple, List, TextLine
 from zope.schema.interfaces import ITextLine, ValidationError
 from zope.publisher.browser import TestRequest
+from zope.interface import Interface, implements
 from zope.interface.verify import verifyClass
 
 from zope.app import zapi
@@ -40,6 +41,24 @@
         True
     """
 
+    def setUpContent(self, desc=u''):
+        class ITestContent(Interface):
+            foo = self._FieldFactory(
+                    title = u"Foo Title",
+                    description = desc,
+                    )
+        class TestObject:
+            implements(ITestContent)
+
+        self.content = TestObject()
+        field = ITestContent['foo']
+        field = field.bind(self.content)
+        request = TestRequest(HTTP_ACCEPT_LANGUAGE='pl')
+        request.form['field.foo'] = u'Foo Value'
+        # sequence widgets take value_type as second argument because of double
+        # dispatch
+        self._widget = self._WidgetFactory(field, TextLine(), request)
+
     def _FieldFactory(self, **kw):
         kw.update({
             '__name__': u'foo', 
@@ -69,23 +88,23 @@
             __name__=u'foo',
             value_type=TextLine(__name__=u'bar'))
         request = TestRequest()
-        widget = ListSequenceWidget(self.field, request)
+        widget = ListSequenceWidget(self.field, TextLine(), request)
         self.failIf(widget.hasInput())
         self.assertEquals(widget.getInputValue(), [])
 
         request = TestRequest(form={'field.foo.add': u'Add bar'})
-        widget = ListSequenceWidget(self.field, request)
+        widget = ListSequenceWidget(self.field, TextLine(), request)
         self.assert_(widget.hasInput())
         self.assertRaises(ValidationError, widget.getInputValue)
 
         request = TestRequest(form={'field.foo.0.bar': u'Hello world!'})
-        widget = ListSequenceWidget(self.field, request)
+        widget = ListSequenceWidget(self.field, TextLine(), request)
         self.assert_(widget.hasInput())
         self.assertEquals(widget.getInputValue(), [u'Hello world!'])
 
     def test_new(self):
         request = TestRequest()
-        widget = TupleSequenceWidget(self.field, request)
+        widget = TupleSequenceWidget(self.field, TextLine(), request)
         self.failIf(widget.hasInput())
         self.assertEquals(widget.getInputValue(), ())
         check_list = ('input', 'name="field.foo.add"')
@@ -93,7 +112,7 @@
 
     def test_add(self):
         request = TestRequest(form={'field.foo.add': u'Add bar'})
-        widget = TupleSequenceWidget(self.field, request)
+        widget = TupleSequenceWidget(self.field, TextLine(), request)
         self.assert_(widget.hasInput())
         self.assertRaises(ValidationError, widget.getInputValue)
         check_list = (
@@ -104,13 +123,13 @@
 
     def test_request(self):
         request = TestRequest(form={'field.foo.0.bar': u'Hello world!'})
-        widget = TupleSequenceWidget(self.field, request)
+        widget = TupleSequenceWidget(self.field, TextLine(), request)
         self.assert_(widget.hasInput())
         self.assertEquals(widget.getInputValue(), (u'Hello world!',))
 
     def test_existing(self):
         request = TestRequest()
-        widget = TupleSequenceWidget(self.field, request)
+        widget = TupleSequenceWidget(self.field, TextLine(), request)
         widget.setRenderedValue((u'existing',))
         self.assert_(widget.hasInput())
         self.assertEquals(widget.getInputValue(), (u'existing',))
@@ -135,7 +154,7 @@
     def test_remove(self):
         request = TestRequest(form={'field.foo.remove_0': u'Hello world!',
             'field.foo.0.bar': u'existing', 'field.foo.1.bar': u'second'})
-        widget = TupleSequenceWidget(self.field, request)
+        widget = TupleSequenceWidget(self.field, TextLine(), request)
         widget.setRenderedValue((u'existing', u'second'))
         self.assertEquals(widget.getInputValue(), (u'second',))
         check_list = (
@@ -148,7 +167,7 @@
     def test_min(self):
         request = TestRequest()
         self.field.min_length = 2
-        widget = TupleSequenceWidget(self.field, request)
+        widget = TupleSequenceWidget(self.field, TextLine(), request)
         widget.setRenderedValue((u'existing',))
         self.assertEquals(widget.getInputValue(), (u'existing',))
         check_list = (
@@ -163,7 +182,7 @@
     def test_max(self):
         request = TestRequest()
         self.field.max_length = 1
-        widget = TupleSequenceWidget(self.field, request)
+        widget = TupleSequenceWidget(self.field, TextLine(), request)
         widget.setRenderedValue((u'existing',))
         self.assertEquals(widget.getInputValue(), (u'existing',))
         s = widget()
@@ -172,7 +191,7 @@
     def test_anonymousfield(self):
         self.field = Tuple(__name__=u'foo', value_type=TextLine())
         request = TestRequest()
-        widget = TupleSequenceWidget(self.field, request)
+        widget = TupleSequenceWidget(self.field, TextLine(), request)
         widget.setRenderedValue((u'existing',))
         s = widget()
         check_list = (


=== Zope3/src/zope/app/form/browser/tests/test_vocabularyquery.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/form/browser/tests/test_vocabularyquery.py:1.1	Sat Apr 24 19:19:07 2004
+++ Zope3/src/zope/app/form/browser/tests/test_vocabularyquery.py	Thu May  6 12:13:41 2004
@@ -19,8 +19,8 @@
 from zope.interface import implements
 from zope.publisher.browser import TestRequest
 from zope.publisher.browser import IBrowserRequest
-from zope.schema import vocabulary, Choice, Sequence
-from zope.schema.interfaces import IVocabularyQuery, IChoice, IChoiceSequence
+from zope.schema import vocabulary, Choice, List
+from zope.schema.interfaces import IVocabularyQuery, IChoice, ICollection
 
 from zope.app import zapi
 from zope.app.tests import ztapi
@@ -178,7 +178,7 @@
     """Query support tests for multi-selection widgets."""
 
     defaultFieldValue = ["splat"]
-    fieldClass = Sequence
+    fieldClass = List
     queryViewLabel = "multi"
     _widgetFactory = MultiSelectWidget
 
@@ -186,16 +186,16 @@
         """Create and return a bound vocabulary field."""
         if vocabulary is None:
             vocabulary = self._sampleVocabulary
-        field = Sequence(__name__="f",
-                         value_type=Choice(vocabulary=vocabulary,
-                                           required=required))
+        field = List(__name__="f",
+                     value_type=Choice(vocabulary=vocabulary,
+                                       required=required))
         if value is self._marker:
             value = self.defaultFieldValue
         content = SampleContent(value)
         return field.bind(content)
 
     def registerViews(self):
-        provideMultiView((ISampleVocabularyQuery, IChoiceSequence),
+        provideMultiView((ISampleVocabularyQuery, ICollection),
                          SampleQueryViewMulti, IVocabularyQueryView)
 
 

=== Removed File Zope3/src/zope/app/form/browser/tests/test_choicesequencetest.py ===




More information about the Zope3-Checkins mailing list