This commit is contained in:
Timo Stollenwerk 2013-04-17 19:04:45 +02:00
parent 00448703f2
commit dcb2d3e7d4
4 changed files with 86 additions and 59 deletions

View File

@ -9,8 +9,9 @@ from Products.CMFCore.utils import getToolByName
from plone.app.testing import TEST_USER_ID, setRoles from plone.app.testing import TEST_USER_ID, setRoles
from plone.app.discussion.testing import \ from plone.app.discussion.testing import (
PLONE_APP_DISCUSSION_INTEGRATION_TESTING PLONE_APP_DISCUSSION_INTEGRATION_TESTING
)
from plone.app.discussion.browser.migration import View from plone.app.discussion.browser.migration import View
@ -24,19 +25,25 @@ class MigrationTest(unittest.TestCase):
def _publish(self, reply): def _publish(self, reply):
# publish the reply # publish the reply
status = self.portal.portal_workflow.getStatusOf( status = self.portal.portal_workflow.getStatusOf(
'comment_review_workflow', reply).copy() 'comment_review_workflow', reply
).copy()
status['review_state'] = 'published' status['review_state'] = 'published'
self.portal.portal_workflow.setStatusOf( self.portal.portal_workflow.setStatusOf(
'comment_review_workflow', reply, status) 'comment_review_workflow',
reply,
status,
)
def setUp(self): def setUp(self):
self.portal = self.layer['portal'] self.portal = self.layer['portal']
self.request = self.layer['request'] self.request = self.layer['request']
setRoles(self.portal, TEST_USER_ID, ['Manager']) setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.portal.invokeFactory(id='doc', self.portal.invokeFactory(
id='doc',
title='Document 1', title='Document 1',
type_name='Document') type_name='Document'
)
# Create a document # Create a document
self.discussion = getToolByName(self.portal, 'portal_discussion', None) self.discussion = getToolByName(self.portal, 'portal_discussion', None)
self.discussion.overrideDiscussionFor(self.portal.doc, 1) self.discussion.overrideDiscussionFor(self.portal.doc, 1)
@ -47,8 +54,10 @@ class MigrationTest(unittest.TestCase):
self.request.set("test", True) self.request.set("test", True)
self.view = View(self.portal, self.request) self.view = View(self.portal, self.request)
self.workflowTool.setChainForPortalTypes(('Discussion Item',), self.workflowTool.setChainForPortalTypes(
'comment_review_workflow') ('Discussion Item',),
'comment_review_workflow'
)
# Create a user Jimmy Jones so comments creator migration can work? # Create a user Jimmy Jones so comments creator migration can work?
acl_users = getToolByName(self.portal, 'acl_users') acl_users = getToolByName(self.portal, 'acl_users')
@ -80,8 +89,9 @@ class MigrationTest(unittest.TestCase):
self.view() self.view()
# Make sure a conversation has been created # Make sure a conversation has been created
self.assertTrue('plone.app.discussion:conversation' in self.assertTrue(
IAnnotations(self.doc)) 'plone.app.discussion:conversation' in IAnnotations(self.doc)
)
conversation = IConversation(self.doc) conversation = IConversation(self.doc)
# Check migration # Check migration
@ -93,20 +103,20 @@ class MigrationTest(unittest.TestCase):
self.assertEqual(comment1.text, '<p>My Text</p>\n') self.assertEqual(comment1.text, '<p>My Text</p>\n')
self.assertEqual(comment1.mime_type, 'text/html') self.assertEqual(comment1.mime_type, 'text/html')
self.assertEqual(comment1.Creator(), 'Jim') self.assertEqual(comment1.Creator(), 'Jim')
self.assertEqual(comment1.creation_date, self.assertEqual(
datetime(2003, 3, 11, 9, 28, 6)) comment1.creation_date,
self.assertEqual(comment1.modification_date, datetime(2003, 3, 11, 9, 28, 6)
datetime(2009, 7, 12, 19, 38, 7)) )
self.assertEqual(
comment1.modification_date,
datetime(2009, 7, 12, 19, 38, 7)
)
self.assertEqual([ self.assertEqual([
{'comment': comment1, 'depth': 0, 'id': long(comment1.id)} {'comment': comment1, 'depth': 0, 'id': long(comment1.id)}
], list(conversation.getThreads())) ], list(conversation.getThreads()))
self.assertFalse(self.doc.talkback) self.assertFalse(self.doc.talkback)
def test_migrate_comment_with_creator(self): def test_migrate_comment_with_creator(self):
# Create a comment # Create a comment
talkback = self.discussion.getDiscussionFor(self.doc) talkback = self.discussion.getDiscussionFor(self.doc)
self.doc.talkback.createReply('My Title', 'My Text', Creator='Jim') self.doc.talkback.createReply('My Title', 'My Text', Creator='Jim')
@ -123,15 +133,16 @@ class MigrationTest(unittest.TestCase):
self.assertTrue('Jim' in reply.listCreators()) self.assertTrue('Jim' in reply.listCreators())
self.assertEqual(talkback.replyCount(self.doc), 1) self.assertEqual(talkback.replyCount(self.doc), 1)
self.assertEqual(reply.inReplyTo(), self.doc) self.assertEqual(reply.inReplyTo(), self.doc)
self.assertEqual(reply.author_username,'Jim') self.assertEqual(reply.author_username, 'Jim')
self.assertEqual(reply.email,'jimmy@jones.xyz') self.assertEqual(reply.email, 'jimmy@jones.xyz')
# 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.assertTrue('plone.app.discussion:conversation' in self.assertTrue(
IAnnotations(self.doc)) 'plone.app.discussion:conversation' in IAnnotations(self.doc)
)
conversation = IConversation(self.doc) conversation = IConversation(self.doc)
# Check migration # Check migration
@ -143,21 +154,26 @@ class MigrationTest(unittest.TestCase):
self.assertEqual(comment1.text, '<p>My Text</p>\n') self.assertEqual(comment1.text, '<p>My Text</p>\n')
self.assertEqual(comment1.mime_type, 'text/html') self.assertEqual(comment1.mime_type, 'text/html')
self.assertEqual(comment1.Creator(), 'Jim') self.assertEqual(comment1.Creator(), 'Jim')
self.assertEqual(comment1.creation_date, self.assertEqual(
datetime(2003, 3, 11, 9, 28, 6)) comment1.creation_date,
self.assertEqual(comment1.modification_date, datetime(2003, 3, 11, 9, 28, 6)
datetime(2009, 7, 12, 19, 38, 7)) )
self.assertEqual(
comment1.modification_date,
datetime(2009, 7, 12, 19, 38, 7)
)
self.assertEqual([ self.assertEqual([
{'comment': comment1, 'depth': 0, 'id': long(comment1.id)} {'comment': comment1, 'depth': 0, 'id': long(comment1.id)}
], list(conversation.getThreads())) ], list(conversation.getThreads()))
self.assertFalse(self.doc.talkback) self.assertFalse(self.doc.talkback)
# Though this should be Jimmy, but looks like getProperty won't pick up 'author_username' # Though this should be Jimmy, but looks like getProperty won't pick
# (reply.author_username is not None), so it's propagating Creator()..? # up 'author_username' (reply.author_username is not None), so it's
self.assertEqual(comment1.author_username,'Jim') # propagating Creator()..?
self.assertEqual(comment1.author_username, 'Jim')
self.assertEqual(comment1.author_name,'Jimmy Jones') self.assertEqual(comment1.author_name, 'Jimmy Jones')
self.assertEqual(comment1.author_email,'jimmy@jones.xyz') self.assertEqual(comment1.author_email, 'jimmy@jones.xyz')
def test_migrate_nested_comments(self): def test_migrate_nested_comments(self):
# Create some nested comments and migrate them # Create some nested comments and migrate them
@ -243,8 +259,8 @@ class MigrationTest(unittest.TestCase):
comment1_4 = conversation.values()[6] comment1_4 = conversation.values()[6]
comment2 = conversation.values()[7] comment2 = conversation.values()[7]
self.assertEqual( self.assertEqual([
[{'comment': comment1, 'depth': 0, 'id': long(comment1.id)}, {'comment': comment1, 'depth': 0, 'id': long(comment1.id)},
{'comment': comment1_1, 'depth': 1, 'id': long(comment1_1.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, 'depth': 2, 'id': long(comment1_1_1.id)},
{'comment': comment1_1_1_1, 'depth': 3, {'comment': comment1_1_1_1, 'depth': 3,
@ -303,8 +319,9 @@ class MigrationTest(unittest.TestCase):
self.view() self.view()
# Make sure no conversation has been created # Make sure no conversation has been created
self.assertTrue('plone.app.discussion:conversation' not in self.assertTrue(
IAnnotations(self.doc)) 'plone.app.discussion:conversation' not in IAnnotations(self.doc)
)
def test_suite(): def test_suite():

View File

@ -107,22 +107,25 @@ class ModerationBulkActionsViewTest(unittest.TestCase):
comment1.text = 'Comment text' comment1.text = 'Comment text'
comment1.Creator = 'Jim' comment1.Creator = 'Jim'
new_id_1 = conversation.addComment(comment1) new_id_1 = conversation.addComment(comment1)
self.comment1 = self.portal.doc1.restrictedTraverse(\ self.comment1 = self.portal.doc1.restrictedTraverse(
'++conversation++default/%s' % new_id_1) '++conversation++default/%s' % new_id_1
)
comment2 = createObject('plone.Comment') comment2 = createObject('plone.Comment')
comment2.title = 'Comment 2' comment2.title = 'Comment 2'
comment2.text = 'Comment text' comment2.text = 'Comment text'
comment2.Creator = 'Joe' comment2.Creator = 'Joe'
new_id_2 = conversation.addComment(comment2) new_id_2 = conversation.addComment(comment2)
self.comment2 = self.portal.doc1.restrictedTraverse(\ self.comment2 = self.portal.doc1.restrictedTraverse(
'++conversation++default/%s' % new_id_2) '++conversation++default/%s' % new_id_2
)
comment3 = createObject('plone.Comment') comment3 = createObject('plone.Comment')
comment3.title = 'Comment 3' comment3.title = 'Comment 3'
comment3.text = 'Comment text' comment3.text = 'Comment text'
comment3.Creator = 'Emma' comment3.Creator = 'Emma'
new_id_3 = conversation.addComment(comment3) new_id_3 = conversation.addComment(comment3)
self.comment3 = self.portal.doc1.restrictedTraverse(\ self.comment3 = self.portal.doc1.restrictedTraverse(
'++conversation++default/%s' % new_id_3) '++conversation++default/%s' % new_id_3
)
self.conversation = conversation self.conversation = conversation
def test_default_bulkaction(self): def test_default_bulkaction(self):

View File

@ -92,8 +92,10 @@ class TestUserNotificationUnit(unittest.TestCase):
def test_do_not_notify_user_when_notification_is_disabled(self): def test_do_not_notify_user_when_notification_is_disabled(self):
registry = queryUtility(IRegistry) registry = queryUtility(IRegistry)
registry['plone.app.discussion.interfaces.IDiscussionSettings.' + registry[
'user_notification_enabled'] = False 'plone.app.discussion.interfaces.IDiscussionSettings.' +
'user_notification_enabled'
] = False
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.text = 'Comment text' comment.text = 'Comment text'
comment.user_notification = True comment.user_notification = True
@ -177,11 +179,14 @@ class TestModeratorNotificationUnit(unittest.TestCase):
self.portal.portal_types['Document'].allow_discussion = True self.portal.portal_types['Document'].allow_discussion = True
self.portal.portal_workflow.setChainForPortalTypes( self.portal.portal_workflow.setChainForPortalTypes(
('Discussion Item',), ('Discussion Item',),
('comment_review_workflow',)) ('comment_review_workflow',)
)
# Enable moderator notification setting # Enable moderator notification setting
registry = queryUtility(IRegistry) registry = queryUtility(IRegistry)
registry['plone.app.discussion.interfaces.IDiscussionSettings.' + registry[
'moderator_notification_enabled'] = True 'plone.app.discussion.interfaces.IDiscussionSettings.' +
'moderator_notification_enabled'
] = True
# Create test content # Create test content
self.portal.invokeFactory('Document', 'doc1') self.portal.invokeFactory('Document', 'doc1')
self.portal_discussion = self.portal.portal_discussion self.portal_discussion = self.portal.portal_discussion

View File

@ -37,9 +37,11 @@ class ToolTest(unittest.TestCase):
# Check that the comment got indexed in the tool: # Check that the comment got indexed in the tool:
tool = queryUtility(ICommentingTool) tool = queryUtility(ICommentingTool)
comment = list(tool.searchResults()) comment = list(tool.searchResults())
self.assertTrue(len(comment) == 1, self.assertTrue(
len(comment) == 1,
"There is only one comment, but we got" "There is only one comment, but we got"
" %s results in the search" % len(comment)) " %s results in the search" % len(comment)
)
self.assertEqual(comment[0].Title, 'Jim on Document 1') self.assertEqual(comment[0].Title, 'Jim on Document 1')
def test_unindexing(self): def test_unindexing(self):