Commit 82a57949 authored by Jérome Perrin's avatar Jérome Perrin

Merge remote-tracking branch 'origin/master' into zope4py2

parents b35b8d44 32e04c8a
......@@ -32,6 +32,7 @@ import unittest
from DateTime import DateTime
from erp5.component.module.DateUtils import addToDate, getIntervalListBetweenDates, \
atTheEndOfPeriod, getClosestDate
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
class TestDateUtils(unittest.TestCase):
"""
......@@ -175,7 +176,31 @@ class TestDateUtils(unittest.TestCase):
self.assertEqual('Sep. 10, 2008 12:00 am GMT-2',
getClosestDate(date=date, target_date=target_date, precision='month', before=False).pCommonZ())
class TestPinDateTime(ERP5TypeTestCase):
def test_pinDateTime(self):
actual_begin_date = DateTime()
datetime = DateTime('2001/01/01 01:01:01')
fixed_date_with_timezone = DateTime('2002/02/02 02:02:02 GMT+2')
self.pinDateTime(datetime)
self.assertEqual(DateTime(), datetime)
self.assertEqual(DateTime('2002/02/02 02:02:02 GMT+2'), fixed_date_with_timezone)
self.unpinDateTime()
self.assertGreaterEqual(DateTime(), actual_begin_date)
def test_pinDateTime_context_manager(self):
actual_begin_date = DateTime()
datetime = DateTime('2001/01/01 01:01:01')
with self.pinDateTime(datetime):
self.assertEqual(DateTime(), datetime)
self.assertGreaterEqual(DateTime(), actual_begin_date)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestDateUtils))
suite.addTest(unittest.makeSuite(TestPinDateTime))
return suite
......@@ -31,12 +31,6 @@ import time
from DateTime import DateTime
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
# As tests rely on documents exported in test bt5, setting up timezone allows
# consistency between test environment execution and virtual ERP5 instance
os.environ['TZ'] = 'GMT'
time.tzset()
DateTime._localzone0 = 'GMT'
class TestDSNSocialDeclarationReport(ERP5TypeTestCase):
"""
Test Suite for the generation of the French Social Declaration Report,
......@@ -50,8 +44,8 @@ class TestDSNSocialDeclarationReport(ERP5TypeTestCase):
"""
This is ran before anything, used to set the environment
"""
self.portal = self.getPortalObject()
self.dsn_module = self.portal.getDefaultModuleValue("DSN Monthly Report")
self.setTimeZoneToUTC()
self.pinDateTime(DateTime(2015, 12, 01))
# Create the id_group 'dsn_event_counter'
self.portal.portal_ids.generateNewId(id_group='dsn_event_counter', id_generator='continuous_integer_increasing')
......
......@@ -373,12 +373,25 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
def pinDateTime(self, date_time):
# pretend time has stopped at a certain date (i.e. the test runs
# infinitely fast), to avoid errors on tests that are started
# infinitely fast), for example to avoid errors on tests that are started
# just before midnight.
# This can be used as a context manager, otherwise use unpinDateTime to
# reset.
global _pinned_date_time
assert date_time is None or isinstance(date_time, DateTime)
_pinned_date_time = date_time
unpinDateTime = self.unpinDateTime
class UnpinContextManager(object):
def __enter__(self):
return self
def __exit__(self, *args):
unpinDateTime()
return UnpinContextManager()
def unpinDateTime(self):
self.pinDateTime(None)
def setTimeZoneToUTC(self):
# Make sure tests runs with UTC timezone. Some tests are checking values
# based on now, and this could give unexpected results:
......@@ -393,9 +406,6 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
mock.patch.object(sys.modules['DateTime.DateTime'], '_multipleZones', new=False).start()
def unpinDateTime(self):
self.pinDateTime(None)
def getDefaultSystemPreference(self):
id = 'default_system_preference'
tool = self.getPreferenceTool()
......
# Specify user login/password used to run the tests.
# <password> and <user_quantity> will be automatically replaced by testnode for each configuration
user_tuple = tuple([('scalability_user_%i' % x, "<password>") for x in range(0, <user_quantity>)])
\ No newline at end of file
user_tuple = tuple([('scalability_user_%i' % x, "<password>") for x in range(0, int('<user_quantity>'))])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment