Commit c4727cf7 authored by Jérome Perrin's avatar Jérome Perrin Committed by Arnaud Fontaine

tests: target DateTime 3 and use mock to monkey patch

mock has several advantages, the main one here is that it errors when
patching does not replace an existing attribute, which happens when we
are not patching the right place.

These attributes are not the same place in DateTime 2 and 3, this code
when using DateTime 2 was replacing the attributes, but in DateTime 3 it
was just creating new attributes that were never used. Update the code
to patch the DateTime 3 location
parent fa9f1018
Pipeline #26143 failed with stage
in 0 seconds
...@@ -26,17 +26,13 @@ ...@@ -26,17 +26,13 @@
############################################################################## ##############################################################################
import unittest import unittest
import os import os
import sys
import time import time
import mock
from unittest import expectedFailure from unittest import expectedFailure
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from DateTime import DateTime from DateTime import DateTime
# explicitly set Europe/Paris timezone
os.environ['TZ']='Europe/Paris'
time.tzset()
DateTime._localzone0 = 'GMT+1'
DateTime._localzone1 = 'GMT+2'
DateTime._multipleZones = True
class TestOpenOrder(ERP5TypeTestCase): class TestOpenOrder(ERP5TypeTestCase):
""" """
...@@ -47,6 +43,19 @@ class TestOpenOrder(ERP5TypeTestCase): ...@@ -47,6 +43,19 @@ class TestOpenOrder(ERP5TypeTestCase):
return 'Test Open Order' return 'Test Open Order'
def afterSetUp(self): def afterSetUp(self):
# explicitly set Europe/Paris timezone
# We use mock, to make sure we patch in the right place, but the stopping
# the patcher does not really work as we also have to set TZ
os.environ['TZ'] = 'Europe/Paris'
time.tzset()
for patcher in (
mock.patch.object(sys.modules['DateTime.DateTime'], '_localzone0', new='GMT+1'),
mock.patch.object(sys.modules['DateTime.DateTime'], '_localzone1', new='GMT+2'),
mock.patch.object(sys.modules['DateTime.DateTime'], '_multipleZones', new=True),
):
patcher.start()
self.addCleanup(patcher.stop)
if getattr(self.portal, '_run_after_setup', None) is not None: if getattr(self.portal, '_run_after_setup', None) is not None:
return return
......
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