[Zope3-checkins] SVN: zope.formlib/branches/faassen-zaf/src/zope/formlib/ Port over objectwidget functional test over to zope.formlib. This

Martijn Faassen faassen at startifact.com
Sat Jan 2 13:30:01 EST 2010


Log message for revision 107564:
  Port over objectwidget functional test over to zope.formlib. This
  actually uncovered a problem in that the widget_macros template
  needs to be registered before it worked.
  
  Hacked up test_functional_objectwidget to set up the right configuration
  to do the test, but it's extremely messy.
  

Changed:
  U   zope.formlib/branches/faassen-zaf/src/zope/formlib/configure.zcml
  U   zope.formlib/branches/faassen-zaf/src/zope/formlib/objectwidget.pt
  A   zope.formlib/branches/faassen-zaf/src/zope/formlib/tests/test_functional_objectwidget.py
  A   zope.formlib/branches/faassen-zaf/src/zope/formlib/widget_macros.pt

-=-
Modified: zope.formlib/branches/faassen-zaf/src/zope/formlib/configure.zcml
===================================================================
--- zope.formlib/branches/faassen-zaf/src/zope/formlib/configure.zcml	2010-01-02 18:22:26 UTC (rev 107563)
+++ zope.formlib/branches/faassen-zaf/src/zope/formlib/configure.zcml	2010-01-02 18:30:00 UTC (rev 107564)
@@ -1,8 +1,19 @@
 <configure
     xmlns="http://namespaces.zope.org/zope"
+    xmlns:browser="http://namespaces.zope.org/browser"
     i18n_domain="zope">
 
+  <include package="zope.component" file="meta.zcml" />
+  <include package="zope.security" file="meta.zcml" />
+  <include package="zope.browserpage" file="meta.zcml" />
 
+  <browser:page
+      for="*"
+      name="widget_macros"
+      permission="zope.Public"
+      template="widget_macros.pt"
+      />
+  
   <adapter factory=".form.default_page_template" name="default" />
   <adapter factory=".form.default_subpage_template" name="default" />
   <adapter factory=".form.render_submit_button" name="render" />

Modified: zope.formlib/branches/faassen-zaf/src/zope/formlib/objectwidget.pt
===================================================================
--- zope.formlib/branches/faassen-zaf/src/zope/formlib/objectwidget.pt	2010-01-02 18:22:26 UTC (rev 107563)
+++ zope.formlib/branches/faassen-zaf/src/zope/formlib/objectwidget.pt	2010-01-02 18:30:00 UTC (rev 107564)
@@ -2,6 +2,6 @@
   <legend tal:content="context/legendTitle"
         i18n:translate="">The Legend</legend>
   <div class="row" tal:repeat="widget context/subwidgets">
-    <metal:block use-macro="context/@@form_macros/widget_row" />
+    <metal:block use-macro="context/@@widget_macros/widget_row" />
   </div>
 </fieldset>

