Implement events for Comment (ICommentModifiedEvent) and Reply(IReplyModifiedEvent) modification

This commit is contained in:
Érico Andrei
2021-09-08 13:02:34 +02:00
parent 49d584e8db
commit 6f3fa11f10
6 changed files with 99 additions and 0 deletions
+56
View File
@@ -6,6 +6,8 @@ from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from Zope2.App import zcml
from zope.component import createObject
from zope.event import notify
from zope.lifecycleevent import ObjectModifiedEvent
import Products.Five
import unittest
@@ -20,8 +22,10 @@ class EventsRegistry(object):
""" Fake registry to be used while testing discussion events
"""
commentAdded = False
commentModified = False
commentRemoved = False
replyAdded = False
replyModified = False
replyRemoved = False
#
@@ -33,6 +37,10 @@ def comment_added(doc, evt):
EventsRegistry.commentAdded = True
def comment_modified(doc, evt):
EventsRegistry.commentModified = True
def comment_removed(doc, evt):
EventsRegistry.commentRemoved = True
@@ -41,6 +49,10 @@ def reply_added(doc, evt):
EventsRegistry.replyAdded = True
def reply_modified(doc, evt):
EventsRegistry.replyModified = True
def reply_removed(doc, evt):
EventsRegistry.replyRemoved = True
@@ -78,6 +90,12 @@ class CommentEventsTest(unittest.TestCase):
handler="plone.app.discussion.tests.test_events.comment_added"
/>
<subscriber
for="plone.app.discussion.interfaces.IComment
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
handler="plone.app.discussion.tests.test_events.comment_modified"
/>
<subscriber
for="OFS.interfaces.ISimpleItem
plone.app.discussion.interfaces.ICommentRemovedEvent"
@@ -96,6 +114,18 @@ class CommentEventsTest(unittest.TestCase):
conversation.addComment(comment)
self.assertTrue(self.registry.commentAdded)
def test_modifyEvent(self):
self.assertFalse(self.registry.commentModified)
comment = createObject('plone.Comment')
conversation = IConversation(self.document)
new_id = conversation.addComment(comment)
comment = self.document.restrictedTraverse(
'++conversation++default/{0}'.format(new_id),
)
comment.text = "foo"
notify(ObjectModifiedEvent(comment))
self.assertTrue(self.registry.commentModified)
def test_removedEvent(self):
self.assertFalse(self.registry.commentRemoved)
comment = createObject('plone.Comment')
@@ -131,6 +161,12 @@ class RepliesEventsTest(unittest.TestCase):
handler="plone.app.discussion.tests.test_events.reply_added"
/>
<subscriber
for="plone.app.discussion.interfaces.IComment
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
handler="plone.app.discussion.tests.test_events.reply_modified"
/>
<subscriber
for="OFS.interfaces.ISimpleItem
plone.app.discussion.interfaces.IReplyRemovedEvent"
@@ -163,6 +199,26 @@ class RepliesEventsTest(unittest.TestCase):
self.assertTrue(self.registry.replyAdded)
def test_modifyEvent(self):
self.assertFalse(self.registry.replyModified)
conversation = IConversation(self.document)
replies = IReplies(conversation)
comment = createObject('plone.Comment')
comment.text = 'Comment text'
comment_id = replies.addComment(comment)
comment = self.document.restrictedTraverse(
'++conversation++default/{0}'.format(comment_id),
)
re_comment = createObject('plone.Comment')
re_comment.text = 'Comment text'
replies = IReplies(comment)
new_id = replies.addComment(re_comment)
reply = replies[new_id]
reply.text = "Another text"
notify(ObjectModifiedEvent(reply))
self.assertTrue(self.registry.replyModified)
def test_removedEvent(self):
self.assertFalse(self.registry.replyRemoved)