[Erp5-report] r19145 - /erp5/trunk/products/ERP5Type/tests/testDateUtils.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Feb 7 19:08:39 CET 2008


Author: nicolas
Date: Thu Feb  7 19:08:34 2008
New Revision: 19145

URL: http://svn.erp5.org?rev=19145&view=rev
Log:
Add test for addToDate

Added:
    erp5/trunk/products/ERP5Type/tests/testDateUtils.py

Added: erp5/trunk/products/ERP5Type/tests/testDateUtils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/testDateUtils.py?rev=19145&view=auto
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/testDateUtils.py (added)
+++ erp5/trunk/products/ERP5Type/tests/testDateUtils.py Thu Feb  7 19:08:34 2008
@@ -1,0 +1,127 @@
+##############################################################################
+#
+# Copyright (c) 2007 Nexedi SARL and Contributors. All Rights Reserved.
+#          Jerome Perrin <jerome at nexedi.com>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+##############################################################################
+
+import unittest
+
+# Make it possible to use Globals.get_request
+class DummyRequest(dict):
+  __allow_access_to_unprotected_subobjects__ = 1
+  def set(self, k, v):
+    self[k] = v
+
+global request
+request = DummyRequest()
+
+def get_request():
+  global request
+  return request
+
+# apply patch (before it's imported by other modules)
+import Globals
+Globals.get_request = get_request
+
+
+# Initialize ERP5Form Product to load monkey patches
+from Testing import ZopeTestCase
+ZopeTestCase.installProduct('ERP5Type')
+
+
+from DateTime import DateTime
+from Products.ERP5Type.DateUtils import addToDate
+
+class TestDateUtils(unittest.TestCase):
+  """Tests field value caching system
+  """
+
+  def getTitle(self):
+    return "Date Utils"
+
+  def test_integer_add_to_date(self):
+    date = DateTime('2000/01/01 UTC')
+    self.assertEqual(DateTime('2000/01/01 00:01:30 UTC').ISO(),
+                              addToDate(date, second=90).ISO())
+    self.assertEqual(DateTime('2000/01/01 01:30:00 UTC').ISO(),
+                              addToDate(date, minute=90).ISO())
+    self.assertEqual(DateTime('2000/01/04 18:00:00 UTC').ISO(),
+                              addToDate(date, hour=90).ISO())
+    self.assertEqual(DateTime('2000/03/31 UTC').ISO(),
+                              addToDate(date, day=90).ISO())
+    self.assertEqual(DateTime('2007/07/01 UTC').ISO(),
+                              addToDate(date, month=90).ISO())
+    self.assertEqual(DateTime('2090/01/01 UTC').ISO(),
+                              addToDate(date, year=90).ISO())
+
+  def test_negative_add_to_date(self):
+    date = DateTime('2000/01/01 UTC')
+    self.assertEqual(DateTime('1999/12/31 23:59:59 UTC').ISO(),
+                              addToDate(date, second=-1).ISO())
+    self.assertEqual(DateTime('1999/12/31 23:59:00 UTC').ISO(),
+                              addToDate(date, minute=-1).ISO())
+    self.assertEqual(DateTime('1999/12/31 23:00:00 UTC').ISO(),
+                              addToDate(date, hour=-1).ISO())
+    self.assertEqual(DateTime('1999/12/31 00:00:00 UTC').ISO(),
+                              addToDate(date, day=-1).ISO())
+    self.assertEqual(DateTime('1999/12/01 00:00:00 UTC').ISO(),
+                              addToDate(date, month=-1).ISO())
+    self.assertEqual(DateTime('1999/01/01').ISO(),
+                              addToDate(date, year=-1).ISO())
+
+  def test_float_add_to_date(self):
+    date = DateTime('2000/01/01 UTC')
+    self.assertEqual(DateTime('2000/01/01').ISO(),
+                              addToDate(date, second=0.5).ISO())
+    self.assertEqual(DateTime('2000/01/01 00:00:30 UTC').ISO(),
+                              addToDate(date, minute=0.5).ISO())
+    self.assertEqual(DateTime('2000/01/01 00:30:00 UTC').ISO(),
+                              addToDate(date, hour=0.5).ISO())
+    self.assertEqual(DateTime('2000/01/01 12:00:00 UTC').ISO(),
+                              addToDate(date, day=0.5).ISO())
+    self.assertEqual(DateTime('2000/01/16 12:00:00 UTC').ISO(),
+                              addToDate(date, month=0.5).ISO())
+    self.assertEqual(DateTime('2000/07/01').ISO(),
+                              addToDate(date, year=0.5).ISO())
+
+  def test_complex_float_add_to_date(self):
+    complex_date = DateTime('2004/03/16 01:23:54 UTC')
+    self.assertEqual(DateTime('2004/03/16 01:23:54 UTC').ISO(),
+                              addToDate(complex_date, second=0.5).ISO())
+    self.assertEqual(DateTime('2004/03/16 01:24:24 UTC').ISO(),
+                              addToDate(complex_date, minute=0.5).ISO())
+    self.assertEqual(DateTime('2004/03/16 01:53:54 UTC').ISO(),
+                              addToDate(complex_date, hour=0.5).ISO())
+    self.assertEqual(DateTime('2004/03/16 13:23:54 UTC').ISO(),
+                              addToDate(complex_date, day=0.5).ISO())
+    self.assertEqual(DateTime('2004/03/31 13:23:54 UTC').ISO(),
+                              addToDate(complex_date, month=0.5).ISO())
+    self.assertEqual(DateTime('2004/09/16 01:23:54 UTC').ISO(),
+                              addToDate(complex_date, year=0.5).ISO())
+
+def test_suite():
+  suite = unittest.TestSuite()
+  suite.addTest(unittest.makeSuite(TestDateUtils))
+  return suite




More information about the Erp5-report mailing list