2009-07-12 19:55:54 +02:00
|
|
|
from datetime import datetime
|
|
|
|
from DateTime import DateTime
|
|
|
|
|
2011-04-16 11:51:28 +02:00
|
|
|
import unittest2 as unittest
|
2009-07-07 18:16:58 +02:00
|
|
|
|
|
|
|
from zope.annotation.interfaces import IAnnotations
|
|
|
|
|
|
|
|
from Products.CMFCore.utils import getToolByName
|
|
|
|
|
2011-04-16 11:51:28 +02:00
|
|
|
from plone.app.testing import TEST_USER_ID, setRoles
|
2009-07-07 18:16:58 +02:00
|
|
|
|
2012-01-09 16:43:54 +01:00
|
|
|
from plone.app.discussion.testing import \
|
|
|
|
PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
2009-07-07 18:16:58 +02:00
|
|
|
|
|
|
|
from plone.app.discussion.browser.migration import View
|
|
|
|
|
|
|
|
from plone.app.discussion.interfaces import IConversation, IComment
|
|
|
|
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2011-04-16 11:51:28 +02:00
|
|
|
class MigrationTest(unittest.TestCase):
|
2009-07-07 18:16:58 +02:00
|
|
|
|
2011-04-16 11:51:28 +02:00
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.portal = self.layer['portal']
|
|
|
|
self.request = self.layer['request']
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-09-29 09:56:36 +02:00
|
|
|
self.portal.invokeFactory(id='doc',
|
2010-12-16 00:52:56 +01:00
|
|
|
title='Document 1',
|
2010-09-29 09:56:36 +02:00
|
|
|
type_name='Document')
|
2009-07-07 18:16:58 +02:00
|
|
|
# Create a document
|
|
|
|
self.discussion = getToolByName(self.portal, 'portal_discussion', None)
|
|
|
|
self.discussion.overrideDiscussionFor(self.portal.doc, 1)
|
|
|
|
# Publish it
|
2011-04-16 11:51:28 +02:00
|
|
|
self.workflowTool = getToolByName(self.portal, 'portal_workflow')
|
|
|
|
self.workflowTool.setDefaultChain('simple_publication_workflow')
|
|
|
|
self.workflowTool.doActionFor(self.portal.doc, 'publish')
|
2009-07-07 18:16:58 +02:00
|
|
|
|
2011-04-16 11:51:28 +02:00
|
|
|
self.request.set("test", True)
|
|
|
|
self.view = View(self.portal, self.request)
|
|
|
|
self.workflowTool.setChainForPortalTypes(('Discussion Item',),
|
2010-08-28 19:06:53 +02:00
|
|
|
'comment_review_workflow')
|
2009-07-07 18:16:58 +02:00
|
|
|
|
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)
|
2011-04-02 23:26:36 +02:00
|
|
|
reply.creation_date = DateTime(2003, 3, 11, 9, 28, 6, 'GMT')
|
|
|
|
reply.modification_date = DateTime(2009, 7, 12, 19, 38, 7, 'GMT')
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(reply.Title(), 'My Title')
|
|
|
|
self.assertEqual(reply.EditableBody(), 'My Text')
|
|
|
|
self.assertTrue('Jim' in reply.listCreators())
|
|
|
|
self.assertEqual(talkback.replyCount(self.doc), 1)
|
|
|
|
self.assertEqual(reply.inReplyTo(), self.doc)
|
2009-07-07 18:16:58 +02:00
|
|
|
|
|
|
|
# Call migration script
|
|
|
|
self.view()
|
|
|
|
|
|
|
|
# Make sure a conversation has been created
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue('plone.app.discussion:conversation' in
|
2010-08-28 19:06:53 +02:00
|
|
|
IAnnotations(self.doc))
|
2009-07-12 09:09:07 +02:00
|
|
|
conversation = IConversation(self.doc)
|
2009-07-07 18:16:58 +02:00
|
|
|
|
|
|
|
# Check migration
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation.total_comments, 1)
|
|
|
|
self.assertTrue(conversation.getComments().next())
|
2009-07-12 18:09:34 +02:00
|
|
|
comment1 = conversation.values()[0]
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(IComment.providedBy(comment1))
|
|
|
|
self.assertEqual(comment1.Title(), 'My Title')
|
|
|
|
self.assertEqual(comment1.text, '<p>My Text</p>\n')
|
|
|
|
self.assertEqual(comment1.mime_type, 'text/html')
|
|
|
|
self.assertEqual(comment1.Creator(), 'Jim')
|
|
|
|
self.assertEqual(comment1.creation_date,
|
2010-08-28 19:06:53 +02:00
|
|
|
datetime(2003, 3, 11, 9, 28, 6))
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(comment1.modification_date,
|
2010-08-28 19:06:53 +02:00
|
|
|
datetime(2009, 7, 12, 19, 38, 7))
|
2012-01-09 16:43:54 +01:00
|
|
|
self.assertEqual([
|
|
|
|
{'comment': comment1, 'depth': 0, 'id': long(comment1.id)}
|
|
|
|
], list(conversation.getThreads()))
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertFalse(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
|
2010-07-13 12:45:53 +02:00
|
|
|
talkback.createReply(title='First comment',
|
|
|
|
text='This is my first comment.')
|
2009-07-12 09:09:07 +02:00
|
|
|
comment1 = talkback.getReplies()[0]
|
|
|
|
talkback_comment1 = self.discussion.getDiscussionFor(comment1)
|
|
|
|
|
2009-07-13 23:01:38 +02:00
|
|
|
# Re: First comment
|
2010-07-13 12:45:53 +02:00
|
|
|
talkback_comment1.createReply(title='Re: First comment',
|
|
|
|
text='This is my first reply.')
|
2009-07-12 09:09:07 +02:00
|
|
|
comment1_1 = talkback_comment1.getReplies()[0]
|
|
|
|
talkback_comment1_1 = self.discussion.getDiscussionFor(comment1_1)
|
|
|
|
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(talkback.getReplies()), 1)
|
|
|
|
self.assertEqual(len(talkback_comment1.getReplies()), 1)
|
|
|
|
self.assertEqual(len(talkback_comment1_1.getReplies()), 0)
|
2009-07-12 09:09:07 +02:00
|
|
|
|
2009-07-13 23:01:38 +02:00
|
|
|
#Re: Re: First comment
|
2010-07-13 12:45:53 +02:00
|
|
|
talkback_comment1_1.createReply(title='Re: Re: First comment',
|
|
|
|
text='This is my first re-reply.')
|
2009-07-13 23:01:38 +02:00
|
|
|
comment1_1_1 = talkback_comment1_1.getReplies()[0]
|
|
|
|
talkback_comment1_1_1 = self.discussion.getDiscussionFor(comment1_1_1)
|
|
|
|
|
|
|
|
# Re: Re: Re: First comment
|
2010-07-13 12:45:53 +02:00
|
|
|
talkback_comment1_1_1.createReply(title='Re: Re: Re: First comment',
|
|
|
|
text='This is my first re-re-reply.')
|
2009-07-13 23:01:38 +02:00
|
|
|
|
|
|
|
# Re: First comment (2)
|
2010-07-13 12:45:53 +02:00
|
|
|
talkback_comment1.createReply(title='Re: First comment (2)',
|
|
|
|
text='This is my first reply (2).')
|
2009-07-13 23:01:38 +02:00
|
|
|
|
2009-07-14 00:14:30 +02:00
|
|
|
# Re: First comment (3)
|
2010-07-13 12:45:53 +02:00
|
|
|
talkback_comment1.createReply(title='Re: First comment (3)',
|
|
|
|
text='This is my first reply (3).')
|
2009-07-14 00:14:30 +02:00
|
|
|
|
|
|
|
# Re: First comment (4)
|
2010-07-13 12:45:53 +02:00
|
|
|
talkback_comment1.createReply(title='Re: First comment (4)',
|
|
|
|
text='This is my first reply (4).')
|
2009-07-14 00:14:30 +02:00
|
|
|
|
2009-07-13 23:01:38 +02:00
|
|
|
# Second comment
|
2010-07-13 12:45:53 +02:00
|
|
|
talkback.createReply(title='Second comment',
|
|
|
|
text='This is my second comment.')
|
2009-07-13 23:01:38 +02:00
|
|
|
|
2009-07-12 09:09:07 +02:00
|
|
|
# Call migration script
|
|
|
|
self.view()
|
|
|
|
|
|
|
|
# Check migration
|
|
|
|
conversation = IConversation(self.doc)
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(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
|
|
|
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(
|
2010-08-28 19:06:53 +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)},
|
|
|
|
{'comment': comment1_3, 'depth': 1, 'id': long(comment1_3.id)},
|
|
|
|
{'comment': comment1_4, 'depth': 1, 'id': long(comment1_4.id)},
|
|
|
|
{'comment': comment2, 'depth': 0, 'id': long(comment2.id)},
|
|
|
|
], 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)
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(talkback.getReplies()), 0)
|
2009-07-14 00:14:30 +02:00
|
|
|
|
2011-04-02 21:33:10 +02:00
|
|
|
def test_migrate_nested_comments_with_filter(self):
|
|
|
|
# Create some nested comments and migrate them.
|
|
|
|
# But use a filter that filters the top-level comment.
|
|
|
|
# All the comments should be removed, but not migrated.
|
|
|
|
#
|
|
|
|
# self.doc
|
|
|
|
# +- First comment
|
|
|
|
# +- Re: First comment
|
|
|
|
|
|
|
|
talkback = self.discussion.getDiscussionFor(self.doc)
|
|
|
|
|
|
|
|
# First comment
|
|
|
|
talkback.createReply(title='First comment',
|
|
|
|
text='This is my first comment.')
|
|
|
|
comment1 = talkback.getReplies()[0]
|
|
|
|
talkback_comment1 = self.discussion.getDiscussionFor(comment1)
|
|
|
|
|
|
|
|
# Re: First comment
|
|
|
|
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)
|
|
|
|
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(talkback.getReplies()), 1)
|
|
|
|
self.assertEqual(len(talkback_comment1.getReplies()), 1)
|
|
|
|
self.assertEqual(len(talkback_comment1_1.getReplies()), 0)
|
2011-04-02 21:33:10 +02:00
|
|
|
|
|
|
|
def deny_comments(reply):
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Call migration script
|
|
|
|
self.view(filter_callback=deny_comments)
|
|
|
|
|
|
|
|
# Check migration
|
|
|
|
conversation = IConversation(self.doc)
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(conversation.total_comments, 0)
|
2011-04-02 21:33:10 +02:00
|
|
|
talkback = self.discussion.getDiscussionFor(self.doc)
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(talkback.getReplies()), 0)
|
2009-07-14 00:14:30 +02:00
|
|
|
|
2011-04-14 18:17:29 +02:00
|
|
|
def test_migrate_no_comment(self):
|
|
|
|
|
|
|
|
# Call migration script
|
|
|
|
self.view()
|
|
|
|
|
|
|
|
# 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.doc))
|
|
|
|
|
|
|
|
|
2009-07-07 18:16:58 +02:00
|
|
|
def test_suite():
|
2010-08-28 19:06:53 +02:00
|
|
|
return unittest.defaultTestLoader.loadTestsFromName(__name__)
|