From 4e43cfed2ea9623b6e7290e6cb04e5058dfaaff6 Mon Sep 17 00:00:00 2001 From: Patrick Gerken Date: Tue, 7 Sep 2010 12:02:55 +0000 Subject: [PATCH] Adding a test to assert that dates get stored utc and not in local time svn path=/plone.app.discussion/trunk/; revision=39725 --- plone/app/discussion/tests/test_comment.py | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plone/app/discussion/tests/test_comment.py b/plone/app/discussion/tests/test_comment.py index 0c18eb0..89b1a44 100644 --- a/plone/app/discussion/tests/test_comment.py +++ b/plone/app/discussion/tests/test_comment.py @@ -1,3 +1,7 @@ +import datetime + +import logging + import unittest from zope.component import createObject @@ -13,6 +17,9 @@ from plone.app.discussion.interfaces import IComment, IConversation, IReplies from plone.app.discussion.browser.comment import View +logger = logging.getLogger('plone.app.discussion.tests') +logger.addHandler(logging.StreamHandler()) + class CommentTest(PloneTestCase): layer = DiscussionLayer @@ -27,6 +34,22 @@ class CommentTest(PloneTestCase): comment1 = createObject('plone.Comment') self.assert_(IComment.providedBy(comment1)) + def test_UTCDates(self): + utc_to_local_diff = datetime.datetime.now() - datetime.datetime.utcnow() + utc_to_local_diff = abs(utc_to_local_diff.seconds) + if utc_to_local_diff < 60: + logger.warning("Your computer is living in a timezone where local " + "time equals utc time. Some potential errors can " + "get hidden by that") + comment1 = createObject('plone.Comment') + local_utc = datetime.datetime.utcnow() + for date in (comment1.creation_date, comment1.modification_date): + difference = abs(date - local_utc) + difference = difference.seconds + # We hope that between comment1 and local_utc happen less than + # 10 seconds + self.assertFalse(difference / 10) + def test_id(self): comment1 = createObject('plone.Comment') comment1.comment_id = 123