Cleanup
Follow https://github.com/plone/jenkins.plone.org/blob/master/docs/source/run-qa-on-package.rst to clean up the code.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Test the plone.app.discussion catalog indexes
|
||||
"""
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from datetime import datetime
|
||||
from plone.app.discussion.interfaces import IConversation
|
||||
from plone.app.discussion.testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING # noqa
|
||||
from plone.app.testing import setRoles
|
||||
from plone.app.testing import TEST_USER_ID
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from zope.annotation.interfaces import IAnnotations
|
||||
from zope.component import createObject
|
||||
|
||||
@@ -74,7 +75,7 @@ class ConversationCatalogTest(unittest.TestCase):
|
||||
'query':
|
||||
'/'.join(self.portal.doc1.getPhysicalPath())
|
||||
},
|
||||
portal_type="Document"
|
||||
portal_type='Document'
|
||||
))
|
||||
self.conversation = conversation
|
||||
self.brains = brains
|
||||
@@ -92,14 +93,15 @@ class ConversationCatalogTest(unittest.TestCase):
|
||||
new_comment2_id = self.conversation.addComment(comment2)
|
||||
|
||||
comment2 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment2_id)
|
||||
'++conversation++default/{0}'.format(new_comment2_id)
|
||||
)
|
||||
comment2.reindexObject()
|
||||
brains = self.catalog.searchResults(dict(
|
||||
path={
|
||||
'query':
|
||||
'/'.join(self.portal.doc1.getPhysicalPath())
|
||||
},
|
||||
portal_type="Document"
|
||||
portal_type='Document'
|
||||
))
|
||||
doc1_brain = brains[0]
|
||||
self.assertEqual(doc1_brain.total_comments, 2)
|
||||
@@ -120,14 +122,15 @@ class ConversationCatalogTest(unittest.TestCase):
|
||||
new_comment2_id = self.conversation.addComment(comment2)
|
||||
|
||||
comment2 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment2_id)
|
||||
'++conversation++default/{0}'.format(new_comment2_id)
|
||||
)
|
||||
comment2.reindexObject()
|
||||
brains = self.catalog.searchResults(dict(
|
||||
path={
|
||||
'query':
|
||||
'/'.join(self.portal.doc1.getPhysicalPath())
|
||||
},
|
||||
portal_type="Document"
|
||||
portal_type='Document'
|
||||
))
|
||||
doc1_brain = brains[0]
|
||||
self.assertEqual(
|
||||
@@ -143,7 +146,7 @@ class ConversationCatalogTest(unittest.TestCase):
|
||||
'query':
|
||||
'/'.join(self.portal.doc1.getPhysicalPath())
|
||||
},
|
||||
portal_type="Document"
|
||||
portal_type='Document'
|
||||
))
|
||||
doc1_brain = brains[0]
|
||||
self.assertEqual(
|
||||
@@ -158,7 +161,7 @@ class ConversationCatalogTest(unittest.TestCase):
|
||||
'query':
|
||||
'/'.join(self.portal.doc1.getPhysicalPath())
|
||||
},
|
||||
portal_type="Document"
|
||||
portal_type='Document'
|
||||
))
|
||||
doc1_brain = brains[0]
|
||||
self.assertEqual(doc1_brain.last_comment_date, None)
|
||||
@@ -176,7 +179,8 @@ class ConversationCatalogTest(unittest.TestCase):
|
||||
new_comment2_id = self.conversation.addComment(comment2)
|
||||
|
||||
comment2 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment2_id)
|
||||
'++conversation++default/{0}'.format(new_comment2_id)
|
||||
)
|
||||
comment2.reindexObject()
|
||||
|
||||
brains = self.catalog.searchResults(dict(
|
||||
@@ -184,7 +188,7 @@ class ConversationCatalogTest(unittest.TestCase):
|
||||
'query':
|
||||
'/'.join(self.portal.doc1.getPhysicalPath())
|
||||
},
|
||||
portal_type="Document"
|
||||
portal_type='Document'
|
||||
))
|
||||
doc1_brain = brains[0]
|
||||
|
||||
@@ -197,7 +201,7 @@ class ConversationCatalogTest(unittest.TestCase):
|
||||
'query':
|
||||
'/'.join(self.portal.doc1.getPhysicalPath())
|
||||
},
|
||||
portal_type="Document"
|
||||
portal_type='Document'
|
||||
))
|
||||
doc1_brain = brains[0]
|
||||
self.assertEqual(doc1_brain.commentators, ('Jim',))
|
||||
@@ -209,7 +213,7 @@ class ConversationCatalogTest(unittest.TestCase):
|
||||
'query':
|
||||
'/'.join(self.portal.doc1.getPhysicalPath())
|
||||
},
|
||||
portal_type="Document"
|
||||
portal_type='Document'
|
||||
))
|
||||
doc1_brain = brains[0]
|
||||
self.assertEqual(doc1_brain.commentators, ())
|
||||
@@ -220,7 +224,7 @@ class ConversationCatalogTest(unittest.TestCase):
|
||||
'query':
|
||||
'/'.join(self.portal.doc1.getPhysicalPath())
|
||||
},
|
||||
portal_type="Discussion Item"
|
||||
portal_type='Discussion Item'
|
||||
))
|
||||
comment1_brain = brains[0]
|
||||
self.assertEqual(comment1_brain.commentators, None)
|
||||
@@ -228,14 +232,14 @@ class ConversationCatalogTest(unittest.TestCase):
|
||||
self.assertEqual(comment1_brain.total_comments, None)
|
||||
|
||||
def test_dont_index_private_commentators(self):
|
||||
self.comment1.manage_permission("View", roles=tuple())
|
||||
self.comment1.manage_permission('View', roles=tuple())
|
||||
self.portal.doc1.reindexObject()
|
||||
brains = self.catalog.searchResults(dict(
|
||||
path={
|
||||
'query':
|
||||
'/'.join(self.portal.doc1.getPhysicalPath())
|
||||
},
|
||||
portal_type="Document"
|
||||
portal_type='Document'
|
||||
))
|
||||
doc1_brain = brains[0]
|
||||
self.assertEqual(doc1_brain.commentators, ())
|
||||
@@ -262,7 +266,8 @@ class CommentCatalogTest(unittest.TestCase):
|
||||
|
||||
# Comment brain
|
||||
self.comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment1_id)
|
||||
'++conversation++default/{0}'.format(new_comment1_id)
|
||||
)
|
||||
brains = self.catalog.searchResults(dict(
|
||||
path={
|
||||
'query':
|
||||
@@ -281,7 +286,8 @@ class CommentCatalogTest(unittest.TestCase):
|
||||
|
||||
# Comment brain
|
||||
comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % cid)
|
||||
'++conversation++default/{0}'.format(cid)
|
||||
)
|
||||
brains = self.catalog.searchResults(dict(
|
||||
path={
|
||||
'query':
|
||||
@@ -289,7 +295,7 @@ class CommentCatalogTest(unittest.TestCase):
|
||||
}
|
||||
))
|
||||
comment_brain = brains[0]
|
||||
self.assertEqual(comment_brain.Title, "Anonymous on Document 1")
|
||||
self.assertEqual(comment_brain.Title, 'Anonymous on Document 1')
|
||||
|
||||
def test_type(self):
|
||||
self.assertEqual(self.comment_brain.portal_type, 'Discussion Item')
|
||||
@@ -329,7 +335,7 @@ class CommentCatalogTest(unittest.TestCase):
|
||||
"""
|
||||
brains = self.catalog.searchResults({'portal_type': 'Discussion Item'})
|
||||
self.assertEqual(len(brains), 1)
|
||||
self.portal.manage_delObjects(["doc1"])
|
||||
self.portal.manage_delObjects(['doc1'])
|
||||
brains = self.catalog.searchResults({'portal_type': 'Discussion Item'})
|
||||
self.assertEqual(len(brains), 0)
|
||||
|
||||
@@ -362,13 +368,13 @@ class CommentCatalogTest(unittest.TestCase):
|
||||
|
||||
# Make sure no old comment brains are
|
||||
brains = self.catalog.searchResults(dict(
|
||||
portal_type="Discussion Item",
|
||||
portal_type='Discussion Item',
|
||||
path={'query': '/'.join(self.portal.folder1.getPhysicalPath())}
|
||||
))
|
||||
self.assertEqual(len(brains), 0)
|
||||
|
||||
brains = self.catalog.searchResults(dict(
|
||||
portal_type="Discussion Item",
|
||||
portal_type='Discussion Item',
|
||||
path={
|
||||
'query': '/'.join(self.portal.folder2.getPhysicalPath())
|
||||
}
|
||||
@@ -411,14 +417,14 @@ class CommentCatalogTest(unittest.TestCase):
|
||||
|
||||
# Make sure no old comment brains are left
|
||||
brains = self.catalog.searchResults(dict(
|
||||
portal_type="Discussion Item",
|
||||
portal_type='Discussion Item',
|
||||
path={'query': '/plone/sourcefolder/moveme'}
|
||||
))
|
||||
self.assertEqual(len(brains), 0)
|
||||
|
||||
# make sure comments are correctly index on the target
|
||||
brains = self.catalog.searchResults(dict(
|
||||
portal_type="Discussion Item",
|
||||
portal_type='Discussion Item',
|
||||
path={'query': '/plone/targetfolder/moveme'}
|
||||
))
|
||||
self.assertEqual(len(brains), 1)
|
||||
@@ -432,7 +438,7 @@ class CommentCatalogTest(unittest.TestCase):
|
||||
# We need to commit here so that _p_jar isn't None and move will work
|
||||
transaction.savepoint(optimistic=True)
|
||||
|
||||
self.portal.manage_renameObject("doc1", "doc2")
|
||||
self.portal.manage_renameObject('doc1', 'doc2')
|
||||
|
||||
brains = self.catalog.searchResults(
|
||||
portal_type='Discussion Item')
|
||||
@@ -535,7 +541,7 @@ class NoConversationCatalogTest(unittest.TestCase):
|
||||
'query':
|
||||
'/'.join(self.portal.doc1.getPhysicalPath())
|
||||
},
|
||||
portal_type="Document"
|
||||
portal_type='Document'
|
||||
))
|
||||
self.conversation = conversation
|
||||
self.brains = brains
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from plone.app.discussion.browser.comment import View
|
||||
from plone.app.discussion.interfaces import IComment
|
||||
from plone.app.discussion.interfaces import IConversation
|
||||
@@ -7,6 +6,7 @@ from plone.app.discussion.interfaces import IReplies
|
||||
from plone.app.discussion.testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING # noqa
|
||||
from plone.app.testing import setRoles
|
||||
from plone.app.testing import TEST_USER_ID
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from zope.component import createObject
|
||||
from zope.component import getMultiAdapter
|
||||
|
||||
@@ -41,9 +41,9 @@ class CommentTest(unittest.TestCase):
|
||||
datetime.datetime.now() - datetime.datetime.utcnow()
|
||||
utc_to_local_diff = abs(utc_to_local_diff.seconds)
|
||||
if utc_to_local_diff < 60:
|
||||
logger.warning("Your computer is living in a timezone where local "
|
||||
"time equals utc time. Some potential errors can "
|
||||
"get hidden by that")
|
||||
logger.warning('Your computer is living in a timezone where local '
|
||||
'time equals utc time. Some potential errors can '
|
||||
'get hidden by that')
|
||||
comment1 = createObject('plone.Comment')
|
||||
local_utc = datetime.datetime.utcnow()
|
||||
for date in (comment1.creation_date, comment1.modification_date):
|
||||
@@ -92,15 +92,15 @@ class CommentTest(unittest.TestCase):
|
||||
def test_title(self):
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.author_name = "Jim Fulton"
|
||||
comment1.author_name = 'Jim Fulton'
|
||||
conversation.addComment(comment1)
|
||||
self.assertEqual("Jim Fulton on Document 1", comment1.Title())
|
||||
self.assertEqual('Jim Fulton on Document 1', comment1.Title())
|
||||
|
||||
def test_no_name_title(self):
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
comment1 = createObject('plone.Comment')
|
||||
conversation.addComment(comment1)
|
||||
self.assertEqual("Anonymous on Document 1", comment1.Title())
|
||||
self.assertEqual('Anonymous on Document 1', comment1.Title())
|
||||
|
||||
def test_title_special_characters(self):
|
||||
self.portal.invokeFactory(
|
||||
@@ -110,9 +110,9 @@ class CommentTest(unittest.TestCase):
|
||||
)
|
||||
conversation = IConversation(self.portal.doc_sp_chars)
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.author_name = u"Tarek Ziadé"
|
||||
comment1.author_name = u'Tarek Ziadé'
|
||||
conversation.addComment(comment1)
|
||||
self.assertEqual(u"Tarek Ziadé on Document äüö", comment1.Title())
|
||||
self.assertEqual(u'Tarek Ziadé on Document äüö', comment1.Title())
|
||||
|
||||
def test_title_special_characters_utf8(self):
|
||||
self.portal.invokeFactory(
|
||||
@@ -122,19 +122,19 @@ class CommentTest(unittest.TestCase):
|
||||
)
|
||||
conversation = IConversation(self.portal.doc_sp_chars_utf8)
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.author_name = "Hüüb Bôûmä"
|
||||
comment1.author_name = 'Hüüb Bôûmä'
|
||||
conversation.addComment(comment1)
|
||||
self.assertEqual(u"Hüüb Bôûmä on Document ëïû", comment1.Title())
|
||||
self.assertEqual(u'Hüüb Bôûmä on Document ëïû', comment1.Title())
|
||||
|
||||
def test_creator(self):
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.creator = "jim"
|
||||
self.assertEqual("jim", comment1.Creator())
|
||||
comment1.creator = 'jim'
|
||||
self.assertEqual('jim', comment1.Creator())
|
||||
|
||||
def test_creator_author_name(self):
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.author_name = "joey"
|
||||
self.assertEqual("joey", comment1.Creator())
|
||||
comment1.author_name = 'joey'
|
||||
self.assertEqual('joey', comment1.Creator())
|
||||
|
||||
def test_owner(self):
|
||||
comment1 = createObject('plone.Comment')
|
||||
@@ -151,25 +151,23 @@ class CommentTest(unittest.TestCase):
|
||||
|
||||
def test_getText(self):
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.text = """First paragraph
|
||||
|
||||
Second paragraph"""
|
||||
comment1.text = 'First paragraph\n\nSecond paragraph'
|
||||
self.assertEqual(
|
||||
comment1.getText(),
|
||||
"<p>First paragraph<br /><br /> Second paragraph</p>"
|
||||
'<p>First paragraph<br /><br />Second paragraph</p>'
|
||||
)
|
||||
|
||||
def test_getText_escapes_HTML(self):
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.text = """<b>Got HTML?</b>"""
|
||||
comment1.text = '<b>Got HTML?</b>'
|
||||
self.assertEqual(
|
||||
comment1.getText(),
|
||||
"<p><b>Got HTML?</b></p>"
|
||||
'<p><b>Got HTML?</b></p>'
|
||||
)
|
||||
|
||||
def test_getText_with_non_ascii_characters(self):
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.text = u"""Umlaute sind ä, ö und ü."""
|
||||
comment1.text = u'Umlaute sind ä, ö und ü.'
|
||||
self.assertEqual(
|
||||
comment1.getText(),
|
||||
'<p>Umlaute sind \xc3\xa4, \xc3\xb6 und \xc3\xbc.</p>'
|
||||
@@ -177,15 +175,15 @@ class CommentTest(unittest.TestCase):
|
||||
|
||||
def test_getText_doesnt_link(self):
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.text = "Go to http://www.plone.org"
|
||||
comment1.text = 'Go to http://www.plone.org'
|
||||
self.assertEqual(
|
||||
comment1.getText(),
|
||||
"<p>Go to http://www.plone.org</p>"
|
||||
'<p>Go to http://www.plone.org</p>'
|
||||
)
|
||||
|
||||
def test_getText_uses_comment_mime_type(self):
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.text = "Go to http://www.plone.org"
|
||||
comment1.text = 'Go to http://www.plone.org'
|
||||
comment1.mime_type = 'text/x-web-intelligent'
|
||||
self.assertEqual(
|
||||
comment1.getText(),
|
||||
@@ -229,7 +227,8 @@ class CommentTest(unittest.TestCase):
|
||||
new_comment1_id = conversation.addComment(comment1)
|
||||
|
||||
comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment1_id)
|
||||
'++conversation++default/{0}'.format(new_comment1_id)
|
||||
)
|
||||
self.assertTrue(IComment.providedBy(comment))
|
||||
|
||||
self.assertEqual(
|
||||
@@ -260,12 +259,13 @@ class CommentTest(unittest.TestCase):
|
||||
comment1.text = 'Comment text'
|
||||
new_comment1_id = conversation.addComment(comment1)
|
||||
comment = self.portal.image1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment1_id)
|
||||
'++conversation++default/{0}'.format(new_comment1_id)
|
||||
)
|
||||
|
||||
view = View(comment, self.request)
|
||||
View.__call__(view)
|
||||
response = self.request.response
|
||||
self.assertIn("/view", response.headers['location'])
|
||||
self.assertIn('/view', response.headers['location'])
|
||||
|
||||
def test_workflow(self):
|
||||
"""Basic test for the 'comment_review_workflow'
|
||||
@@ -301,8 +301,8 @@ class CommentTest(unittest.TestCase):
|
||||
def test_fti(self):
|
||||
# test that we can look up an FTI for Discussion Item
|
||||
|
||||
self.assertTrue(
|
||||
"Discussion Item" in
|
||||
self.assertIn(
|
||||
'Discussion Item',
|
||||
self.portal.portal_types.objectIds()
|
||||
)
|
||||
|
||||
@@ -327,7 +327,8 @@ class CommentTest(unittest.TestCase):
|
||||
new_comment1_id = conversation.addComment(comment1)
|
||||
|
||||
comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment1_id)
|
||||
'++conversation++default/{0}'.format(new_comment1_id)
|
||||
)
|
||||
|
||||
# make sure the view is there
|
||||
self.assertTrue(getMultiAdapter((comment, self.request),
|
||||
@@ -364,7 +365,8 @@ class RepliesTest(unittest.TestCase):
|
||||
comment.text = 'Comment text'
|
||||
new_id = replies.addComment(comment)
|
||||
comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id)
|
||||
'++conversation++default/{0}'.format(new_id)
|
||||
)
|
||||
|
||||
# Add a reply to the CommentReplies adapter of the first comment
|
||||
re_comment = createObject('plone.Comment')
|
||||
@@ -400,7 +402,8 @@ class RepliesTest(unittest.TestCase):
|
||||
comment.text = 'Comment text'
|
||||
new_id = replies.addComment(comment)
|
||||
comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id)
|
||||
'++conversation++default/{0}'.format(new_id)
|
||||
)
|
||||
|
||||
# Add a reply to the CommentReplies adapter of the first comment
|
||||
re_comment = createObject('plone.Comment')
|
||||
@@ -435,7 +438,8 @@ class RepliesTest(unittest.TestCase):
|
||||
comment.text = 'Comment text'
|
||||
new_id = conversation.addComment(comment)
|
||||
comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id)
|
||||
'++conversation++default/{0}'.format(new_id)
|
||||
)
|
||||
|
||||
# Add a reply to the CommentReplies adapter of the first comment
|
||||
re_comment = createObject('plone.Comment')
|
||||
@@ -443,7 +447,7 @@ class RepliesTest(unittest.TestCase):
|
||||
replies = IReplies(comment)
|
||||
new_re_id = replies.addComment(re_comment)
|
||||
re_comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_re_id
|
||||
'++conversation++default/{0}'.format(new_re_id)
|
||||
)
|
||||
|
||||
# Add a reply to the reply
|
||||
@@ -452,7 +456,7 @@ class RepliesTest(unittest.TestCase):
|
||||
replies = IReplies(re_comment)
|
||||
new_re_re_id = replies.addComment(re_re_comment)
|
||||
re_re_comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_re_re_id
|
||||
'++conversation++default/{0}'.format(new_re_re_id)
|
||||
)
|
||||
|
||||
# Add a reply to the replies reply
|
||||
@@ -461,7 +465,8 @@ class RepliesTest(unittest.TestCase):
|
||||
replies = IReplies(re_re_comment)
|
||||
new_re_re_re_id = replies.addComment(re_re_re_comment)
|
||||
re_re_re_comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_re_re_re_id)
|
||||
'++conversation++default/{0}'.format(new_re_re_re_id)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
('', 'plone', 'doc1', '++conversation++default', str(new_id)),
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
from AccessControl import Unauthorized
|
||||
from datetime import datetime
|
||||
from OFS.Image import Image
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from Products.CMFPlone.tests import dummy
|
||||
from plone.app.discussion import interfaces
|
||||
from plone.app.discussion.browser.comment import EditCommentForm
|
||||
from plone.app.discussion.browser.comments import CommentForm
|
||||
@@ -17,6 +15,8 @@ from plone.app.testing import setRoles
|
||||
from plone.app.testing import TEST_USER_ID
|
||||
from plone.app.testing import TEST_USER_NAME
|
||||
from plone.registry.interfaces import IRegistry
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from Products.CMFPlone.tests import dummy
|
||||
from z3c.form.interfaces import IFormLayer
|
||||
from zope import interface
|
||||
from zope.annotation.interfaces import IAttributeAnnotatable
|
||||
@@ -49,7 +49,7 @@ class TestCommentForm(unittest.TestCase):
|
||||
interfaces.IDiscussionLayer,
|
||||
)
|
||||
|
||||
wftool = getToolByName(self.portal, "portal_workflow")
|
||||
wftool = getToolByName(self.portal, 'portal_workflow')
|
||||
wftool.doActionFor(self.portal.doc1, action='publish')
|
||||
self.portal.doc1.allow_discussion = True
|
||||
self.membershipTool = getToolByName(self.folder, 'portal_membership')
|
||||
@@ -80,7 +80,7 @@ class TestCommentForm(unittest.TestCase):
|
||||
adapts=(Interface, IBrowserRequest),
|
||||
provides=Interface,
|
||||
factory=CommentForm,
|
||||
name=u"comment-form"
|
||||
name=u'comment-form'
|
||||
)
|
||||
|
||||
# The form should return an error if the comment text field is empty
|
||||
@@ -88,13 +88,13 @@ class TestCommentForm(unittest.TestCase):
|
||||
|
||||
commentForm = getMultiAdapter(
|
||||
(self.context, request),
|
||||
name=u"comment-form"
|
||||
name=u'comment-form'
|
||||
)
|
||||
commentForm.update()
|
||||
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
||||
|
||||
self.assertEqual(len(errors), 1)
|
||||
self.assertFalse(commentForm.handleComment(commentForm, "foo"))
|
||||
self.assertFalse(commentForm.handleComment(commentForm, 'foo'))
|
||||
|
||||
# The form is submitted successfully, if the required text field is
|
||||
# filled out
|
||||
@@ -102,22 +102,22 @@ class TestCommentForm(unittest.TestCase):
|
||||
|
||||
commentForm = getMultiAdapter(
|
||||
(self.context, request),
|
||||
name=u"comment-form"
|
||||
name=u'comment-form'
|
||||
)
|
||||
commentForm.update()
|
||||
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
||||
|
||||
self.assertEqual(len(errors), 0)
|
||||
self.assertFalse(commentForm.handleComment(commentForm, "foo"))
|
||||
self.assertFalse(commentForm.handleComment(commentForm, 'foo'))
|
||||
|
||||
comments = IConversation(commentForm.context).getComments()
|
||||
comments = [comment for comment in comments] # consume iterator
|
||||
self.assertEqual(len(comments), 1)
|
||||
|
||||
for comment in comments:
|
||||
self.assertEqual(comment.text, u"bar")
|
||||
self.assertEqual(comment.creator, "test_user_1_")
|
||||
self.assertEqual(comment.getOwner().getUserName(), "test-user")
|
||||
self.assertEqual(comment.text, u'bar')
|
||||
self.assertEqual(comment.creator, 'test_user_1_')
|
||||
self.assertEqual(comment.getOwner().getUserName(), 'test-user')
|
||||
local_roles = comment.get_local_roles()
|
||||
self.assertEqual(len(local_roles), 1)
|
||||
userid, roles = local_roles[0]
|
||||
@@ -144,14 +144,14 @@ class TestCommentForm(unittest.TestCase):
|
||||
adapts=(Interface, IBrowserRequest),
|
||||
provides=Interface,
|
||||
factory=CommentForm,
|
||||
name=u"comment-form"
|
||||
name=u'comment-form'
|
||||
)
|
||||
|
||||
provideAdapter(
|
||||
adapts=(Interface, IBrowserRequest),
|
||||
provides=Interface,
|
||||
factory=EditCommentForm,
|
||||
name=u"edit-comment-form"
|
||||
name=u'edit-comment-form'
|
||||
)
|
||||
|
||||
# The form is submitted successfully, if the required text field is
|
||||
@@ -160,13 +160,13 @@ class TestCommentForm(unittest.TestCase):
|
||||
|
||||
commentForm = getMultiAdapter(
|
||||
(self.context, request),
|
||||
name=u"comment-form"
|
||||
name=u'comment-form'
|
||||
)
|
||||
commentForm.update()
|
||||
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
||||
|
||||
self.assertEqual(len(errors), 0)
|
||||
self.assertFalse(commentForm.handleComment(commentForm, "foo"))
|
||||
self.assertFalse(commentForm.handleComment(commentForm, 'foo'))
|
||||
|
||||
# Edit the last comment
|
||||
conversation = IConversation(self.context)
|
||||
@@ -174,25 +174,25 @@ class TestCommentForm(unittest.TestCase):
|
||||
request = make_request(form={'form.widgets.text': u'foobar'})
|
||||
editForm = getMultiAdapter(
|
||||
(comment, request),
|
||||
name=u"edit-comment-form"
|
||||
name=u'edit-comment-form'
|
||||
)
|
||||
editForm.update()
|
||||
data, errors = editForm.extractData() # pylint: disable-msg=W0612
|
||||
|
||||
self.assertEqual(len(errors), 0)
|
||||
self.assertFalse(editForm.handleComment(editForm, "foo"))
|
||||
self.assertFalse(editForm.handleComment(editForm, 'foo'))
|
||||
comment = [x for x in conversation.getComments()][-1]
|
||||
self.assertEquals(comment.text, u"foobar")
|
||||
self.assertEqual(comment.text, u'foobar')
|
||||
|
||||
comments = IConversation(commentForm.context).getComments()
|
||||
comments = [c for c in comments] # consume iterator
|
||||
self.assertEqual(len(comments), 1)
|
||||
|
||||
for comment in comments:
|
||||
self.assertEqual(comment.text, u"foobar")
|
||||
self.assertEqual(comment.creator, "test_user_1_")
|
||||
self.assertEqual(comment.text, u'foobar')
|
||||
self.assertEqual(comment.creator, 'test_user_1_')
|
||||
|
||||
self.assertEqual(comment.getOwner().getUserName(), "test-user")
|
||||
self.assertEqual(comment.getOwner().getUserName(), 'test-user')
|
||||
local_roles = comment.get_local_roles()
|
||||
self.assertEqual(len(local_roles), 1)
|
||||
userid, roles = local_roles[0]
|
||||
@@ -219,7 +219,7 @@ class TestCommentForm(unittest.TestCase):
|
||||
adapts=(Interface, IBrowserRequest),
|
||||
provides=Interface,
|
||||
factory=CommentForm,
|
||||
name=u"comment-form"
|
||||
name=u'comment-form'
|
||||
)
|
||||
|
||||
# The form is submitted successfully, if the required text field is
|
||||
@@ -228,31 +228,31 @@ class TestCommentForm(unittest.TestCase):
|
||||
|
||||
commentForm = getMultiAdapter(
|
||||
(self.context, form_request),
|
||||
name=u"comment-form"
|
||||
name=u'comment-form'
|
||||
)
|
||||
|
||||
commentForm.update()
|
||||
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
||||
self.assertEqual(len(errors), 0)
|
||||
self.assertFalse(commentForm.handleComment(commentForm, "foo"))
|
||||
self.assertFalse(commentForm.handleComment(commentForm, 'foo'))
|
||||
|
||||
# Delete the last comment
|
||||
conversation = IConversation(self.context)
|
||||
comment = [x for x in conversation.getComments()][-1]
|
||||
deleteView = getMultiAdapter(
|
||||
(comment, self.request),
|
||||
name=u"moderate-delete-comment"
|
||||
name=u'moderate-delete-comment'
|
||||
)
|
||||
# try to delete last comment without "Delete comments" permission
|
||||
# try to delete last comment without 'Delete comments' permission
|
||||
setRoles(self.portal, TEST_USER_ID, ['Member'])
|
||||
self.assertRaises(
|
||||
Unauthorized,
|
||||
comment.restrictedTraverse,
|
||||
"@@moderate-delete-comment"
|
||||
'@@moderate-delete-comment'
|
||||
)
|
||||
deleteView()
|
||||
self.assertEqual(1, len([x for x in conversation.getComments()]))
|
||||
# try to delete last comment with "Delete comments" permission
|
||||
# try to delete last comment with 'Delete comments' permission
|
||||
setRoles(self.portal, TEST_USER_ID, ['Reviewer'])
|
||||
deleteView()
|
||||
self.assertEqual(0, len([x for x in conversation.getComments()]))
|
||||
@@ -277,7 +277,7 @@ class TestCommentForm(unittest.TestCase):
|
||||
adapts=(Interface, IBrowserRequest),
|
||||
provides=Interface,
|
||||
factory=CommentForm,
|
||||
name=u"comment-form"
|
||||
name=u'comment-form'
|
||||
)
|
||||
|
||||
# The form is submitted successfully, if the required text field is
|
||||
@@ -286,20 +286,20 @@ class TestCommentForm(unittest.TestCase):
|
||||
|
||||
commentForm = getMultiAdapter(
|
||||
(self.context, form_request),
|
||||
name=u"comment-form"
|
||||
name=u'comment-form'
|
||||
)
|
||||
|
||||
commentForm.update()
|
||||
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
||||
self.assertEqual(len(errors), 0)
|
||||
self.assertFalse(commentForm.handleComment(commentForm, "foo"))
|
||||
self.assertFalse(commentForm.handleComment(commentForm, 'foo'))
|
||||
|
||||
# Delete the last comment
|
||||
conversation = IConversation(self.context)
|
||||
comment = [x for x in conversation.getComments()][-1]
|
||||
deleteView = getMultiAdapter(
|
||||
(comment, self.request),
|
||||
name=u"delete-own-comment"
|
||||
name=u'delete-own-comment'
|
||||
)
|
||||
# try to delete last comment with johndoe
|
||||
setRoles(self.portal, 'johndoe', ['Member'])
|
||||
@@ -307,7 +307,7 @@ class TestCommentForm(unittest.TestCase):
|
||||
self.assertRaises(
|
||||
Unauthorized,
|
||||
comment.restrictedTraverse,
|
||||
"@@delete-own-comment"
|
||||
'@@delete-own-comment'
|
||||
)
|
||||
self.assertEqual(1, len([x for x in conversation.getComments()]))
|
||||
# try to delete last comment with the same user that created it
|
||||
@@ -338,7 +338,7 @@ class TestCommentForm(unittest.TestCase):
|
||||
provideAdapter(adapts=(Interface, IBrowserRequest),
|
||||
provides=Interface,
|
||||
factory=CommentForm,
|
||||
name=u"comment-form")
|
||||
name=u'comment-form')
|
||||
|
||||
# Post an anonymous comment and provide a name
|
||||
request = make_request(form={
|
||||
@@ -348,20 +348,20 @@ class TestCommentForm(unittest.TestCase):
|
||||
|
||||
commentForm = getMultiAdapter(
|
||||
(self.context, request),
|
||||
name=u"comment-form"
|
||||
name=u'comment-form'
|
||||
)
|
||||
commentForm.update()
|
||||
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
||||
|
||||
self.assertEqual(len(errors), 0)
|
||||
self.assertFalse(commentForm.handleComment(commentForm, "action"))
|
||||
self.assertFalse(commentForm.handleComment(commentForm, 'action'))
|
||||
|
||||
comments = IConversation(commentForm.context).getComments()
|
||||
comments = [comment for comment in comments] # consume itertor
|
||||
self.assertEqual(len(comments), 1)
|
||||
|
||||
for comment in IConversation(commentForm.context).getComments():
|
||||
self.assertEqual(comment.text, u"bar")
|
||||
self.assertEqual(comment.text, u'bar')
|
||||
self.assertIsNone(comment.creator)
|
||||
roles = comment.get_local_roles()
|
||||
self.assertEqual(len(roles), 0)
|
||||
@@ -385,13 +385,13 @@ class TestCommentForm(unittest.TestCase):
|
||||
provideAdapter(adapts=(Interface, IBrowserRequest),
|
||||
provides=Interface,
|
||||
factory=CommentForm,
|
||||
name=u"comment-form")
|
||||
name=u'comment-form')
|
||||
|
||||
request = make_request(form={'form.widgets.text': u'bar'})
|
||||
|
||||
commentForm = getMultiAdapter(
|
||||
(self.context, request),
|
||||
name=u"comment-form"
|
||||
name=u'comment-form'
|
||||
)
|
||||
commentForm.update()
|
||||
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
||||
@@ -403,7 +403,7 @@ class TestCommentForm(unittest.TestCase):
|
||||
self.assertRaises(Unauthorized,
|
||||
commentForm.handleComment,
|
||||
commentForm,
|
||||
"foo")
|
||||
'foo')
|
||||
|
||||
def test_anonymous_can_not_add_comments_if_discussion_is_not_allowed(self):
|
||||
"""Make sure that anonymous users can't post comments if anonymous
|
||||
@@ -424,12 +424,12 @@ class TestCommentForm(unittest.TestCase):
|
||||
provideAdapter(adapts=(Interface, IBrowserRequest),
|
||||
provides=Interface,
|
||||
factory=CommentForm,
|
||||
name=u"comment-form")
|
||||
name=u'comment-form')
|
||||
|
||||
request = make_request(form={'form.widgets.text': u'bar'})
|
||||
|
||||
commentForm = getMultiAdapter((self.context, request),
|
||||
name=u"comment-form")
|
||||
name=u'comment-form')
|
||||
commentForm.update()
|
||||
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
||||
|
||||
@@ -438,7 +438,7 @@ class TestCommentForm(unittest.TestCase):
|
||||
Unauthorized,
|
||||
commentForm.handleComment,
|
||||
commentForm,
|
||||
"foo"
|
||||
'foo'
|
||||
)
|
||||
|
||||
|
||||
@@ -519,20 +519,20 @@ class TestCommentsViewlet(unittest.TestCase):
|
||||
self.assertTrue(self.viewlet.comment_transform_message())
|
||||
self.assertEqual(
|
||||
self.viewlet.comment_transform_message(),
|
||||
"You can add a comment by filling out the form below. Plain " +
|
||||
"text formatting.")
|
||||
'You can add a comment by filling out the form below. Plain ' +
|
||||
'text formatting.')
|
||||
|
||||
# Set text transform to intelligent text
|
||||
registry = queryUtility(IRegistry)
|
||||
settings = registry.forInterface(IDiscussionSettings, check=False)
|
||||
settings.text_transform = "text/x-web-intelligent"
|
||||
settings.text_transform = 'text/x-web-intelligent'
|
||||
|
||||
# Make sure the comment description changes accordingly
|
||||
self.assertEqual(
|
||||
self.viewlet.comment_transform_message(),
|
||||
"You can add a comment by filling out the form below. " +
|
||||
"Plain text formatting. Web and email addresses are transformed " +
|
||||
"into clickable links."
|
||||
'You can add a comment by filling out the form below. ' +
|
||||
'Plain text formatting. Web and email addresses are transformed ' +
|
||||
'into clickable links.'
|
||||
)
|
||||
|
||||
# Enable moderation workflow
|
||||
@@ -543,9 +543,9 @@ class TestCommentsViewlet(unittest.TestCase):
|
||||
# Make sure the comment description shows that comments are moderated
|
||||
self.assertEqual(
|
||||
self.viewlet.comment_transform_message(),
|
||||
"You can add a comment by filling out the form below. " +
|
||||
"Plain text formatting. Web and email addresses are transformed " +
|
||||
"into clickable links. Comments are moderated.")
|
||||
'You can add a comment by filling out the form below. ' +
|
||||
'Plain text formatting. Web and email addresses are transformed ' +
|
||||
'into clickable links. Comments are moderated.')
|
||||
|
||||
def test_has_replies(self):
|
||||
self.assertEqual(self.viewlet.has_replies(), False)
|
||||
@@ -599,10 +599,11 @@ class TestCommentsViewlet(unittest.TestCase):
|
||||
reply['actions'][0]['id'],
|
||||
'publish'
|
||||
)
|
||||
expected_url = 'http://nohost/plone/doc1/++conversation++default/{0}' \
|
||||
'/content_status_modify?workflow_action=publish'
|
||||
self.assertEqual(
|
||||
reply['actions'][0]['url'],
|
||||
'http://nohost/plone/doc1/++conversation++default/%s' % int(c1) +
|
||||
'/content_status_modify?workflow_action=publish'
|
||||
expected_url.format(int(c1))
|
||||
)
|
||||
|
||||
def test_get_commenter_home_url(self):
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from plone.app.discussion.interfaces import ICommentAddedEvent
|
||||
from plone.app.discussion.interfaces import ICommentRemovedEvent
|
||||
from plone.app.discussion.interfaces import IConversation, IReplies
|
||||
from plone.app.discussion.interfaces import IConversation
|
||||
from plone.app.discussion.interfaces import IReplies
|
||||
from plone.app.discussion.interfaces import IReplyAddedEvent
|
||||
from plone.app.discussion.interfaces import IReplyRemovedEvent
|
||||
from plone.app.discussion.testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING # noqa
|
||||
@@ -37,10 +38,10 @@ class CommentContentRulesTest(unittest.TestCase):
|
||||
self.document = self.portal['doc1']
|
||||
|
||||
comment = createObject('plone.Comment')
|
||||
comment.text = "This is a comment"
|
||||
comment.author_username = "jim"
|
||||
comment.author_name = "Jim"
|
||||
comment.author_email = "jim@example.com"
|
||||
comment.text = 'This is a comment'
|
||||
comment.author_username = 'jim'
|
||||
comment.author_name = 'Jim'
|
||||
comment.author_email = 'jim@example.com'
|
||||
conversation = IConversation(self.document)
|
||||
conversation.addComment(comment)
|
||||
|
||||
@@ -52,28 +53,28 @@ class CommentContentRulesTest(unittest.TestCase):
|
||||
|
||||
def testCommentIdStringSubstitution(self):
|
||||
comment_id = getAdapter(self.document, IStringSubstitution,
|
||||
name=u"comment_id")
|
||||
name=u'comment_id')
|
||||
self.assertIsInstance(comment_id(), long)
|
||||
|
||||
def testCommentTextStringSubstitution(self):
|
||||
comment_text = getAdapter(self.document, IStringSubstitution,
|
||||
name=u"comment_text")
|
||||
self.assertEqual(comment_text(), u"This is a comment")
|
||||
name=u'comment_text')
|
||||
self.assertEqual(comment_text(), u'This is a comment')
|
||||
|
||||
def testCommentUserIdStringSubstitution(self):
|
||||
comment_user_id = getAdapter(self.document, IStringSubstitution,
|
||||
name=u"comment_user_id")
|
||||
self.assertEqual(comment_user_id(), u"jim")
|
||||
name=u'comment_user_id')
|
||||
self.assertEqual(comment_user_id(), u'jim')
|
||||
|
||||
def testCommentUserFullNameStringSubstitution(self):
|
||||
comment_user_fullname = getAdapter(self.document, IStringSubstitution,
|
||||
name=u"comment_user_fullname")
|
||||
self.assertEqual(comment_user_fullname(), u"Jim")
|
||||
name=u'comment_user_fullname')
|
||||
self.assertEqual(comment_user_fullname(), u'Jim')
|
||||
|
||||
def testCommentUserEmailStringSubstitution(self):
|
||||
comment_user_email = getAdapter(self.document, IStringSubstitution,
|
||||
name=u"comment_user_email")
|
||||
self.assertEqual(comment_user_email(), u"jim@example.com")
|
||||
name=u'comment_user_email')
|
||||
self.assertEqual(comment_user_email(), u'jim@example.com')
|
||||
|
||||
|
||||
class ReplyContentRulesTest(unittest.TestCase):
|
||||
@@ -95,13 +96,14 @@ class ReplyContentRulesTest(unittest.TestCase):
|
||||
comment.text = 'This is a comment'
|
||||
new_id = replies.addComment(comment)
|
||||
comment = self.document.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id)
|
||||
'++conversation++default/{0}'.format(new_id)
|
||||
)
|
||||
|
||||
re_comment = createObject('plone.Comment')
|
||||
re_comment.text = 'This is a reply'
|
||||
re_comment.author_username = "julia"
|
||||
re_comment.author_name = "Juliana"
|
||||
re_comment.author_email = "julia@example.com"
|
||||
re_comment.author_username = 'julia'
|
||||
re_comment.author_name = 'Juliana'
|
||||
re_comment.author_email = 'julia@example.com'
|
||||
|
||||
replies = IReplies(comment)
|
||||
replies.addComment(re_comment)
|
||||
@@ -110,7 +112,7 @@ class ReplyContentRulesTest(unittest.TestCase):
|
||||
reply_id = getAdapter(
|
||||
self.document,
|
||||
IStringSubstitution,
|
||||
name=u"comment_id"
|
||||
name=u'comment_id'
|
||||
)
|
||||
self.assertIsInstance(reply_id(), long)
|
||||
|
||||
@@ -118,30 +120,30 @@ class ReplyContentRulesTest(unittest.TestCase):
|
||||
reply_text = getAdapter(
|
||||
self.document,
|
||||
IStringSubstitution,
|
||||
name=u"comment_text"
|
||||
name=u'comment_text'
|
||||
)
|
||||
self.assertEqual(reply_text(), u"This is a reply")
|
||||
self.assertEqual(reply_text(), u'This is a reply')
|
||||
|
||||
def testReplyUserIdStringSubstitution(self):
|
||||
reply_user_id = getAdapter(
|
||||
self.document,
|
||||
IStringSubstitution,
|
||||
name=u"comment_user_id"
|
||||
name=u'comment_user_id'
|
||||
)
|
||||
self.assertEqual(reply_user_id(), u"julia")
|
||||
self.assertEqual(reply_user_id(), u'julia')
|
||||
|
||||
def testReplyUserFullNameStringSubstitution(self):
|
||||
reply_user_fullname = getAdapter(
|
||||
self.document,
|
||||
IStringSubstitution,
|
||||
name=u"comment_user_fullname"
|
||||
name=u'comment_user_fullname'
|
||||
)
|
||||
self.assertEqual(reply_user_fullname(), u"Juliana")
|
||||
self.assertEqual(reply_user_fullname(), u'Juliana')
|
||||
|
||||
def testReplyUserEmailStringSubstitution(self):
|
||||
reply_user_email = getAdapter(
|
||||
self.document,
|
||||
IStringSubstitution,
|
||||
name=u"comment_user_email"
|
||||
name=u'comment_user_email'
|
||||
)
|
||||
self.assertEqual(reply_user_email(), u"julia@example.com")
|
||||
self.assertEqual(reply_user_email(), u'julia@example.com')
|
||||
|
||||
@@ -29,14 +29,14 @@ class RegistryTest(unittest.TestCase):
|
||||
def test_discussion_controlpanel_view(self):
|
||||
view = getMultiAdapter(
|
||||
(self.portal, self.portal.REQUEST),
|
||||
name="discussion-controlpanel"
|
||||
name='discussion-controlpanel'
|
||||
)
|
||||
view = view.__of__(self.portal)
|
||||
self.assertTrue(view())
|
||||
|
||||
def test_discussion_in_controlpanel(self):
|
||||
# Check if discussion is in the control panel
|
||||
self.controlpanel = getToolByName(self.portal, "portal_controlpanel")
|
||||
self.controlpanel = getToolByName(self.portal, 'portal_controlpanel')
|
||||
self.assertTrue(
|
||||
'discussion' in [
|
||||
a.getAction(self)['id']
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from Acquisition import aq_base
|
||||
from Acquisition import aq_parent
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
from plone.app.discussion import interfaces
|
||||
@@ -13,6 +13,7 @@ from plone.app.testing import setRoles
|
||||
from plone.app.testing import TEST_USER_ID
|
||||
from plone.app.vocabularies.types import BAD_TYPES
|
||||
from plone.registry.interfaces import IRegistry
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from zope import interface
|
||||
from zope.annotation.interfaces import IAnnotations
|
||||
from zope.component import createObject
|
||||
@@ -24,7 +25,7 @@ import unittest2 as unittest
|
||||
try:
|
||||
from plone.dexterity.interfaces import IDexterityContent
|
||||
DEXTERITY = True
|
||||
except:
|
||||
except ImportError:
|
||||
DEXTERITY = False
|
||||
|
||||
|
||||
@@ -82,12 +83,12 @@ class ConversationTest(unittest.TestCase):
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
|
||||
comment = createObject('plone.Comment')
|
||||
comment.author_username = "nobody"
|
||||
comment.author_username = 'nobody'
|
||||
conversation.addComment(comment)
|
||||
comment.manage_permission("View", roles=tuple())
|
||||
comment.manage_permission('View', roles=tuple())
|
||||
self.assertEqual(0, conversation.total_comments())
|
||||
self.assertEqual(None, conversation.last_comment_date)
|
||||
self.assertEqual(["nobody"], list(conversation.commentators))
|
||||
self.assertEqual(['nobody'], list(conversation.commentators))
|
||||
self.assertEqual([], list(conversation.public_commentators))
|
||||
|
||||
def test_delete_comment(self):
|
||||
@@ -434,22 +435,22 @@ class ConversationTest(unittest.TestCase):
|
||||
# swapped in
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.text = 'Comment text'
|
||||
comment1.author_username = "Jim"
|
||||
comment1.author_username = 'Jim'
|
||||
conversation.addComment(comment1)
|
||||
|
||||
comment2 = createObject('plone.Comment')
|
||||
comment2.text = 'Comment text'
|
||||
comment2.author_username = "Joe"
|
||||
comment2.author_username = 'Joe'
|
||||
conversation.addComment(comment2)
|
||||
|
||||
comment3 = createObject('plone.Comment')
|
||||
comment3.text = 'Comment text'
|
||||
comment3.author_username = "Jack"
|
||||
comment3.author_username = 'Jack'
|
||||
new_comment3_id = conversation.addComment(comment3)
|
||||
|
||||
comment4 = createObject('plone.Comment')
|
||||
comment4.text = 'Comment text'
|
||||
comment4.author_username = "Jack"
|
||||
comment4.author_username = 'Jack'
|
||||
new_comment4_id = conversation.addComment(comment4)
|
||||
|
||||
# check if all commentators are in the commentators list
|
||||
@@ -680,10 +681,10 @@ class ConversationEnabledForDexterityTypesTest(unittest.TestCase):
|
||||
)
|
||||
|
||||
if DEXTERITY:
|
||||
interface.alsoProvides(
|
||||
self.portal.doc1,
|
||||
IDexterityContent
|
||||
)
|
||||
interface.alsoProvides(
|
||||
self.portal.doc1,
|
||||
IDexterityContent
|
||||
)
|
||||
|
||||
def _makeOne(self, *args, **kw):
|
||||
return self.portal.doc1.restrictedTraverse('@@conversation_view')
|
||||
@@ -839,16 +840,19 @@ class RepliesTest(unittest.TestCase):
|
||||
# Create the nested comment structure
|
||||
new_id_1 = replies.addComment(comment1)
|
||||
comment1 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id_1)
|
||||
'++conversation++default/{0}'.format(new_id_1)
|
||||
)
|
||||
replies_to_comment1 = IReplies(comment1)
|
||||
new_id_2 = replies.addComment(comment2)
|
||||
comment2 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id_2)
|
||||
'++conversation++default/{0}'.format(new_id_2)
|
||||
)
|
||||
replies_to_comment2 = IReplies(comment2)
|
||||
|
||||
new_id_1_1 = replies_to_comment1.addComment(comment1_1)
|
||||
comment1_1 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id_1_1)
|
||||
'++conversation++default/{0}'.format(new_id_1_1)
|
||||
)
|
||||
replies_to_comment1_1 = IReplies(comment1_1)
|
||||
replies_to_comment1_1.addComment(comment1_1_1)
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from Zope2.App import zcml
|
||||
from plone.app.discussion.interfaces import IConversation
|
||||
from plone.app.discussion.interfaces import IReplies
|
||||
from plone.app.discussion.testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING # noqa
|
||||
from plone.app.testing import setRoles
|
||||
from plone.app.testing import TEST_USER_ID
|
||||
from zope.component import createObject
|
||||
from Zope2.App import zcml
|
||||
|
||||
import Products.Five
|
||||
import unittest2 as unittest
|
||||
@@ -86,7 +86,7 @@ class CommentEventsTest(unittest.TestCase):
|
||||
|
||||
</configure>
|
||||
"""
|
||||
zcml.load_config("configure.zcml", Products.Five)
|
||||
zcml.load_config('configure.zcml', Products.Five)
|
||||
zcml.load_string(configure)
|
||||
|
||||
def test_addEvent(self):
|
||||
@@ -139,7 +139,7 @@ class RepliesEventsTest(unittest.TestCase):
|
||||
|
||||
</configure>
|
||||
"""
|
||||
zcml.load_config("configure.zcml", Products.Five)
|
||||
zcml.load_config('configure.zcml', Products.Five)
|
||||
zcml.load_string(configure)
|
||||
|
||||
def test_addEvent(self):
|
||||
@@ -152,7 +152,8 @@ class RepliesEventsTest(unittest.TestCase):
|
||||
comment.text = 'Comment text'
|
||||
new_id = replies.addComment(comment)
|
||||
comment = self.document.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id)
|
||||
'++conversation++default/{0}'.format(new_id)
|
||||
)
|
||||
|
||||
re_comment = createObject('plone.Comment')
|
||||
re_comment.text = 'Comment text'
|
||||
@@ -172,7 +173,8 @@ class RepliesEventsTest(unittest.TestCase):
|
||||
comment.text = 'Comment text'
|
||||
new_id = replies.addComment(comment)
|
||||
comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id)
|
||||
'++conversation++default/{0}'.format(new_id)
|
||||
)
|
||||
|
||||
re_comment = createObject('plone.Comment')
|
||||
re_comment.text = 'Comment text'
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Test for the plone.app.discussion indexers
|
||||
"""
|
||||
from DateTime import DateTime
|
||||
from datetime import datetime
|
||||
from DateTime import DateTime
|
||||
from plone.app.discussion import catalog
|
||||
from plone.app.discussion.interfaces import IConversation
|
||||
from plone.app.discussion.testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING # noqa
|
||||
@@ -39,24 +40,24 @@ class ConversationIndexersTest(unittest.TestCase):
|
||||
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.text = 'Comment Text'
|
||||
comment1.creator = "jim"
|
||||
comment1.author_username = "Jim"
|
||||
comment1.creator = 'jim'
|
||||
comment1.author_username = 'Jim'
|
||||
comment1.creation_date = datetime(2006, 9, 17, 14, 18, 12)
|
||||
comment1.modification_date = datetime(2006, 9, 17, 14, 18, 12)
|
||||
self.new_id1 = conversation.addComment(comment1)
|
||||
|
||||
comment2 = createObject('plone.Comment')
|
||||
comment2.text = 'Comment Text'
|
||||
comment2.creator = "emma"
|
||||
comment2.author_username = "Emma"
|
||||
comment2.creator = 'emma'
|
||||
comment2.author_username = 'Emma'
|
||||
comment2.creation_date = datetime(2007, 12, 13, 4, 18, 12)
|
||||
comment2.modification_date = datetime(2007, 12, 13, 4, 18, 12)
|
||||
self.new_id2 = conversation.addComment(comment2)
|
||||
|
||||
comment3 = createObject('plone.Comment')
|
||||
comment3.text = 'Comment Text'
|
||||
comment3.creator = "lukas"
|
||||
comment3.author_username = "Lukas"
|
||||
comment3.creator = 'lukas'
|
||||
comment3.author_username = 'Lukas'
|
||||
comment3.creation_date = datetime(2009, 4, 12, 11, 12, 12)
|
||||
comment3.modification_date = datetime(2009, 4, 12, 11, 12, 12)
|
||||
self.new_id3 = conversation.addComment(comment3)
|
||||
@@ -118,8 +119,8 @@ class CommentIndexersTest(unittest.TestCase):
|
||||
|
||||
comment = createObject('plone.Comment')
|
||||
comment.text = 'Lorem ipsum dolor sit amet.'
|
||||
comment.creator = "jim"
|
||||
comment.author_name = "Jim"
|
||||
comment.creator = 'jim'
|
||||
comment.author_name = 'Jim'
|
||||
comment.creation_date = datetime(2006, 9, 17, 14, 18, 12)
|
||||
comment.modification_date = datetime(2008, 3, 12, 7, 32, 52)
|
||||
|
||||
@@ -149,7 +150,7 @@ class CommentIndexersTest(unittest.TestCase):
|
||||
self.conversation.addComment(comment_long)
|
||||
self.assertEqual(
|
||||
catalog.description(comment_long)(),
|
||||
LONG_TEXT_CUT.replace("\n", " ")
|
||||
LONG_TEXT_CUT.replace('\n', ' ')
|
||||
)
|
||||
|
||||
def test_dates(self):
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from plone.app.discussion.browser.moderation import BulkActionsView
|
||||
from plone.app.discussion.browser.moderation import View
|
||||
from plone.app.discussion.interfaces import IConversation
|
||||
from plone.app.discussion.testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING # noqa
|
||||
from plone.app.testing import setRoles
|
||||
from plone.app.testing import TEST_USER_ID
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from zope.component import createObject
|
||||
|
||||
import unittest
|
||||
@@ -75,7 +75,7 @@ class ModerationBulkActionsViewTest(unittest.TestCase):
|
||||
comment1.Creator = 'Jim'
|
||||
new_id_1 = conversation.addComment(comment1)
|
||||
self.comment1 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id_1
|
||||
'++conversation++default/{0}'.format(new_id_1)
|
||||
)
|
||||
comment2 = createObject('plone.Comment')
|
||||
comment2.title = 'Comment 2'
|
||||
@@ -83,7 +83,7 @@ class ModerationBulkActionsViewTest(unittest.TestCase):
|
||||
comment2.Creator = 'Joe'
|
||||
new_id_2 = conversation.addComment(comment2)
|
||||
self.comment2 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id_2
|
||||
'++conversation++default/{0}'.format(new_id_2)
|
||||
)
|
||||
comment3 = createObject('plone.Comment')
|
||||
comment3.title = 'Comment 3'
|
||||
@@ -91,7 +91,7 @@ class ModerationBulkActionsViewTest(unittest.TestCase):
|
||||
comment3.Creator = 'Emma'
|
||||
new_id_3 = conversation.addComment(comment3)
|
||||
self.comment3 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id_3
|
||||
'++conversation++default/{0}'.format(new_id_3)
|
||||
)
|
||||
self.conversation = conversation
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from Acquisition import aq_base
|
||||
from plone.app.discussion.interfaces import IConversation
|
||||
from plone.app.discussion.testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING # noqa
|
||||
from plone.app.testing import setRoles
|
||||
from plone.app.testing import TEST_USER_ID
|
||||
from plone.registry.interfaces import IRegistry
|
||||
from Products.CMFPlone.interfaces import IMailSchema
|
||||
from Products.CMFPlone.tests.utils import MockMailHost
|
||||
from Products.MailHost.interfaces import IMailHost
|
||||
from plone.app.discussion.interfaces import IConversation
|
||||
from plone.app.discussion.testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING # noqa
|
||||
from plone.app.testing import TEST_USER_ID
|
||||
from plone.app.testing import setRoles
|
||||
from plone.registry.interfaces import IRegistry
|
||||
from zope.component import createObject
|
||||
from zope.component import getSiteManager
|
||||
from zope.component import getUtility
|
||||
@@ -32,7 +32,7 @@ class TestUserNotificationUnit(unittest.TestCase):
|
||||
# We need to fake a valid mail setup
|
||||
registry = getUtility(IRegistry)
|
||||
mail_settings = registry.forInterface(IMailSchema, prefix='plone')
|
||||
mail_settings.email_from_address = "portal@plone.test"
|
||||
mail_settings.email_from_address = 'portal@plone.test'
|
||||
self.mailhost = self.portal.MailHost
|
||||
# Enable user notification setting
|
||||
registry = queryUtility(IRegistry)
|
||||
@@ -40,7 +40,7 @@ class TestUserNotificationUnit(unittest.TestCase):
|
||||
'.user_notification_enabled'] = True
|
||||
# Archetypes content types store data as utf-8 encoded strings
|
||||
# The missing u in front of a string is therefor not missing
|
||||
self.portal.doc1.title = 'Kölle Alaaf' # What is "Fasching"?
|
||||
self.portal.doc1.title = 'Kölle Alaaf' # What is 'Fasching'?
|
||||
self.conversation = IConversation(self.portal.doc1)
|
||||
|
||||
def beforeTearDown(self):
|
||||
@@ -56,7 +56,7 @@ class TestUserNotificationUnit(unittest.TestCase):
|
||||
comment = createObject('plone.Comment')
|
||||
comment.text = 'Comment text'
|
||||
comment.user_notification = True
|
||||
comment.author_email = "john@plone.test"
|
||||
comment.author_email = 'john@plone.test'
|
||||
self.conversation.addComment(comment)
|
||||
comment = createObject('plone.Comment')
|
||||
comment.text = 'Comment text'
|
||||
@@ -75,11 +75,10 @@ class TestUserNotificationUnit(unittest.TestCase):
|
||||
# The output should be encoded in a reasonable manner
|
||||
# (in this case quoted-printable):
|
||||
self.assertTrue(
|
||||
"A comment on \'K=C3=B6lle Alaaf\' has been posted here:"
|
||||
'A comment on "K=C3=B6lle Alaaf" has been posted here:'
|
||||
in msg)
|
||||
self.assertTrue(
|
||||
"http://nohost/plone/d=\noc1/view#%s"
|
||||
% comment_id
|
||||
'http://nohost/plone/d=\noc1/view#{0}'.format(comment_id)
|
||||
in msg)
|
||||
self.assertTrue('Comment text' in msg)
|
||||
self.assertFalse('Approve comment' in msg)
|
||||
@@ -94,7 +93,7 @@ class TestUserNotificationUnit(unittest.TestCase):
|
||||
comment = createObject('plone.Comment')
|
||||
comment.text = 'Comment text'
|
||||
comment.user_notification = True
|
||||
comment.author_email = "john@plone.test"
|
||||
comment.author_email = 'john@plone.test'
|
||||
self.conversation.addComment(comment)
|
||||
comment = createObject('plone.Comment')
|
||||
comment.text = 'Comment text'
|
||||
@@ -124,7 +123,7 @@ class TestUserNotificationUnit(unittest.TestCase):
|
||||
comment = createObject('plone.Comment')
|
||||
comment.text = 'Comment text'
|
||||
comment.user_notification = True
|
||||
comment.author_email = "john@plone.test"
|
||||
comment.author_email = 'john@plone.test'
|
||||
self.conversation.addComment(comment)
|
||||
comment = createObject('plone.Comment')
|
||||
comment.text = 'Comment text'
|
||||
@@ -139,12 +138,12 @@ class TestUserNotificationUnit(unittest.TestCase):
|
||||
comment = createObject('plone.Comment')
|
||||
comment.text = 'Comment text'
|
||||
comment.user_notification = True
|
||||
comment.author_email = "john@plone.test"
|
||||
comment.author_email = 'john@plone.test'
|
||||
self.conversation.addComment(comment)
|
||||
comment = createObject('plone.Comment')
|
||||
comment.text = 'Comment text'
|
||||
comment.user_notification = True
|
||||
comment.author_email = "john@plone.test"
|
||||
comment.author_email = 'john@plone.test'
|
||||
|
||||
self.conversation.addComment(comment)
|
||||
|
||||
@@ -171,7 +170,7 @@ class TestModeratorNotificationUnit(unittest.TestCase):
|
||||
# We need to fake a valid mail setup
|
||||
registry = getUtility(IRegistry)
|
||||
mail_settings = registry.forInterface(IMailSchema, prefix='plone')
|
||||
mail_settings.email_from_address = "portal@plone.test"
|
||||
mail_settings.email_from_address = 'portal@plone.test'
|
||||
self.mailhost = self.portal.MailHost
|
||||
# Enable comment moderation
|
||||
self.portal.portal_types['Document'].allow_discussion = True
|
||||
@@ -187,7 +186,7 @@ class TestModeratorNotificationUnit(unittest.TestCase):
|
||||
] = True
|
||||
# Archetypes content types store data as utf-8 encoded strings
|
||||
# The missing u in front of a string is therefor not missing
|
||||
self.portal.doc1.title = 'Kölle Alaaf' # What is "Fasching"?
|
||||
self.portal.doc1.title = 'Kölle Alaaf' # What is 'Fasching'?
|
||||
self.conversation = IConversation(self.portal.doc1)
|
||||
|
||||
def beforeTearDown(self):
|
||||
@@ -216,21 +215,28 @@ class TestModeratorNotificationUnit(unittest.TestCase):
|
||||
# The output should be encoded in a reasonable manner
|
||||
# (in this case quoted-printable):
|
||||
self.assertTrue(
|
||||
"A comment on \'K=C3=B6lle Alaaf\' has been posted here:"
|
||||
'A comment on "K=C3=B6lle Alaaf" has been posted here:'
|
||||
in msg)
|
||||
self.assertTrue(
|
||||
"http://nohost/plone/d=\noc1/view#%s"
|
||||
% comment_id
|
||||
in msg)
|
||||
self.assertTrue('Comment text' in msg)
|
||||
self.assertTrue(
|
||||
'Approve comment:\nhttp://nohost/plone/doc1/' +
|
||||
'++conversation++default/%s/@@moderat=\ne-publish-comment'
|
||||
% comment_id in msg)
|
||||
self.assertTrue(
|
||||
'Delete comment:\nhttp://nohost/plone/doc1/' +
|
||||
'++conversation++default/%s/@@moderat=\ne-delete-comment'
|
||||
% comment_id in msg)
|
||||
self.assertIn(
|
||||
'http://nohost/plone/d=\noc1/view#{0}'.format(comment_id),
|
||||
msg
|
||||
)
|
||||
self.assertIn(
|
||||
'Comment text',
|
||||
msg
|
||||
)
|
||||
text = 'Approve comment:\nhttp://nohost/plone/doc1/' \
|
||||
'++conversation++default/{0}/@@moderat=\ne-publish-comment'
|
||||
self.assertIn(
|
||||
text.format(comment_id),
|
||||
msg
|
||||
)
|
||||
text = 'Delete comment:\nhttp://nohost/plone/doc1/' \
|
||||
'++conversation++default/{0}/@@moderat=\ne-delete-comment'
|
||||
self.assertIn(
|
||||
text.format(comment_id),
|
||||
msg
|
||||
)
|
||||
|
||||
def test_notify_moderator_specific_address(self):
|
||||
# A moderator email address can be specified in the control panel.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from plone.app.discussion.testing import PLONE_APP_DISCUSSION_ROBOT_TESTING
|
||||
from plone.app.testing import ROBOT_TEST_LEVEL
|
||||
from plone.testing import layered
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
"""Test plone.app.discussion workflow and permissions.
|
||||
"""
|
||||
from AccessControl import Unauthorized
|
||||
from Products.CMFCore.permissions import View
|
||||
from Products.CMFCore.utils import _checkPermission as checkPerm
|
||||
from plone.app.discussion.interfaces import IConversation
|
||||
from plone.app.discussion.interfaces import IDiscussionLayer
|
||||
from plone.app.discussion.testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING # noqa
|
||||
@@ -11,6 +9,8 @@ from plone.app.testing import login
|
||||
from plone.app.testing import logout
|
||||
from plone.app.testing import setRoles
|
||||
from plone.app.testing import TEST_USER_ID
|
||||
from Products.CMFCore.permissions import View
|
||||
from Products.CMFCore.utils import _checkPermission as checkPerm
|
||||
from zope.component import createObject
|
||||
from zope.interface import alsoProvides
|
||||
|
||||
@@ -87,7 +87,7 @@ class PermissionsSetupTest(unittest.TestCase):
|
||||
plone.app.discussion assigns this permission to 'Authenticated' as
|
||||
well to emulate the behavior of the old commenting system.
|
||||
"""
|
||||
ReplyToItemPerm = "Reply to item"
|
||||
ReplyToItemPerm = 'Reply to item'
|
||||
# should be allowed as Member
|
||||
self.assertTrue(self.checkPermission(ReplyToItemPerm, self.portal))
|
||||
# should be allowed as Authenticated
|
||||
@@ -126,7 +126,7 @@ class CommentOneStateWorkflowTest(unittest.TestCase):
|
||||
cid = conversation.addComment(comment)
|
||||
|
||||
self.comment = self.folder.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % cid
|
||||
'++conversation++default/{0}'.format(cid)
|
||||
)
|
||||
|
||||
self.portal.acl_users._doAddUser('member', 'secret', ['Member'], [])
|
||||
@@ -192,7 +192,8 @@ class CommentReviewWorkflowTest(unittest.TestCase):
|
||||
comment.text = 'Comment text'
|
||||
comment_id = conversation.addComment(comment)
|
||||
comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % comment_id)
|
||||
'++conversation++default/{0}'.format(comment_id)
|
||||
)
|
||||
|
||||
self.conversation = conversation
|
||||
self.comment_id = comment_id
|
||||
|
||||
Reference in New Issue
Block a user