This commit is contained in:
Timo Stollenwerk 2013-04-18 15:21:00 +02:00
parent 20935da608
commit 849299f233

View File

@ -68,7 +68,6 @@ class ConversationCatalogTest(unittest.TestCase):
Title='Document 1',
type_name='Document'
)
self.catalog = getToolByName(self.portal, 'portal_catalog')
conversation = IConversation(self.portal.doc1)
comment1 = createObject('plone.Comment')
@ -108,8 +107,10 @@ class ConversationCatalogTest(unittest.TestCase):
'++conversation++default/%s' % new_comment2_id)
comment2.reindexObject()
brains = self.catalog.searchResults(dict(
path={'query':
'/'.join(self.portal.doc1.getPhysicalPath())},
path={
'query':
'/'.join(self.portal.doc1.getPhysicalPath())
},
portal_type="Document"
))
doc1_brain = brains[0]
@ -117,8 +118,10 @@ class ConversationCatalogTest(unittest.TestCase):
def test_last_comment_date(self):
self.assertTrue('last_comment_date' in self.doc1_brain)
self.assertEqual(self.doc1_brain.last_comment_date,
datetime(2006, 9, 17, 14, 18, 12))
self.assertEqual(
self.doc1_brain.last_comment_date,
datetime(2006, 9, 17, 14, 18, 12)
)
# Add another comment and check if last comment date is updated.
comment2 = createObject('plone.Comment')
@ -132,31 +135,41 @@ class ConversationCatalogTest(unittest.TestCase):
'++conversation++default/%s' % new_comment2_id)
comment2.reindexObject()
brains = self.catalog.searchResults(dict(
path={'query':
'/'.join(self.portal.doc1.getPhysicalPath())},
path={
'query':
'/'.join(self.portal.doc1.getPhysicalPath())
},
portal_type="Document"
))
doc1_brain = brains[0]
self.assertEqual(doc1_brain.last_comment_date,
datetime(2009, 9, 17, 14, 18, 12))
self.assertEqual(
doc1_brain.last_comment_date,
datetime(2009, 9, 17, 14, 18, 12)
)
# Remove the comment again
del self.conversation[new_comment2_id]
brains = self.catalog.searchResults(dict(
path={'query':
'/'.join(self.portal.doc1.getPhysicalPath())},
path={
'query':
'/'.join(self.portal.doc1.getPhysicalPath())
},
portal_type="Document"
))
doc1_brain = brains[0]
self.assertEqual(doc1_brain.last_comment_date,
datetime(2006, 9, 17, 14, 18, 12))
self.assertEqual(
doc1_brain.last_comment_date,
datetime(2006, 9, 17, 14, 18, 12)
)
# remove all comments
del self.conversation[self.new_comment1_id]
brains = self.catalog.searchResults(dict(
path={'query':
'/'.join(self.portal.doc1.getPhysicalPath())},
path={
'query':
'/'.join(self.portal.doc1.getPhysicalPath())
},
portal_type="Document"
))
doc1_brain = brains[0]
@ -179,8 +192,10 @@ class ConversationCatalogTest(unittest.TestCase):
comment2.reindexObject()
brains = self.catalog.searchResults(dict(
path={'query':
'/'.join(self.portal.doc1.getPhysicalPath())},
path={
'query':
'/'.join(self.portal.doc1.getPhysicalPath())
},
portal_type="Document"
))
doc1_brain = brains[0]
@ -190,8 +205,10 @@ class ConversationCatalogTest(unittest.TestCase):
# remove one comments
del self.conversation[new_comment2_id]
brains = self.catalog.searchResults(dict(
path={'query':
'/'.join(self.portal.doc1.getPhysicalPath())},
path={
'query':
'/'.join(self.portal.doc1.getPhysicalPath())
},
portal_type="Document"
))
doc1_brain = brains[0]
@ -200,8 +217,10 @@ class ConversationCatalogTest(unittest.TestCase):
# remove all comments
del self.conversation[self.new_comment1_id]
brains = self.catalog.searchResults(dict(
path={'query':
'/'.join(self.portal.doc1.getPhysicalPath())},
path={
'query':
'/'.join(self.portal.doc1.getPhysicalPath())
},
portal_type="Document"
))
doc1_brain = brains[0]
@ -209,8 +228,10 @@ class ConversationCatalogTest(unittest.TestCase):
def test_conversation_indexes_not_in_comments(self):
brains = self.catalog.searchResults(dict(
path={'query':
'/'.join(self.portal.doc1.getPhysicalPath())},
path={
'query':
'/'.join(self.portal.doc1.getPhysicalPath())
},
portal_type="Discussion Item"
))
comment1_brain = brains[0]
@ -222,13 +243,16 @@ class ConversationCatalogTest(unittest.TestCase):
self.comment1.manage_permission("View", roles=tuple())
self.portal.doc1.reindexObject()
brains = self.catalog.searchResults(dict(
path={'query':
'/'.join(self.portal.doc1.getPhysicalPath())},
path={
'query':
'/'.join(self.portal.doc1.getPhysicalPath())
},
portal_type="Document"
))
doc1_brain = brains[0]
self.assertEqual(doc1_brain.commentators, ())
class CommentCatalogTest(unittest.TestCase):
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
@ -255,8 +279,11 @@ class CommentCatalogTest(unittest.TestCase):
self.comment = self.portal.doc1.restrictedTraverse(
'++conversation++default/%s' % new_comment1_id)
brains = self.catalog.searchResults(dict(
path={'query':
'/'.join(self.comment.getPhysicalPath())}))
path={
'query':
'/'.join(self.comment.getPhysicalPath())
}
))
self.comment_brain = brains[0]
def test_title(self):
@ -271,8 +298,11 @@ class CommentCatalogTest(unittest.TestCase):
comment = self.portal.doc1.restrictedTraverse(
'++conversation++default/%s' % cid)
brains = self.catalog.searchResults(dict(
path={'query':
'/'.join(comment.getPhysicalPath())}))
path={
'query':
'/'.join(comment.getPhysicalPath())
}
))
comment_brain = brains[0]
self.assertEqual(comment_brain.Title, "Anonymous on Document 1")
@ -301,8 +331,11 @@ class CommentCatalogTest(unittest.TestCase):
# deleted.
del self.conversation[self.comment_id]
brains = self.catalog.searchResults(dict(
path={'query':
'/'.join(self.comment.getPhysicalPath())}))
path={
'query':
'/'.join(self.comment.getPhysicalPath())
}
))
self.assertEqual(len(brains), 0)
def test_remove_comments_when_content_object_is_removed(self):
@ -317,15 +350,21 @@ class CommentCatalogTest(unittest.TestCase):
def test_move_comments_when_content_object_is_moved(self):
# Create two folders and a content object with a comment
self.portal.invokeFactory(id='folder1',
self.portal.invokeFactory(
id='folder1',
title='Folder 1',
type_name='Folder')
self.portal.invokeFactory(id='folder2',
type_name='Folder'
)
self.portal.invokeFactory(
id='folder2',
title='Folder 2',
type_name='Folder')
self.portal.folder1.invokeFactory(id='moveme',
type_name='Folder'
)
self.portal.folder1.invokeFactory(
id='moveme',
title='Move Me',
type_name='Document')
type_name='Document'
)
conversation = IConversation(self.portal.folder1.moveme)
comment = createObject('plone.Comment')
comment_id = conversation.addComment(comment)
@ -350,10 +389,11 @@ class CommentCatalogTest(unittest.TestCase):
}
))
self.assertEqual(len(brains), 1)
self.assertEqual(brains[0].getPath(),
self.assertEqual(
brains[0].getPath(),
'/plone/folder2/moveme/++conversation++default/' +
str(comment_id))
str(comment_id)
)
def test_move_upper_level_folder(self):
# create a folder with a nested structure
@ -371,7 +411,9 @@ class CommentCatalogTest(unittest.TestCase):
type_name='Folder')
# create comment on my-document
conversation = IConversation(self.portal.sourcefolder.moveme.mydocument)
conversation = IConversation(
self.portal.sourcefolder.moveme.mydocument
)
comment = createObject('plone.Comment')
comment_id = conversation.addComment(comment)
@ -395,9 +437,11 @@ class CommentCatalogTest(unittest.TestCase):
path={'query': '/plone/targetfolder/moveme'}
))
self.assertEqual(len(brains), 1)
self.assertEqual(brains[0].getPath(),
self.assertEqual(
brains[0].getPath(),
'/plone/targetfolder/moveme/mydocument/++conversation++default/' +
str(comment_id))
str(comment_id)
)
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
@ -408,9 +452,11 @@ class CommentCatalogTest(unittest.TestCase):
brains = self.catalog.searchResults(
portal_type='Discussion Item')
self.assertEqual(len(brains), 1)
self.assertEqual(brains[0].getPath(),
self.assertEqual(
brains[0].getPath(),
'/plone/doc2/++conversation++default/' +
str(self.comment_id))
str(self.comment_id)
)
def test_clear_and_rebuild_catalog(self):
# Clear and rebuild catalog
@ -421,9 +467,11 @@ class CommentCatalogTest(unittest.TestCase):
self.assertTrue(brains)
comment_brain = brains[0]
self.assertEqual(comment_brain.Title, u'Jim on Document 1')
self.assertEqual(comment_brain.getPath(),
self.assertEqual(
comment_brain.getPath(),
'/plone/doc1/++conversation++default/' +
str(self.comment_id))
str(self.comment_id)
)
def test_clear_and_rebuild_catalog_for_nested_comments(self):
@ -523,8 +571,10 @@ class NoConversationCatalogTest(unittest.TestCase):
conversation = IConversation(self.portal.doc1)
brains = self.catalog.searchResults(dict(
path={'query':
'/'.join(self.portal.doc1.getPhysicalPath())},
path={
'query':
'/'.join(self.portal.doc1.getPhysicalPath())
},
portal_type="Document"
))
self.conversation = conversation