[Checkins] SVN: z3ext.layoutform/trunk/s added basic tests

Nikolay Kim fafhrd at datacom.kz
Thu Nov 27 12:53:33 EST 2008


Log message for revision 93409:
  added basic tests

Changed:
  U   z3ext.layoutform/trunk/setup.py
  U   z3ext.layoutform/trunk/src/z3ext/layoutform/add.py
  A   z3ext.layoutform/trunk/src/z3ext/layoutform/tests/
  A   z3ext.layoutform/trunk/src/z3ext/layoutform/tests/__init__.py
  A   z3ext.layoutform/trunk/src/z3ext/layoutform/tests/ftesting.zcml
  A   z3ext.layoutform/trunk/src/z3ext/layoutform/tests/tests.py
  A   z3ext.layoutform/trunk/src/z3ext/layoutform/tests/tests.txt

-=-
Modified: z3ext.layoutform/trunk/setup.py
===================================================================
--- z3ext.layoutform/trunk/setup.py	2008-11-27 15:48:20 UTC (rev 93408)
+++ z3ext.layoutform/trunk/setup.py	2008-11-27 17:53:32 UTC (rev 93409)
@@ -64,10 +64,7 @@
 			  'z3ext.resourcepackage>=1.2.0',
 			  'z3ext.statusmessage',
                           ],
-      extras_require = dict(test=['zope.app.testing',
-                                  'zope.testing',
-				  'zope.testbrowser',
-                                  ]),
+      extras_require = dict(test=['zope.testing']),
       include_package_data = True,
       zip_safe = False
       )

Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/add.py
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/add.py	2008-11-27 15:48:20 UTC (rev 93408)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/add.py	2008-11-27 17:53:32 UTC (rev 93409)
@@ -74,7 +74,7 @@
             url = absoluteURL(self.context, self.request)
         else:
             url = absoluteURL(self._addedObject, self.request)
-            
+
         return '%s/@@SelectedManagementView.html'%url
 
     def cancelURL(self):

Added: z3ext.layoutform/trunk/src/z3ext/layoutform/tests/__init__.py
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/tests/__init__.py	                        (rev 0)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/tests/__init__.py	2008-11-27 17:53:32 UTC (rev 93409)
@@ -0,0 +1 @@
+# This file is necessary to make this directory a package.

Added: z3ext.layoutform/trunk/src/z3ext/layoutform/tests/ftesting.zcml
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/tests/ftesting.zcml	                        (rev 0)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/tests/ftesting.zcml	2008-11-27 17:53:32 UTC (rev 93409)
@@ -0,0 +1,14 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope">
+
+  <include package="zope.component" file="meta.zcml" />
+  <include package="zope.app.component" file="meta.zcml" />
+  <include package="zope.app.security" file="meta.zcml" />
+  <include package="zope.app.pagetemplate" file="meta.zcml" />
+  <include package="zope.app.security" />
+  <include package="zope.app.zcmlfiles" />
+
+  <include package="z3c.autoinclude" file="meta.zcml" />
+  <include package="z3ext.layoutform" />
+
+</configure>

