2010-08-25 11:19:28 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2010-09-03 22:40:27 +02:00
|
|
|
from AccessControl import Unauthorized
|
2015-05-03 08:16:39 +02:00
|
|
|
from datetime import datetime
|
2009-06-07 22:58:41 +02:00
|
|
|
from OFS.Image import Image
|
2011-04-15 06:29:46 +02:00
|
|
|
from plone.app.discussion import interfaces
|
2015-05-03 08:16:39 +02:00
|
|
|
from plone.app.discussion.browser.comment import EditCommentForm
|
|
|
|
from plone.app.discussion.browser.comments import CommentForm
|
|
|
|
from plone.app.discussion.browser.comments import CommentsViewlet
|
2010-12-16 00:52:56 +01:00
|
|
|
from plone.app.discussion.interfaces import IConversation
|
2010-11-08 18:10:19 +01:00
|
|
|
from plone.app.discussion.interfaces import IDiscussionSettings
|
2022-05-01 23:14:00 +02:00
|
|
|
from plone.app.discussion.testing import ( # noqa
|
|
|
|
PLONE_APP_DISCUSSION_INTEGRATION_TESTING,
|
|
|
|
)
|
2015-05-03 08:16:39 +02:00
|
|
|
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 plone.app.testing import TEST_USER_NAME
|
|
|
|
from plone.registry.interfaces import IRegistry
|
2016-02-05 01:39:53 +01:00
|
|
|
from Products.CMFCore.utils import getToolByName
|
|
|
|
from Products.CMFPlone.tests import dummy
|
2015-05-03 08:16:39 +02:00
|
|
|
from z3c.form.interfaces import IFormLayer
|
|
|
|
from zope import interface
|
|
|
|
from zope.annotation.interfaces import IAttributeAnnotatable
|
|
|
|
from zope.component import createObject
|
|
|
|
from zope.component import getMultiAdapter
|
|
|
|
from zope.component import provideAdapter
|
|
|
|
from zope.component import queryUtility
|
|
|
|
from zope.interface import alsoProvides
|
|
|
|
from zope.interface import Interface
|
|
|
|
from zope.publisher.browser import TestRequest
|
|
|
|
from zope.publisher.interfaces.browser import IBrowserRequest
|
|
|
|
|
|
|
|
import time
|
2017-05-08 09:24:38 +02:00
|
|
|
import unittest
|
2009-06-06 10:23:33 +02:00
|
|
|
|
|
|
|
|
2011-04-16 11:25:16 +02:00
|
|
|
class TestCommentForm(unittest.TestCase):
|
2010-01-22 13:29:26 +01:00
|
|
|
|
2011-04-16 11:25:16 +02:00
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
2010-01-22 13:29:26 +01:00
|
|
|
|
2011-04-16 11:25:16 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.portal = self.layer['portal']
|
|
|
|
self.request = self.layer['request']
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
|
|
|
self.portal.invokeFactory('Folder', 'test-folder')
|
|
|
|
self.folder = self.portal['test-folder']
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2011-04-15 06:29:46 +02:00
|
|
|
interface.alsoProvides(
|
2013-04-17 19:34:17 +02:00
|
|
|
self.portal.REQUEST,
|
|
|
|
interfaces.IDiscussionLayer,
|
|
|
|
)
|
2011-04-15 06:29:46 +02:00
|
|
|
|
2016-02-05 01:39:53 +01:00
|
|
|
wftool = getToolByName(self.portal, 'portal_workflow')
|
2013-08-29 22:20:47 +02:00
|
|
|
wftool.doActionFor(self.portal.doc1, action='publish')
|
2013-10-10 15:36:18 +02:00
|
|
|
self.portal.doc1.allow_discussion = True
|
2012-01-14 07:26:01 +01:00
|
|
|
self.membershipTool = getToolByName(self.folder, 'portal_membership')
|
2010-01-22 13:29:26 +01:00
|
|
|
self.memberdata = self.portal.portal_memberdata
|
2010-09-02 22:00:43 +02:00
|
|
|
self.context = getattr(self.portal, 'doc1')
|
2010-12-14 18:58:46 +01:00
|
|
|
|
|
|
|
# Allow discussion
|
|
|
|
registry = queryUtility(IRegistry)
|
|
|
|
settings = registry.forInterface(IDiscussionSettings)
|
|
|
|
settings.globally_enabled = True
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-02-05 23:40:38 +01:00
|
|
|
def test_add_comment(self):
|
2010-11-08 18:10:19 +01:00
|
|
|
"""Post a comment as logged-in user.
|
|
|
|
"""
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-09-03 22:40:27 +02:00
|
|
|
# Allow discussion
|
2013-10-10 15:36:18 +02:00
|
|
|
self.portal.doc1.allow_discussion = True
|
2010-09-03 22:40:27 +02:00
|
|
|
self.viewlet = CommentsViewlet(self.context, self.request, None, None)
|
2010-09-02 22:00:43 +02:00
|
|
|
|
|
|
|
def make_request(form={}):
|
|
|
|
request = TestRequest()
|
|
|
|
request.form.update(form)
|
|
|
|
alsoProvides(request, IFormLayer)
|
|
|
|
alsoProvides(request, IAttributeAnnotatable)
|
|
|
|
return request
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2013-04-17 19:34:17 +02:00
|
|
|
provideAdapter(
|
|
|
|
adapts=(Interface, IBrowserRequest),
|
|
|
|
provides=Interface,
|
|
|
|
factory=CommentForm,
|
2018-06-18 17:04:41 +02:00
|
|
|
name=u'comment-form',
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-09-03 22:40:27 +02:00
|
|
|
# The form should return an error if the comment text field is empty
|
2010-09-29 09:56:36 +02:00
|
|
|
request = make_request(form={})
|
2010-09-02 22:00:43 +02:00
|
|
|
|
2013-04-17 19:34:17 +02:00
|
|
|
commentForm = getMultiAdapter(
|
|
|
|
(self.context, request),
|
2018-06-18 17:04:41 +02:00
|
|
|
name=u'comment-form',
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2010-09-02 22:00:43 +02:00
|
|
|
commentForm.update()
|
2010-12-16 00:52:56 +01:00
|
|
|
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
|
|
|
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(errors), 1)
|
2016-02-05 01:39:53 +01:00
|
|
|
self.assertFalse(commentForm.handleComment(commentForm, 'foo'))
|
2010-12-16 00:52:56 +01:00
|
|
|
|
|
|
|
# The form is submitted successfully, if the required text field is
|
2010-09-03 22:40:27 +02:00
|
|
|
# filled out
|
2010-09-29 09:56:36 +02:00
|
|
|
request = make_request(form={'form.widgets.text': u'bar'})
|
2010-09-03 22:40:27 +02:00
|
|
|
|
2013-04-17 19:34:17 +02:00
|
|
|
commentForm = getMultiAdapter(
|
|
|
|
(self.context, request),
|
2018-06-18 17:04:41 +02:00
|
|
|
name=u'comment-form',
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2010-09-03 22:40:27 +02:00
|
|
|
commentForm.update()
|
2010-12-16 00:52:56 +01:00
|
|
|
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
2010-09-06 12:40:06 +02:00
|
|
|
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(errors), 0)
|
2016-02-05 01:39:53 +01:00
|
|
|
self.assertFalse(commentForm.handleComment(commentForm, 'foo'))
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2013-11-04 16:30:14 +01:00
|
|
|
comments = IConversation(commentForm.context).getComments()
|
2015-05-03 08:25:19 +02:00
|
|
|
comments = [comment for comment in comments] # consume iterator
|
2013-11-04 16:30:14 +01:00
|
|
|
self.assertEqual(len(comments), 1)
|
|
|
|
|
|
|
|
for comment in comments:
|
2016-02-05 01:39:53 +01:00
|
|
|
self.assertEqual(comment.text, u'bar')
|
|
|
|
self.assertEqual(comment.creator, 'test_user_1_')
|
|
|
|
self.assertEqual(comment.getOwner().getUserName(), 'test-user')
|
2013-11-04 16:30:14 +01:00
|
|
|
local_roles = comment.get_local_roles()
|
|
|
|
self.assertEqual(len(local_roles), 1)
|
|
|
|
userid, roles = local_roles[0]
|
2014-02-02 14:55:37 +01:00
|
|
|
self.assertEqual(userid, 'test_user_1_')
|
2013-11-04 16:30:14 +01:00
|
|
|
self.assertEqual(len(roles), 1)
|
|
|
|
self.assertEqual(roles[0], 'Owner')
|
|
|
|
|
2013-09-17 14:03:46 +02:00
|
|
|
def test_edit_comment(self):
|
|
|
|
"""Edit a comment as logged-in user.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Allow discussion
|
2014-03-03 15:09:30 +01:00
|
|
|
self.portal.doc1.allow_discussion = True
|
2013-09-17 14:03:46 +02:00
|
|
|
self.viewlet = CommentsViewlet(self.context, self.request, None, None)
|
|
|
|
|
|
|
|
def make_request(form={}):
|
|
|
|
request = TestRequest()
|
|
|
|
request.form.update(form)
|
|
|
|
alsoProvides(request, IFormLayer)
|
|
|
|
alsoProvides(request, IAttributeAnnotatable)
|
|
|
|
return request
|
|
|
|
|
|
|
|
provideAdapter(
|
|
|
|
adapts=(Interface, IBrowserRequest),
|
|
|
|
provides=Interface,
|
|
|
|
factory=CommentForm,
|
2018-06-18 17:04:41 +02:00
|
|
|
name=u'comment-form',
|
2013-09-17 14:03:46 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
provideAdapter(
|
|
|
|
adapts=(Interface, IBrowserRequest),
|
|
|
|
provides=Interface,
|
|
|
|
factory=EditCommentForm,
|
2018-06-18 17:04:41 +02:00
|
|
|
name=u'edit-comment-form',
|
2013-09-17 14:03:46 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# The form is submitted successfully, if the required text field is
|
|
|
|
# filled out
|
|
|
|
request = make_request(form={'form.widgets.text': u'bar'})
|
|
|
|
|
|
|
|
commentForm = getMultiAdapter(
|
|
|
|
(self.context, request),
|
2018-06-18 17:04:41 +02:00
|
|
|
name=u'comment-form',
|
2013-09-17 14:03:46 +02:00
|
|
|
)
|
|
|
|
commentForm.update()
|
|
|
|
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
|
|
|
|
|
|
|
self.assertEqual(len(errors), 0)
|
2016-02-05 01:39:53 +01:00
|
|
|
self.assertFalse(commentForm.handleComment(commentForm, 'foo'))
|
2013-09-17 14:03:46 +02:00
|
|
|
|
|
|
|
# Edit the last comment
|
|
|
|
conversation = IConversation(self.context)
|
|
|
|
comment = [x for x in conversation.getComments()][-1]
|
|
|
|
request = make_request(form={'form.widgets.text': u'foobar'})
|
|
|
|
editForm = getMultiAdapter(
|
|
|
|
(comment, request),
|
2018-06-18 17:04:41 +02:00
|
|
|
name=u'edit-comment-form',
|
2013-09-17 14:03:46 +02:00
|
|
|
)
|
|
|
|
editForm.update()
|
|
|
|
data, errors = editForm.extractData() # pylint: disable-msg=W0612
|
|
|
|
|
|
|
|
self.assertEqual(len(errors), 0)
|
2016-02-05 01:39:53 +01:00
|
|
|
self.assertFalse(editForm.handleComment(editForm, 'foo'))
|
2013-09-17 14:03:46 +02:00
|
|
|
comment = [x for x in conversation.getComments()][-1]
|
2016-02-05 01:39:53 +01:00
|
|
|
self.assertEqual(comment.text, u'foobar')
|
2013-09-17 14:03:46 +02:00
|
|
|
|
2014-02-04 11:35:20 +01:00
|
|
|
comments = IConversation(commentForm.context).getComments()
|
2015-05-03 08:42:52 +02:00
|
|
|
comments = [c for c in comments] # consume iterator
|
2014-02-04 11:35:20 +01:00
|
|
|
self.assertEqual(len(comments), 1)
|
|
|
|
|
|
|
|
for comment in comments:
|
2016-02-05 01:39:53 +01:00
|
|
|
self.assertEqual(comment.text, u'foobar')
|
|
|
|
self.assertEqual(comment.creator, 'test_user_1_')
|
2014-03-26 18:22:59 +01:00
|
|
|
|
2016-02-05 01:39:53 +01:00
|
|
|
self.assertEqual(comment.getOwner().getUserName(), 'test-user')
|
2014-02-04 11:35:20 +01:00
|
|
|
local_roles = comment.get_local_roles()
|
2014-03-26 18:07:28 +01:00
|
|
|
self.assertEqual(len(local_roles), 1)
|
2014-02-04 11:35:20 +01:00
|
|
|
userid, roles = local_roles[0]
|
2014-03-26 18:07:28 +01:00
|
|
|
self.assertEqual(userid, 'test_user_1_')
|
2014-02-04 11:35:20 +01:00
|
|
|
self.assertEqual(len(roles), 1)
|
|
|
|
self.assertEqual(roles[0], 'Owner')
|
|
|
|
|
2014-03-26 18:07:28 +01:00
|
|
|
def test_delete_comment(self):
|
|
|
|
"""Delete a comment as logged-in user.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Allow discussion
|
|
|
|
self.portal.doc1.allow_discussion = True
|
|
|
|
self.viewlet = CommentsViewlet(self.context, self.request, None, None)
|
|
|
|
|
|
|
|
def make_request(form={}):
|
|
|
|
request = TestRequest()
|
|
|
|
request.form.update(form)
|
|
|
|
alsoProvides(request, IFormLayer)
|
|
|
|
alsoProvides(request, IAttributeAnnotatable)
|
|
|
|
return request
|
|
|
|
|
|
|
|
provideAdapter(
|
|
|
|
adapts=(Interface, IBrowserRequest),
|
|
|
|
provides=Interface,
|
|
|
|
factory=CommentForm,
|
2018-06-18 17:04:41 +02:00
|
|
|
name=u'comment-form',
|
2014-03-26 18:07:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# The form is submitted successfully, if the required text field is
|
|
|
|
# filled out
|
|
|
|
form_request = make_request(form={'form.widgets.text': u'bar'})
|
|
|
|
|
|
|
|
commentForm = getMultiAdapter(
|
|
|
|
(self.context, form_request),
|
2018-06-18 17:04:41 +02:00
|
|
|
name=u'comment-form',
|
2014-03-26 18:07:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
commentForm.update()
|
|
|
|
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
|
|
|
self.assertEqual(len(errors), 0)
|
2016-02-05 01:39:53 +01:00
|
|
|
self.assertFalse(commentForm.handleComment(commentForm, 'foo'))
|
2014-03-26 18:07:28 +01:00
|
|
|
|
|
|
|
# Delete the last comment
|
|
|
|
conversation = IConversation(self.context)
|
|
|
|
comment = [x for x in conversation.getComments()][-1]
|
|
|
|
deleteView = getMultiAdapter(
|
|
|
|
(comment, self.request),
|
2018-06-18 17:04:41 +02:00
|
|
|
name=u'moderate-delete-comment',
|
2014-03-26 18:07:28 +01:00
|
|
|
)
|
2016-02-05 01:39:53 +01:00
|
|
|
# try to delete last comment without 'Delete comments' permission
|
2014-03-26 18:07:28 +01:00
|
|
|
setRoles(self.portal, TEST_USER_ID, ['Member'])
|
2015-05-03 08:27:03 +02:00
|
|
|
self.assertRaises(
|
|
|
|
Unauthorized,
|
|
|
|
comment.restrictedTraverse,
|
2018-06-18 17:04:41 +02:00
|
|
|
'@@moderate-delete-comment',
|
2015-05-03 08:27:03 +02:00
|
|
|
)
|
2014-03-26 18:07:28 +01:00
|
|
|
deleteView()
|
|
|
|
self.assertEqual(1, len([x for x in conversation.getComments()]))
|
2016-02-05 01:39:53 +01:00
|
|
|
# try to delete last comment with 'Delete comments' permission
|
2014-03-26 18:07:28 +01:00
|
|
|
setRoles(self.portal, TEST_USER_ID, ['Reviewer'])
|
|
|
|
deleteView()
|
|
|
|
self.assertEqual(0, len([x for x in conversation.getComments()]))
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
|
|
|
|
2014-09-20 16:21:55 +02:00
|
|
|
def test_delete_own_comment(self):
|
|
|
|
"""Delete own comment as logged-in user.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Allow discussion
|
|
|
|
self.portal.doc1.allow_discussion = True
|
|
|
|
self.viewlet = CommentsViewlet(self.context, self.request, None, None)
|
|
|
|
|
|
|
|
def make_request(form={}):
|
|
|
|
request = TestRequest()
|
|
|
|
request.form.update(form)
|
|
|
|
alsoProvides(request, IFormLayer)
|
|
|
|
alsoProvides(request, IAttributeAnnotatable)
|
|
|
|
return request
|
|
|
|
|
|
|
|
provideAdapter(
|
|
|
|
adapts=(Interface, IBrowserRequest),
|
|
|
|
provides=Interface,
|
|
|
|
factory=CommentForm,
|
2018-06-18 17:04:41 +02:00
|
|
|
name=u'comment-form',
|
2014-09-20 16:21:55 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# The form is submitted successfully, if the required text field is
|
|
|
|
# filled out
|
|
|
|
form_request = make_request(form={'form.widgets.text': u'bar'})
|
|
|
|
|
|
|
|
commentForm = getMultiAdapter(
|
|
|
|
(self.context, form_request),
|
2018-06-18 17:04:41 +02:00
|
|
|
name=u'comment-form',
|
2014-09-20 16:21:55 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
commentForm.update()
|
|
|
|
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
|
|
|
self.assertEqual(len(errors), 0)
|
2016-02-05 01:39:53 +01:00
|
|
|
self.assertFalse(commentForm.handleComment(commentForm, 'foo'))
|
2014-09-20 16:21:55 +02:00
|
|
|
|
|
|
|
# Delete the last comment
|
|
|
|
conversation = IConversation(self.context)
|
|
|
|
comment = [x for x in conversation.getComments()][-1]
|
|
|
|
deleteView = getMultiAdapter(
|
|
|
|
(comment, self.request),
|
2018-06-18 17:04:41 +02:00
|
|
|
name=u'delete-own-comment',
|
2014-09-20 16:21:55 +02:00
|
|
|
)
|
|
|
|
# try to delete last comment with johndoe
|
|
|
|
setRoles(self.portal, 'johndoe', ['Member'])
|
|
|
|
login(self.portal, 'johndoe')
|
2015-05-03 08:27:03 +02:00
|
|
|
self.assertRaises(
|
|
|
|
Unauthorized,
|
|
|
|
comment.restrictedTraverse,
|
2018-06-18 17:04:41 +02:00
|
|
|
'@@delete-own-comment',
|
2015-05-03 08:27:03 +02:00
|
|
|
)
|
2014-09-20 16:21:55 +02:00
|
|
|
self.assertEqual(1, len([x for x in conversation.getComments()]))
|
|
|
|
# try to delete last comment with the same user that created it
|
|
|
|
login(self.portal, TEST_USER_NAME)
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ['Member'])
|
|
|
|
deleteView()
|
|
|
|
self.assertEqual(0, len([x for x in conversation.getComments()]))
|
|
|
|
|
2010-11-08 18:10:19 +01:00
|
|
|
def test_add_anonymous_comment(self):
|
2013-10-10 15:36:18 +02:00
|
|
|
self.portal.doc1.allow_discussion = True
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-11-08 18:10:19 +01:00
|
|
|
self.viewlet = CommentsViewlet(self.context, self.request, None, None)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-11-08 18:10:19 +01:00
|
|
|
registry = queryUtility(IRegistry)
|
|
|
|
settings = registry.forInterface(IDiscussionSettings, check=False)
|
|
|
|
settings.anonymous_comments = True
|
|
|
|
|
|
|
|
# Logout
|
2011-04-16 11:25:16 +02:00
|
|
|
logout()
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-11-08 18:10:19 +01:00
|
|
|
def make_request(form={}):
|
|
|
|
request = TestRequest()
|
|
|
|
request.form.update(form)
|
|
|
|
alsoProvides(request, IFormLayer)
|
|
|
|
alsoProvides(request, IAttributeAnnotatable)
|
|
|
|
return request
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-11-08 18:10:19 +01:00
|
|
|
provideAdapter(adapts=(Interface, IBrowserRequest),
|
|
|
|
provides=Interface,
|
|
|
|
factory=CommentForm,
|
2016-02-05 01:39:53 +01:00
|
|
|
name=u'comment-form')
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-11-08 18:10:19 +01:00
|
|
|
# Post an anonymous comment and provide a name
|
2013-04-17 19:34:17 +02:00
|
|
|
request = make_request(form={
|
|
|
|
'form.widgets.name': u'john doe',
|
2018-06-18 17:04:41 +02:00
|
|
|
'form.widgets.text': u'bar',
|
2013-04-17 19:34:17 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
commentForm = getMultiAdapter(
|
|
|
|
(self.context, request),
|
2018-06-18 17:04:41 +02:00
|
|
|
name=u'comment-form',
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2010-11-08 18:10:19 +01:00
|
|
|
commentForm.update()
|
2010-12-16 00:52:56 +01:00
|
|
|
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
2010-11-08 18:10:19 +01:00
|
|
|
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(errors), 0)
|
2016-02-05 01:39:53 +01:00
|
|
|
self.assertFalse(commentForm.handleComment(commentForm, 'action'))
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2013-11-04 16:30:14 +01:00
|
|
|
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():
|
2016-02-05 01:39:53 +01:00
|
|
|
self.assertEqual(comment.text, u'bar')
|
2013-11-04 16:30:14 +01:00
|
|
|
self.assertIsNone(comment.creator)
|
|
|
|
roles = comment.get_local_roles()
|
|
|
|
self.assertEqual(len(roles), 0)
|
|
|
|
|
2010-09-03 22:40:27 +02:00
|
|
|
def test_can_not_add_comments_if_discussion_is_not_allowed(self):
|
|
|
|
"""Make sure that comments can't be posted if discussion is disabled.
|
|
|
|
"""
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2013-10-10 15:36:18 +02:00
|
|
|
# Disable discussion
|
|
|
|
registry = queryUtility(IRegistry)
|
|
|
|
settings = registry.forInterface(IDiscussionSettings)
|
|
|
|
settings.globally_enabled = False
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-09-03 22:40:27 +02:00
|
|
|
def make_request(form={}):
|
|
|
|
request = TestRequest()
|
|
|
|
request.form.update(form)
|
|
|
|
alsoProvides(request, IFormLayer)
|
|
|
|
alsoProvides(request, IAttributeAnnotatable)
|
|
|
|
return request
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-09-03 22:40:27 +02:00
|
|
|
provideAdapter(adapts=(Interface, IBrowserRequest),
|
|
|
|
provides=Interface,
|
|
|
|
factory=CommentForm,
|
2016-02-05 01:39:53 +01:00
|
|
|
name=u'comment-form')
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-10-03 21:41:02 +02:00
|
|
|
request = make_request(form={'form.widgets.text': u'bar'})
|
2010-09-02 22:00:43 +02:00
|
|
|
|
2013-04-17 19:34:17 +02:00
|
|
|
commentForm = getMultiAdapter(
|
|
|
|
(self.context, request),
|
2018-06-18 17:04:41 +02:00
|
|
|
name=u'comment-form',
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2010-09-02 22:00:43 +02:00
|
|
|
commentForm.update()
|
2010-12-16 00:52:56 +01:00
|
|
|
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
|
|
|
|
2010-09-03 22:40:27 +02:00
|
|
|
# No form errors, but raise unauthorized because discussion is not
|
|
|
|
# allowed
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(errors), 0)
|
2013-10-10 15:36:18 +02:00
|
|
|
|
2010-09-03 22:40:27 +02:00
|
|
|
self.assertRaises(Unauthorized,
|
|
|
|
commentForm.handleComment,
|
|
|
|
commentForm,
|
2016-02-05 01:39:53 +01:00
|
|
|
'foo')
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-11-08 18:10:19 +01:00
|
|
|
def test_anonymous_can_not_add_comments_if_discussion_is_not_allowed(self):
|
2010-09-03 22:40:27 +02:00
|
|
|
"""Make sure that anonymous users can't post comments if anonymous
|
|
|
|
comments are disabled.
|
|
|
|
"""
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-09-03 22:40:27 +02:00
|
|
|
# Anonymous comments are disabled by default
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2011-04-16 11:25:16 +02:00
|
|
|
logout()
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-09-03 22:40:27 +02:00
|
|
|
def make_request(form={}):
|
|
|
|
request = TestRequest()
|
|
|
|
request.form.update(form)
|
|
|
|
alsoProvides(request, IFormLayer)
|
|
|
|
alsoProvides(request, IAttributeAnnotatable)
|
|
|
|
return request
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-09-03 22:40:27 +02:00
|
|
|
provideAdapter(adapts=(Interface, IBrowserRequest),
|
|
|
|
provides=Interface,
|
|
|
|
factory=CommentForm,
|
2016-02-05 01:39:53 +01:00
|
|
|
name=u'comment-form')
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-10-03 21:41:02 +02:00
|
|
|
request = make_request(form={'form.widgets.text': u'bar'})
|
2010-09-03 22:40:27 +02:00
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
commentForm = getMultiAdapter((self.context, request),
|
2016-02-05 01:39:53 +01:00
|
|
|
name=u'comment-form')
|
2010-09-03 22:40:27 +02:00
|
|
|
commentForm.update()
|
2010-12-16 00:52:56 +01:00
|
|
|
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
|
|
|
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(errors), 0)
|
2013-04-17 19:34:17 +02:00
|
|
|
self.assertRaises(
|
|
|
|
Unauthorized,
|
|
|
|
commentForm.handleComment,
|
|
|
|
commentForm,
|
2018-06-18 17:04:41 +02:00
|
|
|
'foo',
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2010-09-02 22:00:43 +02:00
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2011-04-16 11:25:16 +02:00
|
|
|
class TestCommentsViewlet(unittest.TestCase):
|
2009-06-06 10:23:33 +02:00
|
|
|
|
2011-04-16 11:25:16 +02:00
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2011-04-16 11:25:16 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.portal = self.layer['portal']
|
|
|
|
self.request = self.layer['request']
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
|
|
|
self.portal.invokeFactory('Folder', 'test-folder')
|
|
|
|
self.folder = self.portal['test-folder']
|
2011-04-15 06:29:46 +02:00
|
|
|
interface.alsoProvides(
|
2013-04-17 19:34:17 +02:00
|
|
|
self.request,
|
2018-06-18 17:04:41 +02:00
|
|
|
interfaces.IDiscussionLayer,
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2011-04-16 11:25:16 +02:00
|
|
|
self.workflowTool = getToolByName(self.portal, 'portal_workflow')
|
2017-01-10 18:09:01 +01:00
|
|
|
self.workflowTool.setDefaultChain('comment_one_state_workflow')
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2011-04-16 11:25:16 +02:00
|
|
|
self.membershipTool = getToolByName(self.folder, 'portal_membership')
|
2009-06-07 22:58:41 +02:00
|
|
|
self.memberdata = self.portal.portal_memberdata
|
2009-06-06 10:23:33 +02:00
|
|
|
context = getattr(self.portal, 'doc1')
|
2011-04-16 11:25:16 +02:00
|
|
|
self.viewlet = CommentsViewlet(context, self.request, None, None)
|
2010-01-22 13:29:26 +01:00
|
|
|
|
2010-12-14 18:58:46 +01:00
|
|
|
# Allow discussion
|
|
|
|
registry = queryUtility(IRegistry)
|
|
|
|
settings = registry.forInterface(IDiscussionSettings)
|
|
|
|
settings.globally_enabled = True
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-01-18 10:55:44 +01:00
|
|
|
def test_can_reply(self):
|
2010-01-18 12:04:08 +01:00
|
|
|
# Portal owner can reply
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(self.viewlet.can_reply())
|
2011-04-16 11:25:16 +02:00
|
|
|
logout()
|
2010-01-18 12:04:08 +01:00
|
|
|
# Anonymous users can not reply
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertFalse(self.viewlet.can_reply())
|
2010-01-18 10:55:44 +01:00
|
|
|
|
2010-10-06 15:55:57 +02:00
|
|
|
def test_can_review(self):
|
|
|
|
# Portal owner has 'can review' permission
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(self.viewlet.can_review())
|
2011-04-16 11:25:16 +02:00
|
|
|
logout()
|
2010-10-06 15:55:57 +02:00
|
|
|
# Anonymous has no 'can review' permission
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertFalse(self.viewlet.can_review())
|
2010-10-06 15:55:57 +02:00
|
|
|
# The reviewer role has the 'Review comments' permission
|
2012-01-14 07:26:01 +01:00
|
|
|
self.portal.acl_users._doAddUser(
|
|
|
|
'reviewer', 'secret', ['Reviewer'], [])
|
2011-04-16 11:25:16 +02:00
|
|
|
login(self.portal, 'reviewer')
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(self.viewlet.can_review())
|
2010-11-03 12:26:18 +01:00
|
|
|
|
|
|
|
def test_can_manage(self):
|
|
|
|
"""We keep this method for backward compatibility. This method has been
|
|
|
|
removed in version 1.0b9 and added again in 1.0b11 because we don't
|
|
|
|
do API changes in beta releases.
|
|
|
|
"""
|
|
|
|
# Portal owner has 'can review' permission
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(self.viewlet.can_manage())
|
2011-04-16 11:25:16 +02:00
|
|
|
logout()
|
2010-11-03 12:26:18 +01:00
|
|
|
# Anonymous has no 'can review' permission
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertFalse(self.viewlet.can_manage())
|
2010-11-03 12:26:18 +01:00
|
|
|
# The reviewer role has the 'Review comments' permission
|
2012-01-14 07:26:01 +01:00
|
|
|
self.portal.acl_users._doAddUser(
|
|
|
|
'reviewer', 'secret', ['Reviewer'], [])
|
2011-04-16 11:25:16 +02:00
|
|
|
login(self.portal, 'reviewer')
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(self.viewlet.can_manage())
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-01-18 10:55:44 +01:00
|
|
|
def test_is_discussion_allowed(self):
|
2010-01-18 12:04:08 +01:00
|
|
|
# By default, discussion is disabled
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertFalse(self.viewlet.is_discussion_allowed())
|
2010-01-18 12:04:08 +01:00
|
|
|
# Enable discussion
|
2013-10-10 15:36:18 +02:00
|
|
|
self.portal.doc1.allow_discussion = True
|
2010-01-18 12:04:08 +01:00
|
|
|
# Test if discussion has been enabled
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(self.viewlet.is_discussion_allowed())
|
2010-11-29 23:42:20 +01:00
|
|
|
|
|
|
|
def test_comment_transform_message(self):
|
2011-02-15 17:23:12 +01:00
|
|
|
|
2011-01-07 11:20:24 +01:00
|
|
|
# Default transform is plain/text and comment moderation disabled
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(self.viewlet.comment_transform_message())
|
|
|
|
self.assertEqual(
|
2010-11-29 23:42:20 +01:00
|
|
|
self.viewlet.comment_transform_message(),
|
2016-02-05 01:39:53 +01:00
|
|
|
'You can add a comment by filling out the form below. Plain ' +
|
|
|
|
'text formatting.')
|
2010-11-29 23:42:20 +01:00
|
|
|
|
|
|
|
# Set text transform to intelligent text
|
|
|
|
registry = queryUtility(IRegistry)
|
|
|
|
settings = registry.forInterface(IDiscussionSettings, check=False)
|
2016-02-05 01:39:53 +01:00
|
|
|
settings.text_transform = 'text/x-web-intelligent'
|
2010-11-29 23:42:20 +01:00
|
|
|
|
2011-01-07 11:20:24 +01:00
|
|
|
# Make sure the comment description changes accordingly
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(
|
2010-12-16 00:52:56 +01:00
|
|
|
self.viewlet.comment_transform_message(),
|
2016-02-05 01:39:53 +01:00
|
|
|
'You can add a comment by filling out the form below. ' +
|
|
|
|
'Plain text formatting. Web and email addresses are transformed ' +
|
2018-06-18 17:04:41 +02:00
|
|
|
'into clickable links.',
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2011-02-15 17:23:12 +01:00
|
|
|
|
2011-01-07 11:20:24 +01:00
|
|
|
# Enable moderation workflow
|
2011-04-16 11:25:16 +02:00
|
|
|
self.workflowTool.setChainForPortalTypes(
|
2011-01-07 11:20:24 +01:00
|
|
|
('Discussion Item',),
|
|
|
|
('comment_review_workflow,'))
|
2011-02-15 17:23:12 +01:00
|
|
|
|
|
|
|
# Make sure the comment description shows that comments are moderated
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(
|
2011-01-07 11:20:24 +01:00
|
|
|
self.viewlet.comment_transform_message(),
|
2016-02-05 01:39:53 +01:00
|
|
|
'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.')
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-01-18 12:38:57 +01:00
|
|
|
def test_has_replies(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(self.viewlet.has_replies(), False)
|
2010-01-18 12:04:08 +01:00
|
|
|
comment = createObject('plone.Comment')
|
|
|
|
comment.text = 'Comment text'
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
conversation.addComment(comment)
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(self.viewlet.has_replies(), True)
|
2010-01-22 13:29:26 +01:00
|
|
|
|
2010-01-18 12:38:57 +01:00
|
|
|
def test_get_replies(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertFalse(self.viewlet.get_replies())
|
2010-01-18 12:04:08 +01:00
|
|
|
comment = createObject('plone.Comment')
|
|
|
|
comment.text = 'Comment text'
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
conversation.addComment(comment)
|
|
|
|
conversation.addComment(comment)
|
2010-01-18 13:20:45 +01:00
|
|
|
replies = self.viewlet.get_replies()
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(len(tuple(replies)), 2)
|
2010-01-18 13:20:45 +01:00
|
|
|
replies = self.viewlet.get_replies()
|
2018-01-25 13:04:11 +01:00
|
|
|
next(replies)
|
|
|
|
next(replies)
|
2018-06-12 14:25:01 +02:00
|
|
|
with self.assertRaises(StopIteration):
|
|
|
|
next(replies)
|
2010-01-18 12:04:08 +01:00
|
|
|
|
2013-08-15 00:01:22 +02:00
|
|
|
def test_get_replies_on_non_annotatable_object(self):
|
|
|
|
context = self.portal.MailHost # the mail host is not annotatable
|
|
|
|
viewlet = CommentsViewlet(context, self.request, None, None)
|
|
|
|
replies = viewlet.get_replies()
|
|
|
|
self.assertEqual(len(tuple(replies)), 0)
|
|
|
|
replies = viewlet.get_replies()
|
2018-06-12 14:25:01 +02:00
|
|
|
with self.assertRaises(StopIteration):
|
|
|
|
next(replies)
|
2013-08-15 00:01:22 +02:00
|
|
|
|
2010-01-18 12:38:57 +01:00
|
|
|
def test_get_replies_with_workflow_actions(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertFalse(self.viewlet.get_replies(workflow_actions=True))
|
2010-01-18 12:38:57 +01:00
|
|
|
comment = createObject('plone.Comment')
|
|
|
|
comment.text = 'Comment text'
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
c1 = conversation.addComment(comment)
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(
|
2013-04-17 19:34:17 +02:00
|
|
|
len(tuple(self.viewlet.get_replies(workflow_actions=True))),
|
2018-06-18 17:04:41 +02:00
|
|
|
1,
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2010-01-18 12:38:57 +01:00
|
|
|
# Enable moderation workflow
|
2011-04-16 11:25:16 +02:00
|
|
|
self.workflowTool.setChainForPortalTypes(
|
2010-08-28 19:06:53 +02:00
|
|
|
('Discussion Item',),
|
2018-06-18 17:04:41 +02:00
|
|
|
('comment_review_workflow,'),
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2010-01-18 12:38:57 +01:00
|
|
|
# Check if workflow actions are available
|
2018-01-25 13:04:11 +01:00
|
|
|
reply = next(self.viewlet.get_replies(workflow_actions=True))
|
2012-01-14 07:26:01 +01:00
|
|
|
self.assertTrue('actions' in reply)
|
2013-04-17 19:34:17 +02:00
|
|
|
self.assertEqual(
|
|
|
|
reply['actions'][0]['id'],
|
2020-01-11 11:43:35 +01:00
|
|
|
'mark_as_spam',
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2016-02-05 01:39:53 +01:00
|
|
|
expected_url = 'http://nohost/plone/doc1/++conversation++default/{0}' \
|
2020-01-11 11:43:35 +01:00
|
|
|
'/content_status_modify?workflow_action=mark_as_spam'
|
2013-04-17 19:34:17 +02:00
|
|
|
self.assertEqual(
|
|
|
|
reply['actions'][0]['url'],
|
2018-06-18 17:04:41 +02:00
|
|
|
expected_url.format(int(c1)),
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-01-18 10:55:44 +01:00
|
|
|
def test_get_commenter_home_url(self):
|
2010-01-18 12:04:08 +01:00
|
|
|
comment = createObject('plone.Comment')
|
|
|
|
comment.text = 'Comment text'
|
2010-07-13 12:45:53 +02:00
|
|
|
IConversation(self.portal.doc1)
|
2010-01-18 12:04:08 +01:00
|
|
|
portal_membership = getToolByName(self.portal, 'portal_membership')
|
|
|
|
m = portal_membership.getAuthenticatedMember()
|
2013-04-17 19:34:17 +02:00
|
|
|
self.assertEqual(
|
|
|
|
self.viewlet.get_commenter_home_url(m.getUserName()),
|
2018-06-18 17:04:41 +02:00
|
|
|
'http://nohost/plone/author/test-user',
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2010-01-18 12:38:57 +01:00
|
|
|
|
|
|
|
def test_get_commenter_home_url_is_none(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertFalse(self.viewlet.get_commenter_home_url())
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2009-06-06 10:23:33 +02:00
|
|
|
def test_get_commenter_portrait(self):
|
2009-06-07 22:58:41 +02:00
|
|
|
|
|
|
|
# Add a user with a member image
|
2011-04-16 11:25:16 +02:00
|
|
|
self.membershipTool.addMember('jim', 'Jim', ['Member'], [])
|
2013-04-17 19:34:17 +02:00
|
|
|
self.memberdata._setPortrait(Image(
|
|
|
|
id='jim',
|
|
|
|
file=dummy.File(),
|
2018-06-18 17:04:41 +02:00
|
|
|
title='',
|
2013-04-17 19:34:17 +02:00
|
|
|
), 'jim')
|
|
|
|
self.assertEqual(
|
|
|
|
self.memberdata._getPortrait('jim').getId(),
|
2018-06-18 17:04:41 +02:00
|
|
|
'jim',
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
self.memberdata._getPortrait('jim').meta_type,
|
2018-06-18 17:04:41 +02:00
|
|
|
'Image',
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2009-06-07 22:58:41 +02:00
|
|
|
|
|
|
|
# Add a conversation with a comment
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
comment = createObject('plone.Comment')
|
|
|
|
comment.text = 'Comment text'
|
|
|
|
comment.Creator = 'Jim'
|
|
|
|
comment.author_username = 'jim'
|
2010-07-13 12:45:53 +02:00
|
|
|
conversation.addComment(comment)
|
2009-06-07 22:58:41 +02:00
|
|
|
|
|
|
|
# Call get_commenter_portrait method of the viewlet
|
2009-06-06 10:23:33 +02:00
|
|
|
self.viewlet.update()
|
2009-06-15 10:54:35 +02:00
|
|
|
portrait_url = self.viewlet.get_commenter_portrait('jim')
|
2009-06-07 22:58:41 +02:00
|
|
|
|
2009-06-15 10:54:35 +02:00
|
|
|
# Check if the correct member image URL is returned
|
2013-04-17 19:34:17 +02:00
|
|
|
self.assertEqual(
|
|
|
|
portrait_url,
|
2018-06-18 17:04:41 +02:00
|
|
|
'http://nohost/plone/portal_memberdata/portraits/jim',
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2009-06-06 10:23:33 +02:00
|
|
|
|
2010-01-18 12:38:57 +01:00
|
|
|
def test_get_commenter_portrait_is_none(self):
|
2013-09-17 14:03:46 +02:00
|
|
|
|
|
|
|
self.assertTrue(
|
|
|
|
self.viewlet.get_commenter_portrait() in (
|
|
|
|
'defaultUser.png',
|
|
|
|
'defaultUser.gif',
|
2018-06-18 17:04:41 +02:00
|
|
|
),
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2009-06-06 10:23:33 +02:00
|
|
|
def test_get_commenter_portrait_without_userimage(self):
|
2009-06-07 22:58:41 +02:00
|
|
|
|
2009-06-06 10:23:33 +02:00
|
|
|
# Create a user without a user image
|
2011-04-16 11:25:16 +02:00
|
|
|
self.membershipTool.addMember('jim', 'Jim', ['Member'], [])
|
2009-06-07 22:58:41 +02:00
|
|
|
|
|
|
|
# Add a conversation with a comment
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
comment = createObject('plone.Comment')
|
|
|
|
comment.text = 'Comment text'
|
|
|
|
comment.Creator = 'Jim'
|
|
|
|
comment.author_username = 'jim'
|
2010-07-13 12:45:53 +02:00
|
|
|
conversation.addComment(comment)
|
2009-06-07 22:58:41 +02:00
|
|
|
|
|
|
|
# Call get_commenter_portrait method of the viewlet
|
|
|
|
self.viewlet.update()
|
2009-06-15 10:54:35 +02:00
|
|
|
portrait_url = self.viewlet.get_commenter_portrait('jim')
|
2009-06-07 22:58:41 +02:00
|
|
|
|
2011-02-15 17:19:13 +01:00
|
|
|
# Check if the correct default member image URL is returned.
|
|
|
|
# Note that Products.PlonePAS 4.0.5 and later have .png and
|
|
|
|
# earlier versions have .gif.
|
2013-04-17 19:34:17 +02:00
|
|
|
self.assertTrue(
|
|
|
|
portrait_url in (
|
|
|
|
'http://nohost/plone/defaultUser.png',
|
2018-06-18 17:04:41 +02:00
|
|
|
'http://nohost/plone/defaultUser.gif',
|
|
|
|
),
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2009-06-06 10:23:33 +02:00
|
|
|
|
2010-01-18 10:55:44 +01:00
|
|
|
def test_anonymous_discussion_allowed(self):
|
|
|
|
# Anonymous discussion is not allowed by default
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertFalse(self.viewlet.anonymous_discussion_allowed())
|
2010-01-18 10:55:44 +01:00
|
|
|
# Allow anonymous discussion
|
2010-07-12 15:47:53 +02:00
|
|
|
registry = queryUtility(IRegistry)
|
2013-04-17 19:34:17 +02:00
|
|
|
registry[
|
|
|
|
'plone.app.discussion.interfaces.IDiscussionSettings.' +
|
|
|
|
'anonymous_comments'
|
|
|
|
] = True
|
2010-01-18 10:55:44 +01:00
|
|
|
# Test if anonymous discussion is allowed for the viewlet
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(self.viewlet.anonymous_discussion_allowed())
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-01-18 10:55:44 +01:00
|
|
|
def test_show_commenter_image(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(self.viewlet.show_commenter_image())
|
2010-07-12 15:47:53 +02:00
|
|
|
registry = queryUtility(IRegistry)
|
2013-04-17 19:34:17 +02:00
|
|
|
registry[
|
|
|
|
'plone.app.discussion.interfaces.IDiscussionSettings.' +
|
|
|
|
'show_commenter_image'
|
|
|
|
] = False
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertFalse(self.viewlet.show_commenter_image())
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-01-18 10:55:44 +01:00
|
|
|
def test_is_anonymous(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertFalse(self.viewlet.is_anonymous())
|
2011-04-16 11:25:16 +02:00
|
|
|
logout()
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(self.viewlet.is_anonymous())
|
2009-06-06 10:23:33 +02:00
|
|
|
|
2010-01-18 10:55:44 +01:00
|
|
|
def test_login_action(self):
|
2010-01-18 12:04:08 +01:00
|
|
|
self.viewlet.update()
|
2013-04-17 19:34:17 +02:00
|
|
|
self.assertEqual(
|
|
|
|
self.viewlet.login_action(),
|
2018-06-18 17:04:41 +02:00
|
|
|
'http://nohost/plone/login_form?came_from=http%3A//nohost',
|
2013-04-17 19:34:17 +02:00
|
|
|
)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-01-18 10:55:44 +01:00
|
|
|
def test_format_time(self):
|
2018-03-18 17:01:27 +01:00
|
|
|
python_time = datetime(2009, 2, 1, 23, 32, 3, 57)
|
2010-09-07 14:03:18 +02:00
|
|
|
# Python Time must be utc time. There seems to be no too simple way
|
|
|
|
# to tell datetime to be of utc time.
|
|
|
|
# therefor, we convert the time to seconds since epoch, which seems
|
|
|
|
# to assume, that the datetime was given in local time, and does the
|
|
|
|
# correction to the seconds since epoch. Then time.gmtime returns
|
|
|
|
# a correct utc time that can be used to make datetime set the utc
|
|
|
|
# time of the local time given above. That way, the time for the
|
|
|
|
# example below is correct within each time zone, independent of DST
|
2010-10-06 10:47:24 +02:00
|
|
|
python_time = datetime(
|
2018-06-18 17:04:41 +02:00
|
|
|
*time.gmtime(time.mktime(python_time.timetuple()))[:7])
|
2010-01-18 10:55:44 +01:00
|
|
|
localized_time = self.viewlet.format_time(python_time)
|
2013-08-29 22:20:47 +02:00
|
|
|
self.assertTrue(
|
2018-06-18 17:04:41 +02:00
|
|
|
localized_time in ['Feb 01, 2009 11:32 PM', '2009-02-01 23:32'],
|
|
|
|
)
|