[Zope3-checkins] CVS: Zope3/src/zope/app/publisher/tests - __init__.py:1.2 test_fieldconverters.py:1.1

Tres Seaver tseaver@zope.com
Thu, 13 Feb 2003 12:46:51 -0500


Update of /cvs-repository/Zope3/src/zope/app/publisher/tests
In directory cvs.zope.org:/tmp/cvs-serv4623/src/zope/app/publisher/tests

Added Files:
	__init__.py test_fieldconverters.py 
Log Message:


  - src/zope/publisher/browser.py:

    o Remove dependency on 'zope.app.datetimeutils';  the 'field2date'
      converter is now in 'zope.app.publisher.fieldconverters'.

    o Add an API for registering / overriding field converters from
      application code.

  - src/zope/app/publisher/fieldconverters.py:

    o New home for the 'field2date' converter: it is *not available by
      default*, but must be installed by application code which needs
      it, via the 'registerZopeConverters' API.

      * This choice avoids prescribing a US-centric date/time parsing
        scheme by default.

      * Example application code which activates this converter::

        from zope.app.publisher.zopeconverters import registerZopeConverters
        registerZopeConverters()


=== Zope3/src/zope/app/publisher/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Thu Feb 13 12:46:50 2003
+++ Zope3/src/zope/app/publisher/tests/__init__.py	Thu Feb 13 12:46:20 2003
@@ -0,0 +1 @@
+#  Unit tests for zope.app.publisher.


=== Added File Zope3/src/zope/app/publisher/tests/test_fieldconverters.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.
#
##############################################################################
"""

Revision information:
$Id: test_fieldconverters.py,v 1.1 2003/02/13 17:46:20 tseaver Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from datetime import datetime

class TestFieldConverters(TestCase):

    def test_field2date_dateonly(self):

        from zope.app.publisher.fieldconverters \
            import field2date_via_datetimeutils

        dt = field2date_via_datetimeutils('2003/05/04')
        self.failUnless(isinstance(dt, datetime))
        self.assertEqual(dt.year, 2003)
        self.assertEqual(dt.month, 5)
        self.assertEqual(dt.day, 4)
        self.assertEqual(dt.hour, 0)
        self.assertEqual(dt.minute, 0)
        self.assertEqual(dt.second, 0)
        self.assertEqual(dt.tzinfo, None)

    def test_field2date_timestamp(self):

        from zope.app.publisher.fieldconverters \
            import field2date_via_datetimeutils

        dt = field2date_via_datetimeutils('2003/05/04 19:26:54')
        self.failUnless(isinstance(dt, datetime))
        self.assertEqual(dt.year, 2003)
        self.assertEqual(dt.month, 5)
        self.assertEqual(dt.day, 4)
        self.assertEqual(dt.hour, 19)
        self.assertEqual(dt.minute, 26)
        self.assertEqual(dt.second, 54)
        self.assertEqual(dt.tzinfo, None)

def test_suite():
    suite = TestSuite()
    suite.addTest(makeSuite(TestFieldConverters))
    return suite


if __name__ == '__main__':
    main()