[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/ftests - test_registrations.py:1.2 support.py:1.5 test_filewidget.py:1.5 test_textareawidget.py:1.5 test_textwidget.py:1.6

Garrett Smith garrett at mojave-corp.com
Fri Mar 5 23:17:49 EST 2004


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

Modified Files:
	support.py test_filewidget.py test_textareawidget.py 
	test_textwidget.py 
Added Files:
	test_registrations.py 
Log Message:
Merged changes from garrett-widgets2-branch:

- Changed the way widgets are looked up to use interfaces instead of 
  names.
  
- Refactor of zope/app/form/utility.py -- see 

    http://dev.zope.org/Zope3/WidgetsAndMultiwayAdapters
    
  for details.
  
- Moved configuration of vocab widgets to its own zcml file
  (zope/app/browser/form/vocabularywidget.zcml).

- Removed 'propertyNames' and 'getValue' from widgets. This  is replaced
  by accessing the widget attributes directly.
  
- Deleted depreated methods from widget interface: haveData and getData.


=== Zope3/src/zope/app/browser/form/ftests/test_registrations.py 1.1 => 1.2 ===
--- /dev/null	Fri Mar  5 23:17:49 2004
+++ Zope3/src/zope/app/browser/form/ftests/test_registrations.py	Fri Mar  5 23:17:18 2004
@@ -0,0 +1,262 @@
+import unittest, doctest
+
+from zope.interface import implements
+from zope.app import zapi
+from zope.publisher.browser import TestRequest
+
+import zope.schema as fields
+from zope.schema import interfaces
+from zope.schema import vocabulary
+
+import zope.app.browser.form.vocabularywidget as vocabwidgets
+import zope.app.browser.form.widget as widgets
+from zope.app.browser.form import enumerated
+
+from zope.app.interfaces.form import IDisplayWidget
+from zope.app.interfaces.form import IInputWidget
+
+
+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):
+        self.vocabulary = vocabulary    
+
+class SampleVocabulary(vocabulary.SimpleVocabulary):
+    implements(ISampleVocabulary)
+    def getQuery(self):
+        return SampleVocabularyQuery(self)
+    
+    
+request = TestRequest()
+sample = SampleObject()
+vocab = SampleVocabulary([])
+    
+
+class Tests:
+    """Documents and tests widgets registration for specific field types.
+    
+    Standard Widgets
+    ------------------------------------------------------------------------
+    The relationships between field types and standard widgets are listed
+    below.
+    
+    IField, IDisplayWidget -> DisplayWidget
+        
+        >>> field = fields.Field()
+        >>> widget = zapi.getViewProviding(field, IDisplayWidget, request)
+        >>> isinstance(widget, widgets.DisplayWidget)
+        True
+        
+    ITextLine, IInputWidget -> TextWidget 
+        
+        >>> field = fields.TextLine()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, widgets.TextWidget)
+        True
+        
+    IText, IInputWidget -> TextAreaWidget
+    
+        >>> field = fields.Text()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, widgets.TextAreaWidget)
+        True
+        
+    ISourceText, IInputWidget -> TextAreaWidget
+    
+        >>> field = fields.SourceText()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, widgets.TextAreaWidget)
+        True
+
+    IBytesLine, IInputWidget -> BytesWidget
+    
+        >>> field = fields.BytesLine()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, widgets.BytesWidget)
+        True
+
+    IBytes, IInputWidget -> FileWidget
+    
+        >>> field = fields.Bytes()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, widgets.FileWidget)
+        True
+        
+    IASCII, IInputWidget -> BytesAreaWidget
+    
+        >>> field = fields.ASCII()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, widgets.BytesAreaWidget)
+        True
+        
+    IInt, IInputWidget -> IntWidget
+    
+        >>> field = fields.Int()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, widgets.IntWidget)
+        True
+        
+    IFloat, IInputWidget -> FloatWidget
+    
+        >>> field = fields.Float()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, widgets.FloatWidget)
+        True
+        
+    IDatetime, IInputWidget -> DatetimeWidget
+    
+        >>> field = fields.Datetime()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, widgets.DatetimeWidget)
+        True
+        
+    IDate, IInputWidget -> DateWidget
+    
+        >>> field = fields.Date()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, widgets.DateWidget)
+        True
+        
+    IBool, IInputWidget -> CheckBoxWidget
+    
+        >>> field = fields.Bool()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, widgets.CheckBoxWidget)
+        True
+        
+    ITuple, IInputWidget -> TupleSequenceWidget
+    
+        >>> field = fields.Tuple()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, widgets.TupleSequenceWidget)
+        True
+
+    IList, IInputWidget -> ListSequenceWidget
+    
+        >>> field = fields.List()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, widgets.ListSequenceWidget)
+        True
+
+    IPassword, IInputWidget -> PasswordWidget
+    
+        >>> field = fields.Password()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, widgets.PasswordWidget)
+        True
+
+    IEnumeratedTextLine, IInputWidget -> EnumeratedTextWidget
+    
+        >>> field = fields.EnumeratedTextLine()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, enumerated.EnumeratedTextWidget)
+        True
+
+    IEnumeratedInt, IInputWidget -> EnumeratedIntWidget
+    
+        >>> field = fields.EnumeratedInt()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, enumerated.EnumeratedIntWidget)
+        True
+
+    IEnumeratedFloat, IInputWidget -> EnumeratedFloatWidget
+    
+        >>> field = fields.EnumeratedFloat()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, enumerated.EnumeratedFloatWidget)
+        True
+
+    IEnumeratedDatetime, IInputWidget -> EnumeratedDatetimeWidget
+    
+        >>> field = fields.EnumeratedDatetime()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, enumerated.EnumeratedDatetimeWidget)
+        True
+
+    IEnumeratedDate, IInputWidget -> EnumeratedDateWidget
+    
+        >>> field = fields.EnumeratedDate()
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, enumerated.EnumeratedDateWidget)
+        True
+
+        
+    Vocabulary Widgets
+    ------------------------------------------------------------------------
+    The relationships between vocabulary fields and widgets are listed
+    below. Note that the actual widgets returned are for IVocabulary object,
+    not IVocabularyField objects.
+
+    IVocabularyField, IDisplayWidget -> VocabularyDisplayWidget
+    
+        >>> field = vocabulary.VocabularyField(vocab)
+        >>> field = field.bind(sample)
+        >>> widget = zapi.getViewProviding(field, IDisplayWidget, request)
+        >>> isinstance(widget, vocabwidgets.VocabularyDisplayWidget)
+        True
+                
+    IVocabularyField, IInputWidget = VocabularyEditWidget
+    
+        >>> field = vocabulary.VocabularyField(vocab)
+        >>> field = field.bind(sample)
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, vocabwidgets.VocabularyEditWidget)
+        True
+
+    IVocabularyBagField, IDisplayWidget -> VocabularyBagDisplayWidget
+    
+        >>> field = vocabulary.VocabularyBagField(vocabulary=vocab)
+        >>> field = field.bind(sample)
+        >>> widget = zapi.getViewProviding(field, IDisplayWidget, request)
+        >>> isinstance(widget, vocabwidgets.VocabularyBagDisplayWidget)
+        True
+        
+    IVocabularyListField, IDisplayWidget -> VocabularyListDisplayWidget
+    
+        >>> field = vocabulary.VocabularyListField(vocabulary=vocab)
+        >>> field = field.bind(sample)
+        >>> widget = zapi.getViewProviding(field, IDisplayWidget, request)
+        >>> isinstance(widget, vocabwidgets.VocabularyListDisplayWidget)
+        True
+        
+    IVocabularyListField, IInputWidget -> VocabularyListEditWidget
+    
+        >>> field = vocabulary.VocabularyListField(vocabulary=vocab)
+        >>> field = field.bind(sample)
+        >>> widget = zapi.getViewProviding(field, IInputWidget, request)
+        >>> isinstance(widget, vocabwidgets.VocabularyMultiEditWidget)
+        True
+        
+    IVocabularySetField, IDisplayWidget -> VocabularyBagDisplayWidget
+    
+        >>> field = vocabulary.VocabularySetField(vocabulary=vocab)
+        >>> field = field.bind(sample)
+        >>> widget = zapi.getViewProviding(field, IDisplayWidget, request)
+        >>> isinstance(widget, vocabwidgets.VocabularyBagDisplayWidget)
+        True
+        
+    IVocabularyUniqueListField, IDisplayWidget -> VocabularyListDisplayWidget
+    
+        >>> field = vocabulary.VocabularyUniqueListField(vocabulary=vocab)
+        >>> field = field.bind(sample)
+        >>> widget = zapi.getViewProviding(field, IDisplayWidget, request)
+        >>> isinstance(widget, vocabwidgets.VocabularyListDisplayWidget)
+        True
+        
+    """
+
+def test_suite():    
+    return doctest.DocTestSuite()
+
+if __name__=='__main__':
+    unittest.main(defaultTest='test_suite')


