Pep8
This commit is contained in:
parent
00448703f2
commit
dcb2d3e7d4
@ -9,8 +9,9 @@ from Products.CMFCore.utils import getToolByName
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
from plone.app.discussion.browser.migration import View
|
||||
|
||||
@ -24,19 +25,25 @@ class MigrationTest(unittest.TestCase):
|
||||
def _publish(self, reply):
|
||||
# publish the reply
|
||||
status = self.portal.portal_workflow.getStatusOf(
|
||||
'comment_review_workflow', reply).copy()
|
||||
'comment_review_workflow', reply
|
||||
).copy()
|
||||
status['review_state'] = 'published'
|
||||
self.portal.portal_workflow.setStatusOf(
|
||||
'comment_review_workflow', reply, status)
|
||||
'comment_review_workflow',
|
||||
reply,
|
||||
status,
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
self.portal = self.layer['portal']
|
||||
self.request = self.layer['request']
|
||||
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
||||
|
||||
self.portal.invokeFactory(id='doc',
|
||||
self.portal.invokeFactory(
|
||||
id='doc',
|
||||
title='Document 1',
|
||||
type_name='Document')
|
||||
type_name='Document'
|
||||
)
|
||||
# Create a document
|
||||
self.discussion = getToolByName(self.portal, 'portal_discussion', None)
|
||||
self.discussion.overrideDiscussionFor(self.portal.doc, 1)
|
||||
@ -47,8 +54,10 @@ class MigrationTest(unittest.TestCase):
|
||||
|
||||
self.request.set("test", True)
|
||||
self.view = View(self.portal, self.request)
|
||||
self.workflowTool.setChainForPortalTypes(('Discussion Item',),
|
||||
'comment_review_workflow')
|
||||
self.workflowTool.setChainForPortalTypes(
|
||||
('Discussion Item',),
|
||||
'comment_review_workflow'
|
||||
)
|
||||
|
||||
# Create a user Jimmy Jones so comments creator migration can work?
|
||||
acl_users = getToolByName(self.portal, 'acl_users')
|
||||
@ -80,8 +89,9 @@ class MigrationTest(unittest.TestCase):
|
||||
self.view()
|
||||
|
||||
# Make sure a conversation has been created
|
||||
self.assertTrue('plone.app.discussion:conversation' in
|
||||
IAnnotations(self.doc))
|
||||
self.assertTrue(
|
||||
'plone.app.discussion:conversation' in IAnnotations(self.doc)
|
||||
)
|
||||
conversation = IConversation(self.doc)
|
||||
|
||||
# Check migration
|
||||
@ -93,20 +103,20 @@ class MigrationTest(unittest.TestCase):
|
||||
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,
|
||||
datetime(2003, 3, 11, 9, 28, 6))
|
||||
self.assertEqual(comment1.modification_date,
|
||||
datetime(2009, 7, 12, 19, 38, 7))
|
||||
self.assertEqual(
|
||||
comment1.creation_date,
|
||||
datetime(2003, 3, 11, 9, 28, 6)
|
||||
)
|
||||
self.assertEqual(
|
||||
comment1.modification_date,
|
||||
datetime(2009, 7, 12, 19, 38, 7)
|
||||
)
|
||||
self.assertEqual([
|
||||
{'comment': comment1, 'depth': 0, 'id': long(comment1.id)}
|
||||
], list(conversation.getThreads()))
|
||||
self.assertFalse(self.doc.talkback)
|
||||
|
||||
|
||||
def test_migrate_comment_with_creator(self):
|
||||
|
||||
|
||||
|
||||
# Create a comment
|
||||
talkback = self.discussion.getDiscussionFor(self.doc)
|
||||
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.assertEqual(talkback.replyCount(self.doc), 1)
|
||||
self.assertEqual(reply.inReplyTo(), self.doc)
|
||||
self.assertEqual(reply.author_username,'Jim')
|
||||
self.assertEqual(reply.email,'jimmy@jones.xyz')
|
||||
self.assertEqual(reply.author_username, 'Jim')
|
||||
self.assertEqual(reply.email, 'jimmy@jones.xyz')
|
||||
|
||||
# Call migration script
|
||||
self.view()
|
||||
|
||||
# Make sure a conversation has been created
|
||||
self.assertTrue('plone.app.discussion:conversation' in
|
||||
IAnnotations(self.doc))
|
||||
self.assertTrue(
|
||||
'plone.app.discussion:conversation' in IAnnotations(self.doc)
|
||||
)
|
||||
conversation = IConversation(self.doc)
|
||||
|
||||
# Check migration
|
||||
@ -143,21 +154,26 @@ class MigrationTest(unittest.TestCase):
|
||||
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,
|
||||
datetime(2003, 3, 11, 9, 28, 6))
|
||||
self.assertEqual(comment1.modification_date,
|
||||
datetime(2009, 7, 12, 19, 38, 7))
|
||||
self.assertEqual(
|
||||
comment1.creation_date,
|
||||
datetime(2003, 3, 11, 9, 28, 6)
|
||||
)
|
||||
self.assertEqual(
|
||||
comment1.modification_date,
|
||||
datetime(2009, 7, 12, 19, 38, 7)
|
||||
)
|
||||
self.assertEqual([
|
||||
{'comment': comment1, 'depth': 0, 'id': long(comment1.id)}
|
||||
], list(conversation.getThreads()))
|
||||
self.assertFalse(self.doc.talkback)
|
||||
|
||||
# Though this should be Jimmy, but looks like getProperty won't pick up 'author_username'
|
||||
# (reply.author_username is not None), so it's propagating Creator()..?
|
||||
self.assertEqual(comment1.author_username,'Jim')
|
||||
# Though this should be Jimmy, but looks like getProperty won't pick
|
||||
# up 'author_username' (reply.author_username is not None), so it's
|
||||
# propagating Creator()..?
|
||||
self.assertEqual(comment1.author_username, 'Jim')
|
||||
|
||||
self.assertEqual(comment1.author_name,'Jimmy Jones')
|
||||
self.assertEqual(comment1.author_email,'jimmy@jones.xyz')
|
||||
self.assertEqual(comment1.author_name, 'Jimmy Jones')
|
||||
self.assertEqual(comment1.author_email, 'jimmy@jones.xyz')
|
||||
|
||||
def test_migrate_nested_comments(self):
|
||||
# Create some nested comments and migrate them
|
||||
@ -243,8 +259,8 @@ class MigrationTest(unittest.TestCase):
|
||||
comment1_4 = conversation.values()[6]
|
||||
comment2 = conversation.values()[7]
|
||||
|
||||
self.assertEqual(
|
||||
[{'comment': comment1, 'depth': 0, 'id': long(comment1.id)},
|
||||
self.assertEqual([
|
||||
{'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,
|
||||
@ -303,8 +319,9 @@ class MigrationTest(unittest.TestCase):
|
||||
self.view()
|
||||
|
||||
# Make sure no conversation has been created
|
||||
self.assertTrue('plone.app.discussion:conversation' not in
|
||||
IAnnotations(self.doc))
|
||||
self.assertTrue(
|
||||
'plone.app.discussion:conversation' not in IAnnotations(self.doc)
|
||||
)
|
||||
|
||||
|
||||
def test_suite():
|
||||
|
@ -107,22 +107,25 @@ class ModerationBulkActionsViewTest(unittest.TestCase):
|
||||
comment1.text = 'Comment text'
|
||||
comment1.Creator = 'Jim'
|
||||
new_id_1 = conversation.addComment(comment1)
|
||||
self.comment1 = self.portal.doc1.restrictedTraverse(\
|
||||
'++conversation++default/%s' % new_id_1)
|
||||
self.comment1 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id_1
|
||||
)
|
||||
comment2 = createObject('plone.Comment')
|
||||
comment2.title = 'Comment 2'
|
||||
comment2.text = 'Comment text'
|
||||
comment2.Creator = 'Joe'
|
||||
new_id_2 = conversation.addComment(comment2)
|
||||
self.comment2 = self.portal.doc1.restrictedTraverse(\
|
||||
'++conversation++default/%s' % new_id_2)
|
||||
self.comment2 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id_2
|
||||
)
|
||||
comment3 = createObject('plone.Comment')
|
||||
comment3.title = 'Comment 3'
|
||||
comment3.text = 'Comment text'
|
||||
comment3.Creator = 'Emma'
|
||||
new_id_3 = conversation.addComment(comment3)
|
||||
self.comment3 = self.portal.doc1.restrictedTraverse(\
|
||||
'++conversation++default/%s' % new_id_3)
|
||||
self.comment3 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id_3
|
||||
)
|
||||
self.conversation = conversation
|
||||
|
||||
def test_default_bulkaction(self):
|
||||
|
@ -92,8 +92,10 @@ class TestUserNotificationUnit(unittest.TestCase):
|
||||
|
||||
def test_do_not_notify_user_when_notification_is_disabled(self):
|
||||
registry = queryUtility(IRegistry)
|
||||
registry['plone.app.discussion.interfaces.IDiscussionSettings.' +
|
||||
'user_notification_enabled'] = False
|
||||
registry[
|
||||
'plone.app.discussion.interfaces.IDiscussionSettings.' +
|
||||
'user_notification_enabled'
|
||||
] = False
|
||||
comment = createObject('plone.Comment')
|
||||
comment.text = 'Comment text'
|
||||
comment.user_notification = True
|
||||
@ -177,11 +179,14 @@ class TestModeratorNotificationUnit(unittest.TestCase):
|
||||
self.portal.portal_types['Document'].allow_discussion = True
|
||||
self.portal.portal_workflow.setChainForPortalTypes(
|
||||
('Discussion Item',),
|
||||
('comment_review_workflow',))
|
||||
('comment_review_workflow',)
|
||||
)
|
||||
# Enable moderator notification setting
|
||||
registry = queryUtility(IRegistry)
|
||||
registry['plone.app.discussion.interfaces.IDiscussionSettings.' +
|
||||
'moderator_notification_enabled'] = True
|
||||
registry[
|
||||
'plone.app.discussion.interfaces.IDiscussionSettings.' +
|
||||
'moderator_notification_enabled'
|
||||
] = True
|
||||
# Create test content
|
||||
self.portal.invokeFactory('Document', 'doc1')
|
||||
self.portal_discussion = self.portal.portal_discussion
|
||||
|
@ -37,9 +37,11 @@ class ToolTest(unittest.TestCase):
|
||||
# Check that the comment got indexed in the tool:
|
||||
tool = queryUtility(ICommentingTool)
|
||||
comment = list(tool.searchResults())
|
||||
self.assertTrue(len(comment) == 1,
|
||||
self.assertTrue(
|
||||
len(comment) == 1,
|
||||
"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')
|
||||
|
||||
def test_unindexing(self):
|
||||
|
Loading…
Reference in New Issue
Block a user