[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Formulator/Fields/tests - testGenericFields.py:1.1.2.1

Stephan Richter srichter@cbu.edu
Fri, 1 Mar 2002 02:04:37 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Formulator/Fields/tests
In directory cvs.zope.org:/tmp/cvs-serv22190/Fields/tests

Added Files:
      Tag: srichter-OFS_Formulator-branch
	testGenericFields.py 
Log Message:
Checkin for new Formualtor layout. Much has changed since the initial
checkin:


- Both classes and instances of fields can be used as factory when creating
  views.


- Field: This object is simply a meta-data container for a piece of 
  information; for content objects these are usually its properties.


  Note: It is planned to have a CompositeField for more complex inputs, 
        such as dates.


- FieldViews are virtual objects; they are basically realized Widgets (or 
  Widgets in context)


- Validator: An object that validates data. Note that this object is 
  totally input/protocol-agnostic. Therefore the old concept of some of the
  Zope 2 Formulator validators is not applicable anymore.


- Widget: This is a generic component that is concerned about the 
  presentation of a field in a particular protocol. A difference to the 
  Zope 2 Formulator version is that the widget is also responsible of
  converting possible input-specific representation to a standard one. This
  is not yet fully implemented though.


- Form: A protocol-specific object that is concerned with the overall 
  representation of a form and its action.


- There is a Validator and Field Registry, since Fields and Validators can
  also be used independent of Formulator's goals. Fields should really 
  become the standard way to provide meta-data for properties.


Todo: (too much)


- I need to write a proper metaConfigure.py.


- Make a CompositeField.


- Create XUL Widgets.


- Clean up files.


- Finishing the conversion to the Zope 3 Formulator model.


=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/tests/testGenericFields.py ===
##############################################################################
#
# 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.0 (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
# 
##############################################################################
"""
This test suite tests all **registered** fields. The other fields are there
for historical reasons and may or may not make it into Zope 3.

$Id: testGenericFields.py,v 1.1.2.1 2002/03/01 07:04:35 srichter Exp $
"""

import unittest
from Zope.App.Formulator.Fields.Generic.DateTimeField import DateTimeField
from Zope.App.Formulator.Fields.Generic.EmailField import EmailField
from Zope.App.Formulator.Fields.Generic.FileField import FileField
from Zope.App.Formulator.Fields.Generic.FloatField import FloatField
from Zope.App.Formulator.Fields.Generic.IntegerField import IntegerField
from Zope.App.Formulator.Fields.Generic.ListField import ListField
from Zope.App.Formulator.Fields.Generic.PasswordField import PasswordField
from Zope.App.Formulator.Fields.Generic.PatternField import PatternField
from Zope.App.Formulator.Fields.Generic.StringField import StringField


class Test( unittest.TestCase ):


    def testDateTimeField(self):
        field = DateTimeField(id='some',
                              title='Something',
                              description='This is some field.',
                              required=1,
                              default='1970/01/01 00:00:00.00 GMT')

        self.assertEqual(field.id, 'some')
        self.assertEqual(field.title, 'Something')
        self.assertEqual(field.description, 'This is some field.')
        self.assertEqual(field.required, 1)
        self.assertEqual(field.default, '1970/01/01 00:00:00.00 GMT')


    def testEmailField(self):
        field = EmailField(id='some',
                           title='Something',
                           description='This is some field.',
                           required=1,
                           default='zope3@zope.org')

        self.assertEqual(field.id, 'some')
        self.assertEqual(field.title, 'Something')
        self.assertEqual(field.description, 'This is some field.')
        self.assertEqual(field.required, 1)
        self.assertEqual(field.default, 'zope3@zope.org')


    def testFileField(self):
        field = FileField(id='some',
                          title='Something',
                          description='This is some field.',
                          required=1,
                          default='')

        self.assertEqual(field.id, 'some')
        self.assertEqual(field.title, 'Something')
        self.assertEqual(field.description, 'This is some field.')
        self.assertEqual(field.required, 1)
        self.assertEqual(field.default, '')


    def testFloatField(self):
        field = FloatField(id='some',
                          title='Something',
                          description='This is some field.',
                          required=1,
                          default=3.3)

        self.assertEqual(field.id, 'some')
        self.assertEqual(field.title, 'Something')
        self.assertEqual(field.description, 'This is some field.')
        self.assertEqual(field.required, 1)
        self.assertEqual(field.default, 3.3)


    def testIntegerField(self):
        field = IntegerField(id='some',
                             title='Something',
                             description='This is some field.',
                             required=1,
                             default=3)

        self.assertEqual(field.id, 'some')
        self.assertEqual(field.title, 'Something')
        self.assertEqual(field.description, 'This is some field.')
        self.assertEqual(field.required, 1)
        self.assertEqual(field.default, 3)


    def testListField(self):
        field = ListField(id='some',
                          title='Something',
                          description='This is some field.',
                          required=1,
                          default=[0, 1, 2])

        self.assertEqual(field.id, 'some')
        self.assertEqual(field.title, 'Something')
        self.assertEqual(field.description, 'This is some field.')
        self.assertEqual(field.required, 1)
        self.assertEqual(field.default, [0, 1, 2])


    def testPasswordField(self):
        field = PasswordField(id='some',
                              title='Something',
                              description='This is some field.',
                              required=1,
                              default='pass')

        self.assertEqual(field.id, 'some')
        self.assertEqual(field.title, 'Something')
        self.assertEqual(field.description, 'This is some field.')
        self.assertEqual(field.required, 1)
        self.assertEqual(field.default, 'pass')


    def testPatternField(self):
        field = PatternField(id='some',
                              title='Something',
                              description='This is some field.',
                              required=1,
                              default='eee.dd')

        self.assertEqual(field.id, 'some')
        self.assertEqual(field.title, 'Something')
        self.assertEqual(field.description, 'This is some field.')
        self.assertEqual(field.required, 1)
        self.assertEqual(field.default, 'eee.dd')


    def testStringField(self):
        field = StringField(id='some',
                            title='Something',
                            description='This is some field.',
                            required=1,
                            default='Empty')

        self.assertEqual(field.context, None)
        self.assertEqual(field.id, 'some')
        self.assertEqual(field.title, 'Something')
        self.assertEqual(field.description, 'This is some field.')
        self.assertEqual(field.required, 1)
        self.assertEqual(field.default, 'Empty')



def test_suite():
    loader = unittest.TestLoader()
    return loader.loadTestsFromTestCase( Test )


if __name__=='__main__':
    unittest.TextTestRunner().run( test_suite() )