Copied: zope.formlib/branches/faassen-zaf/src/zope/formlib/tests/test_functional_objectwidget.py (from rev 107495, zope.app.form/branches/faassen-zaf/src/zope/app/form/browser/tests/test_functional_objectwidget.py)
===================================================================
--- zope.formlib/branches/faassen-zaf/src/zope/formlib/tests/test_functional_objectwidget.py	                        (rev 0)
+++ zope.formlib/branches/faassen-zaf/src/zope/formlib/tests/test_functional_objectwidget.py	2010-01-02 18:30:00 UTC (rev 107564)
@@ -0,0 +1,114 @@
+##############################################################################
+#
+# 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.1 (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 object widget
+
+$Id$
+"""
+import unittest
+
+from zope.pagetemplate.pagetemplate import PageTemplate
+import zope.traversing.interfaces
+from zope.component import provideAdapter
+from zope.traversing.adapters import DefaultTraversable
+from zope.component.testing import PlacelessSetup
+from zope.interface import Interface, implements
+from zope.schema import TextLine, Object, Choice
+from zope.formlib import form
+from zope.publisher.browser import TestRequest
+from zope.formlib.tests.support import patternExists
+from zope.formlib.widgets import TextWidget, ObjectWidget
+from zope.formlib.tests.functionalsupport import FunctionalWidgetTestCase
+from zope.formlib.tests.support import VerifyResults
+import zope.schema.interfaces
+from zope.traversing.testing import setUp as traversingSetUp
+from zope.configuration import xmlconfig
+import zope.formlib
+import os
+
+class ITestContact(Interface):
+    name = TextLine()
+    email = TextLine()
+
+class TestContact(object):
+    implements(ITestContact)
+
+class Form(form.EditForm):
+    form_fields = form.fields(ITestContact)
+
+class Test(PlacelessSetup, unittest.TestCase, VerifyResults):
+
+    def setUp(self):
+        super(Test, self).setUp()
+        traversingSetUp()
+        # XXX this whole test setup is rather involved. Is there a
+        # simpler way to publish widget_macros.pt? Probably.
+        
+        # load the registrations for formlib
+        context = xmlconfig.file("configure.zcml",
+                                 zope.formlib)
+
+        # set up the widget_macros macro
+        macro_template = PageTemplate()
+        widget_macros = os.path.join(os.path.dirname(zope.formlib.__file__),
+                                     'widget_macros.pt')
+        
+        f = open(widget_macros, 'r')
+        data = f.read()
+        f.close()
+        macro_template.write(data)
+        class view:
+            zope.component.adapts(None, None)
+            zope.interface.implements(zope.traversing.interfaces.ITraversable)
+            def __init__(self, ob, r=None):
+                pass
+            def traverse(*args):
+                return macro_template.macros
+        provideAdapter(view, name='view')
+        provideAdapter(DefaultTraversable, [None])
+
+    def test_new(self):
+        request = TestRequest()
+        field = Object(ITestContact, __name__=u'foo')
+
+        widget = ObjectWidget(field, request, TestContact)
+
+        self.assertEquals(int(widget.hasInput()), 0)
+        check_list = (
+            'input', 'name="field.foo.name"',
+            'input', 'name="field.foo.email"'
+        )
+        self.verifyResult(widget(), check_list)
+
+    def test_edit(self):
+        request = TestRequest(form={
+            'field.foo.name': u'fred',
+            'field.foo.email': u'fred at fred.com'
+            })
+        field = Object(ITestContact, __name__=u'foo')
+        widget = ObjectWidget(field, request, TestContact)
+        self.assertEquals(int(widget.hasInput()), 1)
+        o = widget.getInputValue()
+        self.assertEquals(hasattr(o, 'name'), 1)
+        self.assertEquals(o.name, u'fred')
+        self.assertEquals(o.email, u'fred at fred.com')
+        check_list = (
+            'input', 'name="field.foo.name"', 'value="fred"',
+            'input', 'name="field.foo.email"', 'value="fred at fred.com"',
+        )
+        self.verifyResult(widget(), check_list)
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(Test))
+    return suite

Copied: zope.formlib/branches/faassen-zaf/src/zope/formlib/widget_macros.pt (from rev 107495, zope.app.form/branches/faassen-zaf/src/zope/app/form/browser/widget_macros.pt)
===================================================================
--- zope.formlib/branches/faassen-zaf/src/zope/formlib/widget_macros.pt	                        (rev 0)
+++ zope.formlib/branches/faassen-zaf/src/zope/formlib/widget_macros.pt	2010-01-02 18:30:00 UTC (rev 107564)
@@ -0,0 +1,26 @@
+<html i18n:domain="want an empty string, but zpt would ignore it :(">
+  <body>
+    <metal:block define-macro="widget_rows">
+      <div class="row" tal:repeat="widget view/widgets">
+        <metal:block define-macro="widget_row">
+          <div class="label">
+            <label for="field.name" title="The widget's hint"
+              tal:attributes="for widget/name; title widget/hint"
+              tal:content="widget/label" i18n:attributes="title"
+              i18n:translate=""
+              >The Label</label>
+          </div>
+          <tal:block define="error widget/error"
+            condition="error" content="structure error"
+            i18n:translate=""
+            >
+            The Error
+          </tal:block>
+          <div class="field" tal:content="structure widget">
+            <input type="text" style="width:100%"/>
+          </div>
+        </metal:block>
+      </div>
+    </metal:block>
+  </body>
+</html>



More information about the Zope3-Checkins mailing list