From 8f69e16e687326ced9a4062502b137b398f0480d Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Thu, 25 Jan 2024 16:03:03 +0100 Subject: [PATCH 1/2] fix tests with timezone --- .../tests/test_publication_fields_fixes.py | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/redturtle/volto/tests/test_publication_fields_fixes.py b/src/redturtle/volto/tests/test_publication_fields_fixes.py index 4039002..832c339 100644 --- a/src/redturtle/volto/tests/test_publication_fields_fixes.py +++ b/src/redturtle/volto/tests/test_publication_fields_fixes.py @@ -1,13 +1,17 @@ # -*- coding: utf-8 -*- import os import unittest +from datetime import timedelta from DateTime import DateTime +from plone.app.event.base import localized_now +from plone.app.event.testing import set_env_timezone from plone.app.testing import SITE_OWNER_NAME from plone.app.testing import SITE_OWNER_PASSWORD from plone.app.testing import TEST_USER_ID from plone.app.testing import setRoles from plone.registry.interfaces import IRegistry +from plone.restapi.serializer.converters import json_compatible from plone.restapi.testing import RelativeSession from transaction import commit from zope.component import getUtility @@ -19,8 +23,9 @@ class TestPublicationFieldsFixes(unittest.TestCase): layer = REDTURTLE_VOLTO_API_FUNCTIONAL_TESTING def setUp(self): - tz = os.environ.get("TZ", "UTC") - + self.orig_env_tz = os.environ.get("TZ", None) + tz = "Europe/Rome" + set_env_timezone(tz) registry = getUtility(IRegistry) self._orig_tz = ( registry["plone.portal_timezone"], @@ -28,6 +33,8 @@ def setUp(self): ) registry["plone.portal_timezone"] = tz registry["plone.available_timezones"] = [tz] + commit() + self.app = self.layer["app"] self.portal = self.layer["portal"] self.portal_url = self.portal.absolute_url() @@ -37,25 +44,24 @@ def setUp(self): self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) - commit() - def tearDown(self): self.api_session.close() registry = getUtility(IRegistry) registry["plone.portal_timezone"] = self._orig_tz[0] registry["plone.available_timezones"] = self._orig_tz[1] + set_env_timezone(self.orig_env_tz) def test_set_effective_date_store_right_value_in_plone(self): - effective = DateTime() - expires = effective + 1 + effective = localized_now() + expires = effective + timedelta(days=1) self.api_session.post( self.portal_url, json={ "@type": "Document", "id": "mydocument", "title": "My Document", - "effective": "{}Z".format(effective.utcdatetime().isoformat()), - "expires": "{}Z".format(expires.utcdatetime().isoformat()), + "effective": f"{json_compatible(effective)}", + "expires": f"{json_compatible(expires)}", }, ) commit() From b945abc62c2cd23e7f93c6c2fa9cb04f42f2811b Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Thu, 25 Jan 2024 16:03:16 +0100 Subject: [PATCH 2/2] fix tests with timezone --- src/redturtle/volto/tests/test_publication_fields_fixes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/redturtle/volto/tests/test_publication_fields_fixes.py b/src/redturtle/volto/tests/test_publication_fields_fixes.py index 832c339..509d594 100644 --- a/src/redturtle/volto/tests/test_publication_fields_fixes.py +++ b/src/redturtle/volto/tests/test_publication_fields_fixes.py @@ -3,7 +3,6 @@ import unittest from datetime import timedelta -from DateTime import DateTime from plone.app.event.base import localized_now from plone.app.event.testing import set_env_timezone from plone.app.testing import SITE_OWNER_NAME