Fix whitespace/Pep8/Pyflakes in tests.

This commit is contained in:
Timo Stollenwerk 2012-01-09 16:43:54 +01:00
parent 1f01a71aac
commit e17cfa68a1
10 changed files with 221 additions and 209 deletions

View File

@ -21,10 +21,10 @@ First we have to set up some things and login.
>>> browser = Browser(app) >>> browser = Browser(app)
>>> browser.handleErrors = False >>> browser.handleErrors = False
>>> browser.addHeader('Authorization', 'Basic admin:secret') >>> browser.addHeader('Authorization', 'Basic admin:secret')
>>> portal = layer['portal'] >>> portal = layer['portal']
>>> portal_url = 'http://nohost/plone' >>> portal_url = 'http://nohost/plone'
By default, only HTTP error codes (e.g. 500 Server Side Error) are shown when an By default, only HTTP error codes (e.g. 500 Server Side Error) are shown when an
error occurs on the server. To see more details, set handleErrors to False: error occurs on the server. To see more details, set handleErrors to False:
>>> browser.handleErrors = False >>> browser.handleErrors = False
@ -46,9 +46,9 @@ Enable commenting.
Enable comment review workflow Enable comment review workflow
------------------------------ ------------------------------
Enable the 'comment review workflow' for comments. Enable the 'comment review workflow' for comments.
>>> portal.portal_workflow.setChainForPortalTypes(('Discussion Item',), ('comment_review_workflow'),) >>> portal.portal_workflow.setChainForPortalTypes(('Discussion Item',), ('comment_review_workflow'),)
>>> portal.portal_workflow.getChainForPortalType('Discussion Item') >>> portal.portal_workflow.getChainForPortalType('Discussion Item')
('comment_review_workflow',) ('comment_review_workflow',)
@ -58,12 +58,12 @@ We need to commit the transaction, otherwise setting the workflow will not work.
>>> import transaction >>> import transaction
>>> transaction.commit() >>> transaction.commit()
Enable anonymous comments Enable anonymous comments
>>> browser.open(portal_url+'/@@discussion-settings')
>>> browser.getControl(name='form.widgets.anonymous_comments:list').value = [True]
>>> browser.getControl(name='form.buttons.save').click()
>>> browser.open(portal_url+'/@@discussion-settings')
>>> browser.getControl(name='form.widgets.anonymous_comments:list').value = [True]
>>> browser.getControl(name='form.buttons.save').click()
Create a public page with comments allowed. Create a public page with comments allowed.
>>> browser.open(portal_url) >>> browser.open(portal_url)
@ -72,7 +72,7 @@ Create a public page with comments allowed.
>>> browser.getControl(name='allowDiscussion:boolean').value = True >>> browser.getControl(name='allowDiscussion:boolean').value = True
>>> browser.getControl(name='form.button.save').click() >>> browser.getControl(name='form.button.save').click()
>>> urldoc = browser.url >>> urldoc = browser.url
Check that the form has been properly submitted Check that the form has been properly submitted
>>> browser.url >>> browser.url
@ -86,25 +86,25 @@ Post some comments as anonymous user:
>>> unprivileged_browser.getControl(name='form.widgets.text').value = "Second anonymous comment" >>> unprivileged_browser.getControl(name='form.widgets.text').value = "Second anonymous comment"
>>> unprivileged_browser.getControl(name='form.buttons.comment').click() >>> unprivileged_browser.getControl(name='form.buttons.comment').click()
Make sure the user gets a notification that the comment awaits moderator Make sure the user gets a notification that the comment awaits moderator
approval. approval.
>>> 'Your comment awaits moderator approval' in unprivileged_browser.contents >>> 'Your comment awaits moderator approval' in unprivileged_browser.contents
True True
Administrators can see all posts and comment actions Administrators can see all posts and comment actions
>>> browser.open(urldoc) >>> browser.open(urldoc)
>>> 'Moderate comments' in browser.contents >>> 'Moderate comments' in browser.contents
True True
>>> 'First anonymous comment' in browser.contents >>> 'First anonymous comment' in browser.contents
True True
>>> 'form.button.DeleteComment' in browser.contents >>> 'form.button.DeleteComment' in browser.contents
True True
>>> 'form.button.PublishComment' in browser.contents >>> 'form.button.PublishComment' in browser.contents
True True
@ -114,18 +114,18 @@ Anonymous user can not see any posts or comment actions
>>> 'Moderate comments' in unprivileged_browser.contents >>> 'Moderate comments' in unprivileged_browser.contents
False False
>>> 'First anonymous comment' in unprivileged_browser.contents >>> 'First anonymous comment' in unprivileged_browser.contents
False False
>>> 'form.button.DeleteComment' in unprivileged_browser.contents >>> 'form.button.DeleteComment' in unprivileged_browser.contents
False False
>>> 'form.button.PublishComment' in unprivileged_browser.contents >>> 'form.button.PublishComment' in unprivileged_browser.contents
False False
Users with 'Review comment' permission can see unapproved comments and comment Users with 'Review comment' permission can see unapproved comments and comment
actions. actions.
>>> browser.open(portal_url + '/logout') >>> browser.open(portal_url + '/logout')
>>> browser.open(portal_url + '/login_form') >>> browser.open(portal_url + '/login_form')
@ -137,13 +137,13 @@ actions.
>>> 'Moderate comments' in browser.contents >>> 'Moderate comments' in browser.contents
True True
>>> 'First anonymous comment' in browser.contents >>> 'First anonymous comment' in browser.contents
True True
>>> 'form.button.DeleteComment' in browser.contents >>> 'form.button.DeleteComment' in browser.contents
True True
>>> 'form.button.PublishComment' in browser.contents >>> 'form.button.PublishComment' in browser.contents
True True
@ -151,19 +151,19 @@ actions.
Publish a comment in the comments view Publish a comment in the comments view
-------------------------------------- --------------------------------------
Publish the first anonymous comment in the main comments view. The publish call Publish the first anonymous comment in the main comments view. The publish call
on the comment currently raises an 404 error, because of a zope.testbrowser on the comment currently raises an 404 error, because of a zope.testbrowser
flaw? Though, the comment is published properly. flaw? Though, the comment is published properly.
>>> browser.open(urldoc) >>> browser.open(urldoc)
>>> 'First anonymous comment' in unprivileged_browser.contents >>> 'First anonymous comment' in unprivileged_browser.contents
False False
>>> browser.open(urldoc) >>> browser.open(urldoc)
>>> browser.handleErrors = True >>> browser.handleErrors = True
>>> browser.raiseHttpErrors = False >>> browser.raiseHttpErrors = False
>>> browser.getControl('Approve', index=0).click() >>> browser.getControl('Approve', index=0).click()
>>> 'Comment approved' in browser.contents >>> 'Comment approved' in browser.contents
True True
@ -180,8 +180,8 @@ Make sure anonyous users see the approved comment, but not the unapproved ones.
Delete a comment in the comments view Delete a comment in the comments view
------------------------------------- -------------------------------------
Delete the second anonymous comment in the main comments view. The delete call Delete the second anonymous comment in the main comments view. The delete call
on the comment currently raises an 404 error, because of a zope.testbrowser on the comment currently raises an 404 error, because of a zope.testbrowser
flaw? Though, the comment is deleted properly. flaw? Though, the comment is deleted properly.
>>> browser.open(urldoc) >>> browser.open(urldoc)
@ -192,7 +192,7 @@ flaw? Though, the comment is deleted properly.
>>> browser.handleErrors = True >>> browser.handleErrors = True
>>> browser.raiseHttpErrors = False >>> browser.raiseHttpErrors = False
>>> browser.getControl('Delete', index=1).click() >>> browser.getControl('Delete', index=1).click()
>>> browser.handleErrors = False >>> browser.handleErrors = False
>>> browser.raiseHttpErrors = True >>> browser.raiseHttpErrors = True
@ -205,4 +205,4 @@ Make sure the second comment has been deleted.
>>> 'Second anonymous comment' in browser.contents >>> 'Second anonymous comment' in browser.contents
False False

