[Zope3-checkins] SVN: zope.formlib/branches/faassen-zaf/src/zope/formlib/tests/ Prepare porting of more functional tests.

Martijn Faassen faassen at startifact.com
Wed Dec 30 19:41:15 EST 2009


Log message for revision 107416:
  Prepare porting of more functional tests.
  

Changed:
  A   zope.formlib/branches/faassen-zaf/src/zope/formlib/tests/functionalsupport.py
  U   zope.formlib/branches/faassen-zaf/src/zope/formlib/tests/test_functional_booleanradiowidget.py

-=-
Added: zope.formlib/branches/faassen-zaf/src/zope/formlib/tests/functionalsupport.py
===================================================================
--- zope.formlib/branches/faassen-zaf/src/zope/formlib/tests/functionalsupport.py	                        (rev 0)
+++ zope.formlib/branches/faassen-zaf/src/zope/formlib/tests/functionalsupport.py	2009-12-31 00:41:15 UTC (rev 107416)
@@ -0,0 +1,91 @@
+"""Support code for functional widget tests.
+"""
+
+from zope.browserpage.namedtemplate import NamedTemplateImplementation
+from zope.component import adapter
+from zope.component import provideAdapter
+from zope.component.testing import setUp, tearDown
+from zope.formlib import form
+from zope.formlib.errors import InvalidErrorView
+from zope.formlib.exception import WidgetInputErrorView
+from zope.formlib.interfaces import (
+    IInputWidget, IForm,
+    IWidgetInputError, IWidgetInputErrorView)
+from zope.formlib.tests.support import patternExists
+from zope.formlib.tests.test_formlib import requestToTZInfo
+from zope.formlib.widgets import BooleanRadioWidget
+from zope.i18n.testing import setUp as i18nSetUp
+from zope.interface import Interface, implements, Invalid
+from zope.publisher.browser import TestRequest
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.schema import Bool
+import unittest
+import zope.i18n
+import zope.schema.interfaces
+
+ at adapter(IForm)
+ at NamedTemplateImplementation
+def TestTemplate(self):
+    status = self.status
+    if status:
+        status = zope.i18n.translate(status,
+                                     context=self.request,
+                                     default=self.status)
+        if getattr(status, 'mapping', 0):
+            status = zope.i18n.interpolate(status, status.mapping)
+
+    result = []
+
+    if self.errors:
+        for error in self.errors:
+            result.append("%s: %s" % (error.__class__.__name__, error))
+
+    for w in self.widgets:
+        result.append(w())
+        error = w.error()
+        if error:
+            result.append(str(error))
+
+    for action in self.availableActions():
+        result.append(action.render())
+
+    return '\n'.join(result)
+
+def formSetUp(test):
+    setUp(test)
+    i18nSetUp(test)
+    provideAdapter(
+        test.widget,
+        (test.field,
+         IBrowserRequest),
+        IInputWidget)
+    
+    provideAdapter(
+       WidgetInputErrorView,
+        (IWidgetInputError,
+         IBrowserRequest),
+        IWidgetInputErrorView,
+        )
+    provideAdapter(
+        InvalidErrorView,
+        (Invalid,
+         IBrowserRequest),
+        IWidgetInputErrorView,
+        )
+
+    provideAdapter(TestTemplate, name='default')
+    provideAdapter(requestToTZInfo)
+    provideAdapter(
+        form.render_submit_button, name='render')
+
+class FunctionalWidgetTestCase(unittest.TestCase):
+    widget = None
+    field = None
+    
+    def setUp(self):
+        formSetUp(self)
+
+    def tearDown(self):
+        tearDown(self)
+
+

Modified: zope.formlib/branches/faassen-zaf/src/zope/formlib/tests/test_functional_booleanradiowidget.py
===================================================================
--- zope.formlib/branches/faassen-zaf/src/zope/formlib/tests/test_functional_booleanradiowidget.py	2009-12-31 00:32:10 UTC (rev 107415)
+++ zope.formlib/branches/faassen-zaf/src/zope/formlib/tests/test_functional_booleanradiowidget.py	2009-12-31 00:41:15 UTC (rev 107416)
@@ -23,86 +23,14 @@
 from zope.publisher.browser import TestRequest
 from zope.formlib.tests.support import patternExists
 from zope.formlib.widgets import BooleanRadioWidget
