[Checkins] SVN: z3ext.layoutform/trunk/ update tests

Nikolay Kim fafhrd91 at gmail.com
Thu Nov 5 01:47:55 EST 2009


Log message for revision 105484:
  update tests

Changed:
  U   z3ext.layoutform/trunk/CHANGES.txt
  U   z3ext.layoutform/trunk/setup.py
  D   z3ext.layoutform/trunk/src/z3ext/layoutform/converter.py
  U   z3ext.layoutform/trunk/src/z3ext/layoutform/form.py
  D   z3ext.layoutform/trunk/src/z3ext/layoutform/overrides.zcml
  A   z3ext.layoutform/trunk/src/z3ext/layoutform/tests/addedit.txt
  U   z3ext.layoutform/trunk/src/z3ext/layoutform/tests/ftesting.zcml
  U   z3ext.layoutform/trunk/src/z3ext/layoutform/tests/tests.py

-=-
Modified: z3ext.layoutform/trunk/CHANGES.txt
===================================================================
--- z3ext.layoutform/trunk/CHANGES.txt	2009-11-04 18:40:41 UTC (rev 105483)
+++ z3ext.layoutform/trunk/CHANGES.txt	2009-11-05 06:47:55 UTC (rev 105484)
@@ -2,7 +2,7 @@
 CHANGES
 =======
 
-1.6.1 (Unreleased)
+1.7.0 (2009-11-04)
 ------------------
 
 - Update tests for z3c.form 2.2

Modified: z3ext.layoutform/trunk/setup.py
===================================================================
--- z3ext.layoutform/trunk/setup.py	2009-11-04 18:40:41 UTC (rev 105483)
+++ z3ext.layoutform/trunk/setup.py	2009-11-05 06:47:55 UTC (rev 105484)
@@ -64,8 +64,10 @@
                           'z3ext.statusmessage',
                           ],
       extras_require = dict(test=['zope.testing',
+                                  'zope.testbrowser',
                                   'zope.app.testing',
                                   'zope.app.zcmlfiles',
+                                  'z3ext.security',
                                   'z3ext.autoinclude',]),
       include_package_data = True,
       zip_safe = False

Deleted: z3ext.layoutform/trunk/src/z3ext/layoutform/converter.py
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/converter.py	2009-11-04 18:40:41 UTC (rev 105483)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/converter.py	2009-11-05 06:47:55 UTC (rev 105484)
@@ -1,51 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2009 Zope Foundation 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.
-#
-##############################################################################
-"""Patched form converters for z3c.form 1.9
-
-This module contains patched versions of z3c.form sequence converters
-that fix an exception raised when the passed value is no more in terms.
-
-This is already fixed in current z3c.form trunk (2.0+), so if you use
-2.0, you don't need these converters.
-
-$Id$
-"""
-from z3c.form import converter
-
-
-class SequenceDataConverter(converter.SequenceDataConverter):
-
-    def toWidgetValue(self, value):
-        if value is self.field.missing_value:
-            return []
-        terms = self.widget.updateTerms()
-        try:
-            return [terms.getTerm(value).token]
-        except LookupError, err:
-            return []
-
-
-class CollectionSequenceDataConverter(converter.CollectionSequenceDataConverter):
-
-    def toWidgetValue(self, value):
-        if value is self.field.missing_value:
-            return []
-        terms = self.widget.updateTerms()
-        values = []
-        for entry in value:
-            try:
-                values.append(terms.getTerm(entry).token)
-            except LookupError, err:
-                pass
-        return values

Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/form.py
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/form.py	2009-11-04 18:40:41 UTC (rev 105483)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/form.py	2009-11-05 06:47:55 UTC (rev 105484)
@@ -82,16 +82,19 @@
     noChangesMessage = _('No changes were applied.')
     formErrorsMessage = _(u'Please fix indicated errors.')
 
-    def extractData(self):
-        data, errors = super(PageletForm, self).extractData()
+    def extractData(self, setErrors=True):
+        data, errors = super(PageletForm, self).extractData(setErrors=setErrors)
         for form in self.groups:
-            formData, formErrors = form.extractData()
+            formData, formErrors = form.extractData(setErrors=setErrors)
             data.update(formData)
             if formErrors:
                 errors += formErrors
 
         for form in self.subforms:
-            formData, formErrors = form.extractData()
+            try:
+                formData, formErrors = form.extractData(setErrors=setErrors)
+            except:
+                raise 'Error', (form,)
             if formErrors:
                 errors += formErrors
 

Deleted: z3ext.layoutform/trunk/src/z3ext/layoutform/overrides.zcml
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/overrides.zcml	2009-11-04 18:40:41 UTC (rev 105483)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/overrides.zcml	2009-11-05 06:47:55 UTC (rev 105484)
@@ -1,11 +0,0 @@
-<configure xmlns="http://namespaces.zope.org/zope">
-
-  <!--
-  Note, that you definitely don't need this file if you are using
-  z3c.form 2.0+ or the current (2009-02-22) z3c.form trunk.
-  -->
-
-  <adapter factory=".converter.SequenceDataConverter" />
-  <adapter factory=".converter.CollectionSequenceDataConverter" />
-
-</configure>

Added: z3ext.layoutform/trunk/src/z3ext/layoutform/tests/addedit.txt
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/tests/addedit.txt	                        (rev 0)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/tests/addedit.txt	2009-11-05 06:47:55 UTC (rev 105484)
@@ -0,0 +1,115 @@
+========
+Add form
+========
+
+  >>> from zope import interface, component, schema
+  >>> from zope.app.component.hooks import setSite
+  >>> from zope.app.testing.functional import getRootFolder
+  >>> from zope.testbrowser.testing import Browser
+  >>> from zope.security.checker import defineChecker, Checker, CheckerPublic
+  >>> from zope.app.security.protectclass import protectSetAttribute
+
+  >>> from z3ext.layoutform import Fields
+  >>> from z3ext.layoutform.add import PageletAddForm
+  >>> from z3ext.layoutform.edit import PageletEditForm
+
+  >>> root = getRootFolder()
+
+  >>> class IPerson(interface.Interface):
+  ...
+  ...     name = schema.TextLine(
+  ...         title=u'Name',
+  ...         missing_value = u'',
+  ...         required=True)
+  ...
+  ...     age = schema.Int(
+  ...         title=u'Age',
+  ...         description=u"The person's age.",
+  ...         min=0,
+  ...         default=20,
+  ...         required=False)
+
+  >>> from z3ext.layoutform.tests.tests import Person
+
+  >>> interface.classImplements(Person, IPerson)
+
+  >>> required = {'name': CheckerPublic,
+  ...             'age': CheckerPublic}
+  >>> defineChecker(Person, Checker(required))
+
+  >>> protectSetAttribute(Person, 'name', CheckerPublic)
+  >>> protectSetAttribute(Person, 'age', CheckerPublic)
+
+implmenent and register person add form
+
+  >>> class AddPersonForm(PageletAddForm):
+  ...
+  ...     fields = Fields(IPerson)
+  ...     
+  ...     def create(self, data):
+  ...         person = Person()
+  ...         person.name = data['name']
+  ...         person.age = data['age']
+  ...         return person
+  ...     
+  ...     def add(self, content):
+  ...         self.context['person'] = content
+  ...         return self.context['person']
+
+  >>> required = {'__call__': CheckerPublic,
+  ...             'browserDefault': CheckerPublic,
+  ...             'publishTraverse': CheckerPublic}
+  >>> defineChecker(AddPersonForm, Checker(required))
+
+  >>> component.getSiteManager().registerAdapter(
+  ...     AddPersonForm, (interface.Interface, interface.Interface),
+  ...     interface.Interface, name='addperson.html')
+
+  >>> actor = Browser()
+  >>> actor.addHeader("Authorization", "Basic mgr:mgrpw")
+  >>> actor.handleErrors = False
+
+  >>> actor.open('http://localhost/addperson.html')
+  >>> actor.getControl('Cancel').click()
+  >>> actor.url
+  'http://localhost/@@contents.html'
+
+  >>> actor.open('http://localhost/addperson.html')
+  >>> actor.getControl('Add').click()
+  >>> 'Please fix indicated errors.' in actor.contents
+  True
+
+  >>> actor.getControl('Name').value = 'Nikolay'
+  >>> actor.getControl('Age').value = '30'
+  >>> actor.getControl('Add').click()
+
+  >>> print list(root.keys())
+  [u'person']
+
+
+  >>> class EditPersonForm(PageletEditForm):
+  ...
+  ...     fields = Fields(IPerson)
+
+  >>> required = {'__call__': CheckerPublic,
+  ...             'browserDefault': CheckerPublic,
+  ...             'publishTraverse': CheckerPublic}
+  >>> defineChecker(EditPersonForm, Checker(required))
+
+  >>> component.getSiteManager().registerAdapter(
+  ...     EditPersonForm, (Person, interface.Interface),
+  ...     interface.Interface, name='edit.html')
+
+  >>> actor.open('http://localhost/person/edit.html')
+
+  >>> actor.getControl('Name').value = 'Nikolay Kim'
+  >>> actor.getControl('Age').value = ''
+  >>> actor.getControl('Save').click()
+
+  >>> actor.getControl('Name').value = 'Nikolay Kim'
+  >>> actor.getControl('Age').value = '25'
+  >>> actor.getControl('Save').click()
+
+  >>> root['person'].name, root['person'].age
+  (u'Nikolay Kim', 25)
+

Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/tests/ftesting.zcml
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/tests/ftesting.zcml	2009-11-04 18:40:41 UTC (rev 105483)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/tests/ftesting.zcml	2009-11-05 06:47:55 UTC (rev 105484)
@@ -1,6 +1,7 @@
 <configure 
    xmlns="http://namespaces.zope.org/zope"
    xmlns:i18n="http://namespaces.zope.org/i18n"
