This commit is contained in:
tisto 2012-01-14 07:26:01 +01:00
parent a3883d7e7b
commit 0558a9b739
5 changed files with 45 additions and 40 deletions

View File

@ -58,8 +58,8 @@ COMMENT_DESCRIPTION_MARKDOWN = _(
COMMENT_DESCRIPTION_INTELLIGENT_TEXT = _( COMMENT_DESCRIPTION_INTELLIGENT_TEXT = _(
u"comment_description_intelligent_text", u"comment_description_intelligent_text",
default=u"You can add a comment by filling out the form below. " + default=u"You can add a comment by filling out the form below. " +
"Plain text formatting. Web and email addresses are transformed " + "Plain text formatting. Web and email addresses are " +
"into clickable links.") "transformed into clickable links.")
COMMENT_DESCRIPTION_MODERATION_ENABLED = _( COMMENT_DESCRIPTION_MODERATION_ENABLED = _(
u"comment_description_moderation_enabled", u"comment_description_moderation_enabled",
@ -113,8 +113,8 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
member_email = member.getProperty('email') member_email = member.getProperty('email')
# Hide the user_notification checkbox if user notification is disabled # Hide the user_notification checkbox if user notification is disabled
# or the user is not logged in. Also check if the user has a valid email # or the user is not logged in. Also check if the user has a valid
# address # email address
if member_email == '' or \ if member_email == '' or \
not settings.user_notification_enabled or \ not settings.user_notification_enabled or \
mtool.isAnonymousUser(): mtool.isAnonymousUser():
@ -185,7 +185,8 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
comment.author_name = author_name comment.author_name = author_name
comment.author_email = author_email comment.author_email = author_email
comment.user_notification = user_notification comment.user_notification = user_notification
comment.creation_date = comment.modification_date = datetime.utcnow() comment.creation_date = datetime.utcnow()
comment.modification_date = datetime.utcnow()
elif not portal_membership.isAnonymousUser() and can_reply: elif not portal_membership.isAnonymousUser() and can_reply:
# Member # Member
member = portal_membership.getAuthenticatedMember() member = portal_membership.getAuthenticatedMember()
@ -204,7 +205,8 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
comment.author_name = fullname comment.author_name = fullname
comment.author_email = email comment.author_email = email
comment.user_notification = user_notification comment.user_notification = user_notification
comment.creation_date = comment.modification_date = datetime.utcnow() comment.creation_date = datetime.utcnow()
comment.modification_date = datetime.utcnow()
else: # pragma: no cover else: # pragma: no cover
raise Unauthorized("Anonymous user tries to post a comment, but " raise Unauthorized("Anonymous user tries to post a comment, but "
"anonymous commenting is disabled. Or user does not have the " "anonymous commenting is disabled. Or user does not have the "

View File

@ -167,7 +167,7 @@ class ConversationCatalogTest(unittest.TestCase):
brains = self.catalog.searchResults(dict( brains = self.catalog.searchResults(dict(
path={'query': path={'query':
'/'.join(self.portal.doc1.getPhysicalPath()) }, '/'.join(self.portal.doc1.getPhysicalPath())},
portal_type="Document" portal_type="Document"
)) ))
doc1_brain = brains[0] doc1_brain = brains[0]
@ -178,7 +178,7 @@ class ConversationCatalogTest(unittest.TestCase):
del self.conversation[new_comment2_id] del self.conversation[new_comment2_id]
brains = self.catalog.searchResults(dict( brains = self.catalog.searchResults(dict(
path={'query': path={'query':
'/'.join(self.portal.doc1.getPhysicalPath()) }, '/'.join(self.portal.doc1.getPhysicalPath())},
portal_type="Document" portal_type="Document"
)) ))
doc1_brain = brains[0] doc1_brain = brains[0]
@ -188,7 +188,7 @@ class ConversationCatalogTest(unittest.TestCase):
del self.conversation[self.new_comment1_id] del self.conversation[self.new_comment1_id]
brains = self.catalog.searchResults(dict( brains = self.catalog.searchResults(dict(
path={'query': path={'query':
'/'.join(self.portal.doc1.getPhysicalPath()) }, '/'.join(self.portal.doc1.getPhysicalPath())},
portal_type="Document" portal_type="Document"
)) ))
doc1_brain = brains[0] doc1_brain = brains[0]
@ -197,7 +197,7 @@ class ConversationCatalogTest(unittest.TestCase):
def test_conversation_indexes_not_in_comments(self): def test_conversation_indexes_not_in_comments(self):
brains = self.catalog.searchResults(dict( brains = self.catalog.searchResults(dict(
path={'query': path={'query':
'/'.join(self.portal.doc1.getPhysicalPath()) }, '/'.join(self.portal.doc1.getPhysicalPath())},
portal_type="Discussion Item" portal_type="Discussion Item"
)) ))
comment1_brain = brains[0] comment1_brain = brains[0]

View File

@ -60,7 +60,7 @@ class TestCommentForm(unittest.TestCase):
'portal_discussion', 'portal_discussion',
None) None)
self.discussionTool.overrideDiscussionFor(self.portal.doc1, False) self.discussionTool.overrideDiscussionFor(self.portal.doc1, False)
self.membershipTool = getToolByName(self.folder, 'portal_membership', None) self.membershipTool = getToolByName(self.folder, 'portal_membership')
self.memberdata = self.portal.portal_memberdata self.memberdata = self.portal.portal_memberdata
self.context = getattr(self.portal, 'doc1') self.context = getattr(self.portal, 'doc1')
@ -261,7 +261,8 @@ class TestCommentsViewlet(unittest.TestCase):
# Anonymous has no 'can review' permission # Anonymous has no 'can review' permission
self.assertFalse(self.viewlet.can_review()) self.assertFalse(self.viewlet.can_review())
# The reviewer role has the 'Review comments' permission # The reviewer role has the 'Review comments' permission
self.portal.acl_users._doAddUser('reviewer', 'secret', ['Reviewer'], []) self.portal.acl_users._doAddUser(
'reviewer', 'secret', ['Reviewer'], [])
login(self.portal, 'reviewer') login(self.portal, 'reviewer')
self.assertTrue(self.viewlet.can_review()) self.assertTrue(self.viewlet.can_review())
@ -276,7 +277,8 @@ class TestCommentsViewlet(unittest.TestCase):
# Anonymous has no 'can review' permission # Anonymous has no 'can review' permission
self.assertFalse(self.viewlet.can_manage()) self.assertFalse(self.viewlet.can_manage())
# The reviewer role has the 'Review comments' permission # The reviewer role has the 'Review comments' permission
self.portal.acl_users._doAddUser('reviewer', 'secret', ['Reviewer'], []) self.portal.acl_users._doAddUser(
'reviewer', 'secret', ['Reviewer'], [])
login(self.portal, 'reviewer') login(self.portal, 'reviewer')
self.assertTrue(self.viewlet.can_manage()) self.assertTrue(self.viewlet.can_manage())
@ -295,8 +297,8 @@ class TestCommentsViewlet(unittest.TestCase):
self.assertTrue(self.viewlet.comment_transform_message()) self.assertTrue(self.viewlet.comment_transform_message())
self.assertEqual( self.assertEqual(
self.viewlet.comment_transform_message(), self.viewlet.comment_transform_message(),
"You can add a comment by filling out the form below. Plain text " + "You can add a comment by filling out the form below. Plain " +
"formatting.") "text formatting.")
# Set text transform to intelligent text # Set text transform to intelligent text
registry = queryUtility(IRegistry) registry = queryUtility(IRegistry)
@ -358,7 +360,7 @@ class TestCommentsViewlet(unittest.TestCase):
('comment_review_workflow,')) ('comment_review_workflow,'))
# Check if workflow actions are available # Check if workflow actions are available
reply = self.viewlet.get_replies(workflow_actions=True).next() reply = self.viewlet.get_replies(workflow_actions=True).next()
self.assertTrue(reply.has_key('actions')) self.assertTrue('actions' in reply)
self.assertEqual(reply['actions'][0]['id'], self.assertEqual(reply['actions'][0]['id'],
'publish') 'publish')
self.assertEqual(reply['actions'][0]['url'], self.assertEqual(reply['actions'][0]['url'],

View File

@ -12,7 +12,8 @@ from Products.CMFCore.utils import getToolByName
from plone.app.testing import TEST_USER_ID, setRoles from plone.app.testing import TEST_USER_ID, setRoles
from plone.app.discussion.interfaces import IDiscussionSettings from plone.app.discussion.interfaces import IDiscussionSettings
from plone.app.discussion.testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING from plone.app.discussion.testing import \
PLONE_APP_DISCUSSION_INTEGRATION_TESTING
class RegistryTest(unittest.TestCase): class RegistryTest(unittest.TestCase):
@ -166,5 +167,6 @@ class ConfigurationChangedSubscriberTest(unittest.TestCase):
# setting itself remains unchanged. # setting itself remains unchanged.
self.settings.moderation_enabled = True self.settings.moderation_enabled = True
def test_suite(): def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__) return unittest.defaultTestLoader.loadTestsFromName(__name__)

View File

@ -15,7 +15,8 @@ from Products.CMFCore.utils import getToolByName
from plone.app.testing import TEST_USER_ID, setRoles from plone.app.testing import TEST_USER_ID, setRoles
from plone.app.discussion.testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING from plone.app.discussion.testing import \
PLONE_APP_DISCUSSION_INTEGRATION_TESTING
from plone.app.discussion import interfaces from plone.app.discussion import interfaces
from plone.app.discussion.interfaces import IConversation from plone.app.discussion.interfaces import IConversation
@ -179,7 +180,6 @@ class ConversationTest(unittest.TestCase):
# 1) allow_discussion attribute: Every content object in Plone # 1) allow_discussion attribute: Every content object in Plone
# has a allow_discussion attribute. By default it is set to None. # has a allow_discussion attribute. By default it is set to None.
# Create a conversation. # Create a conversation.
IConversation(self.portal.doc1) IConversation(self.portal.doc1)
@ -206,7 +206,7 @@ class ConversationTest(unittest.TestCase):
# the content type. So we allow discussion on the Document content # the content type. So we allow discussion on the Document content
# type and check if the Document object allows discussion now. # type and check if the Document object allows discussion now.
document_fti = getattr(portal_types, 'Document') document_fti = getattr(portal_types, 'Document')
document_fti.manage_changeProperties(allow_discussion = True) document_fti.manage_changeProperties(allow_discussion=True)
self.assertEqual(portal_discussion.isDiscussionAllowedFor( self.assertEqual(portal_discussion.isDiscussionAllowedFor(
self.portal.doc1), True) self.portal.doc1), True)
self.assertEqual(self.portal.doc1.getTypeInfo().allowDiscussion(), self.assertEqual(self.portal.doc1.getTypeInfo().allowDiscussion(),
@ -223,7 +223,7 @@ class ConversationTest(unittest.TestCase):
False) False)
# Disallow discussion on the Document content type again # Disallow discussion on the Document content type again
document_fti.manage_changeProperties(allow_discussion = False) document_fti.manage_changeProperties(allow_discussion=False)
self.assertEqual(portal_discussion.isDiscussionAllowedFor( self.assertEqual(portal_discussion.isDiscussionAllowedFor(
self.portal.doc1), False) self.portal.doc1), False)
self.assertEqual(self.portal.doc1.getTypeInfo().allowDiscussion(), self.assertEqual(self.portal.doc1.getTypeInfo().allowDiscussion(),
@ -258,7 +258,7 @@ class ConversationTest(unittest.TestCase):
# otherwise allow_discussion will always return False # otherwise allow_discussion will always return False
portal_types = getToolByName(self.portal, 'portal_types') portal_types = getToolByName(self.portal, 'portal_types')
document_fti = getattr(portal_types, 'Document') document_fti = getattr(portal_types, 'Document')
document_fti.manage_changeProperties(allow_discussion = True) document_fti.manage_changeProperties(allow_discussion=True)
self.assertEqual(conversation.enabled(), True) self.assertEqual(conversation.enabled(), True)
@ -272,7 +272,7 @@ class ConversationTest(unittest.TestCase):
# otherwise allow_discussion will always return False # otherwise allow_discussion will always return False
portal_types = getToolByName(self.portal, 'portal_types') portal_types = getToolByName(self.portal, 'portal_types')
document_fti = getattr(portal_types, 'Document') document_fti = getattr(portal_types, 'Document')
document_fti.manage_changeProperties(allow_discussion = True) document_fti.manage_changeProperties(allow_discussion=True)
# Check if conversation is enabled now # Check if conversation is enabled now
self.assertEqual(conversation.enabled(), True) self.assertEqual(conversation.enabled(), True)
@ -289,7 +289,6 @@ class ConversationTest(unittest.TestCase):
settings.globally_enabled = True settings.globally_enabled = True
self.assertEqual(conversation.enabled(), True) self.assertEqual(conversation.enabled(), True)
def test_allow_discussion_for_news_items(self): def test_allow_discussion_for_news_items(self):
self.typetool.constructContent('News Item', self.portal, 'newsitem') self.typetool.constructContent('News Item', self.portal, 'newsitem')
@ -300,7 +299,7 @@ class ConversationTest(unittest.TestCase):
# otherwise allow_discussion will always return False # otherwise allow_discussion will always return False
portal_types = getToolByName(self.portal, 'portal_types') portal_types = getToolByName(self.portal, 'portal_types')
document_fti = getattr(portal_types, 'News Item') document_fti = getattr(portal_types, 'News Item')
document_fti.manage_changeProperties(allow_discussion = True) document_fti.manage_changeProperties(allow_discussion=True)
# Check if conversation is enabled now # Check if conversation is enabled now
self.assertEqual(conversation.enabled(), True) self.assertEqual(conversation.enabled(), True)
@ -329,7 +328,7 @@ class ConversationTest(unittest.TestCase):
# Allow discussion on Document content type # Allow discussion on Document content type
portal_types = getToolByName(self.portal, 'portal_types') portal_types = getToolByName(self.portal, 'portal_types')
document_fti = getattr(portal_types, 'Document') document_fti = getattr(portal_types, 'Document')
document_fti.manage_changeProperties(allow_discussion = True) document_fti.manage_changeProperties(allow_discussion=True)
# Check if conversation is enabled now # Check if conversation is enabled now
self.assertEqual(conversation.enabled(), True) self.assertEqual(conversation.enabled(), True)
@ -337,7 +336,7 @@ class ConversationTest(unittest.TestCase):
# Disallow discussion on Document content type # Disallow discussion on Document content type
portal_types = getToolByName(self.portal, 'portal_types') portal_types = getToolByName(self.portal, 'portal_types')
document_fti = getattr(portal_types, 'Document') document_fti = getattr(portal_types, 'Document')
document_fti.manage_changeProperties(allow_discussion = False) document_fti.manage_changeProperties(allow_discussion=False)
# Check if conversation is enabled now # Check if conversation is enabled now
self.assertEqual(conversation.enabled(), False) self.assertEqual(conversation.enabled(), False)
@ -358,7 +357,7 @@ class ConversationTest(unittest.TestCase):
# Allow discussion on Folder content type # Allow discussion on Folder content type
portal_types = getToolByName(self.portal, 'portal_types') portal_types = getToolByName(self.portal, 'portal_types')
document_fti = getattr(portal_types, 'Folder') document_fti = getattr(portal_types, 'Folder')
document_fti.manage_changeProperties(allow_discussion = True) document_fti.manage_changeProperties(allow_discussion=True)
# Always return False # Always return False
self.assertFalse(conversation.enabled()) self.assertFalse(conversation.enabled())
@ -710,8 +709,7 @@ class ConversationTest(unittest.TestCase):
self.assertFalse('Discussion Item' in BAD_TYPES) self.assertFalse('Discussion Item' in BAD_TYPES)
def test_no_comment(self): def test_no_comment(self):
conversation = IConversation(self.portal.doc1) IConversation(self.portal.doc1)
# Make sure no conversation has been created # Make sure no conversation has been created
self.assertTrue('plone.app.discussion:conversation' not in self.assertTrue('plone.app.discussion:conversation' not in
IAnnotations(self.portal.doc1)) IAnnotations(self.portal.doc1))
@ -850,5 +848,6 @@ class RepliesTest(unittest.TestCase):
self.assertEqual(len(replies_to_comment1_1), 1) self.assertEqual(len(replies_to_comment1_1), 1)
self.assertEqual(len(replies_to_comment2), 1) self.assertEqual(len(replies_to_comment2), 1)
def test_suite(): def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__) return unittest.defaultTestLoader.loadTestsFromName(__name__)