Added: z3ext.layoutform/trunk/src/z3ext/layoutform/tests/tests.py
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/tests/tests.py	                        (rev 0)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/tests/tests.py	2008-11-27 17:53:32 UTC (rev 93409)
@@ -0,0 +1,33 @@
+##############################################################################
+#
+# Copyright (c) 2008 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.
+#
+##############################################################################
+"""
+
+$Id:  2007-12-12 12:27:02Z fafhrd $
+"""
+import unittest, os
+from zope.testing import doctest
+from zope.app.testing.functional import ZCMLLayer, FunctionalDocFileSuite
+
+layoutformLayer = ZCMLLayer(
+    os.path.join(os.path.split(__file__)[0], 'ftesting.zcml'),
+    __name__, 'layoutformLayer', allow_teardown=True)
+
+
+def test_suite():
+    tests = FunctionalDocFileSuite(
+        "tests.txt",
+        optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
+    tests.layer = layoutformLayer
+
+    return unittest.TestSuite((tests,))

Added: z3ext.layoutform/trunk/src/z3ext/layoutform/tests/tests.txt
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/tests/tests.txt	                        (rev 0)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/tests/tests.txt	2008-11-27 17:53:32 UTC (rev 93409)
@@ -0,0 +1,125 @@
+===========
+z3c.form ui
+===========
+
+  >>> from zope.app.testing.functional import getRootFolder
+  >>> root = getRootFolder()
+
+  >>> from zope import interface, schema
+
+  >>> class AgeError(schema.interfaces.ValidationError):
+  ...     __doc__ = _("""Minimu age is 20 years.""")
+
+  >>> class IPerson(interface.Interface):
+  ...
+  ...     name = schema.TextLine(
+  ...         title=u'Name',
+  ...         required=True)
+  ...
+  ...     age = schema.Int(
+  ...         title=u'Age',
+  ...         description=u"The person's age.",
+  ...         min=0,
+  ...         default=20,
+  ...         required=False)
+  ...     
+  ...     @interface.invariant
+  ...     def startEndDates(person):
+  ...         if person.age < 20:
+  ...             raise AgeError()
+
+
+  >>> from zope.schema.fieldproperty import FieldProperty
+  >>> class Person(object):
+  ...     interface.implements(IPerson)
+  ...
+  ...     name = FieldProperty(IPerson['name'])
+  ...     age = FieldProperty(IPerson['age'])
+  ...
+  ...     def __init__(self, name, age):
+  ...         self.name = name
+  ...         self.age = age
+  ...
+  ...     def __repr__(self):
+  ...         return '<%s %r>' % (self.__class__.__name__, self.name)
+
+
+  >>> from z3c.form import field
+  >>> from z3ext.layoutform import PageletAddForm
+  >>> class PersonAddForm(PageletAddForm):
+  ...
+  ...     fields = field.Fields(IPerson)
+  ...
+  ...     def create(self, data):
+  ...         return Person(**data)
+  ...
+  ...     def add(self, object):
+  ...         self.context[object.id] = object
+  ...
+  ...     def nextURL(self):
+  ...         return 'index.html'
+
+Let's create a request:
+
+  >>> from z3c.form.testing import TestRequest
+  >>> request = TestRequest()
+
+And support the layout form layer for our request:
+
+  >>> from z3ext.layoutform.interfaces import ILayoutFormLayer
+  >>> interface.alsoProvides(request, ILayoutFormLayer)
+
+Now create the form:
+
+  >>> addForm = PersonAddForm(root, request)
+
+Let's now render the page. Note the output doesn't contain the layout template:
+
+  >>> addForm.update()
+  >>> print addForm.render()
+  <div class="z-form z-form-add"><form action="http://127.0.0.1" method="post"
+      enctype="multipart/form-data" name="form" id="form">
+    <div class="z-form-fieldset">
+      <div class="z-form-field">
+        <label for="form-widgets-name" title="">Name</label>
+        <span class="z-form-fieldRequired">&nbsp;</span>
+        <div class="z-form-help"></div>
+        <div><input type="text" id="form-widgets-name"
+                    name="form.widgets.name"
+                    class="text-widget required textline-field" value="" />
+        </div>
+      </div>
+      <div class="z-form-field">
+        <label for="form-widgets-age" title="The person's age.">Age</label>
+        <div class="z-form-help">The person's age.</div>
+        <div><input type="text" id="form-widgets-age"
+                    name="form.widgets.age" class="text-widget int-field"
+                    value="20" />
+        </div>
+      </div>
+    </div>
+    <div class="z-form-controls">
+      <hr />
+      <div class="z-form-field">
+        <label for="add_input_name">Content short name</label>
+        <div class="z-form-help">
+          Should not contain spaces, underscores or mixed case. 
+          Short Name is part of the item's web address.
+        </div>
+        <div>
+          <input type="text" name="add_input_name"
+                 id="add_input_name" />
+        </div>
+      </div>
+      <span>
+        <input type="submit" id="form-buttons-add"
+           name="form.buttons.add"
+           class="z-form-addbutton button-field" value="Add" />
+        <input type="submit" id="form-buttons-cancel"
+           name="form.buttons.cancel"
+           class="z-form-cancelbutton button-field"
+           value="Cancel" />
+      </span>
+    </div>
+  </form>
+  </div>



More information about the Checkins mailing list