View File

@ -2,7 +2,7 @@
plone.app.discussion plone.app.discussion
====================== ======================
This is a functional test for the plone.app.discussion comments viewlet. This is a functional test for the plone.app.discussion comments viewlet.
We use zope.testbrowser to simulate browser interaction in order to show how We use zope.testbrowser to simulate browser interaction in order to show how
the plone.app.discussion commenting works. the plone.app.discussion commenting works.
@ -18,10 +18,10 @@ First we have to set up some things and login.
>>> browser = Browser(app) >>> browser = Browser(app)
>>> browser.handleErrors = False >>> browser.handleErrors = False
>>> browser.addHeader('Authorization', 'Basic admin:secret') >>> browser.addHeader('Authorization', 'Basic admin:secret')
>>> portal = layer['portal'] >>> portal = layer['portal']
>>> portal_url = 'http://nohost/plone' >>> portal_url = 'http://nohost/plone'
By default, only HTTP error codes (e.g. 500 Server Side Error) are shown when an By default, only HTTP error codes (e.g. 500 Server Side Error) are shown when an
error occurs on the server. To see more details, set handleErrors to False: error occurs on the server. To see more details, set handleErrors to False:
>>> browser.handleErrors = False >>> browser.handleErrors = False
@ -47,10 +47,10 @@ Enable commenting.
>>> registry = queryUtility(IRegistry) >>> registry = queryUtility(IRegistry)
>>> settings = registry.forInterface(IDiscussionSettings) >>> settings = registry.forInterface(IDiscussionSettings)
>>> settings.globally_enabled = True >>> settings.globally_enabled = True
>>> import transaction >>> import transaction
>>> transaction.commit() >>> transaction.commit()
Create a public page with comments allowed. Create a public page with comments allowed.
>>> browser.open(portal_url) >>> browser.open(portal_url)
@ -59,7 +59,7 @@ Create a public page with comments allowed.
>>> browser.getControl(name='allowDiscussion:boolean').value = True >>> browser.getControl(name='allowDiscussion:boolean').value = True
>>> browser.getControl(name='form.button.save').click() >>> browser.getControl(name='form.button.save').click()
>>> urldoc1 = browser.url >>> urldoc1 = browser.url
Check that the form has been properly submitted Check that the form has been properly submitted
>>> browser.url >>> browser.url
@ -68,17 +68,17 @@ Check that the form has been properly submitted
Comment Viewlet Comment Viewlet
--------------- ---------------
Check that the old comments viewlet does not show up Check that the old comments viewlet does not show up
>>> 'discussion_reply_form' in browser.contents >>> 'discussion_reply_form' in browser.contents
False False
Check that the comment form/viewlet shows up Check that the comment form/viewlet shows up
>>> 'formfield-form-widgets-in_reply_to' in browser.contents >>> 'formfield-form-widgets-in_reply_to' in browser.contents
True True
>>> 'formfield-form-widgets-text' in browser.contents >>> 'formfield-form-widgets-text' in browser.contents
True True
@ -94,18 +94,18 @@ Login as admin.
Post a comment as admin. Post a comment as admin.
>>> browser.getControl(name='form.widgets.text').value = "Comment from admin" >>> browser.getControl(name='form.widgets.text').value = "Comment from admin"
>>> submit = browser.getControl(name='form.buttons.comment') >>> submit = browser.getControl(name='form.buttons.comment')
>>> submit.click() >>> submit.click()
Check if comment has been added properly. Check if comment has been added properly.
>>> '<a href="http://nohost/plone/author/admin">admin</a>' in browser.contents >>> '<a href="http://nohost/plone/author/admin">admin</a>' in browser.contents
True True
>>> browser.contents >>> browser.contents
'...<a href="http://nohost/plone/author/admin">admin</a>...says:...' '...<a href="http://nohost/plone/author/admin">admin</a>...says:...'
>>> "Comment from admin" in browser.contents >>> "Comment from admin" in browser.contents
True True
@ -120,14 +120,14 @@ Login as user (without the 'Member' role).
>>> browser.getControl(name='__ac_name').value = 'johndoe' >>> browser.getControl(name='__ac_name').value = 'johndoe'
>>> browser.getControl(name='__ac_password').value = 'secret' >>> browser.getControl(name='__ac_password').value = 'secret'
>>> browser.getControl(name='submit').click() >>> browser.getControl(name='submit').click()
Users without the 'Reply to item' permission will not see the comment form, Users without the 'Reply to item' permission will not see the comment form,
because they don't have the 'Reply to item' permission. By default, this because they don't have the 'Reply to item' permission. By default, this
permission is only granted to the 'Member' role. permission is only granted to the 'Member' role.
>>> 'form.widgets.text' in browser.contents >>> 'form.widgets.text' in browser.contents
False False
>>> 'form.buttons.comment' in browser.contents >>> 'form.buttons.comment' in browser.contents
False False
@ -135,7 +135,7 @@ permission is only granted to the 'Member' role.
Post a comment as member Post a comment as member
------------------------ ------------------------
Login as user 'jim'. Login as user 'jim'.
>>> browser.open(portal_url + '/logout') >>> browser.open(portal_url + '/logout')
>>> browser.open(portal_url + '/login_form') >>> browser.open(portal_url + '/login_form')
@ -146,9 +146,9 @@ Login as user 'jim'.
Post a comment as user jim. Post a comment as user jim.
>>> browser.open(urldoc1) >>> browser.open(urldoc1)
>>> browser.getControl(name='form.widgets.text').value = "Comment from Jim" >>> browser.getControl(name='form.widgets.text').value = "Comment from Jim"
>>> submit = browser.getControl(name='form.buttons.comment') >>> submit = browser.getControl(name='form.buttons.comment')
>>> submit.click() >>> submit.click()
Check if the comment has been added properly. Check if the comment has been added properly.
@ -161,24 +161,24 @@ Check if the comment has been added properly.
Post a comment as anonymous user Post a comment as anonymous user
-------------------------------- --------------------------------
Login and post comment as Anonymous Login and post comment as Anonymous
>>> unprivileged_browser.open(urldoc1) >>> unprivileged_browser.open(urldoc1)
>>> 'Log in to add comments' in unprivileged_browser.contents >>> 'Log in to add comments' in unprivileged_browser.contents
True True
Enable anonymous comment Enable anonymous comment
>>> browser.open(portal_url + '/logout') >>> browser.open(portal_url + '/logout')
>>> browser.open(portal_url + '/login_form') >>> browser.open(portal_url + '/login_form')
>>> browser.getControl(name='__ac_name').value = 'admin' >>> browser.getControl(name='__ac_name').value = 'admin'
>>> browser.getControl(name='__ac_password').value = 'secret' >>> browser.getControl(name='__ac_password').value = 'secret'
>>> browser.getControl(name='submit').click() >>> browser.getControl(name='submit').click()
>>> browser.open(portal_url+'/@@discussion-settings') >>> browser.open(portal_url+'/@@discussion-settings')
>>> browser.getControl(name='form.widgets.anonymous_comments:list').value = [True] >>> browser.getControl(name='form.widgets.anonymous_comments:list').value = [True]
>>> browser.getControl(name='form.buttons.save').click() >>> browser.getControl(name='form.buttons.save').click()
>>> browser.open(portal_url + '/logout') >>> browser.open(portal_url + '/logout')
Now we can post an anonymous comment. Now we can post an anonymous comment.
@ -186,13 +186,13 @@ Now we can post an anonymous comment.
>>> unprivileged_browser.open(urldoc1) >>> unprivileged_browser.open(urldoc1)
>>> unprivileged_browser.getControl(name='form.widgets.text').value = "This is an anonymous comment" >>> unprivileged_browser.getControl(name='form.widgets.text').value = "This is an anonymous comment"
>>> unprivileged_browser.getControl(name='form.buttons.comment').click() >>> unprivileged_browser.getControl(name='form.buttons.comment').click()
>>> '<span>Anonymous</span>' in unprivileged_browser.contents >>> '<span>Anonymous</span>' in unprivileged_browser.contents
True True
>>> 'says' in unprivileged_browser.contents >>> 'says' in unprivileged_browser.contents
True True
>>> 'This is an anonymous comment' in unprivileged_browser.contents >>> 'This is an anonymous comment' in unprivileged_browser.contents
True True
@ -206,10 +206,10 @@ Make sure special characters work as well.
>>> tarek_fullname in unprivileged_browser.contents >>> tarek_fullname in unprivileged_browser.contents
True True
>>> 'says' in unprivileged_browser.contents >>> 'says' in unprivileged_browser.contents
True True
>>> 'This is an äüö comment' in unprivileged_browser.contents >>> 'This is an äüö comment' in unprivileged_browser.contents
True True
@ -230,7 +230,7 @@ Find a comment id to reply to.
>>> id = re.findall('"([^"]*)"', comment_div)[2] >>> id = re.findall('"([^"]*)"', comment_div)[2]
Post a reply to an existing comment. Post a reply to an existing comment.
>>> browser.getControl(name='form.widgets.in_reply_to').value = id >>> browser.getControl(name='form.widgets.in_reply_to').value = id
>>> browser.getControl(name='form.widgets.text').value = "Reply comment" >>> browser.getControl(name='form.widgets.text').value = "Reply comment"
>>> browser.getControl(name='form.buttons.comment').click() >>> browser.getControl(name='form.buttons.comment').click()
@ -239,7 +239,7 @@ Check that the reply has been posted properly.
>>> 'Reply comment' in browser.contents >>> 'Reply comment' in browser.contents
True True
>>> 'replyTreeLevel1' in browser.contents >>> 'replyTreeLevel1' in browser.contents
True True
@ -248,7 +248,7 @@ Post a comment with comment review workflow enabled
--------------------------------------------------- ---------------------------------------------------
Enable the 'comment review workflow' for comments. Enable the 'comment review workflow' for comments.
>>> portal.portal_workflow.setChainForPortalTypes(('Discussion Item',), ('comment_review_workflow'),) >>> portal.portal_workflow.setChainForPortalTypes(('Discussion Item',), ('comment_review_workflow'),)
>>> portal.portal_workflow.getChainForPortalType('Discussion Item') >>> portal.portal_workflow.getChainForPortalType('Discussion Item')
('comment_review_workflow',) ('comment_review_workflow',)
@ -269,8 +269,8 @@ Make sure the comment has not been published.
>>> 'Comment review workflow comment' not in unprivileged_browser.contents >>> 'Comment review workflow comment' not in unprivileged_browser.contents
True True
Make sure the user gets a notification that the comment awaits moderator Make sure the user gets a notification that the comment awaits moderator
approval. approval.
>>> 'Your comment awaits moderator approval' in unprivileged_browser.contents >>> 'Your comment awaits moderator approval' in unprivileged_browser.contents
True True
@ -280,7 +280,7 @@ Edit the content object after a comment has been posted
------------------------------------------------------- -------------------------------------------------------
Make sure we still can edit the content object after a comment has been posted. Make sure we still can edit the content object after a comment has been posted.
This is a regression test for http://dev.plone.org/plone/ticket/11157 This is a regression test for http://dev.plone.org/plone/ticket/11157
(TypeError: Can't pickle objects in acquisition wrappers). (TypeError: Can't pickle objects in acquisition wrappers).
Login as admin. Login as admin.
@ -290,7 +290,7 @@ Login as admin.
>>> browser.getControl(name='__ac_name').value = 'admin' >>> browser.getControl(name='__ac_name').value = 'admin'
>>> browser.getControl(name='__ac_password').value = 'secret' >>> browser.getControl(name='__ac_password').value = 'secret'
>>> browser.getControl(name='submit').click() >>> browser.getControl(name='submit').click()
Edit the content object. Edit the content object.
>>> browser.open(urldoc1 + "/edit") >>> browser.open(urldoc1 + "/edit")
@ -298,7 +298,7 @@ Edit the content object.
>>> browser.getControl(name='form.button.save').click() >>> browser.getControl(name='form.button.save').click()
Make sure the edit was successful. Make sure the edit was successful.
>>> 'Lorem ipsum' in browser.contents >>> 'Lorem ipsum' in browser.contents
True True