+   xmlns:browser="http://namespaces.zope.org/browser"
    i18n_domain="zope">
 
   <include package="z3ext.autoinclude" file="meta.zcml" />
@@ -8,4 +9,26 @@
 
   <adapter factory="z3ext.statusmessage.tests.tests.getSession" />
 
+  <interface
+     name="DefaultSkin"
+     interface="z3ext.layoutform.tests.tests.IDefaultSkin"
+     type="zope.publisher.interfaces.browser.IBrowserSkinType" />
+
+  <browser:defaultSkin name="DefaultSkin" />
+
+  <securityPolicy
+     component="z3ext.security.securitypolicy.SecurityPolicy" />
+
+  <role id="zope.Manager" title="Site Manager" />
+  
+  <!-- Principal that tests generally run as -->
+  <principal
+      id="zope.mgr"
+      title="Manager"
+      login="mgr"
+      password="mgrpw" />
+
+  <grant role="zope.Manager" principal="zope.mgr" />
+  <grantAll role="zope.Manager" />
+ 
 </configure>

Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/tests/tests.py
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/tests/tests.py	2009-11-04 18:40:41 UTC (rev 105483)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/tests/tests.py	2009-11-05 06:47:55 UTC (rev 105484)
@@ -16,23 +16,40 @@
 $Id:  2007-12-12 12:27:02Z fafhrd $
 """
 import unittest, os
+from persistent import Persistent
 from zope.testing import doctest
 from zope.app.testing.functional import ZCMLLayer, FunctionalDocFileSuite
+from zope.app.rotterdam import Rotterdam
+from z3ext.layoutform.interfaces import ILayoutFormLayer
 
+
 layoutformLayer = ZCMLLayer(
     os.path.join(os.path.split(__file__)[0], 'ftesting.zcml'),
     __name__, 'layoutformLayer', allow_teardown=True)
 
 
+class IDefaultSkin(ILayoutFormLayer, Rotterdam):
+    """ skin """
+
+
+class Person(Persistent):
+    pass
+
+
 def test_suite():
     form = FunctionalDocFileSuite(
         "form.txt",
         optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
     form.layer = layoutformLayer
 
+    addedit = FunctionalDocFileSuite(
+        "addedit.txt",
+        optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
+    addedit.layer = layoutformLayer
+
     tests = FunctionalDocFileSuite(
         "tests.txt",
         optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
     tests.layer = layoutformLayer
 
-    return unittest.TestSuite((form, tests,))
+    return unittest.TestSuite((form, tests, addedit))



More information about the checkins mailing list