=== Zope3/src/zope/app/browser/form/ftests/support.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/browser/form/ftests/support.py:1.4	Tue Mar  2 13:27:37 2004
+++ Zope3/src/zope/app/browser/form/ftests/support.py	Fri Mar  5 23:17:18 2004
@@ -47,20 +47,22 @@
         """ % (class_, schema, schema))
 
 
-def defineWidgetView(name, field_interface, widget_class):
+def defineWidgetView(field_interface, widget_class, view_type):
     field_interface = field_interface.__identifier__
     widget_class = '%s.%s' % (widget_class.__module__, widget_class.__name__)
+    view_type = '%s.%s' % (view_type.__module__, view_type.__name__)
     xmlconfig.string("""
-        <configure xmlns="http://namespaces.zope.org/browser">
-          <include package="zope.app.publisher.browser" file="meta.zcml" />
-          <page
-            name="%s"
-            permission="zope.Public"
-            allowed_interface="zope.app.browser.interfaces.form.IBrowserWidget"
+        <configure xmlns="http://namespaces.zope.org/zope">
+          <include package="zope.app.component" file="meta.zcml" />
+          <view
             for="%s"
-            class="%s" />
+            type="zope.publisher.interfaces.browser.IBrowserRequest"
+            factory="%s"
+            provides="%s"
+            permission="zope.Public"
+            />
         </configure>
