2010-08-28 19:06:53 +02:00
|
|
|
"""Test the plone.app.discussion catalog indexes
|
|
|
|
"""
|
2011-04-16 11:13:39 +02:00
|
|
|
import unittest2 as unittest
|
2009-07-01 22:57:55 +02:00
|
|
|
|
2011-07-03 20:36:02 +02:00
|
|
|
import transaction
|
|
|
|
|
2009-07-01 22:57:55 +02:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
from zope.component import createObject
|
2011-04-14 18:17:29 +02:00
|
|
|
from zope.annotation.interfaces import IAnnotations
|
2009-07-01 22:57:55 +02:00
|
|
|
|
|
|
|
from Products.CMFCore.utils import getToolByName
|
|
|
|
|
2011-04-16 11:13:39 +02:00
|
|
|
from plone.app.testing import TEST_USER_ID, setRoles
|
2009-07-01 22:57:55 +02:00
|
|
|
|
2011-04-16 11:13:39 +02:00
|
|
|
from plone.app.discussion.testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
2009-07-01 22:57:55 +02:00
|
|
|
|
2010-07-13 12:45:53 +02:00
|
|
|
from plone.app.discussion.interfaces import IConversation
|
2009-07-01 22:57:55 +02:00
|
|
|
|
2011-04-14 22:17:10 +02:00
|
|
|
|
2011-04-16 11:13:39 +02:00
|
|
|
class CatalogSetupTest(unittest.TestCase):
|
2009-07-01 22:59:58 +02:00
|
|
|
|
2011-04-16 11:13:39 +02:00
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
2009-07-01 22:59:58 +02:00
|
|
|
|
2011-04-16 11:13:39 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.portal = self.layer['portal']
|
|
|
|
|
2009-07-01 22:59:58 +02:00
|
|
|
def test_catalog_installed(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue('total_comments' in
|
2010-08-28 19:06:53 +02:00
|
|
|
self.portal.portal_catalog.indexes())
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue('commentators' in
|
2010-08-28 19:06:53 +02:00
|
|
|
self.portal.portal_catalog.indexes())
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue('total_comments' in
|
2010-08-28 19:06:53 +02:00
|
|
|
self.portal.portal_catalog.schema())
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue('in_response_to' in
|
2010-08-28 19:06:53 +02:00
|
|
|
self.portal.portal_catalog.schema())
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2009-07-01 22:59:58 +02:00
|
|
|
def test_collection_criteria_installed(self):
|
|
|
|
try:
|
|
|
|
self.portal.portal_atct.getIndex('commentators')
|
|
|
|
self.portal.portal_atct.getIndex('total_comments')
|
|
|
|
self.portal.portal_atct.getMetadata('total_comments')
|
|
|
|
except AttributeError:
|
|
|
|
self.fail()
|
|
|
|
|
2010-08-28 19:06:53 +02:00
|
|
|
|
2011-04-16 11:13:39 +02:00
|
|
|
class ConversationCatalogTest(unittest.TestCase):
|
2009-07-01 22:57:55 +02:00
|
|
|
|
2011-04-16 11:13:39 +02:00
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
2009-07-01 22:57:55 +02:00
|
|
|
|
2011-04-16 11:13:39 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.portal = self.layer['portal']
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
2010-12-16 00:52:56 +01:00
|
|
|
self.portal.invokeFactory(id='doc1',
|
|
|
|
Title='Document 1',
|
2010-09-29 09:56:36 +02:00
|
|
|
type_name='Document')
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2009-07-01 22:57:55 +02:00
|
|
|
self.catalog = getToolByName(self.portal, 'portal_catalog')
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
comment1.title = 'Comment 1'
|
|
|
|
comment1.text = 'Comment text'
|
|
|
|
comment1.creator = 'Jim'
|
2009-07-03 08:37:14 +02:00
|
|
|
comment1.author_username = 'Jim'
|
2009-07-01 22:57:55 +02:00
|
|
|
comment1.creation_date = datetime(2006, 9, 17, 14, 18, 12)
|
|
|
|
comment1.modification_date = datetime(2006, 9, 17, 14, 18, 12)
|
|
|
|
|
|
|
|
new_comment1_id = conversation.addComment(comment1)
|
|
|
|
self.comment_id = new_comment1_id
|
|
|
|
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults(dict(
|
2011-04-14 22:17:10 +02:00
|
|
|
path={'query':
|
2010-08-28 19:06:53 +02:00
|
|
|
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
2011-04-14 22:17:10 +02:00
|
|
|
portal_type="Document"
|
2011-04-15 18:17:02 +02:00
|
|
|
))
|
2009-07-01 22:57:55 +02:00
|
|
|
self.conversation = conversation
|
2009-10-17 10:28:50 +02:00
|
|
|
self.brains = brains
|
|
|
|
self.doc1_brain = brains[0]
|
2009-07-01 22:57:55 +02:00
|
|
|
self.comment1 = comment1
|
2009-07-03 08:37:14 +02:00
|
|
|
self.new_comment1_id = new_comment1_id
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2009-07-01 22:57:55 +02:00
|
|
|
def test_total_comments(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue('total_comments' in self.doc1_brain)
|
|
|
|
self.assertEqual(self.doc1_brain.total_comments, 1)
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2009-07-01 22:57:55 +02:00
|
|
|
comment2 = createObject('plone.Comment')
|
|
|
|
comment2.title = 'Comment 2'
|
|
|
|
comment2.text = 'Comment text'
|
|
|
|
comment2.creator = 'Emma'
|
|
|
|
new_comment2_id = self.conversation.addComment(comment2)
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2010-08-28 19:06:53 +02:00
|
|
|
comment2 = self.portal.doc1.restrictedTraverse(
|
|
|
|
'++conversation++default/%s' % new_comment2_id)
|
2009-07-01 22:57:55 +02:00
|
|
|
comment2.reindexObject()
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults(dict(
|
2011-04-14 22:17:10 +02:00
|
|
|
path={'query':
|
2010-08-28 19:06:53 +02:00
|
|
|
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
2011-04-14 22:17:10 +02:00
|
|
|
portal_type="Document"
|
2011-04-15 18:17:02 +02:00
|
|
|
))
|
2009-10-17 10:28:50 +02:00
|
|
|
doc1_brain = brains[0]
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(doc1_brain.total_comments, 2)
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2009-07-01 22:57:55 +02:00
|
|
|
def test_last_comment_date(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue('last_comment_date' in self.doc1_brain)
|
|
|
|
self.assertEqual(self.doc1_brain.last_comment_date,
|
2010-08-28 19:06:53 +02:00
|
|
|
datetime(2006, 9, 17, 14, 18, 12))
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2009-07-03 08:37:14 +02:00
|
|
|
# Add another comment and check if last comment date is updated.
|
|
|
|
comment2 = createObject('plone.Comment')
|
|
|
|
comment2.title = 'Comment 2'
|
|
|
|
comment2.text = 'Comment text'
|
|
|
|
comment2.creator = 'Emma'
|
|
|
|
comment2.creation_date = datetime(2009, 9, 17, 14, 18, 12)
|
|
|
|
comment2.modification_date = datetime(2009, 9, 17, 14, 18, 12)
|
|
|
|
new_comment2_id = self.conversation.addComment(comment2)
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2010-08-28 19:06:53 +02:00
|
|
|
comment2 = self.portal.doc1.restrictedTraverse(
|
|
|
|
'++conversation++default/%s' % new_comment2_id)
|
2009-07-03 08:37:14 +02:00
|
|
|
comment2.reindexObject()
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults(dict(
|
2011-04-14 22:17:10 +02:00
|
|
|
path={'query':
|
2010-08-28 19:06:53 +02:00
|
|
|
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
2011-04-14 22:17:10 +02:00
|
|
|
portal_type="Document"
|
2011-04-15 18:17:02 +02:00
|
|
|
))
|
2009-10-17 10:28:50 +02:00
|
|
|
doc1_brain = brains[0]
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(doc1_brain.last_comment_date,
|
2010-08-28 19:06:53 +02:00
|
|
|
datetime(2009, 9, 17, 14, 18, 12))
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2009-07-03 08:37:14 +02:00
|
|
|
# Remove the comment again
|
|
|
|
del self.conversation[new_comment2_id]
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults(dict(
|
2011-04-14 22:17:10 +02:00
|
|
|
path={'query':
|
2010-08-28 19:06:53 +02:00
|
|
|
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
2011-04-14 22:17:10 +02:00
|
|
|
portal_type="Document"
|
2011-04-15 18:17:02 +02:00
|
|
|
))
|
2009-10-17 10:28:50 +02:00
|
|
|
doc1_brain = brains[0]
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(doc1_brain.last_comment_date,
|
2010-08-28 19:06:53 +02:00
|
|
|
datetime(2006, 9, 17, 14, 18, 12))
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2009-07-03 08:37:14 +02:00
|
|
|
# remove all comments
|
|
|
|
del self.conversation[self.new_comment1_id]
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults(dict(
|
2011-04-14 22:17:10 +02:00
|
|
|
path={'query':
|
2010-08-28 19:06:53 +02:00
|
|
|
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
2011-04-14 22:17:10 +02:00
|
|
|
portal_type="Document"
|
2011-04-15 18:17:02 +02:00
|
|
|
))
|
2009-10-17 10:28:50 +02:00
|
|
|
doc1_brain = brains[0]
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(doc1_brain.last_comment_date, None)
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2009-07-01 22:57:55 +02:00
|
|
|
def test_commentators(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue('commentators' in self.doc1_brain)
|
|
|
|
self.assertEqual(self.doc1_brain.commentators, ('Jim',))
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2009-07-03 08:37:14 +02:00
|
|
|
# add another comment with another author
|
|
|
|
comment2 = createObject('plone.Comment')
|
|
|
|
comment2.title = 'Comment 2'
|
|
|
|
comment2.text = 'Comment text'
|
|
|
|
comment2.creator = 'Emma'
|
|
|
|
comment2.author_username = 'Emma'
|
|
|
|
new_comment2_id = self.conversation.addComment(comment2)
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2010-08-28 19:06:53 +02:00
|
|
|
comment2 = self.portal.doc1.restrictedTraverse(
|
|
|
|
'++conversation++default/%s' % new_comment2_id)
|
2009-07-03 08:37:14 +02:00
|
|
|
comment2.reindexObject()
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults(dict(
|
2011-04-14 22:17:10 +02:00
|
|
|
path={'query':
|
2010-08-28 19:06:53 +02:00
|
|
|
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
2011-04-14 22:17:10 +02:00
|
|
|
portal_type="Document"
|
2011-04-15 18:17:02 +02:00
|
|
|
))
|
2009-10-17 10:28:50 +02:00
|
|
|
doc1_brain = brains[0]
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(doc1_brain.commentators, ('Emma', 'Jim'))
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2009-07-03 08:37:14 +02:00
|
|
|
# remove one comments
|
|
|
|
del self.conversation[new_comment2_id]
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults(dict(
|
2011-04-14 22:17:10 +02:00
|
|
|
path={'query':
|
2010-08-28 19:06:53 +02:00
|
|
|
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
2011-04-14 22:17:10 +02:00
|
|
|
portal_type="Document"
|
2011-04-15 18:17:02 +02:00
|
|
|
))
|
2009-10-17 10:28:50 +02:00
|
|
|
doc1_brain = brains[0]
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(doc1_brain.commentators, ('Jim',))
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2009-07-03 08:37:14 +02:00
|
|
|
# remove all comments
|
|
|
|
del self.conversation[self.new_comment1_id]
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults(dict(
|
2011-04-14 22:17:10 +02:00
|
|
|
path={'query':
|
2010-08-28 19:06:53 +02:00
|
|
|
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
2011-04-14 22:17:10 +02:00
|
|
|
portal_type="Document"
|
2011-04-15 18:17:02 +02:00
|
|
|
))
|
2009-10-17 10:28:50 +02:00
|
|
|
doc1_brain = brains[0]
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(doc1_brain.commentators, ())
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2009-07-06 18:56:09 +02:00
|
|
|
def test_conversation_indexes_not_in_comments(self):
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults(dict(
|
2011-04-14 22:17:10 +02:00
|
|
|
path={'query':
|
2010-08-28 19:06:53 +02:00
|
|
|
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
2011-04-14 22:17:10 +02:00
|
|
|
portal_type="Discussion Item"
|
2011-04-15 18:17:02 +02:00
|
|
|
))
|
2009-07-06 18:56:09 +02:00
|
|
|
comment1_brain = brains[0]
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(comment1_brain.commentators, None)
|
|
|
|
self.assertEqual(comment1_brain.last_comment_date, None)
|
|
|
|
self.assertEqual(comment1_brain.total_comments, None)
|
2009-07-06 18:56:09 +02:00
|
|
|
|
2011-04-14 22:17:10 +02:00
|
|
|
|
2011-04-16 11:13:39 +02:00
|
|
|
class CommentCatalogTest(unittest.TestCase):
|
|
|
|
|
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.portal = self.layer['portal']
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
2010-12-16 00:52:56 +01:00
|
|
|
self.portal.invokeFactory(id='doc1',
|
|
|
|
title='Document 1',
|
2010-09-29 09:56:36 +02:00
|
|
|
type_name='Document')
|
2009-07-01 22:57:55 +02:00
|
|
|
self.catalog = getToolByName(self.portal, 'portal_catalog')
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2009-07-01 22:57:55 +02:00
|
|
|
conversation = IConversation(self.portal.doc1)
|
2009-10-15 12:11:12 +02:00
|
|
|
self.conversation = conversation
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2009-07-01 22:57:55 +02:00
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
comment1.text = 'Comment text'
|
|
|
|
comment1.creator = 'Jim'
|
|
|
|
new_comment1_id = conversation.addComment(comment1)
|
|
|
|
self.comment_id = new_comment1_id
|
2011-04-16 11:13:39 +02:00
|
|
|
|
2010-09-29 09:56:36 +02:00
|
|
|
# Comment brain
|
2010-08-28 19:06:53 +02:00
|
|
|
self.comment = self.portal.doc1.restrictedTraverse(
|
|
|
|
'++conversation++default/%s' % new_comment1_id)
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults(dict(
|
2011-04-14 22:17:10 +02:00
|
|
|
path={'query':
|
2011-04-15 18:17:02 +02:00
|
|
|
'/'.join(self.comment.getPhysicalPath())}))
|
2009-07-01 22:57:55 +02:00
|
|
|
self.comment_brain = brains[0]
|
2011-07-03 20:36:02 +02:00
|
|
|
|
2009-07-01 22:57:55 +02:00
|
|
|
def test_title(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(self.comment_brain.Title, 'Jim on Document 1')
|
2011-07-03 20:36:02 +02:00
|
|
|
|
2010-09-29 12:52:11 +02:00
|
|
|
def test_no_name_title(self):
|
|
|
|
comment = createObject('plone.Comment')
|
|
|
|
comment.text = 'Comment text'
|
|
|
|
cid = self.conversation.addComment(comment)
|
|
|
|
|
|
|
|
# Comment brain
|
|
|
|
comment = self.portal.doc1.restrictedTraverse(
|
|
|
|
'++conversation++default/%s' % cid)
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults(dict(
|
2011-04-14 22:17:10 +02:00
|
|
|
path={'query':
|
2011-04-15 18:17:02 +02:00
|
|
|
'/'.join(comment.getPhysicalPath())}))
|
2010-09-29 12:52:11 +02:00
|
|
|
comment_brain = brains[0]
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(comment_brain.Title, "Anonymous on Document 1")
|
2009-07-01 22:57:55 +02:00
|
|
|
|
|
|
|
def test_type(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(self.comment_brain.portal_type, 'Discussion Item')
|
|
|
|
self.assertEqual(self.comment_brain.meta_type, 'Discussion Item')
|
|
|
|
self.assertEqual(self.comment_brain.Type, 'Comment')
|
2009-07-01 22:57:55 +02:00
|
|
|
|
|
|
|
def test_review_state(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(self.comment_brain.review_state, 'published')
|
2009-07-01 22:57:55 +02:00
|
|
|
|
|
|
|
def test_creator(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(self.comment_brain.Creator, 'Jim')
|
2009-07-01 22:57:55 +02:00
|
|
|
|
2009-07-03 10:03:09 +02:00
|
|
|
def test_in_response_to(self):
|
2010-09-29 09:56:36 +02:00
|
|
|
"""Make sure in_response_to returns the title or id of the content
|
|
|
|
object the comment was added to.
|
|
|
|
"""
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(self.comment_brain.in_response_to, 'Document 1')
|
2009-07-03 10:03:09 +02:00
|
|
|
|
2010-03-03 20:20:02 +01:00
|
|
|
def test_add_comment(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(self.comment_brain)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-03-03 20:20:02 +01:00
|
|
|
def test_delete_comment(self):
|
|
|
|
# Make sure a comment is removed from the catalog as well when it is
|
|
|
|
# deleted.
|
|
|
|
del self.conversation[self.comment_id]
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults(dict(
|
2011-04-14 22:17:10 +02:00
|
|
|
path={'query':
|
2011-04-15 18:17:02 +02:00
|
|
|
'/'.join(self.comment.getPhysicalPath())}))
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(brains), 0)
|
2010-03-03 20:20:02 +01:00
|
|
|
|
|
|
|
def test_remove_comments_when_content_object_is_removed(self):
|
2010-10-02 16:50:17 +02:00
|
|
|
"""Make sure all comments are removed from the catalog, if the content
|
|
|
|
object is removed.
|
|
|
|
"""
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults({'portal_type': 'Discussion Item'})
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(brains), 1)
|
2010-10-02 16:50:17 +02:00
|
|
|
self.portal.manage_delObjects(["doc1"])
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults({'portal_type': 'Discussion Item'})
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(brains), 0)
|
2011-07-04 09:27:16 +02:00
|
|
|
|
|
|
|
def test_move_comments_when_content_object_is_moved(self):
|
2011-08-04 17:53:21 +02:00
|
|
|
# Create two folders and a content object with a comment
|
2011-07-04 09:27:16 +02:00
|
|
|
self.portal.invokeFactory(id='folder1',
|
|
|
|
title='Folder 1',
|
|
|
|
type_name='Folder')
|
2011-08-04 17:53:21 +02:00
|
|
|
self.portal.invokeFactory(id='folder2',
|
|
|
|
title='Folder 2',
|
|
|
|
type_name='Folder')
|
|
|
|
self.portal.folder1.invokeFactory(id='moveme',
|
|
|
|
title='Move Me',
|
|
|
|
type_name='Document')
|
|
|
|
conversation = IConversation(self.portal.folder1.moveme)
|
|
|
|
comment = createObject('plone.Comment')
|
|
|
|
comment_id = conversation.addComment(comment)
|
|
|
|
# We need to commit here so that _p_jar isn't None and move will work
|
|
|
|
transaction.savepoint(optimistic=True)
|
2011-07-04 09:27:16 +02:00
|
|
|
|
2011-08-04 17:53:21 +02:00
|
|
|
# Move moveme from folder1 to folder2
|
|
|
|
cp = self.portal.folder1.manage_cutObjects(ids=('moveme',))
|
|
|
|
self.portal.folder2.manage_pasteObjects(cp)
|
2011-07-04 09:27:16 +02:00
|
|
|
|
2011-08-04 17:53:21 +02:00
|
|
|
# Make sure no old comment brains are
|
|
|
|
brains = self.catalog.searchResults(dict(
|
|
|
|
portal_type="Discussion Item",
|
|
|
|
path={'query': '/'.join(self.portal.folder1.getPhysicalPath())}
|
|
|
|
))
|
|
|
|
self.assertEquals(len(brains), 0)
|
|
|
|
|
|
|
|
brains = self.catalog.searchResults(dict(
|
|
|
|
portal_type="Discussion Item",
|
|
|
|
path={'query': '/'.join(self.portal.folder2.getPhysicalPath())}
|
|
|
|
))
|
|
|
|
self.assertEquals(len(brains), 1)
|
2011-07-04 09:27:16 +02:00
|
|
|
self.assertEquals(brains[0].getPath(),
|
2011-08-04 17:53:21 +02:00
|
|
|
'/plone/folder2/moveme/++conversation++default/' +
|
|
|
|
str(comment_id))
|
2011-08-04 16:13:01 +02:00
|
|
|
|
|
|
|
def test_update_comments_when_content_object_is_renamed(self):
|
|
|
|
# We need to commit here so that _p_jar isn't None and move will work
|
|
|
|
transaction.savepoint(optimistic=True)
|
|
|
|
|
|
|
|
self.portal.manage_renameObject("doc1", "doc2")
|
|
|
|
|
|
|
|
brains = self.catalog.searchResults(portal_type = 'Discussion Item')
|
|
|
|
self.assertEquals(len(brains), 1)
|
|
|
|
self.assertEquals(brains[0].getPath(),
|
|
|
|
'/plone/doc2/++conversation++default/' +
|
|
|
|
str(self.comment_id))
|
|
|
|
|
2009-07-03 13:22:21 +02:00
|
|
|
def test_clear_and_rebuild_catalog(self):
|
2010-01-27 15:54:07 +01:00
|
|
|
# Clear and rebuild catalog
|
2009-10-14 16:58:08 +02:00
|
|
|
self.catalog.clearFindAndRebuild()
|
|
|
|
|
|
|
|
# Check if comment is still there
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults({'portal_type': 'Discussion Item'})
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(brains)
|
2009-10-14 16:58:08 +02:00
|
|
|
comment_brain = brains[0]
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(comment_brain.Title, u'Jim on Document 1')
|
2011-12-21 19:37:40 +01:00
|
|
|
self.assertEqual(comment_brain.getPath(),
|
|
|
|
'/plone/doc1/++conversation++default/' +
|
|
|
|
str(self.comment_id))
|
2009-07-03 13:22:21 +02:00
|
|
|
|
2009-10-15 12:11:12 +02:00
|
|
|
def test_clear_and_rebuild_catalog_for_nested_comments(self):
|
|
|
|
|
|
|
|
# Create a nested comment structure:
|
|
|
|
#
|
|
|
|
# Conversation
|
|
|
|
# +- Comment 1
|
|
|
|
# +- Comment 1_1
|
|
|
|
# | +- Comment 1_1_1
|
|
|
|
# +- Comment 1_2
|
|
|
|
# +- Comment 2
|
|
|
|
# +- Comment 2_1
|
|
|
|
|
|
|
|
comment1_1 = createObject('plone.Comment')
|
|
|
|
comment1_1.title = 'Re: Comment 1'
|
|
|
|
comment1_1.text = 'Comment text'
|
|
|
|
|
|
|
|
comment1_1_1 = createObject('plone.Comment')
|
|
|
|
comment1_1_1.title = 'Re: Re: Comment 1'
|
|
|
|
comment1_1_1.text = 'Comment text'
|
|
|
|
|
|
|
|
comment1_2 = createObject('plone.Comment')
|
|
|
|
comment1_2.title = 'Re: Comment 1 (2)'
|
|
|
|
comment1_2.text = 'Comment text'
|
|
|
|
|
|
|
|
comment2 = createObject('plone.Comment')
|
|
|
|
comment2.title = 'Comment 2'
|
|
|
|
comment2.text = 'Comment text'
|
|
|
|
|
|
|
|
comment2_1 = createObject('plone.Comment')
|
|
|
|
comment2_1.title = 'Re: Comment 2'
|
|
|
|
comment2_1.text = 'Comment text'
|
|
|
|
|
|
|
|
# Create the nested comment structure
|
|
|
|
new_id_1 = self.conversation.addComment(self.comment)
|
|
|
|
new_id_2 = self.conversation.addComment(comment2)
|
|
|
|
|
|
|
|
comment1_1.in_reply_to = self.comment_id
|
|
|
|
new_id_1_1 = self.conversation.addComment(comment1_1)
|
|
|
|
|
|
|
|
comment1_1_1.in_reply_to = new_id_1_1
|
2010-07-13 12:45:53 +02:00
|
|
|
self.conversation.addComment(comment1_1_1)
|
2009-10-15 12:11:12 +02:00
|
|
|
|
|
|
|
comment1_2.in_reply_to = new_id_1
|
2010-07-13 12:45:53 +02:00
|
|
|
self.conversation.addComment(comment1_2)
|
2009-10-15 12:11:12 +02:00
|
|
|
|
|
|
|
comment2_1.in_reply_to = new_id_2
|
2010-07-13 12:45:53 +02:00
|
|
|
self.conversation.addComment(comment2_1)
|
2009-10-15 12:11:12 +02:00
|
|
|
|
|
|
|
# Clear and rebuild catalog
|
|
|
|
self.catalog.clearFindAndRebuild()
|
|
|
|
|
|
|
|
# Check if comments are still there
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults({'portal_type': 'Discussion Item'})
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(brains)
|
|
|
|
self.assertEqual(len(brains), 6)
|
2009-10-15 12:11:12 +02:00
|
|
|
|
2010-02-05 23:40:38 +01:00
|
|
|
def test_collection(self):
|
2010-12-16 00:52:56 +01:00
|
|
|
self.portal.invokeFactory(id='topic', type_name='Topic')
|
2010-02-05 23:40:38 +01:00
|
|
|
topic = self.portal.topic
|
2010-03-17 16:00:19 +01:00
|
|
|
crit = topic.addCriterion('Type', 'ATSimpleStringCriterion')
|
2010-03-18 14:22:06 +01:00
|
|
|
crit.setValue('Comment')
|
2010-02-05 23:40:38 +01:00
|
|
|
query = topic.buildQuery()
|
|
|
|
|
2010-03-17 16:00:19 +01:00
|
|
|
# Make sure the comment we just added is returned by the collection
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(query), 1)
|
|
|
|
self.assertEqual(query['Type'], 'Comment')
|
|
|
|
self.assertEqual(len(topic.queryCatalog()), 1)
|
2010-02-05 23:40:38 +01:00
|
|
|
|
2011-04-14 18:17:29 +02:00
|
|
|
|
2011-04-16 11:13:39 +02:00
|
|
|
class NoConversationCatalogTest(unittest.TestCase):
|
2011-04-14 18:17:29 +02:00
|
|
|
|
2011-04-16 11:13:39 +02:00
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
2011-04-14 18:17:29 +02:00
|
|
|
|
2011-04-16 11:13:39 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.portal = self.layer['portal']
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
2011-04-14 18:17:29 +02:00
|
|
|
self.portal.invokeFactory(id='doc1',
|
|
|
|
Title='Document 1',
|
|
|
|
type_name='Document')
|
|
|
|
|
|
|
|
self.catalog = getToolByName(self.portal, 'portal_catalog')
|
|
|
|
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
|
2011-04-15 18:17:02 +02:00
|
|
|
brains = self.catalog.searchResults(dict(
|
2011-04-14 22:17:10 +02:00
|
|
|
path={'query':
|
2011-04-15 18:17:02 +02:00
|
|
|
'/'.join(self.portal.doc1.getPhysicalPath())},
|
2011-04-14 22:17:10 +02:00
|
|
|
portal_type="Document"
|
2011-04-15 18:17:02 +02:00
|
|
|
))
|
2011-04-14 18:17:29 +02:00
|
|
|
self.conversation = conversation
|
|
|
|
self.brains = brains
|
|
|
|
self.doc1_brain = brains[0]
|
|
|
|
|
|
|
|
def test_total_comments(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue('total_comments' in self.doc1_brain)
|
|
|
|
self.assertEqual(self.doc1_brain.total_comments, 0)
|
2011-04-14 18:17:29 +02:00
|
|
|
|
|
|
|
# Make sure no conversation has been created
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue('plone.app.discussion:conversation' not in
|
2011-04-14 18:17:29 +02:00
|
|
|
IAnnotations(self.portal.doc1))
|
|
|
|
|
|
|
|
|
2009-07-01 22:57:55 +02:00
|
|
|
def test_suite():
|
2010-03-18 14:22:06 +01:00
|
|
|
return unittest.defaultTestLoader.loadTestsFromName(__name__)
|