2009-07-12 19:55:54 +02:00
|
|
|
from datetime import datetime
|
|
|
|
from DateTime import DateTime
|
|
|
|
|
2009-07-07 18:16:58 +02:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from zope.annotation.interfaces import IAnnotations
|
|
|
|
|
|
|
|
from Products.CMFCore.utils import getToolByName
|
|
|
|
|
|
|
|
from Products.PloneTestCase.ptc import PloneTestCase
|
|
|
|
|
|
|
|
from plone.app.discussion.tests.layer import DiscussionLayer
|
|
|
|
|
|
|
|
from plone.app.discussion.browser.migration import View
|
|
|
|
|
|
|
|
from plone.app.discussion.interfaces import IConversation, IComment
|
|
|
|
|
|
|
|
class MigrationTest(PloneTestCase):
|
|
|
|
|
2010-02-11 22:05:28 +01:00
|
|
|
layer = DiscussionLayer
|
|
|
|
|
2009-07-07 18:16:58 +02:00
|
|
|
def afterSetUp(self):
|
|
|
|
self.loginAsPortalOwner()
|
|
|
|
typetool = self.portal.portal_types
|
|
|
|
typetool.constructContent('Document', self.portal, 'doc')
|
|
|
|
# Create a document
|
|
|
|
self.discussion = getToolByName(self.portal, 'portal_discussion', None)
|
|
|
|
self.discussion.overrideDiscussionFor(self.portal.doc, 1)
|
|
|
|
# Publish it
|
|
|
|
self.workflow = self.portal.portal_workflow
|
|
|
|
self.workflow.doActionFor(self.portal.doc, 'publish')
|
|
|
|
|
|
|
|
request = self.app.REQUEST
|
2010-01-03 18:36:01 +01:00
|
|
|
request.set("test", True)
|
2009-07-07 18:16:58 +02:00
|
|
|
context = getattr(self.portal, 'doc')
|
|
|
|
self.view = View(context, request)
|
|
|
|
self.workflow.setChainForPortalTypes(('Discussion Item',), 'comment_review_workflow')
|
|
|
|
|
2009-07-12 09:09:07 +02:00
|
|
|
self.doc = self.portal.doc
|
|
|
|
|
2009-07-07 18:16:58 +02:00
|
|
|
def test_migrate_comment(self):
|
|
|
|
|
2009-07-12 20:19:29 +02:00
|
|
|
# Create a comment
|
2009-07-12 18:09:34 +02:00
|
|
|
talkback = self.discussion.getDiscussionFor(self.doc)
|
2009-07-12 09:09:07 +02:00
|
|
|
self.doc.talkback.createReply('My Title', 'My Text', Creator='Jim')
|
2009-07-12 18:09:34 +02:00
|
|
|
reply = talkback.getReplies()[0]
|
|
|
|
reply.setReplyTo(self.doc)
|
2009-07-12 19:55:54 +02:00
|
|
|
reply.creation_date = DateTime(2003, 3, 11, 9, 28, 6)
|
|
|
|
reply.modification_date = DateTime(2009, 7, 12, 19, 38, 7)
|
2009-07-12 18:09:34 +02:00
|
|
|
self.assertEquals(reply.Title(), 'My Title')
|
|
|
|
self.assertEquals(reply.EditableBody(), 'My Text')
|
2009-07-12 09:09:07 +02:00
|
|
|
self.failUnless('Jim' in reply.listCreators())
|
2009-07-12 18:09:34 +02:00
|
|
|
self.assertEquals(talkback.replyCount(self.doc), 1)
|
|
|
|
self.assertEquals(reply.inReplyTo(), self.doc)
|
2009-07-07 18:16:58 +02:00
|
|
|
|
|
|
|
# Call migration script
|
|
|
|
self.view()
|
|
|
|
|
|
|
|
# Make sure a conversation has been created
|
2009-07-12 09:09:07 +02:00
|
|
|
self.failUnless('plone.app.discussion:conversation' in IAnnotations(self.doc))
|
|
|
|
conversation = IConversation(self.doc)
|
2009-07-07 18:16:58 +02:00
|
|
|
|
|
|
|
# Check migration
|
|
|
|
self.assertEquals(conversation.total_comments, 1)
|
|
|
|
self.failUnless(conversation.getComments().next())
|
2009-07-12 18:09:34 +02:00
|
|
|
comment1 = conversation.values()[0]
|
|
|
|
self.assert_(IComment.providedBy(comment1))
|
|
|
|
self.assertEquals(comment1.Title(), 'My Title')
|
|
|
|
self.assertEquals(comment1.text, 'My Text')
|
|
|
|
self.assertEquals(comment1.Creator(), 'Jim')
|
2009-07-12 19:55:54 +02:00
|
|
|
self.assertEquals(comment1.creation_date, datetime(2003, 3, 11, 9, 28, 6))
|
|
|
|
self.assertEquals(comment1.modification_date, datetime(2009, 7, 12, 19, 38, 7))
|
2009-07-12 18:09:34 +02:00
|
|
|
self.assertEquals(
|
|
|
|
[{'comment': comment1, 'depth': 0, 'id': long(comment1.id)},]
|
|
|
|
, list(conversation.getThreads()))
|
2009-07-13 22:22:37 +02:00
|
|
|
self.failIf(self.doc.talkback)
|
2009-07-12 18:09:34 +02:00
|
|
|
|
2009-07-12 09:09:07 +02:00
|
|
|
def test_migrate_nested_comments(self):
|
|
|
|
# Create some nested comments and migrate them
|
|
|
|
#
|
|
|
|
# self.doc
|
|
|
|
# +- First comment
|
|
|
|
# +- Re: First comment
|
2009-07-13 23:01:38 +02:00
|
|
|
# + Re: Re: First comment
|
|
|
|
# + Re: Re: Re: First comment
|
|
|
|
# +- Re: First comment (2)
|
2009-07-14 00:14:30 +02:00
|
|
|
# +- Re: First comment (3)
|
|
|
|
# +- Re: First comment (4)
|
2009-07-13 23:01:38 +02:00
|
|
|
# +- Second comment
|
2009-07-12 09:09:07 +02:00
|
|
|
|
|
|
|
talkback = self.discussion.getDiscussionFor(self.doc)
|
|
|
|
|
2009-07-13 23:01:38 +02:00
|
|
|
# First comment
|
2009-07-12 09:09:07 +02:00
|
|
|
comment1_id = talkback.createReply(title='First comment',
|
|
|
|
text='This is my first comment.')
|
|
|
|
comment1 = talkback.getReplies()[0]
|
|
|
|
talkback_comment1 = self.discussion.getDiscussionFor(comment1)
|
|
|
|
|
2009-07-13 23:01:38 +02:00
|
|
|
# Re: First comment
|
2009-07-12 09:09:07 +02:00
|
|
|
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)
|
|
|
|
|
2009-07-13 23:01:38 +02:00
|
|
|
#Re: Re: First comment
|
|
|
|
comment1_1_1_id = talkback_comment1_1.createReply(title='Re: Re: First comment',
|
|
|
|
text='This is my first re-reply.')
|
|
|
|
comment1_1_1 = talkback_comment1_1.getReplies()[0]
|
|
|
|
talkback_comment1_1_1 = self.discussion.getDiscussionFor(comment1_1_1)
|
|
|
|
|
|
|
|
# Re: Re: Re: First comment
|
|
|
|
comment1_1_1_1_id = talkback_comment1_1_1.createReply(title='Re: Re: Re: First comment',
|
|
|
|
text='This is my first re-re-reply.')
|
|
|
|
comment1_1_1_1 = talkback_comment1_1_1.getReplies()[0]
|
|
|
|
talkback_comment1_1_1_1 = self.discussion.getDiscussionFor(comment1_1_1_1)
|
|
|
|
|
|
|
|
# Re: First comment (2)
|
|
|
|
comment1_2_id = talkback_comment1.createReply(title='Re: First comment (2)',
|
|
|
|
text='This is my first reply (2).')
|
2009-07-14 00:14:30 +02:00
|
|
|
comment1_2 = talkback_comment1.getReplies()[1]
|
2009-07-13 23:01:38 +02:00
|
|
|
talkback_comment1_2 = self.discussion.getDiscussionFor(comment1_2)
|
|
|
|
|
2009-07-14 00:14:30 +02:00
|
|
|
# Re: First comment (3)
|
|
|
|
comment1_3_id = talkback_comment1.createReply(title='Re: First comment (3)',
|
|
|
|
text='This is my first reply (3).')
|
|
|
|
comment1_3 = talkback_comment1.getReplies()[2]
|
|
|
|
talkback_comment1_3 = self.discussion.getDiscussionFor(comment1_3)
|
|
|
|
|
|
|
|
# Re: First comment (4)
|
|
|
|
comment1_4_id = talkback_comment1.createReply(title='Re: First comment (4)',
|
|
|
|
text='This is my first reply (4).')
|
|
|
|
comment1_4 = talkback_comment1.getReplies()[3]
|
|
|
|
talkback_comment1_4 = self.discussion.getDiscussionFor(comment1_4)
|
|
|
|
|
2009-07-13 23:01:38 +02:00
|
|
|
# Second comment
|
|
|
|
comment2_id = talkback.createReply(title='Second comment',
|
|
|
|
text='This is my second comment.')
|
2009-07-14 00:14:30 +02:00
|
|
|
comment2 = talkback.getReplies()[1]
|
2009-07-13 23:01:38 +02:00
|
|
|
talkback_comment2 = self.discussion.getDiscussionFor(comment2)
|
|
|
|
|
2009-07-12 09:09:07 +02:00
|
|
|
# Call migration script
|
|
|
|
self.view()
|
|
|
|
|
|
|
|
# Check migration
|
|
|
|
conversation = IConversation(self.doc)
|
2009-07-14 00:14:30 +02:00
|
|
|
self.assertEquals(conversation.total_comments, 8)
|
2009-07-12 09:09:07 +02:00
|
|
|
|
2009-07-12 18:09:34 +02:00
|
|
|
comment1 = conversation.values()[0]
|
2009-07-13 23:01:38 +02:00
|
|
|
comment1_1 = conversation.values()[1]
|
|
|
|
comment1_1_1 = conversation.values()[2]
|
|
|
|
comment1_1_1_1 = conversation.values()[3]
|
|
|
|
comment1_2 = conversation.values()[4]
|
2009-07-14 00:14:30 +02:00
|
|
|
comment1_3 = conversation.values()[5]
|
|
|
|
comment1_4 = conversation.values()[6]
|
|
|
|
comment2 = conversation.values()[7]
|
2009-07-12 18:09:34 +02:00
|
|
|
|
|
|
|
self.assertEquals(
|
2009-07-13 23:01:38 +02:00
|
|
|
[{'comment': comment1, 'depth': 0, 'id': long(comment1.id)},
|
|
|
|
{'comment': comment1_1, 'depth': 1, 'id': long(comment1_1.id)},
|
|
|
|
{'comment': comment1_1_1, 'depth': 2, 'id': long(comment1_1_1.id)},
|
|
|
|
{'comment': comment1_1_1_1, 'depth': 3, 'id': long(comment1_1_1_1.id)},
|
|
|
|
{'comment': comment1_2, 'depth': 1, 'id': long(comment1_2.id)},
|
2009-07-14 00:14:30 +02:00
|
|
|
{'comment': comment1_3, 'depth': 1, 'id': long(comment1_3.id)},
|
|
|
|
{'comment': comment1_4, 'depth': 1, 'id': long(comment1_4.id)},
|
2009-07-13 23:01:38 +02:00
|
|
|
{'comment': comment2, 'depth': 0, 'id': long(comment2.id)},
|
2009-07-12 18:09:34 +02:00
|
|
|
], list(conversation.getThreads()))
|
2009-07-07 18:16:58 +02:00
|
|
|
|
2009-07-14 00:14:30 +02:00
|
|
|
talkback = self.discussion.getDiscussionFor(self.doc)
|
|
|
|
self.assertEquals(len(talkback.getReplies()), 0)
|
|
|
|
|
|
|
|
|
2009-07-07 18:16:58 +02:00
|
|
|
def test_suite():
|
|
|
|
return unittest.defaultTestLoader.loadTestsFromName(__name__)
|