Skip to content

Commit

Permalink
Merge branch 'master' into bug50853_recurrence_catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Jan 29, 2024
2 parents b7e406b + 35ccaf0 commit e506570
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/redturtle/volto/tests/test_publication_fields_fixes.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# -*- 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
Expand All @@ -19,15 +22,18 @@ 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"],
registry["plone.available_timezones"],
)
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()
Expand All @@ -37,25 +43,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()
Expand Down

0 comments on commit e506570

Please sign in to comment.