-from zope.component.testing import setUp, tearDown
-from zope.component import provideAdapter
-from zope.i18n.testing import setUp as i18nSetUp
-from zope.publisher.interfaces.browser import IBrowserRequest
-import zope.formlib
-from zope.formlib.tests.test_formlib import requestToTZInfo
-from zope.formlib.exception import WidgetInputErrorView
-from zope.formlib.interfaces import IWidgetInputError, IWidgetInputErrorView
-import zope.interface
-from zope.formlib.errors import InvalidErrorView
+from zope.formlib.tests.functionalsupport import FunctionalWidgetTestCase
 import zope.schema.interfaces
-from zope.formlib.interfaces import IInputWidget, IForm
-from zope.interface import Invalid
-from zope.browserpage.namedtemplate import NamedTemplateImplementation
-from zope.component import adapter
-import zope.i18n
 
- at adapter(IForm)
- at NamedTemplateImplementation
-def TestTemplate(self):
-    status = self.status
-    if status:
-        status = zope.i18n.translate(status,
-                                     context=self.request,
-                                     default=self.status)
-        if getattr(status, 'mapping', 0):
-            status = zope.i18n.interpolate(status, status.mapping)
-
-    result = []
-
-    if self.errors:
-        for error in self.errors:
-            result.append("%s: %s" % (error.__class__.__name__, error))
-
-    for w in self.widgets:
-        result.append(w())
-        error = w.error()
-        if error:
-            result.append(str(error))
-
-    for action in self.availableActions():
-        result.append(action.render())
-
-    return '\n'.join(result)
-
-def formSetUp(test):
-    setUp(test)
-    i18nSetUp(test)
-    provideAdapter(
-        BooleanRadioWidget,
-        (zope.schema.interfaces.IBool,
-         IBrowserRequest),
-        IInputWidget)
-    
-    provideAdapter(
-       WidgetInputErrorView,
-        (IWidgetInputError,
-         IBrowserRequest),
-        IWidgetInputErrorView,
-        )
-    provideAdapter(
-        InvalidErrorView,
-        (Invalid,
-         IBrowserRequest),
-        IWidgetInputErrorView,
-        )
-
-    provideAdapter(TestTemplate, name='default')
-    provideAdapter(requestToTZInfo)
-    provideAdapter(
-        zope.formlib.form.render_submit_button, name='render')
-    
 class IFoo(Interface):
-
     bar = Bool(title=u'Bar')
 
 class Foo(object):
-
     implements(IFoo)
-
     def __init__(self):
         self.bar = True
 
@@ -111,13 +39,10 @@
     form_fields['bar'].custom_widget = BooleanRadioWidget
 
     
-class Test(unittest.TestCase):
-    def setUp(self):
-        formSetUp(self)
-
-    def tearDown(self):
-        tearDown(self)
-    
+class Test(FunctionalWidgetTestCase):
+    widget = BooleanRadioWidget
+    field = zope.schema.interfaces.IBool
+        
     def test_display_editform(self):
         foo = Foo()
         request = TestRequest()
@@ -143,7 +68,7 @@
         request = TestRequest()
         request.form['form.bar'] = 'off'
         request.form['form.actions.apply'] = u''
-        html = Form(foo, request)()
+        Form(foo, request)()
 
         self.assertEqual(foo.bar, False)
 
@@ -158,7 +83,7 @@
         request.form['form.bar-empty-marker'] = ''
         request.form['form.actions.apply'] = u''
 
-        html = Form(foo, request)()
+        Form(foo, request)()
  
         # confirm use of missing_value as new object value
         self.assert_(IFoo['bar'].missing_value is None)
@@ -199,6 +124,3 @@
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(Test))
     return suite
-
-if __name__=='__main__':
-    unittest.main(defaultTest='test_suite')



More information about the Zope3-Checkins mailing list