2022-05-02 00:39:34 +02:00
|
|
|
from ..interfaces import IComment
|
|
|
|
from ..interfaces import IConversation
|
|
|
|
from ..interfaces import IDiscussionLayer
|
|
|
|
from ..interfaces import IDiscussionSettings
|
|
|
|
from ..interfaces import IReplies
|
|
|
|
from ..testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
2015-05-03 08:16:39 +02:00
|
|
|
from Acquisition import aq_base
|
|
|
|
from Acquisition import aq_parent
|
|
|
|
from datetime import datetime
|
|
|
|
from datetime import timedelta
|
2022-10-18 16:40:30 +02:00
|
|
|
from datetime import timezone
|
2022-10-21 17:11:19 +02:00
|
|
|
from dateutil import tz
|
|
|
|
from plone.app.event.base import default_timezone
|
2015-05-03 08:16:39 +02:00
|
|
|
from plone.app.testing import setRoles
|
|
|
|
from plone.app.testing import TEST_USER_ID
|
|
|
|
from plone.app.vocabularies.types import BAD_TYPES
|
2022-05-01 23:27:37 +02:00
|
|
|
from plone.dexterity.interfaces import IDexterityContent
|
2015-05-03 08:16:39 +02:00
|
|
|
from plone.registry.interfaces import IRegistry
|
2016-02-05 01:39:53 +01:00
|
|
|
from Products.CMFCore.utils import getToolByName
|
2015-05-03 08:16:39 +02:00
|
|
|
from zope import interface
|
|
|
|
from zope.annotation.interfaces import IAnnotations
|
|
|
|
from zope.component import createObject
|
2022-10-22 11:48:10 +02:00
|
|
|
from zope.component import getUtility
|
2015-05-03 08:16:39 +02:00
|
|
|
from zope.component import queryUtility
|
|
|
|
|
2018-06-15 10:22:11 +02:00
|
|
|
import unittest
|
2018-01-25 13:04:11 +01:00
|
|
|
|
|
|
|
|
2011-04-16 11:27:15 +02:00
|
|
|
class ConversationTest(unittest.TestCase):
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2011-04-16 11:27:15 +02:00
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2011-04-16 11:27:15 +02:00
|
|
|
def setUp(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
self.portal = self.layer["portal"]
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ["Manager"])
|
2022-05-02 00:39:34 +02:00
|
|
|
interface.alsoProvides(self.portal.REQUEST, IDiscussionLayer)
|
2011-04-15 06:29:46 +02:00
|
|
|
|
2022-10-22 11:48:10 +02:00
|
|
|
# Set the portal timezone to something non-utc
|
|
|
|
reg_key = "plone.portal_timezone"
|
|
|
|
registry = getUtility(IRegistry)
|
2022-10-24 22:09:49 +02:00
|
|
|
registry[reg_key] = "America/Los_Angeles"
|
2022-10-22 11:48:10 +02:00
|
|
|
|
2015-03-10 05:51:45 +01:00
|
|
|
self.typetool = self.portal.portal_types
|
2013-04-17 19:27:30 +02:00
|
|
|
self.portal_discussion = getToolByName(
|
|
|
|
self.portal,
|
2022-05-01 23:14:09 +02:00
|
|
|
"portal_discussion",
|
2013-04-17 19:27:30 +02:00
|
|
|
None,
|
|
|
|
)
|
2010-12-14 18:58:46 +01:00
|
|
|
# Allow discussion
|
|
|
|
registry = queryUtility(IRegistry)
|
|
|
|
settings = registry.forInterface(IDiscussionSettings)
|
|
|
|
settings.globally_enabled = True
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2017-01-10 18:09:01 +01:00
|
|
|
workflow = self.portal.portal_workflow
|
2022-05-01 23:14:09 +02:00
|
|
|
workflow.doActionFor(self.portal.doc1, "publish")
|
2017-01-10 18:09:01 +01:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_add_comment(self):
|
|
|
|
# Create a conversation. In this case we doesn't assign it to an
|
|
|
|
# object, as we just want to check the Conversation object API.
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
# Add a comment. Note: in real life, we always create comments via the
|
2010-08-28 19:06:53 +02:00
|
|
|
# factory to allow different factories to be swapped in
|
2009-05-18 17:15:36 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment = createObject("plone.Comment")
|
|
|
|
comment.text = "Comment text"
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
new_id = conversation.addComment(comment)
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
# Check that the conversation methods return the correct data
|
2018-06-12 14:25:01 +02:00
|
|
|
self.assertTrue(isinstance(comment.comment_id, int))
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(IComment.providedBy(conversation[new_id]))
|
2013-04-17 19:27:30 +02:00
|
|
|
self.assertEqual(
|
|
|
|
aq_base(conversation[new_id].__parent__),
|
2018-06-18 17:04:41 +02:00
|
|
|
aq_base(conversation),
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(new_id, comment.comment_id)
|
|
|
|
self.assertEqual(len(list(conversation.getComments())), 1)
|
|
|
|
self.assertEqual(len(tuple(conversation.getThreads())), 1)
|
2015-02-16 16:35:43 +01:00
|
|
|
self.assertEqual(conversation.total_comments(), 1)
|
2013-04-17 19:27:30 +02:00
|
|
|
self.assertTrue(
|
2022-10-23 10:24:59 +02:00
|
|
|
datetime.now().astimezone(tz.gettz(default_timezone()))
|
2022-10-23 10:35:27 +02:00
|
|
|
- conversation.last_comment_date
|
|
|
|
>= timedelta(seconds=0)
|
|
|
|
<= timedelta(seconds=1),
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2022-10-21 15:19:27 +02:00
|
|
|
def test_timezone_naive_comment(self):
|
|
|
|
# Create a conversation. In this case we doesn't assign it to an
|
|
|
|
# object, as we just want to check the Conversation object API.
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
|
|
|
|
# Add a comment. Note: in real life, we always create comments via the
|
|
|
|
# factory to allow different factories to be swapped in
|
|
|
|
comment = createObject("plone.Comment")
|
|
|
|
comment.text = "Comment text"
|
|
|
|
|
2022-10-23 10:35:27 +02:00
|
|
|
conversation.addComment(comment)
|
2022-10-21 15:19:27 +02:00
|
|
|
|
2022-10-22 11:48:10 +02:00
|
|
|
# Check that comments have the correct portal timezones
|
2022-10-24 22:09:49 +02:00
|
|
|
self.assertTrue(comment.creation_date.tzinfo, tz.gettz("America/Los_Angeles"))
|
|
|
|
self.assertTrue(comment.modification_date.tzinfo, tz.gettz("America/Los_Angeles"))
|
2022-10-23 10:35:27 +02:00
|
|
|
|
2022-10-21 15:19:27 +02:00
|
|
|
# Remove the timezone from the comment dates
|
2022-10-22 11:48:10 +02:00
|
|
|
comment.creation_date = datetime.utcnow()
|
|
|
|
comment.modification_date = datetime.utcnow()
|
2022-10-23 10:35:27 +02:00
|
|
|
|
2022-10-22 11:48:10 +02:00
|
|
|
# Check that the timezone naive date is converted to UTC
|
|
|
|
# See https://github.com/plone/plone.app.discussion/pull/204
|
2022-10-21 15:19:27 +02:00
|
|
|
self.assertTrue(
|
2022-10-23 10:35:27 +02:00
|
|
|
datetime.utcnow().replace(tzinfo=timezone.utc)
|
|
|
|
- conversation.last_comment_date
|
|
|
|
>= timedelta(seconds=0)
|
|
|
|
<= timedelta(seconds=1),
|
2022-10-21 15:19:27 +02:00
|
|
|
)
|
2022-10-22 11:48:10 +02:00
|
|
|
self.assertTrue(comment.creation_date.tzinfo, timezone.utc)
|
|
|
|
self.assertTrue(comment.modification_date.tzinfo, timezone.utc)
|
2022-10-21 15:19:27 +02:00
|
|
|
|
2013-03-28 14:28:22 +01:00
|
|
|
def test_private_comment(self):
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment = createObject("plone.Comment")
|
|
|
|
comment.author_username = "nobody"
|
2013-03-28 14:28:22 +01:00
|
|
|
conversation.addComment(comment)
|
2022-05-01 23:14:09 +02:00
|
|
|
comment.manage_permission("View", roles=tuple())
|
2015-02-16 16:35:43 +01:00
|
|
|
self.assertEqual(0, conversation.total_comments())
|
2013-10-10 16:28:24 +02:00
|
|
|
self.assertEqual(None, conversation.last_comment_date)
|
2022-05-01 23:14:09 +02:00
|
|
|
self.assertEqual(["nobody"], list(conversation.commentators))
|
2013-10-10 16:28:24 +02:00
|
|
|
self.assertEqual([], list(conversation.public_commentators))
|
2013-03-28 14:28:22 +01:00
|
|
|
|
2009-05-23 13:52:57 +02:00
|
|
|
def test_delete_comment(self):
|
2009-05-23 16:18:35 +02:00
|
|
|
# Create a conversation. In this case we doesn't assign it to an
|
|
|
|
# object, as we just want to check the Conversation object API.
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
# Add a comment. Note: in real life, we always create comments via the
|
2010-08-28 19:06:53 +02:00
|
|
|
# factory to allow different factories to be swapped in
|
2009-05-23 16:18:35 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment = createObject("plone.Comment")
|
|
|
|
comment.text = "Comment text"
|
2009-05-23 16:18:35 +02:00
|
|
|
|
|
|
|
new_id = conversation.addComment(comment)
|
|
|
|
|
2009-05-23 16:24:24 +02:00
|
|
|
# make sure the comment has been added
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(list(conversation.getComments())), 1)
|
|
|
|
self.assertEqual(len(tuple(conversation.getThreads())), 1)
|
2015-02-16 16:35:43 +01:00
|
|
|
self.assertEqual(conversation.total_comments(), 1)
|
2009-05-23 16:24:24 +02:00
|
|
|
|
2009-05-23 16:18:35 +02:00
|
|
|
# delete the comment we just created
|
2009-05-24 16:19:06 +02:00
|
|
|
del conversation[new_id]
|
2009-05-23 16:18:35 +02:00
|
|
|
|
|
|
|
# make sure there is no comment left in the conversation
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(list(conversation.getComments())), 0)
|
|
|
|
self.assertEqual(len(tuple(conversation.getThreads())), 0)
|
2015-02-16 16:35:43 +01:00
|
|
|
self.assertEqual(conversation.total_comments(), 0)
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-24 18:19:21 +02:00
|
|
|
def test_delete_recursive(self):
|
|
|
|
# Create a conversation. In this case we doesn't assign it to an
|
|
|
|
# object, as we just want to check the Conversation object API.
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
|
2010-07-13 12:45:53 +02:00
|
|
|
IReplies(conversation)
|
2009-05-24 18:19:21 +02:00
|
|
|
|
|
|
|
# Create a nested comment structure:
|
|
|
|
#
|
|
|
|
# Conversation
|
|
|
|
# +- Comment 1
|
|
|
|
# +- Comment 1_1
|
|
|
|
# | +- Comment 1_1_1
|
|
|
|
# +- Comment 1_2
|
|
|
|
# +- Comment 2
|
|
|
|
# +- Comment 2_1
|
|
|
|
|
|
|
|
# Create all comments
|
2022-05-01 23:14:09 +02:00
|
|
|
comment1 = createObject("plone.Comment")
|
|
|
|
comment1.text = "Comment text"
|
2009-05-24 18:19:21 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment1_1 = createObject("plone.Comment")
|
|
|
|
comment1_1.text = "Comment text"
|
2009-05-24 18:19:21 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment1_1_1 = createObject("plone.Comment")
|
|
|
|
comment1_1_1.text = "Comment text"
|
2009-05-24 18:19:21 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment1_2 = createObject("plone.Comment")
|
|
|
|
comment1_2.text = "Comment text"
|
2009-05-24 18:19:21 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment2 = createObject("plone.Comment")
|
|
|
|
comment2.text = "Comment text"
|
2009-05-24 18:19:21 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment2_1 = createObject("plone.Comment")
|
|
|
|
comment2_1.text = "Comment text"
|
2009-05-24 18:19:21 +02:00
|
|
|
|
|
|
|
# Create the nested comment structure
|
|
|
|
new_id_1 = conversation.addComment(comment1)
|
|
|
|
new_id_2 = conversation.addComment(comment2)
|
2009-05-25 12:38:58 +02:00
|
|
|
|
2009-05-24 18:19:21 +02:00
|
|
|
comment1_1.in_reply_to = new_id_1
|
|
|
|
new_id_1_1 = conversation.addComment(comment1_1)
|
2009-05-25 12:38:58 +02:00
|
|
|
|
2009-05-24 18:19:21 +02:00
|
|
|
comment1_1_1.in_reply_to = new_id_1_1
|
2010-07-13 12:45:53 +02:00
|
|
|
conversation.addComment(comment1_1_1)
|
2009-05-25 12:38:58 +02:00
|
|
|
|
2009-05-24 18:19:21 +02:00
|
|
|
comment1_2.in_reply_to = new_id_1
|
2010-07-13 12:45:53 +02:00
|
|
|
conversation.addComment(comment1_2)
|
2009-05-25 12:38:58 +02:00
|
|
|
|
2009-05-24 18:19:21 +02:00
|
|
|
comment2_1.in_reply_to = new_id_2
|
|
|
|
new_id_2_1 = conversation.addComment(comment2_1)
|
2009-05-25 12:38:58 +02:00
|
|
|
|
2009-05-24 18:19:21 +02:00
|
|
|
del conversation[new_id_1]
|
2009-05-25 12:38:58 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
self.assertEqual(
|
|
|
|
[
|
|
|
|
{"comment": comment2, "depth": 0, "id": new_id_2},
|
|
|
|
{"comment": comment2_1, "depth": 1, "id": new_id_2_1},
|
|
|
|
],
|
|
|
|
list(conversation.getThreads()),
|
|
|
|
)
|
2009-05-25 12:38:58 +02:00
|
|
|
|
2010-03-16 12:09:40 +01:00
|
|
|
def test_delete_comment_when_content_object_is_deleted(self):
|
2010-12-16 00:52:56 +01:00
|
|
|
# Make sure all comments of a content object are deleted when the
|
2010-08-28 19:06:53 +02:00
|
|
|
# object itself is deleted.
|
2010-03-16 12:09:40 +01:00
|
|
|
conversation = IConversation(self.portal.doc1)
|
2022-05-01 23:14:09 +02:00
|
|
|
comment = createObject("plone.Comment")
|
|
|
|
comment.text = "Comment text"
|
2010-07-13 12:45:53 +02:00
|
|
|
conversation.addComment(comment)
|
2010-03-16 12:09:40 +01:00
|
|
|
|
|
|
|
# Delete the content object
|
2022-05-01 23:14:09 +02:00
|
|
|
self.portal.manage_delObjects(["doc1"])
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-03-16 12:09:40 +01:00
|
|
|
# Make sure the comment has been deleted as well
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(list(conversation.getComments())), 0)
|
|
|
|
self.assertEqual(len(tuple(conversation.getThreads())), 0)
|
2015-02-16 16:35:43 +01:00
|
|
|
self.assertEqual(conversation.total_comments(), 0)
|
2010-03-16 12:09:40 +01:00
|
|
|
|
2010-08-20 13:52:05 +02:00
|
|
|
def test_comments_enabled_on_doc_in_subfolder(self):
|
|
|
|
typetool = self.portal.portal_types
|
2022-05-01 23:14:09 +02:00
|
|
|
typetool.constructContent("Folder", self.portal, "folder1")
|
|
|
|
typetool.constructContent("Document", self.portal.folder1, "doc2")
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-08-20 13:52:05 +02:00
|
|
|
folder = self.portal.folder1
|
2013-08-29 22:20:47 +02:00
|
|
|
|
|
|
|
folder.allow_discussion = True
|
2010-08-20 13:52:05 +02:00
|
|
|
self.assertTrue(aq_base(folder).allow_discussion)
|
2013-08-29 22:20:47 +02:00
|
|
|
folder.allow_discussion = False
|
2010-08-20 13:52:05 +02:00
|
|
|
self.assertFalse(aq_base(folder).allow_discussion)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-08-20 13:52:05 +02:00
|
|
|
doc = self.portal.folder1.doc2
|
2022-05-01 23:14:09 +02:00
|
|
|
conversation = doc.restrictedTraverse("@@conversation_view")
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation.enabled(), False)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-08-20 13:52:05 +02:00
|
|
|
# We have to allow discussion on Document content type, since
|
|
|
|
# otherwise allow_discussion will always return False
|
2022-05-01 23:14:09 +02:00
|
|
|
portal_types = getToolByName(self.portal, "portal_types")
|
|
|
|
document_fti = getattr(portal_types, "Document")
|
2012-01-14 07:26:01 +01:00
|
|
|
document_fti.manage_changeProperties(allow_discussion=True)
|
2010-08-20 13:52:05 +02:00
|
|
|
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation.enabled(), True)
|
2010-08-20 13:52:05 +02:00
|
|
|
|
2009-06-11 12:14:44 +02:00
|
|
|
def test_disable_commenting_globally(self):
|
|
|
|
|
|
|
|
# Create a conversation.
|
2022-05-01 23:14:09 +02:00
|
|
|
conversation = self.portal.doc1.restrictedTraverse("@@conversation_view")
|
2009-06-11 12:14:44 +02:00
|
|
|
|
|
|
|
# We have to allow discussion on Document content type, since
|
|
|
|
# otherwise allow_discussion will always return False
|
2022-05-01 23:14:09 +02:00
|
|
|
portal_types = getToolByName(self.portal, "portal_types")
|
|
|
|
document_fti = getattr(portal_types, "Document")
|
2012-01-14 07:26:01 +01:00
|
|
|
document_fti.manage_changeProperties(allow_discussion=True)
|
2009-06-11 12:14:44 +02:00
|
|
|
|
|
|
|
# Check if conversation is enabled now
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation.enabled(), True)
|
2009-06-11 12:14:44 +02:00
|
|
|
|
|
|
|
# Disable commenting in the registry
|
2010-07-12 15:47:53 +02:00
|
|
|
registry = queryUtility(IRegistry)
|
2009-07-12 21:13:42 +02:00
|
|
|
settings = registry.forInterface(IDiscussionSettings)
|
2009-06-11 12:14:44 +02:00
|
|
|
settings.globally_enabled = False
|
|
|
|
|
|
|
|
# Check if commenting is disabled on the conversation
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation.enabled(), False)
|
2009-06-11 12:14:44 +02:00
|
|
|
|
|
|
|
# Enable discussion again
|
|
|
|
settings.globally_enabled = True
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation.enabled(), True)
|
2009-06-11 12:14:44 +02:00
|
|
|
|
2009-07-07 16:48:39 +02:00
|
|
|
def test_allow_discussion_for_news_items(self):
|
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
self.typetool.constructContent("News Item", self.portal, "newsitem")
|
2009-07-07 16:48:39 +02:00
|
|
|
newsitem = self.portal.newsitem
|
2022-05-01 23:14:09 +02:00
|
|
|
conversation = newsitem.restrictedTraverse("@@conversation_view")
|
2009-07-07 16:48:39 +02:00
|
|
|
|
|
|
|
# We have to allow discussion on Document content type, since
|
|
|
|
# otherwise allow_discussion will always return False
|
2022-05-01 23:14:09 +02:00
|
|
|
portal_types = getToolByName(self.portal, "portal_types")
|
|
|
|
document_fti = getattr(portal_types, "News Item")
|
2012-01-14 07:26:01 +01:00
|
|
|
document_fti.manage_changeProperties(allow_discussion=True)
|
2009-07-07 16:48:39 +02:00
|
|
|
|
|
|
|
# Check if conversation is enabled now
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation.enabled(), True)
|
2009-07-07 16:48:39 +02:00
|
|
|
|
|
|
|
# Disable commenting in the registry
|
2010-07-12 15:47:53 +02:00
|
|
|
registry = queryUtility(IRegistry)
|
2009-07-12 21:13:42 +02:00
|
|
|
settings = registry.forInterface(IDiscussionSettings)
|
2009-07-07 16:48:39 +02:00
|
|
|
settings.globally_enabled = False
|
|
|
|
|
|
|
|
# Check if commenting is disabled on the conversation
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation.enabled(), False)
|
2009-07-07 16:48:39 +02:00
|
|
|
|
|
|
|
# Enable discussion again
|
|
|
|
settings.globally_enabled = True
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation.enabled(), True)
|
2009-07-07 16:48:39 +02:00
|
|
|
|
2009-06-11 12:14:44 +02:00
|
|
|
def test_disable_commenting_for_content_type(self):
|
|
|
|
|
|
|
|
# Create a conversation.
|
2011-04-15 06:29:46 +02:00
|
|
|
conversation = self.portal.doc1.restrictedTraverse(
|
2022-05-01 23:14:09 +02:00
|
|
|
"@@conversation_view",
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
2009-06-11 12:14:44 +02:00
|
|
|
|
|
|
|
# The Document content type is disabled by default
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation.enabled(), False)
|
2009-06-11 12:14:44 +02:00
|
|
|
|
|
|
|
# Allow discussion on Document content type
|
2022-05-01 23:14:09 +02:00
|
|
|
portal_types = getToolByName(self.portal, "portal_types")
|
|
|
|
document_fti = getattr(portal_types, "Document")
|
2012-01-14 07:26:01 +01:00
|
|
|
document_fti.manage_changeProperties(allow_discussion=True)
|
2009-06-11 12:14:44 +02:00
|
|
|
|
|
|
|
# Check if conversation is enabled now
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation.enabled(), True)
|
2009-06-11 12:14:44 +02:00
|
|
|
|
|
|
|
# Disallow discussion on Document content type
|
2022-05-01 23:14:09 +02:00
|
|
|
portal_types = getToolByName(self.portal, "portal_types")
|
|
|
|
document_fti = getattr(portal_types, "Document")
|
2012-01-14 07:26:01 +01:00
|
|
|
document_fti.manage_changeProperties(allow_discussion=False)
|
2009-06-11 12:14:44 +02:00
|
|
|
|
|
|
|
# Check if conversation is enabled now
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation.enabled(), False)
|
2009-06-11 12:14:44 +02:00
|
|
|
|
2009-06-18 22:57:47 +02:00
|
|
|
def test_allow_discussion_on_folder(self):
|
2013-08-29 22:20:47 +02:00
|
|
|
# The ATContentTypes based allow_discussion method did not allow to
|
|
|
|
# allow discussion on a folder. The dexerity behavior shipped with
|
|
|
|
# plone.app.contenttypes does not have this restriction any longer.
|
2009-06-18 23:12:38 +02:00
|
|
|
|
2013-08-29 22:20:47 +02:00
|
|
|
# Create a folder
|
2022-05-01 23:14:09 +02:00
|
|
|
self.typetool.constructContent("Folder", self.portal, "f1")
|
2013-12-15 12:02:32 +01:00
|
|
|
|
2009-06-18 23:12:38 +02:00
|
|
|
# Usually we don't create a conversation on a folder
|
2022-05-01 23:14:09 +02:00
|
|
|
conversation = self.portal.f1.restrictedTraverse("@@conversation_view")
|
2009-06-18 23:12:38 +02:00
|
|
|
|
|
|
|
# Allow discussion for the folder
|
2013-10-10 15:36:18 +02:00
|
|
|
self.portal.f1.allow_discussion = True
|
2009-06-18 23:12:38 +02:00
|
|
|
|
|
|
|
# Allow discussion on Folder content type
|
2022-05-01 23:14:09 +02:00
|
|
|
portal_types = getToolByName(self.portal, "portal_types")
|
|
|
|
document_fti = getattr(portal_types, "Folder")
|
2012-01-14 07:26:01 +01:00
|
|
|
document_fti.manage_changeProperties(allow_discussion=True)
|
2009-06-18 23:12:38 +02:00
|
|
|
|
2013-08-29 22:20:47 +02:00
|
|
|
self.assertTrue(conversation.enabled())
|
2009-06-18 22:57:47 +02:00
|
|
|
|
2009-06-11 12:14:44 +02:00
|
|
|
def test_is_discussion_allowed_on_content_object(self):
|
|
|
|
# Allow discussion on a single content object
|
|
|
|
|
|
|
|
# Create a conversation.
|
2011-04-15 06:29:46 +02:00
|
|
|
conversation = self.portal.doc1.restrictedTraverse(
|
2022-05-01 23:14:09 +02:00
|
|
|
"@@conversation_view",
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
2009-06-11 12:14:44 +02:00
|
|
|
|
|
|
|
# Discussion is disallowed by default
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation.enabled(), False)
|
2009-06-11 12:14:44 +02:00
|
|
|
|
|
|
|
# Allow discussion on content object
|
2013-10-10 15:36:18 +02:00
|
|
|
self.portal.doc1.allow_discussion = True
|
2009-06-11 12:14:44 +02:00
|
|
|
|
|
|
|
# Check if discussion is now allowed on the content object
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation.enabled(), True)
|
2009-06-11 12:14:44 +02:00
|
|
|
|
2013-10-10 15:36:18 +02:00
|
|
|
self.portal.doc1.allow_discussion = False
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation.enabled(), False)
|
2009-05-24 18:19:21 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_dict_operations(self):
|
2009-05-20 17:39:45 +02:00
|
|
|
# test dict operations and acquisition wrapping
|
2009-05-24 12:53:13 +02:00
|
|
|
|
|
|
|
# Create a conversation. In this case we doesn't assign it to an
|
|
|
|
# object, as we just want to check the Conversation object API.
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
# Add a comment. Note: in real life, we always create comments via the
|
2010-08-28 19:06:53 +02:00
|
|
|
# factory to allow different factories to be swapped in
|
2009-05-24 12:53:13 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment1 = createObject("plone.Comment")
|
|
|
|
comment1.text = "Comment text"
|
2009-05-24 12:53:13 +02:00
|
|
|
|
|
|
|
new_id1 = conversation.addComment(comment1)
|
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment2 = createObject("plone.Comment")
|
|
|
|
comment2.text = "Comment text"
|
2009-05-24 12:53:13 +02:00
|
|
|
|
|
|
|
new_id2 = conversation.addComment(comment2)
|
|
|
|
|
|
|
|
# check if get returns a comment object, and None if the key
|
|
|
|
# can not be found
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(IComment.providedBy(conversation.get(new_id1)))
|
|
|
|
self.assertTrue(IComment.providedBy(conversation.get(new_id2)))
|
|
|
|
self.assertEqual(conversation.get(123), None)
|
2009-05-24 12:53:13 +02:00
|
|
|
|
|
|
|
# check if keys return the ids of all comments
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(conversation.keys()), 2)
|
|
|
|
self.assertTrue(new_id1 in conversation.keys())
|
|
|
|
self.assertTrue(new_id2 in conversation.keys())
|
|
|
|
self.assertFalse(123 in conversation.keys())
|
2009-05-24 12:53:13 +02:00
|
|
|
|
|
|
|
# check if items returns (key, comment object) pairs
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(conversation.items()), 2)
|
|
|
|
self.assertTrue((new_id1, comment1) in conversation.items())
|
|
|
|
self.assertTrue((new_id2, comment2) in conversation.items())
|
2009-05-24 12:53:13 +02:00
|
|
|
|
|
|
|
# check if values returns the two comment objects
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(conversation.values()), 2)
|
|
|
|
self.assertTrue(comment1 in conversation.values())
|
|
|
|
self.assertTrue(comment2 in conversation.values())
|
2009-05-24 12:53:13 +02:00
|
|
|
|
|
|
|
# check if comment ids are in iterkeys
|
2022-05-01 23:14:41 +02:00
|
|
|
self.assertTrue(new_id1 in conversation.keys())
|
|
|
|
self.assertTrue(new_id2 in conversation.keys())
|
|
|
|
self.assertFalse(123 in conversation.keys())
|
2009-05-24 12:53:13 +02:00
|
|
|
|
|
|
|
# check if comment objects are in itervalues
|
2022-05-01 23:14:41 +02:00
|
|
|
self.assertTrue(comment1 in conversation.values())
|
|
|
|
self.assertTrue(comment2 in conversation.values())
|
2009-05-24 12:53:13 +02:00
|
|
|
|
|
|
|
# check if iteritems returns (key, comment object) pairs
|
2022-05-01 23:14:41 +02:00
|
|
|
self.assertTrue((new_id1, comment1) in conversation.items())
|
|
|
|
self.assertTrue((new_id2, comment2) in conversation.items())
|
2009-05-24 12:53:13 +02:00
|
|
|
|
2018-06-18 17:04:41 +02:00
|
|
|
# TODO test acquisition wrapping # noqa T000
|
2015-05-13 14:03:11 +02:00
|
|
|
# self.assertTrue(aq_base(aq_parent(comment1)) is conversation)
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_total_comments(self):
|
2009-05-20 17:39:45 +02:00
|
|
|
# Create a conversation. In this case we doesn't assign it to an
|
|
|
|
# object, as we just want to check the Conversation object API.
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
|
2009-05-20 18:07:29 +02:00
|
|
|
# Add a three comments. Note: in real life, we always create
|
|
|
|
# comments via the factory to allow different factories to be
|
|
|
|
# swapped in
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment1 = createObject("plone.Comment")
|
|
|
|
comment1.text = "Comment text"
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment2 = createObject("plone.Comment")
|
|
|
|
comment2.text = "Comment text"
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment3 = createObject("plone.Comment")
|
|
|
|
comment3.text = "Comment text"
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2010-07-13 12:45:53 +02:00
|
|
|
conversation.addComment(comment1)
|
|
|
|
conversation.addComment(comment2)
|
|
|
|
conversation.addComment(comment3)
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2015-02-16 16:35:43 +01:00
|
|
|
self.assertEqual(conversation.total_comments(), 3)
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_commentators(self):
|
2009-05-20 17:39:45 +02:00
|
|
|
# add and remove a few comments to make sure the commentators
|
2009-05-18 17:15:36 +02:00
|
|
|
# property returns a true set
|
2009-05-23 18:28:10 +02:00
|
|
|
|
|
|
|
# Create a conversation. In this case we doesn't assign it to an
|
|
|
|
# object, as we just want to check the Conversation object API.
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
|
2015-02-16 16:35:43 +01:00
|
|
|
self.assertEqual(conversation.total_comments(), 0)
|
2009-07-02 19:50:20 +02:00
|
|
|
|
2009-05-23 19:17:06 +02:00
|
|
|
# Add a four comments from three different users
|
2009-05-23 18:28:10 +02:00
|
|
|
# Note: in real life, we always create
|
|
|
|
# comments via the factory to allow different factories to be
|
|
|
|
# swapped in
|
2022-05-01 23:14:09 +02:00
|
|
|
comment1 = createObject("plone.Comment")
|
|
|
|
comment1.text = "Comment text"
|
|
|
|
comment1.author_username = "Jim"
|
2010-07-13 12:45:53 +02:00
|
|
|
conversation.addComment(comment1)
|
2009-05-23 18:28:10 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment2 = createObject("plone.Comment")
|
|
|
|
comment2.text = "Comment text"
|
|
|
|
comment2.author_username = "Joe"
|
2010-07-13 12:45:53 +02:00
|
|
|
conversation.addComment(comment2)
|
2009-05-23 18:28:10 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment3 = createObject("plone.Comment")
|
|
|
|
comment3.text = "Comment text"
|
|
|
|
comment3.author_username = "Jack"
|
2009-05-23 18:28:10 +02:00
|
|
|
new_comment3_id = conversation.addComment(comment3)
|
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment4 = createObject("plone.Comment")
|
|
|
|
comment4.text = "Comment text"
|
|
|
|
comment4.author_username = "Jack"
|
2009-05-23 19:17:06 +02:00
|
|
|
new_comment4_id = conversation.addComment(comment4)
|
|
|
|
|
2009-05-23 18:28:10 +02:00
|
|
|
# check if all commentators are in the commentators list
|
2015-02-16 16:35:43 +01:00
|
|
|
self.assertEqual(conversation.total_comments(), 4)
|
2022-05-01 23:14:09 +02:00
|
|
|
self.assertTrue("Jim" in conversation.commentators)
|
|
|
|
self.assertTrue("Joe" in conversation.commentators)
|
|
|
|
self.assertTrue("Jack" in conversation.commentators)
|
2009-05-23 19:17:06 +02:00
|
|
|
|
|
|
|
# remove the comment from Jack
|
|
|
|
del conversation[new_comment3_id]
|
|
|
|
|
|
|
|
# check if Jack is still in the commentators list (since
|
|
|
|
# he had added two comments)
|
2022-05-01 23:14:09 +02:00
|
|
|
self.assertTrue("Jim" in conversation.commentators)
|
|
|
|
self.assertTrue("Joe" in conversation.commentators)
|
|
|
|
self.assertTrue("Jack" in conversation.commentators)
|
2015-02-16 16:35:43 +01:00
|
|
|
self.assertEqual(conversation.total_comments(), 3)
|
2009-05-23 18:28:10 +02:00
|
|
|
|
2009-05-23 19:17:06 +02:00
|
|
|
# remove the second comment from Jack
|
|
|
|
del conversation[new_comment4_id]
|
2009-05-23 18:28:10 +02:00
|
|
|
|
2009-05-23 19:17:06 +02:00
|
|
|
# check if Jack has been removed from the commentators list
|
2022-05-01 23:14:09 +02:00
|
|
|
self.assertTrue("Jim" in conversation.commentators)
|
|
|
|
self.assertTrue("Joe" in conversation.commentators)
|
|
|
|
self.assertFalse("Jack" in conversation.commentators)
|
2015-02-16 16:35:43 +01:00
|
|
|
self.assertEqual(conversation.total_comments(), 2)
|
2009-05-23 18:28:10 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_last_comment_date(self):
|
2009-05-23 20:04:39 +02:00
|
|
|
# add and remove some comments and check if last_comment_date
|
|
|
|
# is properly updated
|
|
|
|
|
|
|
|
# Create a conversation. In this case we doesn't assign it to an
|
|
|
|
# object, as we just want to check the Conversation object API.
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
|
|
|
|
# Add a three comments that are at least one day old
|
|
|
|
# Note: in real life, we always create
|
|
|
|
# comments via the factory to allow different factories to be
|
|
|
|
# swapped in
|
2022-05-01 23:14:09 +02:00
|
|
|
comment1 = createObject("plone.Comment")
|
|
|
|
comment1.text = "Comment text"
|
2022-10-23 10:35:27 +02:00
|
|
|
comment1.creation_date = datetime.now().astimezone(
|
|
|
|
tz.gettz(default_timezone())
|
|
|
|
) - timedelta(4)
|
2010-07-13 12:45:53 +02:00
|
|
|
conversation.addComment(comment1)
|
2009-05-23 20:04:39 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment2 = createObject("plone.Comment")
|
|
|
|
comment2.text = "Comment text"
|
2022-10-23 10:35:27 +02:00
|
|
|
comment2.creation_date = datetime.now().astimezone(
|
|
|
|
tz.gettz(default_timezone())
|
|
|
|
) - timedelta(2)
|
2009-05-23 20:04:39 +02:00
|
|
|
new_comment2_id = conversation.addComment(comment2)
|
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment3 = createObject("plone.Comment")
|
|
|
|
comment3.text = "Comment text"
|
2022-10-23 10:35:27 +02:00
|
|
|
comment3.creation_date = datetime.now().astimezone(
|
|
|
|
tz.gettz(default_timezone())
|
|
|
|
) - timedelta(1)
|
2009-05-23 20:04:39 +02:00
|
|
|
new_comment3_id = conversation.addComment(comment3)
|
|
|
|
|
|
|
|
# check if the latest comment is exactly one day old
|
2013-04-17 19:27:30 +02:00
|
|
|
self.assertTrue(
|
2022-05-01 23:14:09 +02:00
|
|
|
conversation.last_comment_date
|
2022-10-21 17:11:19 +02:00
|
|
|
< datetime.now().astimezone(tz.gettz(default_timezone()))
|
2022-10-18 16:40:30 +02:00
|
|
|
- timedelta(hours=23, minutes=59, seconds=59),
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
|
|
|
self.assertTrue(
|
2022-05-01 23:14:09 +02:00
|
|
|
conversation.last_comment_date
|
2022-10-21 17:11:19 +02:00
|
|
|
> datetime.now().astimezone(tz.gettz(default_timezone()))
|
2022-10-18 16:40:30 +02:00
|
|
|
- timedelta(days=1, seconds=1),
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
2009-05-23 20:04:39 +02:00
|
|
|
|
|
|
|
# remove the latest comment
|
|
|
|
del conversation[new_comment3_id]
|
|
|
|
|
|
|
|
# check if the latest comment has been updated
|
|
|
|
# the latest comment should be exactly two days old
|
2013-04-17 19:27:30 +02:00
|
|
|
self.assertTrue(
|
2022-05-01 23:14:09 +02:00
|
|
|
conversation.last_comment_date
|
2022-10-21 17:11:19 +02:00
|
|
|
< datetime.now().astimezone(tz.gettz(default_timezone()))
|
2022-10-18 16:40:30 +02:00
|
|
|
- timedelta(days=1, hours=23, minutes=59, seconds=59),
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
|
|
|
self.assertTrue(
|
2022-05-01 23:14:09 +02:00
|
|
|
conversation.last_comment_date
|
2022-10-21 17:11:19 +02:00
|
|
|
> datetime.now().astimezone(tz.gettz(default_timezone()))
|
2022-10-18 16:40:30 +02:00
|
|
|
- timedelta(days=2, seconds=1),
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
2009-05-23 20:04:39 +02:00
|
|
|
|
|
|
|
# remove the latest comment again
|
|
|
|
del conversation[new_comment2_id]
|
|
|
|
|
|
|
|
# check if the latest comment has been updated
|
|
|
|
# the latest comment should be exactly four days old
|
2013-04-17 19:27:30 +02:00
|
|
|
self.assertTrue(
|
2022-05-01 23:14:09 +02:00
|
|
|
conversation.last_comment_date
|
2022-10-21 17:11:19 +02:00
|
|
|
< datetime.now().astimezone(tz.gettz(default_timezone()))
|
2022-10-18 16:40:30 +02:00
|
|
|
- timedelta(days=3, hours=23, minutes=59, seconds=59),
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
|
|
|
self.assertTrue(
|
2022-05-01 23:14:09 +02:00
|
|
|
conversation.last_comment_date
|
2022-10-21 17:11:19 +02:00
|
|
|
> datetime.now().astimezone(tz.gettz(default_timezone()))
|
2022-10-18 16:40:30 +02:00
|
|
|
- timedelta(days=4, seconds=2),
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-24 18:04:49 +02:00
|
|
|
def test_get_comments_full(self):
|
2009-05-18 17:15:36 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
def test_get_comments_batched(self):
|
2009-05-23 06:55:06 +02:00
|
|
|
pass
|
2009-05-18 17:15:36 +02:00
|
|
|
|
|
|
|
def test_get_threads(self):
|
2009-05-25 12:38:58 +02:00
|
|
|
|
2009-05-24 18:04:49 +02:00
|
|
|
# Create a conversation. In this case we doesn't assign it to an
|
|
|
|
# object, as we just want to check the Conversation object API.
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
|
2010-07-13 12:45:53 +02:00
|
|
|
IReplies(conversation)
|
2009-05-24 18:04:49 +02:00
|
|
|
|
|
|
|
# Create a nested comment structure:
|
|
|
|
#
|
|
|
|
# Conversation
|
|
|
|
# +- Comment 1
|
|
|
|
# +- Comment 1_1
|
|
|
|
# | +- Comment 1_1_1
|
|
|
|
# +- Comment 1_2
|
|
|
|
# +- Comment 2
|
|
|
|
# +- Comment 2_1
|
|
|
|
|
|
|
|
# Create all comments
|
2022-05-01 23:14:09 +02:00
|
|
|
comment1 = createObject("plone.Comment")
|
|
|
|
comment1.text = "Comment text"
|
2009-05-24 18:04:49 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment1_1 = createObject("plone.Comment")
|
|
|
|
comment1_1.text = "Comment text"
|
2009-05-24 18:04:49 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment1_1_1 = createObject("plone.Comment")
|
|
|
|
comment1_1_1.text = "Comment text"
|
2009-05-24 18:04:49 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment1_2 = createObject("plone.Comment")
|
|
|
|
comment1_2.text = "Comment text"
|
2009-05-24 18:04:49 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment2 = createObject("plone.Comment")
|
|
|
|
comment2.text = "Comment text"
|
2009-05-24 18:04:49 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment2_1 = createObject("plone.Comment")
|
|
|
|
comment2_1.text = "Comment text"
|
2009-05-24 18:04:49 +02:00
|
|
|
|
|
|
|
# Create the nested comment structure
|
|
|
|
new_id_1 = conversation.addComment(comment1)
|
|
|
|
new_id_2 = conversation.addComment(comment2)
|
2009-05-25 12:38:58 +02:00
|
|
|
|
2009-05-24 18:04:49 +02:00
|
|
|
comment1_1.in_reply_to = new_id_1
|
|
|
|
new_id_1_1 = conversation.addComment(comment1_1)
|
2009-05-25 12:38:58 +02:00
|
|
|
|
2009-05-24 18:04:49 +02:00
|
|
|
comment1_1_1.in_reply_to = new_id_1_1
|
|
|
|
new_id_1_1_1 = conversation.addComment(comment1_1_1)
|
2009-05-25 12:38:58 +02:00
|
|
|
|
2009-05-24 18:04:49 +02:00
|
|
|
comment1_2.in_reply_to = new_id_1
|
|
|
|
new_id_1_2 = conversation.addComment(comment1_2)
|
2009-05-25 12:38:58 +02:00
|
|
|
|
2009-05-24 18:04:49 +02:00
|
|
|
comment2_1.in_reply_to = new_id_2
|
|
|
|
new_id_2_1 = conversation.addComment(comment2_1)
|
2009-05-25 12:38:58 +02:00
|
|
|
|
2009-05-24 18:04:49 +02:00
|
|
|
# Get threads
|
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
self.assertEqual(
|
|
|
|
[
|
|
|
|
{"comment": comment1, "depth": 0, "id": new_id_1},
|
|
|
|
{"comment": comment1_1, "depth": 1, "id": new_id_1_1},
|
|
|
|
{"comment": comment1_1_1, "depth": 2, "id": new_id_1_1_1},
|
|
|
|
{"comment": comment1_2, "depth": 1, "id": new_id_1_2},
|
|
|
|
{"comment": comment2, "depth": 0, "id": new_id_2},
|
|
|
|
{"comment": comment2_1, "depth": 1, "id": new_id_2_1},
|
|
|
|
],
|
|
|
|
list(conversation.getThreads()),
|
|
|
|
)
|
2009-05-18 17:15:36 +02:00
|
|
|
|
|
|
|
def test_get_threads_batched(self):
|
2018-06-18 17:04:41 +02:00
|
|
|
# TODO: test start, size, root and depth arguments to getThreads() # noqa T000
|
2009-05-24 18:04:49 +02:00
|
|
|
# - may want to split this into multiple tests
|
2009-05-18 17:15:36 +02:00
|
|
|
pass
|
2009-05-23 16:18:35 +02:00
|
|
|
|
2009-05-23 13:52:57 +02:00
|
|
|
def test_traversal(self):
|
|
|
|
# make sure we can traverse to conversations and get a URL and path
|
2009-05-23 16:18:35 +02:00
|
|
|
|
2010-08-28 19:06:53 +02:00
|
|
|
conversation = self.portal.doc1.restrictedTraverse(
|
2022-05-01 23:14:09 +02:00
|
|
|
"++conversation++default",
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(IConversation.providedBy(conversation))
|
2009-05-23 16:18:35 +02:00
|
|
|
|
2013-04-17 19:27:30 +02:00
|
|
|
self.assertEqual(
|
2022-05-01 23:14:09 +02:00
|
|
|
("", "plone", "doc1", "++conversation++default"),
|
2018-06-18 17:04:41 +02:00
|
|
|
conversation.getPhysicalPath(),
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
2022-05-01 23:14:09 +02:00
|
|
|
"http://nohost/plone/doc1/++conversation++default",
|
2018-06-18 17:04:41 +02:00
|
|
|
conversation.absolute_url(),
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
2009-05-18 17:15:36 +02:00
|
|
|
|
2012-11-16 10:28:00 +01:00
|
|
|
def test_unconvertible_id(self):
|
|
|
|
# make sure the conversation view doesn't break when given comment id
|
2018-06-12 14:25:01 +02:00
|
|
|
# can't be converted to int
|
2012-11-16 10:28:00 +01:00
|
|
|
|
|
|
|
conversation = self.portal.doc1.restrictedTraverse(
|
2022-05-01 23:14:09 +02:00
|
|
|
"++conversation++default/ThisCantBeRight",
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
2012-11-16 10:28:00 +01:00
|
|
|
self.assertEqual(conversation, None)
|
|
|
|
|
2009-06-11 12:14:44 +02:00
|
|
|
def test_parent(self):
|
|
|
|
# Check that conversation has a content object as parent
|
|
|
|
|
|
|
|
# Create a conversation.
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
|
|
|
|
# Check the parent
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(conversation.__parent__)
|
|
|
|
self.assertTrue(aq_parent(conversation))
|
2009-06-18 22:57:47 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
self.assertEqual(conversation.__parent__.getId(), "doc1")
|
2009-06-11 12:14:44 +02:00
|
|
|
|
2009-05-31 19:54:14 +02:00
|
|
|
def test_discussion_item_not_in_bad_types(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
self.assertFalse("Discussion Item" in BAD_TYPES)
|
2009-05-31 19:54:14 +02:00
|
|
|
|
2011-04-14 18:17:29 +02:00
|
|
|
def test_no_comment(self):
|
2012-01-14 07:26:01 +01:00
|
|
|
IConversation(self.portal.doc1)
|
2011-04-14 18:17:29 +02:00
|
|
|
# Make sure no conversation has been created
|
2013-04-17 19:27:30 +02:00
|
|
|
self.assertTrue(
|
2022-05-01 23:14:09 +02:00
|
|
|
"plone.app.discussion:conversation" not in IAnnotations(self.portal.doc1),
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
2011-04-14 18:17:29 +02:00
|
|
|
|
2009-06-04 17:38:12 +02:00
|
|
|
|
2012-06-30 10:59:49 +02:00
|
|
|
class ConversationEnabledForDexterityTypesTest(unittest.TestCase):
|
|
|
|
|
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
|
|
|
|
|
|
|
def setUp(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
self.portal = self.layer["portal"]
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ["Manager"])
|
2012-06-30 10:59:49 +02:00
|
|
|
interface.alsoProvides(
|
|
|
|
self.portal.REQUEST,
|
2022-05-02 00:39:34 +02:00
|
|
|
IDiscussionLayer,
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
2012-06-30 10:59:49 +02:00
|
|
|
|
2022-05-01 23:27:37 +02:00
|
|
|
interface.alsoProvides(
|
|
|
|
self.portal.doc1,
|
|
|
|
IDexterityContent,
|
|
|
|
)
|
2012-06-30 10:59:49 +02:00
|
|
|
|
|
|
|
def _makeOne(self, *args, **kw):
|
2022-05-01 23:14:09 +02:00
|
|
|
return self.portal.doc1.restrictedTraverse("@@conversation_view")
|
2012-06-30 10:59:49 +02:00
|
|
|
|
|
|
|
def _globally_enable_discussion(self, value):
|
|
|
|
registry = queryUtility(IRegistry)
|
|
|
|
settings = registry.forInterface(IDiscussionSettings)
|
|
|
|
settings.globally_enabled = value
|
|
|
|
|
|
|
|
def _enable_discussion_on_portal_type(self, portal_type, allow_discussion):
|
2022-05-01 23:14:09 +02:00
|
|
|
portal_types = getToolByName(self.portal, "portal_types")
|
2012-06-30 10:59:49 +02:00
|
|
|
document_fti = getattr(portal_types, portal_type)
|
|
|
|
document_fti.manage_changeProperties(allow_discussion=allow_discussion)
|
|
|
|
|
|
|
|
def test_conversation_is_not_enabled_by_default(self):
|
2022-05-01 23:27:37 +02:00
|
|
|
conversation = self._makeOne(self.portal.doc1)
|
|
|
|
self.assertFalse(conversation.enabled())
|
2012-06-30 10:59:49 +02:00
|
|
|
|
|
|
|
def test_conversation_is_not_enabled_by_default_on_portal_type(self):
|
2022-05-01 23:27:37 +02:00
|
|
|
self._globally_enable_discussion(True)
|
|
|
|
conversation = self._makeOne(self.portal.doc1)
|
|
|
|
self.assertFalse(conversation.enabled())
|
2012-06-30 10:59:49 +02:00
|
|
|
|
|
|
|
def test_conversation_needs_to_be_enabled_globally_and_for_type(self):
|
2022-05-01 23:27:37 +02:00
|
|
|
self._globally_enable_discussion(True)
|
|
|
|
self._enable_discussion_on_portal_type("Document", True)
|
|
|
|
conversation = self._makeOne(self.portal.doc1)
|
|
|
|
self.assertTrue(conversation.enabled())
|
2012-06-30 10:59:49 +02:00
|
|
|
|
|
|
|
def test_disable_discussion(self):
|
2022-05-01 23:27:37 +02:00
|
|
|
self._globally_enable_discussion(True)
|
|
|
|
self._enable_discussion_on_portal_type("Document", True)
|
|
|
|
self.portal.doc1.allow_discussion = False
|
|
|
|
conversation = self._makeOne(self.portal.doc1)
|
|
|
|
self.assertFalse(conversation.enabled())
|
2012-06-30 10:59:49 +02:00
|
|
|
|
|
|
|
def test_enable_discussion(self):
|
2022-05-01 23:27:37 +02:00
|
|
|
self._globally_enable_discussion(True)
|
|
|
|
self._enable_discussion_on_portal_type("Document", True)
|
|
|
|
self.portal.doc1.allow_discussion = True
|
|
|
|
conversation = self._makeOne(self.portal.doc1)
|
|
|
|
self.assertTrue(conversation.enabled())
|
2012-06-30 10:59:49 +02:00
|
|
|
|
|
|
|
|
2011-04-16 11:27:15 +02:00
|
|
|
class RepliesTest(unittest.TestCase):
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
# test the IReplies adapter on a conversation
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2011-04-16 11:27:15 +02:00
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2011-04-16 11:27:15 +02:00
|
|
|
def setUp(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
self.portal = self.layer["portal"]
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ["Manager"])
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2017-01-10 18:09:01 +01:00
|
|
|
workflow = self.portal.portal_workflow
|
2022-05-01 23:14:09 +02:00
|
|
|
workflow.doActionFor(self.portal.doc1, "publish")
|
2017-01-10 18:09:01 +01:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_add_comment(self):
|
2009-05-24 14:34:15 +02:00
|
|
|
# Add comments to a ConversationReplies adapter
|
|
|
|
|
|
|
|
# Create a conversation. In this case we doesn't assign it to an
|
|
|
|
# object, as we just want to check the Conversation object API.
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
|
|
|
|
replies = IReplies(conversation)
|
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment = createObject("plone.Comment")
|
|
|
|
comment.text = "Comment text"
|
2009-05-24 14:34:15 +02:00
|
|
|
|
|
|
|
new_id = replies.addComment(comment)
|
|
|
|
|
|
|
|
# check that replies provides the IReplies interface
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(IReplies.providedBy(replies))
|
2009-05-24 17:25:49 +02:00
|
|
|
|
2009-05-24 16:19:06 +02:00
|
|
|
# Make sure our comment was added
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(new_id in replies)
|
2009-05-24 17:25:49 +02:00
|
|
|
|
2009-05-24 16:19:06 +02:00
|
|
|
# Make sure it is also reflected in the conversation
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(new_id in conversation)
|
2009-05-24 17:25:49 +02:00
|
|
|
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation[new_id].comment_id, new_id)
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_delete_comment(self):
|
2009-05-24 18:23:49 +02:00
|
|
|
# Create and remove a comment and check if the replies adapter
|
|
|
|
# has been updated accordingly
|
|
|
|
|
|
|
|
# Create a conversation. In this case we doesn't assign it to an
|
|
|
|
# object, as we just want to check the Conversation object API.
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
|
|
|
|
replies = IReplies(conversation)
|
|
|
|
|
|
|
|
# Add a comment.
|
2022-05-01 23:14:09 +02:00
|
|
|
comment = createObject("plone.Comment")
|
|
|
|
comment.text = "Comment text"
|
2009-05-24 18:23:49 +02:00
|
|
|
|
|
|
|
new_id = replies.addComment(comment)
|
|
|
|
|
|
|
|
# make sure the comment has been added
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(replies), 1)
|
2009-05-24 18:23:49 +02:00
|
|
|
|
|
|
|
# delete the comment we just created
|
|
|
|
del replies[new_id]
|
|
|
|
|
|
|
|
# make sure there is no comment left in the conversation
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(replies), 0)
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_dict_api(self):
|
2009-05-25 12:38:58 +02:00
|
|
|
# This test is for the ConversationReplies as well as the
|
|
|
|
# CommentReplies adapter.
|
|
|
|
#
|
2009-05-24 17:25:49 +02:00
|
|
|
# Ensure all operations use only top-level comments. Add some
|
2009-05-24 16:19:06 +02:00
|
|
|
# deeper children and ensure that these are not exposed through the
|
|
|
|
# IReplies dict.
|
2009-05-24 17:25:49 +02:00
|
|
|
|
|
|
|
# Create a conversation. In this case we doesn't assign it to an
|
|
|
|
# object, as we just want to check the Conversation object API.
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
|
|
|
|
replies = IReplies(conversation)
|
|
|
|
|
|
|
|
# Create a nested comment structure:
|
|
|
|
#
|
|
|
|
# Conversation
|
|
|
|
# +- Comment 1
|
|
|
|
# +- Comment 1_1
|
|
|
|
# | +- Comment 1_1_1
|
|
|
|
# +- Comment 1_2
|
|
|
|
# +- Comment 2
|
|
|
|
# +- Comment 2_1
|
|
|
|
|
|
|
|
# Create all comments
|
2022-05-01 23:14:09 +02:00
|
|
|
comment1 = createObject("plone.Comment")
|
|
|
|
comment1.text = "Comment text"
|
2009-05-24 17:25:49 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment1_1 = createObject("plone.Comment")
|
|
|
|
comment1_1.text = "Comment text"
|
2009-05-24 17:25:49 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment1_1_1 = createObject("plone.Comment")
|
|
|
|
comment1_1_1.text = "Comment text"
|
2009-05-24 17:25:49 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment1_2 = createObject("plone.Comment")
|
|
|
|
comment1_2.text = "Comment text"
|
2009-05-24 17:25:49 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment2 = createObject("plone.Comment")
|
|
|
|
comment2.text = "Comment text"
|
2009-05-24 17:25:49 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
comment2_1 = createObject("plone.Comment")
|
|
|
|
comment2_1.text = "Comment text"
|
2009-05-24 17:25:49 +02:00
|
|
|
|
|
|
|
# Create the nested comment structure
|
|
|
|
new_id_1 = replies.addComment(comment1)
|
2010-08-28 19:06:53 +02:00
|
|
|
comment1 = self.portal.doc1.restrictedTraverse(
|
2022-05-01 23:14:41 +02:00
|
|
|
f"++conversation++default/{new_id_1}",
|
2016-02-05 01:39:53 +01:00
|
|
|
)
|
2009-05-24 17:25:49 +02:00
|
|
|
replies_to_comment1 = IReplies(comment1)
|
|
|
|
new_id_2 = replies.addComment(comment2)
|
2010-08-28 19:06:53 +02:00
|
|
|
comment2 = self.portal.doc1.restrictedTraverse(
|
2022-05-01 23:14:41 +02:00
|
|
|
f"++conversation++default/{new_id_2}",
|
2016-02-05 01:39:53 +01:00
|
|
|
)
|
2009-05-24 17:25:49 +02:00
|
|
|
replies_to_comment2 = IReplies(comment2)
|
|
|
|
|
|
|
|
new_id_1_1 = replies_to_comment1.addComment(comment1_1)
|
2010-08-28 19:06:53 +02:00
|
|
|
comment1_1 = self.portal.doc1.restrictedTraverse(
|
2022-05-01 23:14:41 +02:00
|
|
|
f"++conversation++default/{new_id_1_1}",
|
2016-02-05 01:39:53 +01:00
|
|
|
)
|
2009-05-24 17:25:49 +02:00
|
|
|
replies_to_comment1_1 = IReplies(comment1_1)
|
2010-07-13 12:45:53 +02:00
|
|
|
replies_to_comment1_1.addComment(comment1_1_1)
|
2009-05-24 17:25:49 +02:00
|
|
|
|
2010-07-13 12:45:53 +02:00
|
|
|
replies_to_comment1.addComment(comment1_2)
|
2009-05-24 17:25:49 +02:00
|
|
|
|
2010-07-13 12:45:53 +02:00
|
|
|
replies_to_comment2.addComment(comment2_1)
|
2009-05-24 17:25:49 +02:00
|
|
|
|
2009-05-24 17:36:31 +02:00
|
|
|
# check that replies only contain the direct comments
|
|
|
|
# and no comments deeper than 1
|
2015-02-16 16:35:43 +01:00
|
|
|
self.assertEqual(conversation.total_comments(), 6)
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(replies), 2)
|
|
|
|
self.assertEqual(len(replies_to_comment1), 2)
|
|
|
|
self.assertEqual(len(replies_to_comment1_1), 1)
|
|
|
|
self.assertEqual(len(replies_to_comment2), 1)
|