Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set timezone for creation and modification dates of comments #204

Merged
merged 24 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
16123e2
Set timezone for creation and modification dates of comments
instification Oct 18, 2022
42e5238
Update tests
instification Oct 18, 2022
9f34a7f
Add changelog
instification Oct 18, 2022
f1b753d
Update tests
instification Oct 18, 2022
d6bbff8
update conversation tests
instification Oct 18, 2022
45ef9a5
Fix syntax errors
instification Oct 18, 2022
fd1cfa8
Use local timezone when setting dates
instification Oct 21, 2022
103bd89
Use correct timezone when indexing comments
instification Oct 21, 2022
2506286
Create custom __getattribute__ method to return timezone aware dates …
instification Oct 21, 2022
c70abe2
Create a test for the custom getter to ensure timezones are being added
instification Oct 21, 2022
f0cd076
Update test_indexers to account for local timezones. Test across dayl…
instification Oct 21, 2022
9944796
Fix timezone tests
instification Oct 21, 2022
b28d6d1
Don't set the server timezone, seems to break other tests
instification Oct 21, 2022
194f2d9
Use configured portal timezone in tests
instification Oct 22, 2022
35b11a0
Prevent test failures when converting to timezone
instification Oct 22, 2022
2df8ff4
Try reindexing comment and increasing delta (in case of slow test cau…
instification Oct 22, 2022
0d64396
Don't convert time when adding timezone in getter. Refactor time comp…
instification Oct 23, 2022
2380bda
black/flake8
instification Oct 23, 2022
a069f49
Change timezone to America/Los_Angeles to expose DateTime exceptions
instification Oct 24, 2022
ab92def
Use plone.app.event.base.DT to convert datetime -> DateTime
instification Oct 24, 2022
a95e67b
Use py3 super syntax
instification Oct 24, 2022
a3818a4
Update changelog
instification Oct 24, 2022
c5f17dc
Bump version for linked plone.restapi test_statictime version check
instification Oct 24, 2022
aa38be3
Use correct date when indexing. Update comment indexes to use America…
instification Oct 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
black/flake8
  • Loading branch information
instification committed Oct 23, 2022
commit 2380bdacb3b0f4a1d758247a2717bfb0d9ef81b7
2 changes: 0 additions & 2 deletions plone/app/discussion/browser/comments.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from AccessControl import getSecurityManager
from AccessControl import Unauthorized
from Acquisition import aq_inner
from datetime import datetime
from datetime import timezone
from DateTime import DateTime
from plone.app.discussion import _
from plone.app.discussion.browser.validator import CaptchaValidator
Expand Down
3 changes: 1 addition & 2 deletions plone/app/discussion/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
from Acquisition import aq_base
from Acquisition import aq_parent
from Acquisition import Implicit
from datetime import datetime
from datetime import timezone
from OFS.owner import Owned
from OFS.role import RoleManager
from OFS.Traversable import Traversable
from datetime import timezone
from persistent import Persistent
from plone.app.discussion import _
from plone.app.discussion.events import CommentAddedEvent
Expand Down
39 changes: 21 additions & 18 deletions plone/app/discussion/tests/test_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ def test_add_comment(self):
self.assertEqual(conversation.total_comments(), 1)
self.assertTrue(
datetime.now().astimezone(tz.gettz(default_timezone()))
- conversation.last_comment_date
>= timedelta(seconds=0) <= timedelta(seconds=1),
- conversation.last_comment_date
>= timedelta(seconds=0)
<= timedelta(seconds=1),
)

def test_timezone_naive_comment(self):
Expand All @@ -94,24 +95,23 @@ def test_timezone_naive_comment(self):
comment = createObject("plone.Comment")
comment.text = "Comment text"

new_id = conversation.addComment(comment)
conversation.addComment(comment)

# Check that comments have the correct portal timezones
self.assertTrue(comment.creation_date.tzinfo,
tz.gettz("Europe/Berlin"))
self.assertTrue(comment.modification_date.tzinfo,
tz.gettz("Europe/Berlin"))

self.assertTrue(comment.creation_date.tzinfo, tz.gettz("Europe/Berlin"))
self.assertTrue(comment.modification_date.tzinfo, tz.gettz("Europe/Berlin"))

# Remove the timezone from the comment dates
comment.creation_date = datetime.utcnow()
comment.modification_date = datetime.utcnow()

# Check that the timezone naive date is converted to UTC
# See https://github.com/plone/plone.app.discussion/pull/204
self.assertTrue(
datetime.utcnow().replace(tzinfo=timezone.utc)
- conversation.last_comment_date
>= timedelta(seconds=0) <= timedelta(seconds=1),
datetime.utcnow().replace(tzinfo=timezone.utc)
- conversation.last_comment_date
>= timedelta(seconds=0)
<= timedelta(seconds=1),
)
self.assertTrue(comment.creation_date.tzinfo, timezone.utc)
self.assertTrue(comment.modification_date.tzinfo, timezone.utc)
Expand Down Expand Up @@ -531,20 +531,23 @@ def test_last_comment_date(self):
# swapped in
comment1 = createObject("plone.Comment")
comment1.text = "Comment text"
comment1.creation_date =\
datetime.now().astimezone(tz.gettz(default_timezone())) - timedelta(4)
comment1.creation_date = datetime.now().astimezone(
tz.gettz(default_timezone())
) - timedelta(4)
conversation.addComment(comment1)

comment2 = createObject("plone.Comment")
comment2.text = "Comment text"
comment2.creation_date =\
datetime.now().astimezone(tz.gettz(default_timezone())) - timedelta(2)
comment2.creation_date = datetime.now().astimezone(
tz.gettz(default_timezone())
) - timedelta(2)
new_comment2_id = conversation.addComment(comment2)

comment3 = createObject("plone.Comment")
comment3.text = "Comment text"
comment3.creation_date =\
datetime.now().astimezone(tz.gettz(default_timezone())) - timedelta(1)
comment3.creation_date = datetime.now().astimezone(
tz.gettz(default_timezone())
) - timedelta(1)
new_comment3_id = conversation.addComment(comment3)

# check if the latest comment is exactly one day old
Expand Down
8 changes: 2 additions & 6 deletions plone/app/discussion/tests/test_indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
from ..interfaces import IConversation
from ..testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING # noqa
from datetime import datetime
from datetime import timezone
from dateutil import tz
from DateTime import DateTime
from plone.app.event.base import localized_now
from plone.app.event.base import default_timezone
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
Expand All @@ -16,8 +14,6 @@
from zope.component import createObject
from zope.component import getUtility

import time
import os
import unittest


Expand Down Expand Up @@ -147,10 +143,10 @@ def setUp(self):
comment.text = "Lorem ipsum dolor sit amet."
comment.creator = "jim"
comment.author_name = "Jim"

# Create date in CEST (ie not daylight savings = UTC+2)
comment.creation_date = datetime(2006, 9, 17, 14, 18, 12).replace(tzinfo=tz.gettz("Europe/Berlin"))

# Create date in CET (ie daylight savings = UTC+1)
comment.modification_date = datetime(2008, 3, 12, 7, 32, 52).replace(tzinfo=tz.gettz("Europe/Berlin"))

Expand Down