diff --git a/plone/app/discussion/tests/test_catalog.py b/plone/app/discussion/tests/test_catalog.py index b0e5e36..d85c8fc 100644 --- a/plone/app/discussion/tests/test_catalog.py +++ b/plone/app/discussion/tests/test_catalog.py @@ -67,8 +67,7 @@ class ConversationCatalogTest(unittest.TestCase): id='doc1', Title='Document 1', type_name='Document' - ) - + ) self.catalog = getToolByName(self.portal, 'portal_catalog') conversation = IConversation(self.portal.doc1) comment1 = createObject('plone.Comment') @@ -108,17 +107,21 @@ class ConversationCatalogTest(unittest.TestCase): '++conversation++default/%s' % new_comment2_id) comment2.reindexObject() brains = self.catalog.searchResults(dict( - path={'query': - '/'.join(self.portal.doc1.getPhysicalPath())}, - portal_type="Document" - )) + path={ + 'query': + '/'.join(self.portal.doc1.getPhysicalPath()) + }, + portal_type="Document" + )) doc1_brain = brains[0] self.assertEqual(doc1_brain.total_comments, 2) 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,33 +135,43 @@ class ConversationCatalogTest(unittest.TestCase): '++conversation++default/%s' % new_comment2_id) comment2.reindexObject() brains = self.catalog.searchResults(dict( - path={'query': - '/'.join(self.portal.doc1.getPhysicalPath())}, - portal_type="Document" - )) + 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())}, - portal_type="Document" - )) + 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())}, - portal_type="Document" - )) + path={ + 'query': + '/'.join(self.portal.doc1.getPhysicalPath()) + }, + portal_type="Document" + )) doc1_brain = brains[0] self.assertEqual(doc1_brain.last_comment_date, None) @@ -179,10 +192,12 @@ class ConversationCatalogTest(unittest.TestCase): comment2.reindexObject() brains = self.catalog.searchResults(dict( - path={'query': - '/'.join(self.portal.doc1.getPhysicalPath())}, - portal_type="Document" - )) + path={ + 'query': + '/'.join(self.portal.doc1.getPhysicalPath()) + }, + portal_type="Document" + )) doc1_brain = brains[0] self.assertEqual(doc1_brain.commentators, ('Jim', 'Emma')) @@ -190,29 +205,35 @@ 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())}, - portal_type="Document" - )) + path={ + 'query': + '/'.join(self.portal.doc1.getPhysicalPath()) + }, + portal_type="Document" + )) doc1_brain = brains[0] self.assertEqual(doc1_brain.commentators, ('Jim',)) # remove all comments del self.conversation[self.new_comment1_id] brains = self.catalog.searchResults(dict( - path={'query': - '/'.join(self.portal.doc1.getPhysicalPath())}, - portal_type="Document" - )) + path={ + 'query': + '/'.join(self.portal.doc1.getPhysicalPath()) + }, + portal_type="Document" + )) doc1_brain = brains[0] self.assertEqual(doc1_brain.commentators, ()) def test_conversation_indexes_not_in_comments(self): brains = self.catalog.searchResults(dict( - path={'query': - '/'.join(self.portal.doc1.getPhysicalPath())}, - portal_type="Discussion Item" - )) + path={ + 'query': + '/'.join(self.portal.doc1.getPhysicalPath()) + }, + portal_type="Discussion Item" + )) comment1_brain = brains[0] self.assertEqual(comment1_brain.commentators, None) self.assertEqual(comment1_brain.last_comment_date, None) @@ -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())}, - portal_type="Document" - )) + 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', - title='Folder 1', - type_name='Folder') - self.portal.invokeFactory(id='folder2', - title='Folder 2', - type_name='Folder') - self.portal.folder1.invokeFactory(id='moveme', - title='Move Me', - type_name='Document') + self.portal.invokeFactory( + id='folder1', + title='Folder 1', + type_name='Folder' + ) + 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) @@ -338,22 +377,23 @@ class CommentCatalogTest(unittest.TestCase): # Make sure no old comment brains are brains = self.catalog.searchResults(dict( - portal_type="Discussion Item", - path={'query': '/'.join(self.portal.folder1.getPhysicalPath())} - )) + portal_type="Discussion Item", + path={'query': '/'.join(self.portal.folder1.getPhysicalPath())} + )) self.assertEqual(len(brains), 0) brains = self.catalog.searchResults(dict( - portal_type="Discussion Item", - path={ - 'query': '/'.join(self.portal.folder2.getPhysicalPath()) - } - )) + portal_type="Discussion Item", + path={ + 'query': '/'.join(self.portal.folder2.getPhysicalPath()) + } + )) self.assertEqual(len(brains), 1) - self.assertEqual(brains[0].getPath(), - '/plone/folder2/moveme/++conversation++default/' + - str(comment_id)) - + self.assertEqual( + brains[0].getPath(), + '/plone/folder2/moveme/++conversation++default/' + + 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) @@ -384,20 +426,22 @@ class CommentCatalogTest(unittest.TestCase): # Make sure no old comment brains are left brains = self.catalog.searchResults(dict( - portal_type="Discussion Item", - path={'query': '/plone/sourcefolder/moveme'} - )) + portal_type="Discussion Item", + path={'query': '/plone/sourcefolder/moveme'} + )) self.assertEqual(len(brains), 0) # make sure comments are correctly index on the target brains = self.catalog.searchResults(dict( - portal_type="Discussion Item", - path={'query': '/plone/targetfolder/moveme'} - )) + portal_type="Discussion Item", + path={'query': '/plone/targetfolder/moveme'} + )) self.assertEqual(len(brains), 1) - self.assertEqual(brains[0].getPath(), - '/plone/targetfolder/moveme/mydocument/++conversation++default/' + - str(comment_id)) + self.assertEqual( + brains[0].getPath(), + '/plone/targetfolder/moveme/mydocument/++conversation++default/' + + 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(), - '/plone/doc2/++conversation++default/' + - str(self.comment_id)) + self.assertEqual( + brains[0].getPath(), + '/plone/doc2/++conversation++default/' + + 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): @@ -496,9 +544,9 @@ class CommentCatalogTest(unittest.TestCase): self.portal.invokeFactory('Collection', id='collection') collection = self.portal.collection collection.query = [{ - 'i': 'Type', - 'o': 'plone.app.querystring.operation.string.is', - 'v': 'Comment', + 'i': 'Type', + 'o': 'plone.app.querystring.operation.string.is', + 'v': 'Comment', }] self.assertEqual(len(collection.results()), 1) @@ -523,10 +571,12 @@ class NoConversationCatalogTest(unittest.TestCase): conversation = IConversation(self.portal.doc1) brains = self.catalog.searchResults(dict( - path={'query': - '/'.join(self.portal.doc1.getPhysicalPath())}, - portal_type="Document" - )) + path={ + 'query': + '/'.join(self.portal.doc1.getPhysicalPath()) + }, + portal_type="Document" + )) self.conversation = conversation self.brains = brains self.doc1_brain = brains[0]