-        """ % (name, field_interface, widget_class))
+        """ % (field_interface, widget_class, view_type))
 
 
 def patternExists(pattern, source, flags=0):
@@ -69,7 +71,7 @@
 
 def validationErrorExists(field, error_msg, source):
     return patternExists(
-        'name="field.%s".*%s' % (field, error_msg), source)
+        'name="field.%s".*%s' % (field, error_msg), source, re.DOTALL)
 
 
 def missingInputErrorExists(field, source):


=== Zope3/src/zope/app/browser/form/ftests/test_filewidget.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/browser/form/ftests/test_filewidget.py:1.4	Mon Jan 19 07:31:56 2004
+++ Zope3/src/zope/app/browser/form/ftests/test_filewidget.py	Fri Mar  5 23:17:18 2004
@@ -33,6 +33,7 @@
 from zope.app.traversing import traverse
 
 from zope.testing.functional import BrowserTestCase
+from zope.app.interfaces.form import IInputWidget
 
 class IFileField(IEnumerated, IField):
     """Field for representing a file that can be edited by FileWidget."""
@@ -43,7 +44,7 @@
     implements(IFileField)
 
 
-defineWidgetView('edit', IFileField, FileWidget)
+defineWidgetView(IFileField, FileWidget, IInputWidget)
 
 
 class IFileTest(Interface):


=== Zope3/src/zope/app/browser/form/ftests/test_textareawidget.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/browser/form/ftests/test_textareawidget.py:1.4	Mon Jan 19 07:31:56 2004
+++ Zope3/src/zope/app/browser/form/ftests/test_textareawidget.py	Fri Mar  5 23:17:18 2004
@@ -114,8 +114,8 @@
             'field.s1' : 'foo' }) # not unicode
 
         self.assertEqual(response.getStatus(), 200)
-        self.assert_(patternExists(
-            'name="field.s1".*Wrong type', response.getBody()))
+        self.assert_(validationErrorExists(
+            's1', 'Wrong type', response.getBody()))
 
 
     def test_missing_value(self):
@@ -166,8 +166,8 @@
             'UPDATE_SUBMIT' : '',
             'field.s1' : u'a' })
         self.assertEqual(response.getStatus(), 200)
-        self.assert_(patternExists(
-            'name="field.s1".*Too short', response.getBody()))
+        self.assert_(validationErrorExists(
+            's1', 'Too short', response.getBody()))
 
         # submit value for s1 that is too long
         response = self.publish('/test/edit.html', form={


=== Zope3/src/zope/app/browser/form/ftests/test_textwidget.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/browser/form/ftests/test_textwidget.py:1.5	Mon Jan 19 07:31:56 2004
+++ Zope3/src/zope/app/browser/form/ftests/test_textwidget.py	Fri Mar  5 23:17:18 2004
@@ -116,8 +116,8 @@
             'field.s1' : 'foo' }) # not unicode
 
         self.assertEqual(response.getStatus(), 200)
-        self.assert_(patternExists(
-            'name="field.s1".*Wrong type', response.getBody()))
+        self.assert_(validationErrorExists(
+            's1', 'Wrong type', response.getBody()))
 
 
     def test_missing_value(self):
@@ -180,16 +180,16 @@
             'UPDATE_SUBMIT' : '',
             'field.s1' : u'a' })
         self.assertEqual(response.getStatus(), 200)
-        self.assert_(patternExists(
-            'name="field.s1".*Too short', response.getBody()))
+        self.assert_(validationErrorExists(
+            's1', 'Too short', response.getBody()))
 
         # submit value for s1 that is too long
         response = self.publish('/test/edit.html', form={
             'UPDATE_SUBMIT' : '',
             'field.s1' : u'12345678901' })
         self.assertEqual(response.getStatus(), 200)
-        self.assert_(validationErrorExists('s1', 'Too long',
-            response.getBody()))
+        self.assert_(validationErrorExists(
+            's1', 'Too long', response.getBody()))
 
 
     def test_omitted_value(self):




More information about the Zope3-Checkins mailing list