add migration test for comment Creator and nested comments.

svn path=/plone.app.discussion/trunk/; revision=27960
This commit is contained in:
Timo Stollenwerk 2009-07-12 07:09:07 +00:00
parent 88cbd01379
commit d7eaab75c8
2 changed files with 52 additions and 8 deletions

View File

@ -35,7 +35,7 @@ class View(BrowserView):
dtool = context.portal_discussion dtool = context.portal_discussion
brains = catalog.searchResults( brains = catalog.searchResults(
object_provides='Products.CMFCore.interfaces._content.IContentish') object_provides='Products.CMFCore.interfaces._content.IContentish')
log("Found %s content object to migrate." % len(brains)) log("Found %s content objects to migrate." % len(brains))
for brain in brains: for brain in brains:
if brain.portal_type != 'Discussion Item': if brain.portal_type != 'Discussion Item':
@ -56,6 +56,7 @@ class View(BrowserView):
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.title = old_comment.Title() comment.title = old_comment.Title()
comment.text = old_comment.text comment.text = old_comment.text
comment.Creator = old_comment.Creator
conversation.addComment(comment) conversation.addComment(comment)
log("Comment migration finished.") log("Comment migration finished.")

View File

@ -30,29 +30,72 @@ class MigrationTest(PloneTestCase):
self.view = View(context, request) self.view = View(context, request)
self.workflow.setChainForPortalTypes(('Discussion Item',), 'comment_review_workflow') self.workflow.setChainForPortalTypes(('Discussion Item',), 'comment_review_workflow')
self.doc = self.portal.doc
def test_migrate_comment(self): def test_migrate_comment(self):
# Create one comment # Create one comment
self.discussion.getDiscussionFor(self.portal.doc) self.discussion.getDiscussionFor(self.doc)
self.portal.doc.talkback.createReply('My Title', 'My Text') self.doc.talkback.createReply('My Title', 'My Text', Creator='Jim')
reply = self.portal.doc.talkback.objectValues()[0] reply = self.doc.talkback.objectValues()[0]
self.assertEqual(reply.Title(), 'My Title') self.assertEqual(reply.Title(), 'My Title')
self.assertEqual(reply.EditableBody(), 'My Text') self.assertEqual(reply.EditableBody(), 'My Text')
self.failUnless('Jim' in reply.listCreators())
# Call migration script # Call migration script
self.view() self.view()
# Make sure a conversation has been created # Make sure a conversation has been created
self.failUnless('plone.app.discussion:conversation' in IAnnotations(self.portal.doc)) self.failUnless('plone.app.discussion:conversation' in IAnnotations(self.doc))
conversation = IConversation(self.portal.doc) conversation = IConversation(self.doc)
# Check migration # Check migration
self.assertEquals(conversation.total_comments, 1) self.assertEquals(conversation.total_comments, 1)
self.failUnless(conversation.getComments().next()) self.failUnless(conversation.getComments().next())
self.assert_(IComment.providedBy(conversation.getComments().next())) self.assert_(IComment.providedBy(conversation.getComments().next()))
self.assertEquals(conversation.getComments().next().Title(), 'My Title') self.assertEquals(conversation.values()[0].Title(), 'My Title')
self.assertEquals(conversation.getComments().next().text, 'My Text') self.assertEquals(conversation.values()[0].text, 'My Text')
self.assertEquals(conversation.values()[0].Creator(), 'Jim')
def test_migrate_nested_comments(self):
# Create some nested comments and migrate them
#
# self.doc
# +- First comment
# +- Re: First comment
talkback = self.discussion.getDiscussionFor(self.doc)
# Create comment
comment1_id = talkback.createReply(title='First comment',
text='This is my first comment.')
comment1 = talkback.getReplies()[0]
talkback_comment1 = self.discussion.getDiscussionFor(comment1)
# Create reply to comment
comment1_1_id = talkback_comment1.createReply(title='Re: First comment',
text='This is my first reply.')
comment1_1 = talkback_comment1.getReplies()[0]
talkback_comment1_1 = self.discussion.getDiscussionFor(comment1_1)
self.assertEquals(len(talkback.getReplies()), 1)
self.assertEquals(len(talkback_comment1.getReplies()), 1)
self.assertEquals(len(talkback_comment1_1.getReplies()), 0)
# Call migration script
self.view()
# Check migration
conversation = IConversation(self.doc)
self.assertEquals(conversation.total_comments, 2)
self.assert_(IComment.providedBy(conversation.getComments().next()))
# XXX: This is not very elegant
self.failUnless('First comment' in conversation.values()[0].Title() or
'Re: First comment' in conversation.values()[0].Title())
self.failUnless('This is my first comment.' in conversation.values()[0].text or
'This is my first reply.' in conversation.values()[1].text)
def test_suite(): def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__) return unittest.defaultTestLoader.loadTestsFromName(__name__)