2014-05-12 19:20:18 +02:00
|
|
|
from plone.app.discussion.interfaces import ICommentAddedEvent
|
|
|
|
from plone.app.discussion.interfaces import ICommentRemovedEvent
|
2016-02-05 01:39:53 +01:00
|
|
|
from plone.app.discussion.interfaces import IConversation
|
|
|
|
from plone.app.discussion.interfaces import IReplies
|
2014-05-12 19:20:18 +02:00
|
|
|
from plone.app.discussion.interfaces import IReplyAddedEvent
|
|
|
|
from plone.app.discussion.interfaces import IReplyRemovedEvent
|
2022-05-01 23:14:00 +02:00
|
|
|
from plone.app.discussion.testing import ( # noqa
|
|
|
|
PLONE_APP_DISCUSSION_INTEGRATION_TESTING,
|
|
|
|
)
|
2015-05-03 08:16:39 +02:00
|
|
|
from plone.app.testing import setRoles
|
|
|
|
from plone.app.testing import TEST_USER_ID
|
|
|
|
from plone.contentrules.rule.interfaces import IRuleEventType
|
|
|
|
from plone.stringinterp.interfaces import IStringSubstitution
|
|
|
|
from zope.component import createObject
|
|
|
|
from zope.component import getAdapter
|
|
|
|
|
2017-05-08 09:24:38 +02:00
|
|
|
import unittest
|
2014-05-12 19:20:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CommentContentRulesTest(unittest.TestCase):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Test custom comments events"""
|
|
|
|
|
2014-05-12 19:20:18 +02:00
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
# Setup sandbox
|
2022-05-01 23:14:09 +02:00
|
|
|
self.portal = self.layer["portal"]
|
|
|
|
self.request = self.layer["request"]
|
2014-05-12 19:20:18 +02:00
|
|
|
|
|
|
|
# Setup current user properties
|
|
|
|
member = self.portal.portal_membership.getMemberById(TEST_USER_ID)
|
2022-05-01 23:14:09 +02:00
|
|
|
member.setMemberProperties(
|
|
|
|
{
|
|
|
|
"fullname": "X Manager",
|
|
|
|
"email": "xmanager@example.com",
|
|
|
|
}
|
|
|
|
)
|
2014-05-12 19:20:18 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
setRoles(self.portal, TEST_USER_ID, ["Manager"])
|
2014-05-12 19:20:18 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
self.document = self.portal["doc1"]
|
2014-05-12 19:20:18 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment = createObject("plone.Comment")
|
|
|
|
comment.text = "This is a comment"
|
|
|
|
comment.author_username = "jim"
|
|
|
|
comment.author_name = "Jim"
|
|
|
|
comment.author_email = "jim@example.com"
|
2014-05-12 19:20:18 +02:00
|
|
|
conversation = IConversation(self.document)
|
|
|
|
conversation.addComment(comment)
|
|
|
|
|
|
|
|
def testEventTypesMarked(self):
|
|
|
|
self.assertTrue(IRuleEventType.providedBy(ICommentAddedEvent))
|
|
|
|
self.assertTrue(IRuleEventType.providedBy(ICommentRemovedEvent))
|
|
|
|
self.assertTrue(IRuleEventType.providedBy(IReplyAddedEvent))
|
|
|
|
self.assertTrue(IRuleEventType.providedBy(IReplyRemovedEvent))
|
|
|
|
|
|
|
|
def testCommentIdStringSubstitution(self):
|
2022-05-01 23:14:41 +02:00
|
|
|
comment_id = getAdapter(self.document, IStringSubstitution, name="comment_id")
|
2018-06-12 14:25:01 +02:00
|
|
|
self.assertIsInstance(comment_id(), int)
|
2014-05-12 19:20:18 +02:00
|
|
|
|
|
|
|
def testCommentTextStringSubstitution(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
comment_text = getAdapter(
|
2022-05-01 23:14:41 +02:00
|
|
|
self.document, IStringSubstitution, name="comment_text"
|
2022-05-01 23:14:09 +02:00
|
|
|
)
|
2022-05-01 23:14:41 +02:00
|
|
|
self.assertEqual(comment_text(), "This is a comment")
|
2014-05-12 19:20:18 +02:00
|
|
|
|
|
|
|
def testCommentUserIdStringSubstitution(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
comment_user_id = getAdapter(
|
2022-05-01 23:14:41 +02:00
|
|
|
self.document, IStringSubstitution, name="comment_user_id"
|
2022-05-01 23:14:09 +02:00
|
|
|
)
|
2022-05-01 23:14:41 +02:00
|
|
|
self.assertEqual(comment_user_id(), "jim")
|
2014-05-12 19:20:18 +02:00
|
|
|
|
|
|
|
def testCommentUserFullNameStringSubstitution(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
comment_user_fullname = getAdapter(
|
2022-05-01 23:14:41 +02:00
|
|
|
self.document, IStringSubstitution, name="comment_user_fullname"
|
2022-05-01 23:14:09 +02:00
|
|
|
)
|
2022-05-01 23:14:41 +02:00
|
|
|
self.assertEqual(comment_user_fullname(), "Jim")
|
2014-05-12 19:20:18 +02:00
|
|
|
|
|
|
|
def testCommentUserEmailStringSubstitution(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
comment_user_email = getAdapter(
|
2022-05-01 23:14:41 +02:00
|
|
|
self.document, IStringSubstitution, name="comment_user_email"
|
2022-05-01 23:14:09 +02:00
|
|
|
)
|
2022-05-01 23:14:41 +02:00
|
|
|
self.assertEqual(comment_user_email(), "jim@example.com")
|
2014-05-12 19:20:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ReplyContentRulesTest(unittest.TestCase):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Test custom comments events"""
|
|
|
|
|
2014-05-12 19:20:18 +02:00
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
# Setup sandbox
|
2022-05-01 23:14:09 +02:00
|
|
|
self.portal = self.layer["portal"]
|
|
|
|
self.request = self.layer["request"]
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ["Manager"])
|
2014-05-12 19:20:18 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
self.document = self.portal["doc1"]
|
2014-05-12 19:20:18 +02:00
|
|
|
conversation = IConversation(self.document)
|
|
|
|
replies = IReplies(conversation)
|
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment = createObject("plone.Comment")
|
|
|
|
comment.text = "This is a comment"
|
2014-05-12 19:20:18 +02:00
|
|
|
new_id = replies.addComment(comment)
|
|
|
|
comment = self.document.restrictedTraverse(
|
2022-05-01 23:14:41 +02:00
|
|
|
f"++conversation++default/{new_id}",
|
2016-02-05 01:39:53 +01:00
|
|
|
)
|
2014-05-12 19:20:18 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
re_comment = createObject("plone.Comment")
|
|
|
|
re_comment.text = "This is a reply"
|
|
|
|
re_comment.author_username = "julia"
|
|
|
|
re_comment.author_name = "Juliana"
|
|
|
|
re_comment.author_email = "julia@example.com"
|
2014-05-12 19:20:18 +02:00
|
|
|
|
|
|
|
replies = IReplies(comment)
|
2015-05-03 08:27:21 +02:00
|
|
|
replies.addComment(re_comment)
|
2014-05-12 19:20:18 +02:00
|
|
|
|
|
|
|
def testReplyIdStringSubstitution(self):
|
2015-05-03 08:27:03 +02:00
|
|
|
reply_id = getAdapter(
|
|
|
|
self.document,
|
|
|
|
IStringSubstitution,
|
2022-05-01 23:14:41 +02:00
|
|
|
name="comment_id",
|
2015-05-03 08:27:03 +02:00
|
|
|
)
|
2018-06-12 14:25:01 +02:00
|
|
|
self.assertIsInstance(reply_id(), int)
|
2014-05-12 19:20:18 +02:00
|
|
|
|
|
|
|
def testReplyTextStringSubstitution(self):
|
2015-05-03 08:27:03 +02:00
|
|
|
reply_text = getAdapter(
|
|
|
|
self.document,
|
|
|
|
IStringSubstitution,
|
2022-05-01 23:14:41 +02:00
|
|
|
name="comment_text",
|
2015-05-03 08:27:03 +02:00
|
|
|
)
|
2022-05-01 23:14:41 +02:00
|
|
|
self.assertEqual(reply_text(), "This is a reply")
|
2014-05-12 19:20:18 +02:00
|
|
|
|
|
|
|
def testReplyUserIdStringSubstitution(self):
|
2015-05-03 08:27:03 +02:00
|
|
|
reply_user_id = getAdapter(
|
|
|
|
self.document,
|
|
|
|
IStringSubstitution,
|
2022-05-01 23:14:41 +02:00
|
|
|
name="comment_user_id",
|
2015-05-03 08:27:03 +02:00
|
|
|
)
|
2022-05-01 23:14:41 +02:00
|
|
|
self.assertEqual(reply_user_id(), "julia")
|
2014-05-12 19:20:18 +02:00
|
|
|
|
|
|
|
def testReplyUserFullNameStringSubstitution(self):
|
2015-05-03 08:27:03 +02:00
|
|
|
reply_user_fullname = getAdapter(
|
|
|
|
self.document,
|
|
|
|
IStringSubstitution,
|
2022-05-01 23:14:41 +02:00
|
|
|
name="comment_user_fullname",
|
2015-05-03 08:27:03 +02:00
|
|
|
)
|
2022-05-01 23:14:41 +02:00
|
|
|
self.assertEqual(reply_user_fullname(), "Juliana")
|
2014-05-12 19:20:18 +02:00
|
|
|
|
|
|
|
def testReplyUserEmailStringSubstitution(self):
|
2015-05-03 08:27:03 +02:00
|
|
|
reply_user_email = getAdapter(
|
|
|
|
self.document,
|
|
|
|
IStringSubstitution,
|
2022-05-01 23:14:41 +02:00
|
|
|
name="comment_user_email",
|
2015-05-03 08:27:03 +02:00
|
|
|
)
|
2022-05-01 23:14:41 +02:00
|
|
|
self.assertEqual(reply_user_email(), "julia@example.com")
|