[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/ftests -
test_registrations.py:1.1.4.1 support.py:1.3.14.1
test_filewidget.py:1.4.14.1 test_textareawidget.py:1.4.14.1
test_textwidget.py:1.5.14.1
Garrett Smith
garrett at mojave-corp.com
Thu Feb 26 00:11:21 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/browser/form/ftests
In directory cvs.zope.org:/tmp/cvs-serv25181/src/zope/app/browser/form/ftests
Modified Files:
Tag: garrett-widgets2-branch
support.py test_filewidget.py test_textareawidget.py
test_textwidget.py
Added Files:
Tag: garrett-widgets2-branch
test_registrations.py
Log Message:
Yet another branch for widgets refactoring (YABFWR).
=== Added File Zope3/src/zope/app/browser/form/ftests/test_registrations.py ===
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 IEditWidget
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, IEditWidget -> TextWidget
>>> field = fields.TextLine()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, widgets.TextWidget)
True
IText, IEditWidget -> TextAreaWidget
>>> field = fields.Text()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, widgets.TextAreaWidget)
True
ISourceText, IEditWidget -> TextAreaWidget
>>> field = fields.SourceText()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, widgets.TextAreaWidget)
True
IBytesLine, IEditWidget -> BytesWidget
>>> field = fields.BytesLine()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, widgets.BytesWidget)
True
IBytes, IEditWidget -> FileWidget
>>> field = fields.Bytes()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, widgets.FileWidget)
True
IASCII, IEditWidget -> BytesAreaWidget
>>> field = fields.ASCII()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, widgets.BytesAreaWidget)
True
IInt, IEditWidget -> IntWidget
>>> field = fields.Int()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, widgets.IntWidget)
True
IFloat, IEditWidget -> FloatWidget
>>> field = fields.Float()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, widgets.FloatWidget)
True
IDatetime, IEditWidget -> DatetimeWidget
>>> field = fields.Datetime()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, widgets.DatetimeWidget)
True
IDate, IEditWidget -> DateWidget
>>> field = fields.Date()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, widgets.DateWidget)
True
IBool, IEditWidget -> CheckBoxWidget
>>> field = fields.Bool()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, widgets.CheckBoxWidget)
True
ITuple, IEditWidget -> TupleSequenceWidget
>>> field = fields.Tuple()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, widgets.TupleSequenceWidget)
True
IList, IEditWidget -> ListSequenceWidget
>>> field = fields.List()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, widgets.ListSequenceWidget)
True
IPassword, IEditWidget -> PasswordWidget
>>> field = fields.Password()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, widgets.PasswordWidget)
True
IEnumeratedTextLine, IEditWidget -> EnumeratedTextWidget
>>> field = fields.EnumeratedTextLine()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, enumerated.EnumeratedTextWidget)
True
IEnumeratedInt, IEditWidget -> EnumeratedIntWidget
>>> field = fields.EnumeratedInt()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, enumerated.EnumeratedIntWidget)
True
IEnumeratedFloat, IEditWidget -> EnumeratedFloatWidget
>>> field = fields.EnumeratedFloat()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, enumerated.EnumeratedFloatWidget)
True
IEnumeratedDatetime, IEditWidget -> EnumeratedDatetimeWidget
>>> field = fields.EnumeratedDatetime()
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, enumerated.EnumeratedDatetimeWidget)
True
IEnumeratedDate, IEditWidget -> EnumeratedDateWidget
>>> field = fields.EnumeratedDate()
>>> widget = zapi.getViewProviding(field, IEditWidget, 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. This is counterintuitive given a reading
of configure.zcml. (XXX this should be cleaned up)
IVocabularyField, IDisplayWidget -> VocabularyDisplayWidget
>>> field = vocabulary.VocabularyField(vocab)
>>> field = field.bind(sample)
>>> widget = zapi.getViewProviding(field, IDisplayWidget, request)
>>> isinstance(widget, vocabwidgets.VocabularyDisplayWidget)
True
IVocabularyField, IEditWidget = VocabularyEditWidget
>>> field = vocabulary.VocabularyField(vocab)
>>> field = field.bind(sample)
>>> widget = zapi.getViewProviding(field, IEditWidget, 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
IVocabularyBagField, IEditWidget -> VocabularyMultiEditWidget
>>> field = vocabulary.VocabularyBagField(vocabulary=vocab)
>>> field = field.bind(sample)
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, vocabwidgets.VocabularyMultiEditWidget)
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, IEditWidget -> VocabularyListEditWidget
>>> field = vocabulary.VocabularyListField(vocabulary=vocab)
>>> field = field.bind(sample)
>>> widget = zapi.getViewProviding(field, IEditWidget, 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
IVocabularySetField, IEditWidget -> VocabularyMultiEditWidget
>>> field = vocabulary.VocabularySetField(vocabulary=vocab)
>>> field = field.bind(sample)
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, vocabwidgets.VocabularyMultiEditWidget)
True
IVocabularyUniqueListField, IDisplayWidget -> VocabularyListDisplayWidget
>>> field = vocabulary.VocabularyUniqueListField(vocabulary=vocab)
>>> field = field.bind(sample)
>>> widget = zapi.getViewProviding(field, IDisplayWidget, request)
>>> isinstance(widget, vocabwidgets.VocabularyListDisplayWidget)
True
IVocabularyUniqueListField, IEditWidget -> VocabularyMultiEditWidget
>>> field = vocabulary.VocabularyUniqueListField(vocabulary=vocab)
>>> field = field.bind(sample)
>>> widget = zapi.getViewProviding(field, IEditWidget, request)
>>> isinstance(widget, vocabwidgets.VocabularyMultiEditWidget)
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.3 => 1.3.14.1 ===
--- Zope3/src/zope/app/browser/form/ftests/support.py:1.3 Mon Jan 19 07:31:56 2004
+++ Zope3/src/zope/app/browser/form/ftests/support.py Thu Feb 26 00:10:50 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.interfaces.browser.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.4.14.1 ===
--- 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 Thu Feb 26 00:10:50 2004
@@ -33,6 +33,7 @@
from zope.app.traversing import traverse
from zope.testing.functional import BrowserTestCase
+from zope.app.interfaces.form import IEditWidget
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, IEditWidget)
class IFileTest(Interface):
=== Zope3/src/zope/app/browser/form/ftests/test_textareawidget.py 1.4 => 1.4.14.1 ===
--- 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 Thu Feb 26 00:10:50 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.5.14.1 ===
--- 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 Thu Feb 26 00:10:50 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