View File

@ -1,19 +1,18 @@
server: http://localhost:9876 server: http://localhost:9876
load: load:
# Add these lines to load the equiv function and adapter in order, before the # Add these lines to load the equiv function and adapter in order, before the
# tests (assuming they are saved to tests/qunit/) # tests (assuming they are saved to tests/qunit/)
- qunit/equiv.js - qunit/equiv.js
- qunit/QUnitAdapter.js - qunit/QUnitAdapter.js
# This is where we load the qunit tests # This is where we load the qunit tests
- javascripts/*.js - javascripts/*.js
# And this loads the source files we are testing # And this loads the source files we are testing
- ../browser/javascripts/*.js - ../browser/javascripts/*.js
plugin: plugin:
- name: "coverage" - name: "coverage"
jar: "../../../../parts/jstestdriver/coverage.jar" jar: "../../../../parts/jstestdriver/coverage.jar"
module: "com.google.jstestdriver.coverage.CoverageModule" module: "com.google.jstestdriver.coverage.CoverageModule"

View File

@ -13,7 +13,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.interfaces import IConversation from plone.app.discussion.interfaces import IConversation
@ -24,7 +25,7 @@ class CatalogSetupTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.portal = self.layer['portal'] self.portal = self.layer['portal']
def test_catalog_installed(self): def test_catalog_installed(self):
self.assertTrue('total_comments' in self.assertTrue('total_comments' in
self.portal.portal_catalog.indexes()) self.portal.portal_catalog.indexes())
@ -34,7 +35,7 @@ class CatalogSetupTest(unittest.TestCase):
self.portal.portal_catalog.schema()) self.portal.portal_catalog.schema())
self.assertTrue('in_response_to' in self.assertTrue('in_response_to' in
self.portal.portal_catalog.schema()) self.portal.portal_catalog.schema())
def test_collection_criteria_installed(self): def test_collection_criteria_installed(self):
try: try:
self.portal.portal_atct.getIndex('commentators') self.portal.portal_atct.getIndex('commentators')
@ -54,7 +55,7 @@ class ConversationCatalogTest(unittest.TestCase):
self.portal.invokeFactory(id='doc1', self.portal.invokeFactory(id='doc1',
Title='Document 1', Title='Document 1',
type_name='Document') type_name='Document')
self.catalog = getToolByName(self.portal, 'portal_catalog') self.catalog = getToolByName(self.portal, 'portal_catalog')
conversation = IConversation(self.portal.doc1) conversation = IConversation(self.portal.doc1)
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
@ -69,26 +70,26 @@ class ConversationCatalogTest(unittest.TestCase):
self.comment_id = new_comment1_id self.comment_id = 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"
)) ))
self.conversation = conversation self.conversation = conversation
self.brains = brains self.brains = brains
self.doc1_brain = brains[0] self.doc1_brain = brains[0]
self.comment1 = comment1 self.comment1 = comment1
self.new_comment1_id = new_comment1_id self.new_comment1_id = new_comment1_id
def test_total_comments(self): def test_total_comments(self):
self.assertTrue('total_comments' in self.doc1_brain) self.assertTrue('total_comments' in self.doc1_brain)
self.assertEqual(self.doc1_brain.total_comments, 1) self.assertEqual(self.doc1_brain.total_comments, 1)
comment2 = createObject('plone.Comment') comment2 = createObject('plone.Comment')
comment2.title = 'Comment 2' comment2.title = 'Comment 2'
comment2.text = 'Comment text' comment2.text = 'Comment text'
comment2.creator = 'Emma' comment2.creator = 'Emma'
new_comment2_id = self.conversation.addComment(comment2) new_comment2_id = self.conversation.addComment(comment2)
comment2 = self.portal.doc1.restrictedTraverse( comment2 = self.portal.doc1.restrictedTraverse(
'++conversation++default/%s' % new_comment2_id) '++conversation++default/%s' % new_comment2_id)
comment2.reindexObject() comment2.reindexObject()
@ -99,12 +100,12 @@ class ConversationCatalogTest(unittest.TestCase):
)) ))
doc1_brain = brains[0] doc1_brain = brains[0]
self.assertEqual(doc1_brain.total_comments, 2) self.assertEqual(doc1_brain.total_comments, 2)
def test_last_comment_date(self): def test_last_comment_date(self):
self.assertTrue('last_comment_date' in self.doc1_brain) self.assertTrue('last_comment_date' in self.doc1_brain)
self.assertEqual(self.doc1_brain.last_comment_date, self.assertEqual(self.doc1_brain.last_comment_date,
datetime(2006, 9, 17, 14, 18, 12)) datetime(2006, 9, 17, 14, 18, 12))
# Add another comment and check if last comment date is updated. # Add another comment and check if last comment date is updated.
comment2 = createObject('plone.Comment') comment2 = createObject('plone.Comment')
comment2.title = 'Comment 2' comment2.title = 'Comment 2'
@ -113,7 +114,7 @@ class ConversationCatalogTest(unittest.TestCase):
comment2.creation_date = datetime(2009, 9, 17, 14, 18, 12) comment2.creation_date = datetime(2009, 9, 17, 14, 18, 12)
comment2.modification_date = datetime(2009, 9, 17, 14, 18, 12) comment2.modification_date = datetime(2009, 9, 17, 14, 18, 12)
new_comment2_id = self.conversation.addComment(comment2) new_comment2_id = self.conversation.addComment(comment2)
comment2 = self.portal.doc1.restrictedTraverse( comment2 = self.portal.doc1.restrictedTraverse(
'++conversation++default/%s' % new_comment2_id) '++conversation++default/%s' % new_comment2_id)
comment2.reindexObject() comment2.reindexObject()
@ -125,10 +126,10 @@ class ConversationCatalogTest(unittest.TestCase):
doc1_brain = brains[0] doc1_brain = brains[0]
self.assertEqual(doc1_brain.last_comment_date, self.assertEqual(doc1_brain.last_comment_date,
datetime(2009, 9, 17, 14, 18, 12)) datetime(2009, 9, 17, 14, 18, 12))
# Remove the comment again # Remove the comment again
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()) },
@ -137,7 +138,7 @@ class ConversationCatalogTest(unittest.TestCase):
doc1_brain = brains[0] doc1_brain = brains[0]
self.assertEqual(doc1_brain.last_comment_date, self.assertEqual(doc1_brain.last_comment_date,
datetime(2006, 9, 17, 14, 18, 12)) datetime(2006, 9, 17, 14, 18, 12))
# remove all comments # remove all comments
del self.conversation[self.new_comment1_id] del self.conversation[self.new_comment1_id]
brains = self.catalog.searchResults(dict( brains = self.catalog.searchResults(dict(
@ -147,11 +148,11 @@ class ConversationCatalogTest(unittest.TestCase):
)) ))
doc1_brain = brains[0] doc1_brain = brains[0]
self.assertEqual(doc1_brain.last_comment_date, None) self.assertEqual(doc1_brain.last_comment_date, None)
def test_commentators(self): def test_commentators(self):
self.assertTrue('commentators' in self.doc1_brain) self.assertTrue('commentators' in self.doc1_brain)
self.assertEqual(self.doc1_brain.commentators, ('Jim',)) self.assertEqual(self.doc1_brain.commentators, ('Jim',))
# add another comment with another author # add another comment with another author
comment2 = createObject('plone.Comment') comment2 = createObject('plone.Comment')
comment2.title = 'Comment 2' comment2.title = 'Comment 2'
@ -159,20 +160,20 @@ class ConversationCatalogTest(unittest.TestCase):
comment2.creator = 'Emma' comment2.creator = 'Emma'
comment2.author_username = 'Emma' comment2.author_username = 'Emma'
new_comment2_id = self.conversation.addComment(comment2) new_comment2_id = self.conversation.addComment(comment2)
comment2 = self.portal.doc1.restrictedTraverse( comment2 = self.portal.doc1.restrictedTraverse(
'++conversation++default/%s' % new_comment2_id) '++conversation++default/%s' % new_comment2_id)
comment2.reindexObject() comment2.reindexObject()
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]
self.assertEqual(doc1_brain.commentators, ('Emma', 'Jim')) self.assertEqual(doc1_brain.commentators, ('Emma', 'Jim'))
# remove one comments # remove one comments
del self.conversation[new_comment2_id] del self.conversation[new_comment2_id]
brains = self.catalog.searchResults(dict( brains = self.catalog.searchResults(dict(
@ -182,7 +183,7 @@ class ConversationCatalogTest(unittest.TestCase):
)) ))
doc1_brain = brains[0] doc1_brain = brains[0]
self.assertEqual(doc1_brain.commentators, ('Jim',)) self.assertEqual(doc1_brain.commentators, ('Jim',))
# remove all comments # remove all comments
del self.conversation[self.new_comment1_id] del self.conversation[self.new_comment1_id]
brains = self.catalog.searchResults(dict( brains = self.catalog.searchResults(dict(
@ -192,7 +193,7 @@ class ConversationCatalogTest(unittest.TestCase):
)) ))
doc1_brain = brains[0] doc1_brain = brains[0]
self.assertEqual(doc1_brain.commentators, ()) self.assertEqual(doc1_brain.commentators, ())
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':
@ -206,9 +207,9 @@ class ConversationCatalogTest(unittest.TestCase):
class CommentCatalogTest(unittest.TestCase): class CommentCatalogTest(unittest.TestCase):
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
def setUp(self): def setUp(self):
self.portal = self.layer['portal'] self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager']) setRoles(self.portal, TEST_USER_ID, ['Manager'])
@ -216,16 +217,16 @@ class CommentCatalogTest(unittest.TestCase):
title='Document 1', title='Document 1',
type_name='Document') type_name='Document')
self.catalog = getToolByName(self.portal, 'portal_catalog') self.catalog = getToolByName(self.portal, 'portal_catalog')
conversation = IConversation(self.portal.doc1) conversation = IConversation(self.portal.doc1)
self.conversation = conversation self.conversation = conversation
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
comment1.text = 'Comment text' comment1.text = 'Comment text'
comment1.creator = 'Jim' comment1.creator = 'Jim'
new_comment1_id = conversation.addComment(comment1) new_comment1_id = conversation.addComment(comment1)
self.comment_id = new_comment1_id self.comment_id = new_comment1_id
# Comment brain # Comment brain
self.comment = self.portal.doc1.restrictedTraverse( self.comment = self.portal.doc1.restrictedTraverse(
'++conversation++default/%s' % new_comment1_id) '++conversation++default/%s' % new_comment1_id)
@ -233,10 +234,10 @@ class CommentCatalogTest(unittest.TestCase):
path={'query': path={'query':
'/'.join(self.comment.getPhysicalPath())})) '/'.join(self.comment.getPhysicalPath())}))
self.comment_brain = brains[0] self.comment_brain = brains[0]
def test_title(self): def test_title(self):
self.assertEqual(self.comment_brain.Title, 'Jim on Document 1') self.assertEqual(self.comment_brain.Title, 'Jim on Document 1')
def test_no_name_title(self): def test_no_name_title(self):
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.text = 'Comment text' comment.text = 'Comment text'
@ -289,7 +290,7 @@ class CommentCatalogTest(unittest.TestCase):
self.portal.manage_delObjects(["doc1"]) self.portal.manage_delObjects(["doc1"])
brains = self.catalog.searchResults({'portal_type': 'Discussion Item'}) brains = self.catalog.searchResults({'portal_type': 'Discussion Item'})
self.assertEqual(len(brains), 0) self.assertEqual(len(brains), 0)
def test_move_comments_when_content_object_is_moved(self): def test_move_comments_when_content_object_is_moved(self):
# Create two folders and a content object with a comment # Create two folders and a content object with a comment
self.portal.invokeFactory(id='folder1', self.portal.invokeFactory(id='folder1',
@ -300,43 +301,46 @@ class CommentCatalogTest(unittest.TestCase):
type_name='Folder') type_name='Folder')
self.portal.folder1.invokeFactory(id='moveme', self.portal.folder1.invokeFactory(id='moveme',
title='Move Me', title='Move Me',
type_name='Document') type_name='Document')
conversation = IConversation(self.portal.folder1.moveme) conversation = IConversation(self.portal.folder1.moveme)
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment_id = conversation.addComment(comment) comment_id = conversation.addComment(comment)
# We need to commit here so that _p_jar isn't None and move will work # We need to commit here so that _p_jar isn't None and move will work
transaction.savepoint(optimistic=True) transaction.savepoint(optimistic=True)
# Move moveme from folder1 to folder2 # Move moveme from folder1 to folder2
cp = self.portal.folder1.manage_cutObjects(ids=('moveme',)) cp = self.portal.folder1.manage_cutObjects(ids=('moveme',))
self.portal.folder2.manage_pasteObjects(cp) self.portal.folder2.manage_pasteObjects(cp)
# Make sure no old comment brains are # Make sure no old comment brains are
brains = self.catalog.searchResults(dict( brains = self.catalog.searchResults(dict(
portal_type="Discussion Item", portal_type="Discussion Item",
path={'query': '/'.join(self.portal.folder1.getPhysicalPath())} path={'query': '/'.join(self.portal.folder1.getPhysicalPath())}
)) ))
self.assertEquals(len(brains), 0) self.assertEquals(len(brains), 0)
brains = self.catalog.searchResults(dict( brains = self.catalog.searchResults(dict(
portal_type="Discussion Item", portal_type="Discussion Item",
path={'query': '/'.join(self.portal.folder2.getPhysicalPath())} path={
'query': '/'.join(self.portal.folder2.getPhysicalPath())
}
)) ))
self.assertEquals(len(brains), 1) self.assertEquals(len(brains), 1)
self.assertEquals(brains[0].getPath(), self.assertEquals(brains[0].getPath(),
'/plone/folder2/moveme/++conversation++default/' + '/plone/folder2/moveme/++conversation++default/' +
str(comment_id)) str(comment_id))
def test_update_comments_when_content_object_is_renamed(self): def test_update_comments_when_content_object_is_renamed(self):
# We need to commit here so that _p_jar isn't None and move will work # We need to commit here so that _p_jar isn't None and move will work
transaction.savepoint(optimistic=True) transaction.savepoint(optimistic=True)
self.portal.manage_renameObject("doc1", "doc2") self.portal.manage_renameObject("doc1", "doc2")
brains = self.catalog.searchResults(portal_type = 'Discussion Item') brains = self.catalog.searchResults(
portal_type='Discussion Item')
self.assertEquals(len(brains), 1) self.assertEquals(len(brains), 1)
self.assertEquals(brains[0].getPath(), self.assertEquals(brains[0].getPath(),
'/plone/doc2/++conversation++default/' + '/plone/doc2/++conversation++default/' +
str(self.comment_id)) str(self.comment_id))
def test_clear_and_rebuild_catalog(self): def test_clear_and_rebuild_catalog(self):

View File

@ -13,7 +13,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.interfaces import IComment, IConversation, IReplies from plone.app.discussion.interfaces import IComment, IConversation, IReplies
@ -23,6 +24,7 @@ from plone.app.discussion.browser.comment import View
logger = logging.getLogger('plone.app.discussion.tests') logger = logging.getLogger('plone.app.discussion.tests')
logger.addHandler(logging.StreamHandler()) logger.addHandler(logging.StreamHandler())
class CommentTest(unittest.TestCase): class CommentTest(unittest.TestCase):
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
@ -37,14 +39,15 @@ class CommentTest(unittest.TestCase):
type_name='Document') type_name='Document')
self.catalog = getToolByName(self.portal, 'portal_catalog') self.catalog = getToolByName(self.portal, 'portal_catalog')
self.document_brain = self.catalog.searchResults( self.document_brain = self.catalog.searchResults(
portal_type = 'Document')[0] portal_type='Document')[0]
def test_factory(self): def test_factory(self):
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
self.assertTrue(IComment.providedBy(comment1)) self.assertTrue(IComment.providedBy(comment1))
def test_UTCDates(self): def test_UTCDates(self):
utc_to_local_diff = datetime.datetime.now() - datetime.datetime.utcnow() utc_to_local_diff = \
datetime.datetime.now() - datetime.datetime.utcnow()
utc_to_local_diff = abs(utc_to_local_diff.seconds) utc_to_local_diff = abs(utc_to_local_diff.seconds)
if utc_to_local_diff < 60: if utc_to_local_diff < 60:
logger.warning("Your computer is living in a timezone where local " logger.warning("Your computer is living in a timezone where local "
@ -71,7 +74,7 @@ class CommentTest(unittest.TestCase):
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
conversation.addComment(comment1) conversation.addComment(comment1)
comment_brain = self.catalog.searchResults( comment_brain = self.catalog.searchResults(
portal_type = 'Discussion Item')[0] portal_type='Discussion Item')[0]
self.assertTrue(comment_brain.UID) self.assertTrue(comment_brain.UID)
def test_uid_is_unique(self): def test_uid_is_unique(self):
@ -81,7 +84,7 @@ class CommentTest(unittest.TestCase):
comment2 = createObject('plone.Comment') comment2 = createObject('plone.Comment')
conversation.addComment(comment2) conversation.addComment(comment2)
brains = self.catalog.searchResults( brains = self.catalog.searchResults(
portal_type = 'Discussion Item') portal_type='Discussion Item')
self.assertNotEqual(brains[0].UID, brains[1].UID) self.assertNotEqual(brains[0].UID, brains[1].UID)
def test_comment_uid_differs_from_content_uid(self): def test_comment_uid_differs_from_content_uid(self):
@ -89,7 +92,7 @@ class CommentTest(unittest.TestCase):
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
conversation.addComment(comment1) conversation.addComment(comment1)
comment_brain = self.catalog.searchResults( comment_brain = self.catalog.searchResults(
portal_type = 'Discussion Item')[0] portal_type='Discussion Item')[0]
self.assertNotEqual(self.document_brain.UID, comment_brain.UID) self.assertNotEqual(self.document_brain.UID, comment_brain.UID)
def test_title(self): def test_title(self):
@ -131,13 +134,13 @@ class CommentTest(unittest.TestCase):
Second paragraph""" Second paragraph"""
self.assertEqual(comment1.getText(), 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): def test_getText_escapes_HTML(self):
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
comment1.text = """<b>Got HTML?</b>""" comment1.text = """<b>Got HTML?</b>"""
self.assertEqual(comment1.getText(), self.assertEqual(comment1.getText(),
"<p>&lt;b&gt;Got HTML?&lt;/b&gt;</p>") "<p>&lt;b&gt;Got HTML?&lt;/b&gt;</p>")
def test_getText_with_non_ascii_characters(self): def test_getText_with_non_ascii_characters(self):
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
comment1.text = u"""Umlaute sind ä, ö und ü.""" comment1.text = u"""Umlaute sind ä, ö und ü."""
@ -149,13 +152,13 @@ class CommentTest(unittest.TestCase):
comment1.text = "Go to http://www.plone.org" comment1.text = "Go to http://www.plone.org"
self.assertEqual(comment1.getText(), 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): def test_getText_uses_comment_mime_type(self):
comment1 = createObject('plone.Comment') 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' comment1.mime_type = 'text/x-web-intelligent'
self.assertEqual(comment1.getText(), self.assertEqual(comment1.getText(),
'Go to <a href="http://www.plone.org" rel="nofollow">http://www.plone.org</a>') 'Go to <a href="http://www.plone.org" rel="nofollow">http://www.plone.org</a>')
def test_getText_w_custom_targetMimetype(self): def test_getText_w_custom_targetMimetype(self):
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')

View File

@ -35,7 +35,8 @@ from plone.app.discussion.browser.comments import CommentsViewlet
from plone.app.discussion.browser.comments import CommentForm from plone.app.discussion.browser.comments import CommentForm
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
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.interfaces import IDiscussionSettings from plone.app.discussion.interfaces import IDiscussionSettings
@ -49,7 +50,7 @@ class TestCommentForm(unittest.TestCase):
setRoles(self.portal, TEST_USER_ID, ['Manager']) setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.portal.invokeFactory('Folder', 'test-folder') self.portal.invokeFactory('Folder', 'test-folder')
self.folder = self.portal['test-folder'] self.folder = self.portal['test-folder']
interface.alsoProvides( interface.alsoProvides(
self.portal.REQUEST, interfaces.IDiscussionLayer) self.portal.REQUEST, interfaces.IDiscussionLayer)
@ -227,10 +228,10 @@ class TestCommentsViewlet(unittest.TestCase):
self.folder = self.portal['test-folder'] self.folder = self.portal['test-folder']
interface.alsoProvides( interface.alsoProvides(
self.request, interfaces.IDiscussionLayer) self.request, interfaces.IDiscussionLayer)
self.workflowTool = getToolByName(self.portal, 'portal_workflow') self.workflowTool = getToolByName(self.portal, 'portal_workflow')
self.workflowTool.setDefaultChain('one_state_workflow') self.workflowTool.setDefaultChain('one_state_workflow')
typetool = self.portal.portal_types typetool = self.portal.portal_types
typetool.constructContent('Document', self.portal, 'doc1') typetool.constructContent('Document', self.portal, 'doc1')
self.portal_discussion = getToolByName(self.portal, self.portal_discussion = getToolByName(self.portal,

View File

@ -8,14 +8,15 @@ from zope.annotation.interfaces import IAnnotations
from Products.CMFCore.utils import getToolByName 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.testing import logout, login
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.browser.migration import View from plone.app.discussion.browser.migration import View
from plone.app.discussion.interfaces import IConversation, IComment from plone.app.discussion.interfaces import IConversation, IComment
class MigrationTest(unittest.TestCase): class MigrationTest(unittest.TestCase):
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
@ -37,7 +38,6 @@ class MigrationTest(unittest.TestCase):
self.workflowTool.doActionFor(self.portal.doc, 'publish') self.workflowTool.doActionFor(self.portal.doc, 'publish')
self.request.set("test", True) self.request.set("test", True)
context = getattr(self.portal, 'doc')
self.view = View(self.portal, self.request) self.view = View(self.portal, self.request)
self.workflowTool.setChainForPortalTypes(('Discussion Item',), self.workflowTool.setChainForPortalTypes(('Discussion Item',),
'comment_review_workflow') 'comment_review_workflow')
@ -80,9 +80,9 @@ class MigrationTest(unittest.TestCase):
datetime(2003, 3, 11, 9, 28, 6)) datetime(2003, 3, 11, 9, 28, 6))
self.assertEqual(comment1.modification_date, self.assertEqual(comment1.modification_date,
datetime(2009, 7, 12, 19, 38, 7)) datetime(2009, 7, 12, 19, 38, 7))
self.assertEqual( self.assertEqual([
[{'comment': comment1, 'depth': 0, 'id': long(comment1.id)},] {'comment': comment1, 'depth': 0, 'id': long(comment1.id)}
, list(conversation.getThreads())) ], list(conversation.getThreads()))
self.assertFalse(self.doc.talkback) self.assertFalse(self.doc.talkback)
def test_migrate_nested_comments(self): def test_migrate_nested_comments(self):

View File

@ -18,9 +18,9 @@ from plone.app.discussion.interfaces import IConversation
class ModerationViewTest(unittest.TestCase): class ModerationViewTest(unittest.TestCase):
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
def setUp(self): def setUp(self):
self.app = self.layer['app'] self.app = self.layer['app']
self.portal = self.layer['portal'] self.portal = self.layer['portal']
@ -41,13 +41,13 @@ class ModerationViewTest(unittest.TestCase):
self.portal.portal_workflow.setChainForPortalTypes( self.portal.portal_workflow.setChainForPortalTypes(
('Discussion Item',), 'comment_review_workflow') ('Discussion Item',), 'comment_review_workflow')
self.wf_tool = self.portal.portal_workflow self.wf_tool = self.portal.portal_workflow
def test_moderation_enabled(self): def test_moderation_enabled(self):
"""Make sure that moderation_enabled returns true if the comment """Make sure that moderation_enabled returns true if the comment
workflow implements a 'pending' state. workflow implements a 'pending' state.
""" """
# If workflow is not set, enabled must return False # If workflow is not set, enabled must return False
self.wf_tool.setChainForPortalTypes(('Discussion Item',),()) self.wf_tool.setChainForPortalTypes(('Discussion Item',), ())
self.assertEqual(self.view.moderation_enabled(), False) self.assertEqual(self.view.moderation_enabled(), False)
# The one_state_workflow does not have a 'pending' state # The one_state_workflow does not have a 'pending' state
self.wf_tool.setChainForPortalTypes(('Discussion Item',), self.wf_tool.setChainForPortalTypes(('Discussion Item',),
@ -57,13 +57,15 @@ class ModerationViewTest(unittest.TestCase):
self.wf_tool.setChainForPortalTypes(('Discussion Item',), self.wf_tool.setChainForPortalTypes(('Discussion Item',),
('comment_review_workflow,')) ('comment_review_workflow,'))
self.assertEqual(self.view.moderation_enabled(), True) self.assertEqual(self.view.moderation_enabled(), True)
def test_old_comments_not_shown_in_moderation_view(self): def test_old_comments_not_shown_in_moderation_view(self):
# Create old comment # Create old comment
discussion = getToolByName(self.portal, 'portal_discussion', None) discussion = getToolByName(self.portal, 'portal_discussion', None)
discussion.overrideDiscussionFor(self.portal.doc1, 1) discussion.overrideDiscussionFor(self.portal.doc1, 1)
talkback = discussion.getDiscussionFor(self.portal.doc1) talkback = discussion.getDiscussionFor(self.portal.doc1)
self.portal.doc1.talkback.createReply('My Title', 'My Text', Creator='Jim') self.portal.doc1.talkback.createReply('My Title',
'My Text',
Creator='Jim')
reply = talkback.getReplies()[0] reply = talkback.getReplies()[0]
reply.setReplyTo(self.portal.doc1) reply.setReplyTo(self.portal.doc1)
reply.creation_date = DateTime(2003, 3, 11, 9, 28, 6) reply.creation_date = DateTime(2003, 3, 11, 9, 28, 6)
@ -73,12 +75,13 @@ class ModerationViewTest(unittest.TestCase):
self.assertTrue('Jim' in reply.listCreators()) self.assertTrue('Jim' in reply.listCreators())
self.assertEqual(talkback.replyCount(self.portal.doc1), 1) self.assertEqual(talkback.replyCount(self.portal.doc1), 1)
self.assertEqual(reply.inReplyTo(), self.portal.doc1) self.assertEqual(reply.inReplyTo(), self.portal.doc1)
view = self.view() view = self.view()
self.assertTrue('No comments to moderate' in view) self.assertTrue('No comments to moderate' in view)
self.assertEqual(len(self.view.comments), 0) self.assertEqual(len(self.view.comments), 0)
class ModerationBulkActionsViewTest(unittest.TestCase): class ModerationBulkActionsViewTest(unittest.TestCase):
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
@ -126,17 +129,17 @@ class ModerationBulkActionsViewTest(unittest.TestCase):
# Make sure no error is raised when no bulk actions has been supplied # Make sure no error is raised when no bulk actions has been supplied
self.request.set('form.select.BulkAction', '-1') self.request.set('form.select.BulkAction', '-1')
self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())]) self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())])
view = BulkActionsView(self.portal, self.request) view = BulkActionsView(self.portal, self.request)
self.assertFalse(view()) self.assertFalse(view())
def test_retract(self): def test_retract(self):
self.request.set('form.select.BulkAction', 'retract') self.request.set('form.select.BulkAction', 'retract')
self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())]) self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())])
view = BulkActionsView(self.portal, self.request) view = BulkActionsView(self.portal, self.request)
self.assertRaises(NotImplementedError, self.assertRaises(NotImplementedError,
view) view)
@ -144,9 +147,9 @@ class ModerationBulkActionsViewTest(unittest.TestCase):
self.request.set('form.select.BulkAction', 'publish') self.request.set('form.select.BulkAction', 'publish')
self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())]) self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())])
view = BulkActionsView(self.portal, self.request) view = BulkActionsView(self.portal, self.request)
view() view()
# Count published comments # Count published comments
published_comments = 0 published_comments = 0
for r in self.conversation.getThreads(): for r in self.conversation.getThreads():
@ -156,16 +159,16 @@ class ModerationBulkActionsViewTest(unittest.TestCase):
published_comments += 1 published_comments += 1
# Make sure the comment has been published # Make sure the comment has been published
self.assertEqual(published_comments, 1) self.assertEqual(published_comments, 1)
def test_mark_as_spam(self): def test_mark_as_spam(self):
self.request.set('form.select.BulkAction', 'mark_as_spam') self.request.set('form.select.BulkAction', 'mark_as_spam')
self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())]) self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())])
view = BulkActionsView(self.portal, self.request) view = BulkActionsView(self.portal, self.request)
self.assertRaises(NotImplementedError, self.assertRaises(NotImplementedError,
view) view)
def test_delete(self): def test_delete(self):
# Initially we have three comments # Initially we have three comments
self.assertEqual(self.conversation.total_comments, 3) self.assertEqual(self.conversation.total_comments, 3)
@ -174,14 +177,15 @@ class ModerationBulkActionsViewTest(unittest.TestCase):
self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath()), self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath()),
'/'.join(self.comment3.getPhysicalPath())]) '/'.join(self.comment3.getPhysicalPath())])
view = BulkActionsView(self.app, self.request) view = BulkActionsView(self.app, self.request)
view() view()
# Make sure that the two comments have been deleted # Make sure that the two comments have been deleted
self.assertEqual(self.conversation.total_comments, 1) self.assertEqual(self.conversation.total_comments, 1)
comment = self.conversation.getComments().next() comment = self.conversation.getComments().next()
self.assertTrue(comment) self.assertTrue(comment)
self.assertEqual(comment, self.comment2) self.assertEqual(comment, self.comment2)
def test_suite(): def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__) return unittest.defaultTestLoader.loadTestsFromName(__name__)

View File

@ -24,7 +24,7 @@ from plone.app.discussion.testing import\
class TestUserNotificationUnit(unittest.TestCase): class TestUserNotificationUnit(unittest.TestCase):
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
def setUp(self): def setUp(self):
self.portal = self.layer['portal'] self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager']) setRoles(self.portal, TEST_USER_ID, ['Manager'])
@ -46,16 +46,16 @@ class TestUserNotificationUnit(unittest.TestCase):
self.portal_discussion = self.portal.portal_discussion self.portal_discussion = self.portal.portal_discussion
# Archetypes content types store data as utf-8 encoded strings # Archetypes content types store data as utf-8 encoded strings
# The missing u in front of a string is therefor not missing # 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) self.conversation = IConversation(self.portal.doc1)
def beforeTearDown(self): def beforeTearDown(self):
self.portal.MailHost = self.portal._original_MailHost self.portal.MailHost = self.portal._original_MailHost
sm = getSiteManager(context=self.portal) sm = getSiteManager(context=self.portal)
sm.unregisterUtility(provided=IMailHost) sm.unregisterUtility(provided=IMailHost)
sm.registerUtility(aq_base(self.portal._original_MailHost), sm.registerUtility(aq_base(self.portal._original_MailHost),
provided=IMailHost) provided=IMailHost)
def test_notify_user(self): def test_notify_user(self):
# Add a comment with user notification enabled. Add another comment # Add a comment with user notification enabled. Add another comment
# and make sure an email is send to the user of the first comment. # and make sure an email is send to the user of the first comment.
@ -66,9 +66,9 @@ class TestUserNotificationUnit(unittest.TestCase):
self.conversation.addComment(comment) self.conversation.addComment(comment)
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.text = 'Comment text' comment.text = 'Comment text'
comment_id = self.conversation.addComment(comment) comment_id = self.conversation.addComment(comment)
self.assertEqual(len(self.mailhost.messages), 1) self.assertEqual(len(self.mailhost.messages), 1)
self.assertTrue(self.mailhost.messages[0]) self.assertTrue(self.mailhost.messages[0])
msg = str(self.mailhost.messages[0]) msg = str(self.mailhost.messages[0])
@ -84,13 +84,13 @@ class TestUserNotificationUnit(unittest.TestCase):
"A comment on \'K=C3=B6lle Alaaf\' has been posted here:" "A comment on \'K=C3=B6lle Alaaf\' has been posted here:"
in msg) in msg)
self.assertTrue( self.assertTrue(
"http://nohost/plone/d=\noc1/view#%s" "http://nohost/plone/d=\noc1/view#%s"
% comment_id % comment_id
in msg) in msg)
self.assertTrue('Comment text' in msg) self.assertTrue('Comment text' in msg)
self.assertFalse('Approve comment' in msg) self.assertFalse('Approve comment' in msg)
self.assertFalse('Delete comment' in msg) self.assertFalse('Delete comment' in msg)
def test_do_not_notify_user_when_notification_is_disabled(self): def test_do_not_notify_user_when_notification_is_disabled(self):
registry = queryUtility(IRegistry) registry = queryUtility(IRegistry)
registry['plone.app.discussion.interfaces.IDiscussionSettings.' + registry['plone.app.discussion.interfaces.IDiscussionSettings.' +
@ -102,11 +102,11 @@ class TestUserNotificationUnit(unittest.TestCase):
self.conversation.addComment(comment) self.conversation.addComment(comment)
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.text = 'Comment text' comment.text = 'Comment text'
self.conversation.addComment(comment) self.conversation.addComment(comment)
self.assertEqual(len(self.mailhost.messages), 0) self.assertEqual(len(self.mailhost.messages), 0)
def test_do_not_notify_user_when_email_address_is_given(self): def test_do_not_notify_user_when_email_address_is_given(self):
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.text = 'Comment text' comment.text = 'Comment text'
@ -114,11 +114,11 @@ class TestUserNotificationUnit(unittest.TestCase):
self.conversation.addComment(comment) self.conversation.addComment(comment)
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.text = 'Comment text' comment.text = 'Comment text'
self.conversation.addComment(comment) self.conversation.addComment(comment)
self.assertEqual(len(self.mailhost.messages), 0) self.assertEqual(len(self.mailhost.messages), 0)
def test_do_not_notify_user_when_no_sender_is_available(self): def test_do_not_notify_user_when_no_sender_is_available(self):
# Set sender mail address to none and make sure no email is send to # Set sender mail address to none and make sure no email is send to
# the moderator. # the moderator.
@ -130,11 +130,11 @@ class TestUserNotificationUnit(unittest.TestCase):
self.conversation.addComment(comment) self.conversation.addComment(comment)
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.text = 'Comment text' comment.text = 'Comment text'
self.conversation.addComment(comment) self.conversation.addComment(comment)
self.assertEqual(len(self.mailhost.messages), 0) self.assertEqual(len(self.mailhost.messages), 0)
def test_notify_only_once(self): def test_notify_only_once(self):
# When a user has added two comments in a conversation and has # When a user has added two comments in a conversation and has
# both times requested email notification, do not send him two # both times requested email notification, do not send him two
@ -148,9 +148,9 @@ class TestUserNotificationUnit(unittest.TestCase):
comment.text = 'Comment text' comment.text = 'Comment text'
comment.user_notification = True comment.user_notification = True
comment.author_email = "john@plone.test" comment.author_email = "john@plone.test"
self.conversation.addComment(comment) self.conversation.addComment(comment)
# Note that we might want to get rid of this message, as the # Note that we might want to get rid of this message, as the
# new comment is added by the same user. # new comment is added by the same user.
self.assertEqual(len(self.mailhost.messages), 1) self.assertEqual(len(self.mailhost.messages), 1)
@ -161,7 +161,7 @@ class TestUserNotificationUnit(unittest.TestCase):
class TestModeratorNotificationUnit(unittest.TestCase): class TestModeratorNotificationUnit(unittest.TestCase):
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
def setUp(self): def setUp(self):
self.portal = self.layer['portal'] self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager']) setRoles(self.portal, TEST_USER_ID, ['Manager'])
@ -188,23 +188,23 @@ class TestModeratorNotificationUnit(unittest.TestCase):
self.portal_discussion = self.portal.portal_discussion self.portal_discussion = self.portal.portal_discussion
# Archetypes content types store data as utf-8 encoded strings # Archetypes content types store data as utf-8 encoded strings
# The missing u in front of a string is therefor not missing # 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) self.conversation = IConversation(self.portal.doc1)
def beforeTearDown(self): def beforeTearDown(self):
self.portal.MailHost = self.portal._original_MailHost self.portal.MailHost = self.portal._original_MailHost
sm = getSiteManager(context=self.portal) sm = getSiteManager(context=self.portal)
sm.unregisterUtility(provided=IMailHost) sm.unregisterUtility(provided=IMailHost)
sm.registerUtility(aq_base(self.portal._original_MailHost), sm.registerUtility(aq_base(self.portal._original_MailHost),
provided=IMailHost) provided=IMailHost)
def test_notify_moderator(self): def test_notify_moderator(self):
# Add a comment and make sure an email is send to the moderator. # Add a comment and make sure an email is send to the moderator.
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.text = 'Comment text' comment.text = 'Comment text'
comment_id = self.conversation.addComment(comment) comment_id = self.conversation.addComment(comment)
self.assertEqual(len(self.mailhost.messages), 1) self.assertEqual(len(self.mailhost.messages), 1)
self.assertTrue(self.mailhost.messages[0]) self.assertTrue(self.mailhost.messages[0])
msg = self.mailhost.messages[0] msg = self.mailhost.messages[0]
@ -220,7 +220,7 @@ class TestModeratorNotificationUnit(unittest.TestCase):
"A comment on \'K=C3=B6lle Alaaf\' has been posted here:" "A comment on \'K=C3=B6lle Alaaf\' has been posted here:"
in msg) in msg)
self.assertTrue( self.assertTrue(
"http://nohost/plone/d=\noc1/view#%s" "http://nohost/plone/d=\noc1/view#%s"
% comment_id % comment_id
in msg) in msg)
self.assertTrue('Comment text' in msg) self.assertTrue('Comment text' in msg)
@ -230,7 +230,7 @@ class TestModeratorNotificationUnit(unittest.TestCase):
self.assertTrue( self.assertTrue(
'Delete comment:\nhttp://nohost/plone/doc1/++conversation++default/%s/@@moderat=\ne-delete-comment' 'Delete comment:\nhttp://nohost/plone/doc1/++conversation++default/%s/@@moderat=\ne-delete-comment'
% comment_id in msg) % comment_id in msg)
def test_notify_moderator_specific_address(self): def test_notify_moderator_specific_address(self):
# A moderator email address can be specified in the control panel. # A moderator email address can be specified in the control panel.
registry = queryUtility(IRegistry) registry = queryUtility(IRegistry)
@ -238,27 +238,27 @@ class TestModeratorNotificationUnit(unittest.TestCase):
'.moderator_email'] = 'test@example.com' '.moderator_email'] = 'test@example.com'
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.text = 'Comment text' comment.text = 'Comment text'
self.conversation.addComment(comment) self.conversation.addComment(comment)
self.assertEqual(len(self.mailhost.messages), 1) self.assertEqual(len(self.mailhost.messages), 1)
msg = self.mailhost.messages[0] msg = self.mailhost.messages[0]
if not isinstance(msg, str): if not isinstance(msg, str):
self.assertTrue('test@example.com' in msg.mto) self.assertTrue('test@example.com' in msg.mto)
else: else:
self.assertTrue('To: test@example.com' in msg) self.assertTrue('To: test@example.com' in msg)
def test_do_not_notify_moderator_when_no_sender_is_available(self): def test_do_not_notify_moderator_when_no_sender_is_available(self):
# Set sender mail address to nonw and make sure no email is send to the # Set sender mail address to nonw and make sure no email is send to the
# moderator. # moderator.
self.portal.email_from_address = None self.portal.email_from_address = None
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.text = 'Comment text' comment.text = 'Comment text'
self.conversation.addComment(comment) self.conversation.addComment(comment)
self.assertEqual(len(self.mailhost.messages), 0) self.assertEqual(len(self.mailhost.messages), 0)
def test_do_not_notify_moderator_when_notification_is_disabled(self): def test_do_not_notify_moderator_when_notification_is_disabled(self):
# Disable moderator notification setting and make sure no email is send # Disable moderator notification setting and make sure no email is send
# to the moderator. # to the moderator.
@ -267,10 +267,11 @@ class TestModeratorNotificationUnit(unittest.TestCase):
'moderator_notification_enabled'] = False 'moderator_notification_enabled'] = False
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.text = 'Comment text' comment.text = 'Comment text'
self.conversation.addComment(comment) self.conversation.addComment(comment)
self.assertEqual(len(self.mailhost.messages), 0) self.assertEqual(len(self.mailhost.messages), 0)
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.permissions import View
from plone.app.testing import TEST_USER_ID, setRoles from plone.app.testing import TEST_USER_ID, setRoles
from plone.app.testing import logout, login from plone.app.testing import logout, login
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.interfaces import IConversation, IDiscussionLayer from plone.app.discussion.interfaces import IConversation, IDiscussionLayer
@ -105,7 +106,7 @@ class CommentOneStateWorkflowTest(unittest.TestCase):
self.portal = self.layer['portal'] self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager']) setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.portal.invokeFactory('Folder', 'test-folder') self.portal.invokeFactory('Folder', 'test-folder')
self.folder = self.portal['test-folder'] self.folder = self.portal['test-folder']
self.catalog = self.portal.portal_catalog self.catalog = self.portal.portal_catalog
self.workflow = self.portal.portal_workflow self.workflow = self.portal.portal_workflow
self.workflow.setChainForPortalTypes(['Document'], self.workflow.setChainForPortalTypes(['Document'],
@ -125,7 +126,7 @@ class CommentOneStateWorkflowTest(unittest.TestCase):
self.portal.acl_users._doAddUser('member', 'secret', ['Member'], []) self.portal.acl_users._doAddUser('member', 'secret', ['Member'], [])
self.portal.acl_users._doAddUser('reviewer', 'secret', ['Reviewer'], []) self.portal.acl_users._doAddUser('reviewer', 'secret', ['Reviewer'], [])
self.portal.acl_users._doAddUser('manager', 'secret', ['Manager'], []) self.portal.acl_users._doAddUser('manager', 'secret', ['Manager'], [])
self.portal.acl_users._doAddUser('editor' , ' secret', ['Editor'],[]) self.portal.acl_users._doAddUser('editor', ' secret', ['Editor'], [])
self.portal.acl_users._doAddUser('reader', 'secret', ['Reader'], []) self.portal.acl_users._doAddUser('reader', 'secret', ['Reader'], [])
def test_initial_workflow_state(self): def test_initial_workflow_state(self):
@ -163,12 +164,11 @@ class CommentReviewWorkflowTest(unittest.TestCase):
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
def setUp(self): def setUp(self):
self.portal = self.layer['portal'] self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager']) setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.portal.invokeFactory('Folder', 'test-folder') self.portal.invokeFactory('Folder', 'test-folder')
self.folder = self.portal['test-folder'] self.folder = self.portal['test-folder']
# Allow discussion on the Document content type # Allow discussion on the Document content type
self.portal.portal_types['Document'].allow_discussion = True self.portal.portal_types['Document'].allow_discussion = True