Remove portal_discussion tool.
This commit is contained in:
		
							parent
							
								
									3eae5378ff
								
							
						
					
					
						commit
						fbc78e2951
					
				
							
								
								
									
										10
									
								
								CHANGES.rst
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								CHANGES.rst
									
									
									
									
									
								
							@ -4,14 +4,20 @@ Changelog
 | 
			
		||||
2.3.0 (unreleased)
 | 
			
		||||
------------------
 | 
			
		||||
 | 
			
		||||
- Refactor tests to use the PLONE_APP_CONTENTTYPES_FIXTURE instead of the PLONE_FIXTURE.
 | 
			
		||||
- Remove portal_discussion tool.
 | 
			
		||||
  [timo]
 | 
			
		||||
 | 
			
		||||
- Refactor tests to use the PLONE_APP_CONTENTTYPES_FIXTURE instead of
 | 
			
		||||
  PLONE_FIXTURE.
 | 
			
		||||
  [timo]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
2.2.10 (2013-09-24)
 | 
			
		||||
-------------------
 | 
			
		||||
 | 
			
		||||
- Revert "Refactor tests to use the PLONE_APP_CONTENTTYPES_FIXTURE instead of the PLONE_FIXTURE." that has been accidentially introduced into the 2.2.9 release.
 | 
			
		||||
- Revert "Refactor tests to use the PLONE_APP_CONTENTTYPES_FIXTURE instead of
 | 
			
		||||
  the PLONE_FIXTURE." that has been accidentially introduced into the 2.2.9
 | 
			
		||||
  release.
 | 
			
		||||
  [timo]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -184,38 +184,6 @@ class ICaptcha(Interface):
 | 
			
		||||
                              required=False)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ICommentingTool(Interface):
 | 
			
		||||
    """A tool that indexes all comments for usage by the management interface.
 | 
			
		||||
 | 
			
		||||
    This means the management interface can still work even though we don't
 | 
			
		||||
    index the comments in portal_catalog.
 | 
			
		||||
 | 
			
		||||
    The default implementation of this interface simply defers to
 | 
			
		||||
    portal_catalog, but a custom version of the tool can be used to provide
 | 
			
		||||
    an alternate indexing mechanism.
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    def indexObject(comment):
 | 
			
		||||
        """Indexes a comment
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
    def reindexObject(comment):
 | 
			
		||||
        """Reindex a comment
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
    def unindexObject(comment):
 | 
			
		||||
        """Removes a comment from the indexes
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
    def uniqueValuesFor(name):
 | 
			
		||||
        """Get unique values for FieldIndex name
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
    def searchResults(REQUEST=None, **kw):
 | 
			
		||||
        """Perform a search over all indexed comments.
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class IDiscussionSettings(Interface):
 | 
			
		||||
    """Global discussion settings. This describes records stored in the
 | 
			
		||||
    configuration registry and obtainable via plone.registry.
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,5 @@
 | 
			
		||||
from Products.CMFCore.utils import getToolByName
 | 
			
		||||
 | 
			
		||||
from zope.component import queryUtility
 | 
			
		||||
 | 
			
		||||
from Acquisition import aq_inner, aq_parent
 | 
			
		||||
@ -8,7 +10,6 @@ from Products.CMFPlone.utils import base_hasattr
 | 
			
		||||
from Products.CMFPlone.utils import safe_callable
 | 
			
		||||
 | 
			
		||||
from plone.app.discussion.conversation import ANNOTATION_KEY
 | 
			
		||||
from plone.app.discussion.interfaces import ICommentingTool
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def patchedClearFindAndRebuild(self):
 | 
			
		||||
@ -26,14 +27,14 @@ def patchedClearFindAndRebuild(self):
 | 
			
		||||
                obj.indexObject()
 | 
			
		||||
 | 
			
		||||
                annotions = IAnnotations(obj)
 | 
			
		||||
                ctool = queryUtility(ICommentingTool)
 | 
			
		||||
                catalog = getToolByName(obj, "portal_catalog")
 | 
			
		||||
                if ANNOTATION_KEY in annotions:
 | 
			
		||||
                    conversation = annotions[ANNOTATION_KEY]
 | 
			
		||||
                    conversation = conversation.__of__(obj)
 | 
			
		||||
                    for comment in conversation.getComments():
 | 
			
		||||
                        try:
 | 
			
		||||
                            if ctool:
 | 
			
		||||
                                ctool.indexObject(comment)
 | 
			
		||||
                            if catalog:
 | 
			
		||||
                                catalog.indexObject(comment)
 | 
			
		||||
                        except StopIteration:  # pragma: no cover
 | 
			
		||||
                            pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,9 +0,0 @@
 | 
			
		||||
<?xml version="1.0"?>
 | 
			
		||||
<componentregistry>
 | 
			
		||||
 <utilities>
 | 
			
		||||
  <utility
 | 
			
		||||
      interface="plone.app.discussion.interfaces.ICommentingTool"
 | 
			
		||||
      object="portal_discussion"
 | 
			
		||||
      />
 | 
			
		||||
 </utilities>
 | 
			
		||||
</componentregistry>
 | 
			
		||||
@ -1,5 +0,0 @@
 | 
			
		||||
<?xml version="1.0"?>
 | 
			
		||||
<tool-setup>
 | 
			
		||||
 <required tool_id="portal_discussion"
 | 
			
		||||
           class="plone.app.discussion.tool.CommentingTool"/>
 | 
			
		||||
</tool-setup>
 | 
			
		||||
							
								
								
									
										14
									
								
								plone/app/discussion/subscribers.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								plone/app/discussion/subscribers.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
			
		||||
from Products.CMFCore.utils import getToolByName
 | 
			
		||||
 | 
			
		||||
def index_object(obj, event):
 | 
			
		||||
    """Index the object when it is added to the conversation.
 | 
			
		||||
    """
 | 
			
		||||
    catalog = getToolByName(obj, 'portal_catalog')
 | 
			
		||||
    return catalog.reindexObject(obj)
 | 
			
		||||
 | 
			
		||||
def unindex_object(obj, event):
 | 
			
		||||
    """Unindex the object when it is removed from the conversation.
 | 
			
		||||
    """
 | 
			
		||||
    catalog = getToolByName(obj, 'portal_catalog')
 | 
			
		||||
    return catalog.unindexObject(obj)
 | 
			
		||||
 | 
			
		||||
@ -24,13 +24,13 @@
 | 
			
		||||
    <subscriber
 | 
			
		||||
        for="plone.app.discussion.interfaces.IComment
 | 
			
		||||
             zope.lifecycleevent.interfaces.IObjectAddedEvent"
 | 
			
		||||
        handler=".tool.index_object"
 | 
			
		||||
        handler=".subscribers.index_object"
 | 
			
		||||
        />
 | 
			
		||||
 | 
			
		||||
    <subscriber
 | 
			
		||||
        for="plone.app.discussion.interfaces.IComment
 | 
			
		||||
             zope.lifecycleevent.interfaces.IObjectRemovedEvent"
 | 
			
		||||
        handler=".tool.unindex_object"
 | 
			
		||||
        handler=".subscribers.unindex_object"
 | 
			
		||||
        />
 | 
			
		||||
 | 
			
		||||
    <subscriber
 | 
			
		||||
 | 
			
		||||
@ -459,6 +459,9 @@ class CommentCatalogTest(unittest.TestCase):
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_clear_and_rebuild_catalog(self):
 | 
			
		||||
        brains = self.catalog.searchResults({'portal_type': 'Discussion Item'})
 | 
			
		||||
        self.assertTrue(brains)
 | 
			
		||||
 | 
			
		||||
        # Clear and rebuild catalog
 | 
			
		||||
        self.catalog.clearFindAndRebuild()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -61,12 +61,7 @@ class TestCommentForm(unittest.TestCase):
 | 
			
		||||
        typetool.constructContent('Document', self.portal, 'doc1')
 | 
			
		||||
        wftool = getToolByName(self.portal, "portal_workflow")
 | 
			
		||||
        wftool.doActionFor(self.portal.doc1, action='publish')
 | 
			
		||||
        self.discussionTool = getToolByName(
 | 
			
		||||
            self.portal,
 | 
			
		||||
            'portal_discussion',
 | 
			
		||||
            None
 | 
			
		||||
        )
 | 
			
		||||
        self.discussionTool.overrideDiscussionFor(self.portal.doc1, False)
 | 
			
		||||
        self.portal.doc1.allow_discussion = True
 | 
			
		||||
        self.membershipTool = getToolByName(self.folder, 'portal_membership')
 | 
			
		||||
        self.memberdata = self.portal.portal_memberdata
 | 
			
		||||
        self.context = getattr(self.portal, 'doc1')
 | 
			
		||||
@ -81,7 +76,7 @@ class TestCommentForm(unittest.TestCase):
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
        # Allow discussion
 | 
			
		||||
        self.discussionTool.overrideDiscussionFor(self.portal.doc1, True)
 | 
			
		||||
        self.portal.doc1.allow_discussion = True
 | 
			
		||||
        self.viewlet = CommentsViewlet(self.context, self.request, None, None)
 | 
			
		||||
 | 
			
		||||
        def make_request(form={}):
 | 
			
		||||
@ -126,7 +121,7 @@ class TestCommentForm(unittest.TestCase):
 | 
			
		||||
        self.assertFalse(commentForm.handleComment(commentForm, "foo"))
 | 
			
		||||
 | 
			
		||||
    def test_add_anonymous_comment(self):
 | 
			
		||||
        self.discussionTool.overrideDiscussionFor(self.portal.doc1, True)
 | 
			
		||||
        self.portal.doc1.allow_discussion = True
 | 
			
		||||
 | 
			
		||||
        self.viewlet = CommentsViewlet(self.context, self.request, None, None)
 | 
			
		||||
 | 
			
		||||
@ -169,7 +164,10 @@ class TestCommentForm(unittest.TestCase):
 | 
			
		||||
        """Make sure that comments can't be posted if discussion is disabled.
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
        # Discussion is disabled by default
 | 
			
		||||
        # Disable discussion
 | 
			
		||||
        registry = queryUtility(IRegistry)
 | 
			
		||||
        settings = registry.forInterface(IDiscussionSettings)
 | 
			
		||||
        settings.globally_enabled = False
 | 
			
		||||
 | 
			
		||||
        def make_request(form={}):
 | 
			
		||||
            request = TestRequest()
 | 
			
		||||
@ -195,6 +193,7 @@ class TestCommentForm(unittest.TestCase):
 | 
			
		||||
        # No form errors, but raise unauthorized because discussion is not
 | 
			
		||||
        # allowed
 | 
			
		||||
        self.assertEqual(len(errors), 0)
 | 
			
		||||
 | 
			
		||||
        self.assertRaises(Unauthorized,
 | 
			
		||||
                          commentForm.handleComment,
 | 
			
		||||
                          commentForm,
 | 
			
		||||
@ -257,11 +256,6 @@ class TestCommentsViewlet(unittest.TestCase):
 | 
			
		||||
 | 
			
		||||
        typetool = self.portal.portal_types
 | 
			
		||||
        typetool.constructContent('Document', self.portal, 'doc1')
 | 
			
		||||
        self.portal_discussion = getToolByName(
 | 
			
		||||
            self.portal,
 | 
			
		||||
            'portal_discussion',
 | 
			
		||||
            None
 | 
			
		||||
        )
 | 
			
		||||
        self.membershipTool = getToolByName(self.folder, 'portal_membership')
 | 
			
		||||
        self.memberdata = self.portal.portal_memberdata
 | 
			
		||||
        context = getattr(self.portal, 'doc1')
 | 
			
		||||
@ -311,8 +305,7 @@ class TestCommentsViewlet(unittest.TestCase):
 | 
			
		||||
        # By default, discussion is disabled
 | 
			
		||||
        self.assertFalse(self.viewlet.is_discussion_allowed())
 | 
			
		||||
        # Enable discussion
 | 
			
		||||
        portal_discussion = getToolByName(self.portal, 'portal_discussion')
 | 
			
		||||
        portal_discussion.overrideDiscussionFor(self.portal.doc1, True)
 | 
			
		||||
        self.portal.doc1.allow_discussion = True
 | 
			
		||||
        # Test if discussion has been enabled
 | 
			
		||||
        self.assertTrue(self.viewlet.is_discussion_allowed())
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -313,7 +313,7 @@ class ConversationTest(unittest.TestCase):
 | 
			
		||||
        conversation = self.portal.f1.restrictedTraverse('@@conversation_view')
 | 
			
		||||
 | 
			
		||||
        # Allow discussion for the folder
 | 
			
		||||
        self.portal_discussion.overrideDiscussionFor(f1, True)
 | 
			
		||||
        self.portal.f1.allow_discussion = True
 | 
			
		||||
 | 
			
		||||
        # Allow discussion on Folder content type
 | 
			
		||||
        portal_types = getToolByName(self.portal, 'portal_types')
 | 
			
		||||
@ -334,12 +334,12 @@ class ConversationTest(unittest.TestCase):
 | 
			
		||||
        self.assertEqual(conversation.enabled(), False)
 | 
			
		||||
 | 
			
		||||
        # Allow discussion on content object
 | 
			
		||||
        self.portal_discussion.overrideDiscussionFor(self.portal.doc1, True)
 | 
			
		||||
        self.portal.doc1.allow_discussion = True
 | 
			
		||||
 | 
			
		||||
        # Check if discussion is now allowed on the content object
 | 
			
		||||
        self.assertEqual(conversation.enabled(), True)
 | 
			
		||||
 | 
			
		||||
        self.portal_discussion.overrideDiscussionFor(self.portal.doc1, False)
 | 
			
		||||
        self.portal.doc1.allow_discussion = False
 | 
			
		||||
        self.assertEqual(conversation.enabled(), False)
 | 
			
		||||
 | 
			
		||||
    def test_dict_operations(self):
 | 
			
		||||
 | 
			
		||||
@ -1,328 +0,0 @@
 | 
			
		||||
from datetime import datetime
 | 
			
		||||
from DateTime import DateTime
 | 
			
		||||
 | 
			
		||||
import unittest2 as unittest
 | 
			
		||||
 | 
			
		||||
from zope.annotation.interfaces import IAnnotations
 | 
			
		||||
 | 
			
		||||
from Products.CMFCore.utils import getToolByName
 | 
			
		||||
 | 
			
		||||
from plone.app.testing import TEST_USER_ID, setRoles
 | 
			
		||||
 | 
			
		||||
from plone.app.discussion.testing import (
 | 
			
		||||
    PLONE_APP_DISCUSSION_INTEGRATION_TESTING
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
from plone.app.discussion.browser.migration import View
 | 
			
		||||
 | 
			
		||||
from plone.app.discussion.interfaces import IConversation, IComment
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class MigrationTest(unittest.TestCase):
 | 
			
		||||
 | 
			
		||||
    layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
 | 
			
		||||
 | 
			
		||||
    def _publish(self, reply):
 | 
			
		||||
        # publish the reply
 | 
			
		||||
        status = self.portal.portal_workflow.getStatusOf(
 | 
			
		||||
            'comment_review_workflow', reply
 | 
			
		||||
        ).copy()
 | 
			
		||||
        status['review_state'] = 'published'
 | 
			
		||||
        self.portal.portal_workflow.setStatusOf(
 | 
			
		||||
            'comment_review_workflow',
 | 
			
		||||
            reply,
 | 
			
		||||
            status,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.portal = self.layer['portal']
 | 
			
		||||
        self.request = self.layer['request']
 | 
			
		||||
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
 | 
			
		||||
 | 
			
		||||
        self.portal.invokeFactory(
 | 
			
		||||
            id='doc',
 | 
			
		||||
            title='Document 1',
 | 
			
		||||
            type_name='Document'
 | 
			
		||||
        )
 | 
			
		||||
        # Create a document
 | 
			
		||||
        self.discussion = getToolByName(self.portal, 'portal_discussion', None)
 | 
			
		||||
        self.discussion.overrideDiscussionFor(self.portal.doc, 1)
 | 
			
		||||
        # Publish it
 | 
			
		||||
        self.workflowTool = getToolByName(self.portal, 'portal_workflow')
 | 
			
		||||
        self.workflowTool.setDefaultChain('simple_publication_workflow')
 | 
			
		||||
        self.workflowTool.doActionFor(self.portal.doc, 'publish')
 | 
			
		||||
 | 
			
		||||
        self.request.set("test", True)
 | 
			
		||||
        self.view = View(self.portal, self.request)
 | 
			
		||||
        self.workflowTool.setChainForPortalTypes(
 | 
			
		||||
            ('Discussion Item',),
 | 
			
		||||
            'comment_review_workflow'
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        # Create a user Jimmy Jones so comments creator migration can work?
 | 
			
		||||
        acl_users = getToolByName(self.portal, 'acl_users')
 | 
			
		||||
        acl_users.userFolderAddUser('Jim', 'secret', ['Member'], [])
 | 
			
		||||
        mt = getToolByName(self.portal, 'portal_membership')
 | 
			
		||||
        member = mt.getMemberById('Jim')
 | 
			
		||||
        member.fullname = 'Jimmy Jones'
 | 
			
		||||
 | 
			
		||||
        self.doc = self.portal.doc
 | 
			
		||||
 | 
			
		||||
    def test_migrate_comment(self):
 | 
			
		||||
 | 
			
		||||
        # Create a comment
 | 
			
		||||
        talkback = self.discussion.getDiscussionFor(self.doc)
 | 
			
		||||
        self.doc.talkback.createReply('My Title', 'My Text', Creator='Jim')
 | 
			
		||||
        reply = talkback.getReplies()[0]
 | 
			
		||||
        reply.setReplyTo(self.doc)
 | 
			
		||||
        reply.creation_date = DateTime(2003, 3, 11, 9, 28, 6, 'GMT')
 | 
			
		||||
        reply.modification_date = DateTime(2009, 7, 12, 19, 38, 7, 'GMT')
 | 
			
		||||
 | 
			
		||||
        self._publish(reply)
 | 
			
		||||
        self.assertEqual(reply.Title(), 'My Title')
 | 
			
		||||
        self.assertEqual(reply.EditableBody(), 'My Text')
 | 
			
		||||
        self.assertTrue('Jim' in reply.listCreators())
 | 
			
		||||
        self.assertEqual(talkback.replyCount(self.doc), 1)
 | 
			
		||||
        self.assertEqual(reply.inReplyTo(), self.doc)
 | 
			
		||||
 | 
			
		||||
        # Call migration script
 | 
			
		||||
        self.view()
 | 
			
		||||
 | 
			
		||||
        # Make sure a conversation has been created
 | 
			
		||||
        self.assertTrue(
 | 
			
		||||
            'plone.app.discussion:conversation' in IAnnotations(self.doc)
 | 
			
		||||
        )
 | 
			
		||||
        conversation = IConversation(self.doc)
 | 
			
		||||
 | 
			
		||||
        # Check migration
 | 
			
		||||
        self.assertEqual(conversation.total_comments, 1)
 | 
			
		||||
        self.assertTrue(conversation.getComments().next())
 | 
			
		||||
        comment1 = conversation.values()[0]
 | 
			
		||||
        self.assertTrue(IComment.providedBy(comment1))
 | 
			
		||||
        self.assertEqual(comment1.Title(), 'My Title')
 | 
			
		||||
        self.assertEqual(comment1.text, '<p>My Text</p>\n')
 | 
			
		||||
        self.assertEqual(comment1.mime_type, 'text/html')
 | 
			
		||||
        self.assertEqual(comment1.Creator(), 'Jim')
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            comment1.creation_date,
 | 
			
		||||
            datetime(2003, 3, 11, 9, 28, 6)
 | 
			
		||||
        )
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            comment1.modification_date,
 | 
			
		||||
            datetime(2009, 7, 12, 19, 38, 7)
 | 
			
		||||
        )
 | 
			
		||||
        self.assertEqual([
 | 
			
		||||
            {'comment': comment1, 'depth': 0, 'id': long(comment1.id)}
 | 
			
		||||
        ], list(conversation.getThreads()))
 | 
			
		||||
        self.assertFalse(self.doc.talkback)
 | 
			
		||||
 | 
			
		||||
    def test_migrate_comment_with_creator(self):
 | 
			
		||||
        # Create a comment
 | 
			
		||||
        talkback = self.discussion.getDiscussionFor(self.doc)
 | 
			
		||||
        self.doc.talkback.createReply('My Title', 'My Text', Creator='Jim')
 | 
			
		||||
        reply = talkback.getReplies()[0]
 | 
			
		||||
        reply.setReplyTo(self.doc)
 | 
			
		||||
        reply.creation_date = DateTime(2003, 3, 11, 9, 28, 6, 'GMT')
 | 
			
		||||
        reply.modification_date = DateTime(2009, 7, 12, 19, 38, 7, 'GMT')
 | 
			
		||||
        reply.author_username = 'Jim'
 | 
			
		||||
        reply.email = 'jimmy@jones.xyz'
 | 
			
		||||
 | 
			
		||||
        self._publish(reply)
 | 
			
		||||
        self.assertEqual(reply.Title(), 'My Title')
 | 
			
		||||
        self.assertEqual(reply.EditableBody(), 'My Text')
 | 
			
		||||
        self.assertTrue('Jim' in reply.listCreators())
 | 
			
		||||
        self.assertEqual(talkback.replyCount(self.doc), 1)
 | 
			
		||||
        self.assertEqual(reply.inReplyTo(), self.doc)
 | 
			
		||||
        self.assertEqual(reply.author_username, 'Jim')
 | 
			
		||||
        self.assertEqual(reply.email, 'jimmy@jones.xyz')
 | 
			
		||||
 | 
			
		||||
        # Call migration script
 | 
			
		||||
        self.view()
 | 
			
		||||
 | 
			
		||||
        # Make sure a conversation has been created
 | 
			
		||||
        self.assertTrue(
 | 
			
		||||
            'plone.app.discussion:conversation' in IAnnotations(self.doc)
 | 
			
		||||
        )
 | 
			
		||||
        conversation = IConversation(self.doc)
 | 
			
		||||
 | 
			
		||||
        # Check migration
 | 
			
		||||
        self.assertEqual(conversation.total_comments, 1)
 | 
			
		||||
        self.assertTrue(conversation.getComments().next())
 | 
			
		||||
        comment1 = conversation.values()[0]
 | 
			
		||||
        self.assertTrue(IComment.providedBy(comment1))
 | 
			
		||||
        self.assertEqual(comment1.Title(), 'My Title')
 | 
			
		||||
        self.assertEqual(comment1.text, '<p>My Text</p>\n')
 | 
			
		||||
        self.assertEqual(comment1.mime_type, 'text/html')
 | 
			
		||||
        self.assertEqual(comment1.Creator(), 'Jim')
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            comment1.creation_date,
 | 
			
		||||
            datetime(2003, 3, 11, 9, 28, 6)
 | 
			
		||||
        )
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            comment1.modification_date,
 | 
			
		||||
            datetime(2009, 7, 12, 19, 38, 7)
 | 
			
		||||
        )
 | 
			
		||||
        self.assertEqual([
 | 
			
		||||
            {'comment': comment1, 'depth': 0, 'id': long(comment1.id)}
 | 
			
		||||
        ], list(conversation.getThreads()))
 | 
			
		||||
        self.assertFalse(self.doc.talkback)
 | 
			
		||||
 | 
			
		||||
        # Though this should be Jimmy, but looks like getProperty won't pick
 | 
			
		||||
        # up 'author_username' (reply.author_username is not None), so it's
 | 
			
		||||
        # propagating Creator()..?
 | 
			
		||||
        self.assertEqual(comment1.author_username, 'Jim')
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(comment1.author_name, 'Jimmy Jones')
 | 
			
		||||
        self.assertEqual(comment1.author_email, 'jimmy@jones.xyz')
 | 
			
		||||
 | 
			
		||||
    def test_migrate_nested_comments(self):
 | 
			
		||||
        # Create some nested comments and migrate them
 | 
			
		||||
        #
 | 
			
		||||
        # self.doc
 | 
			
		||||
        # +- First comment
 | 
			
		||||
        #    +- Re: First comment
 | 
			
		||||
        #       + Re: Re: First comment
 | 
			
		||||
        #         + Re: Re: Re: First comment
 | 
			
		||||
        #    +- Re: First comment (2)
 | 
			
		||||
        #    +- Re: First comment (3)
 | 
			
		||||
        #    +- Re: First comment (4)
 | 
			
		||||
        # +- Second comment
 | 
			
		||||
 | 
			
		||||
        talkback = self.discussion.getDiscussionFor(self.doc)
 | 
			
		||||
 | 
			
		||||
        # First comment
 | 
			
		||||
        talkback.createReply(title='First comment',
 | 
			
		||||
                             text='This is my first comment.')
 | 
			
		||||
        comment1 = talkback.getReplies()[0]
 | 
			
		||||
        self._publish(comment1)
 | 
			
		||||
 | 
			
		||||
        talkback_comment1 = self.discussion.getDiscussionFor(comment1)
 | 
			
		||||
 | 
			
		||||
        # Re: First comment
 | 
			
		||||
        talkback_comment1.createReply(title='Re: First comment',
 | 
			
		||||
                                      text='This is my first reply.')
 | 
			
		||||
        comment1_1 = talkback_comment1.getReplies()[0]
 | 
			
		||||
        self._publish(comment1_1)
 | 
			
		||||
 | 
			
		||||
        talkback_comment1_1 = self.discussion.getDiscussionFor(comment1_1)
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(len(talkback.getReplies()), 1)
 | 
			
		||||
        self.assertEqual(len(talkback_comment1.getReplies()), 1)
 | 
			
		||||
        self.assertEqual(len(talkback_comment1_1.getReplies()), 0)
 | 
			
		||||
 | 
			
		||||
        #Re: Re: First comment
 | 
			
		||||
        talkback_comment1_1.createReply(title='Re: Re: First comment',
 | 
			
		||||
                                        text='This is my first re-reply.')
 | 
			
		||||
        comment1_1_1 = talkback_comment1_1.getReplies()[0]
 | 
			
		||||
        self._publish(comment1_1_1)
 | 
			
		||||
 | 
			
		||||
        talkback_comment1_1_1 = self.discussion.getDiscussionFor(comment1_1_1)
 | 
			
		||||
 | 
			
		||||
        # Re: Re: Re: First comment
 | 
			
		||||
        talkback_comment1_1_1.createReply(title='Re: Re: Re: First comment',
 | 
			
		||||
                                          text='This is my first re-re-reply.')
 | 
			
		||||
        self._publish(talkback_comment1_1_1.getReplies()[0])
 | 
			
		||||
 | 
			
		||||
        # Re: First comment (2)
 | 
			
		||||
        talkback_comment1.createReply(title='Re: First comment (2)',
 | 
			
		||||
                                      text='This is my first reply (2).')
 | 
			
		||||
        self._publish(talkback_comment1.getReplies()[1])
 | 
			
		||||
 | 
			
		||||
        # Re: First comment (3)
 | 
			
		||||
        talkback_comment1.createReply(title='Re: First comment (3)',
 | 
			
		||||
                                      text='This is my first reply (3).')
 | 
			
		||||
        self._publish(talkback_comment1.getReplies()[2])
 | 
			
		||||
 | 
			
		||||
        # Re: First comment (4)
 | 
			
		||||
        talkback_comment1.createReply(title='Re: First comment (4)',
 | 
			
		||||
                                      text='This is my first reply (4).')
 | 
			
		||||
        self._publish(talkback_comment1.getReplies()[3])
 | 
			
		||||
 | 
			
		||||
        # Second comment
 | 
			
		||||
        talkback.createReply(title='Second comment',
 | 
			
		||||
                             text='This is my second comment.')
 | 
			
		||||
        self._publish(talkback.getReplies()[1])
 | 
			
		||||
 | 
			
		||||
        # Call migration script
 | 
			
		||||
        self.view()
 | 
			
		||||
 | 
			
		||||
        # Check migration
 | 
			
		||||
        conversation = IConversation(self.doc)
 | 
			
		||||
        self.assertEqual(conversation.total_comments, 8)
 | 
			
		||||
 | 
			
		||||
        comment1 = conversation.values()[0]
 | 
			
		||||
        comment1_1 = conversation.values()[1]
 | 
			
		||||
        comment1_1_1 = conversation.values()[2]
 | 
			
		||||
        comment1_1_1_1 = conversation.values()[3]
 | 
			
		||||
        comment1_2 = conversation.values()[4]
 | 
			
		||||
        comment1_3 = conversation.values()[5]
 | 
			
		||||
        comment1_4 = conversation.values()[6]
 | 
			
		||||
        comment2 = conversation.values()[7]
 | 
			
		||||
 | 
			
		||||
        self.assertEqual([
 | 
			
		||||
            {'comment': comment1, 'depth': 0, 'id': long(comment1.id)},
 | 
			
		||||
            {'comment': comment1_1, 'depth': 1, 'id': long(comment1_1.id)},
 | 
			
		||||
            {'comment': comment1_1_1, 'depth': 2, 'id': long(comment1_1_1.id)},
 | 
			
		||||
            {'comment': comment1_1_1_1, 'depth': 3,
 | 
			
		||||
             'id': long(comment1_1_1_1.id)},
 | 
			
		||||
            {'comment': comment1_2, 'depth': 1, 'id': long(comment1_2.id)},
 | 
			
		||||
            {'comment': comment1_3, 'depth': 1, 'id': long(comment1_3.id)},
 | 
			
		||||
            {'comment': comment1_4, 'depth': 1, 'id': long(comment1_4.id)},
 | 
			
		||||
            {'comment': comment2, 'depth': 0, 'id': long(comment2.id)},
 | 
			
		||||
        ], list(conversation.getThreads()))
 | 
			
		||||
 | 
			
		||||
        talkback = self.discussion.getDiscussionFor(self.doc)
 | 
			
		||||
        self.assertEqual(len(talkback.getReplies()), 0)
 | 
			
		||||
 | 
			
		||||
    def test_migrate_nested_comments_with_filter(self):
 | 
			
		||||
        # Create some nested comments and migrate them.
 | 
			
		||||
        # But use a filter that filters the top-level comment.
 | 
			
		||||
        # All the comments should be removed, but not migrated.
 | 
			
		||||
        #
 | 
			
		||||
        # self.doc
 | 
			
		||||
        # +- First comment
 | 
			
		||||
        #    +- Re: First comment
 | 
			
		||||
 | 
			
		||||
        talkback = self.discussion.getDiscussionFor(self.doc)
 | 
			
		||||
 | 
			
		||||
        # First comment
 | 
			
		||||
        talkback.createReply(title='First comment',
 | 
			
		||||
                             text='This is my first comment.')
 | 
			
		||||
        comment1 = talkback.getReplies()[0]
 | 
			
		||||
        talkback_comment1 = self.discussion.getDiscussionFor(comment1)
 | 
			
		||||
 | 
			
		||||
        # Re: First comment
 | 
			
		||||
        talkback_comment1.createReply(title='Re: First comment',
 | 
			
		||||
                                      text='This is my first reply.')
 | 
			
		||||
        comment1_1 = talkback_comment1.getReplies()[0]
 | 
			
		||||
        talkback_comment1_1 = self.discussion.getDiscussionFor(comment1_1)
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(len(talkback.getReplies()), 1)
 | 
			
		||||
        self.assertEqual(len(talkback_comment1.getReplies()), 1)
 | 
			
		||||
        self.assertEqual(len(talkback_comment1_1.getReplies()), 0)
 | 
			
		||||
 | 
			
		||||
        def deny_comments(reply):
 | 
			
		||||
            return False
 | 
			
		||||
 | 
			
		||||
        # Call migration script
 | 
			
		||||
        self.view(filter_callback=deny_comments)
 | 
			
		||||
 | 
			
		||||
        # Check migration
 | 
			
		||||
        conversation = IConversation(self.doc)
 | 
			
		||||
        self.assertEqual(conversation.total_comments, 0)
 | 
			
		||||
        talkback = self.discussion.getDiscussionFor(self.doc)
 | 
			
		||||
        self.assertEqual(len(talkback.getReplies()), 0)
 | 
			
		||||
 | 
			
		||||
    def test_migrate_no_comment(self):
 | 
			
		||||
 | 
			
		||||
        # Call migration script
 | 
			
		||||
        self.view()
 | 
			
		||||
 | 
			
		||||
        # Make sure no conversation has been created
 | 
			
		||||
        self.assertTrue(
 | 
			
		||||
            'plone.app.discussion:conversation' not in IAnnotations(self.doc)
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_suite():
 | 
			
		||||
    return unittest.defaultTestLoader.loadTestsFromName(__name__)
 | 
			
		||||
@ -58,29 +58,6 @@ class ModerationViewTest(unittest.TestCase):
 | 
			
		||||
                                            ('comment_review_workflow,'))
 | 
			
		||||
        self.assertEqual(self.view.moderation_enabled(), True)
 | 
			
		||||
 | 
			
		||||
    def test_old_comments_not_shown_in_moderation_view(self):
 | 
			
		||||
        # Create old comment
 | 
			
		||||
        discussion = getToolByName(self.portal, 'portal_discussion', None)
 | 
			
		||||
        discussion.overrideDiscussionFor(self.portal.doc1, 1)
 | 
			
		||||
        talkback = discussion.getDiscussionFor(self.portal.doc1)
 | 
			
		||||
        self.portal.doc1.talkback.createReply('My Title',
 | 
			
		||||
                                              'My Text',
 | 
			
		||||
                                              Creator='Jim')
 | 
			
		||||
        reply = talkback.getReplies()[0]
 | 
			
		||||
        reply.setReplyTo(self.portal.doc1)
 | 
			
		||||
        reply.creation_date = DateTime(2003, 3, 11, 9, 28, 6)
 | 
			
		||||
        reply.modification_date = DateTime(2009, 7, 12, 19, 38, 7)
 | 
			
		||||
        self.assertEqual(reply.Title(), 'My Title')
 | 
			
		||||
        self.assertEqual(reply.EditableBody(), 'My Text')
 | 
			
		||||
        self.assertTrue('Jim' in reply.listCreators())
 | 
			
		||||
        self.assertEqual(talkback.replyCount(self.portal.doc1), 1)
 | 
			
		||||
        self.assertEqual(reply.inReplyTo(), self.portal.doc1)
 | 
			
		||||
 | 
			
		||||
        view = self.view()
 | 
			
		||||
 | 
			
		||||
        self.assertTrue('No comments to moderate' in view)
 | 
			
		||||
        self.assertEqual(len(self.view.comments), 0)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ModerationBulkActionsViewTest(unittest.TestCase):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -42,7 +42,6 @@ class TestUserNotificationUnit(unittest.TestCase):
 | 
			
		||||
                 '.user_notification_enabled'] = True
 | 
			
		||||
        # Create test content
 | 
			
		||||
        self.portal.invokeFactory('Document', 'doc1')
 | 
			
		||||
        self.portal_discussion = self.portal.portal_discussion
 | 
			
		||||
        # Archetypes content types store data as utf-8 encoded strings
 | 
			
		||||
        # The missing u in front of a string is therefor not missing
 | 
			
		||||
        self.portal.doc1.title = 'Kölle Alaaf'  # What is "Fasching"?
 | 
			
		||||
@ -189,7 +188,6 @@ class TestModeratorNotificationUnit(unittest.TestCase):
 | 
			
		||||
        ] = True
 | 
			
		||||
        # Create test content
 | 
			
		||||
        self.portal.invokeFactory('Document', 'doc1')
 | 
			
		||||
        self.portal_discussion = self.portal.portal_discussion
 | 
			
		||||
        # Archetypes content types store data as utf-8 encoded strings
 | 
			
		||||
        # The missing u in front of a string is therefor not missing
 | 
			
		||||
        self.portal.doc1.title = 'Kölle Alaaf'  # What is "Fasching"?
 | 
			
		||||
 | 
			
		||||
@ -1,56 +0,0 @@
 | 
			
		||||
import unittest2 as unittest
 | 
			
		||||
 | 
			
		||||
from zope.component import queryUtility, createObject
 | 
			
		||||
 | 
			
		||||
from plone.app.testing import TEST_USER_ID, setRoles
 | 
			
		||||
 | 
			
		||||
from plone.app.discussion.testing import \
 | 
			
		||||
    PLONE_APP_DISCUSSION_INTEGRATION_TESTING
 | 
			
		||||
 | 
			
		||||
from plone.app.discussion.interfaces import ICommentingTool, IConversation
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ToolTest(unittest.TestCase):
 | 
			
		||||
 | 
			
		||||
    layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
 | 
			
		||||
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.portal = self.layer['portal']
 | 
			
		||||
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
 | 
			
		||||
        self.portal.invokeFactory(id='doc1',
 | 
			
		||||
                                  title='Document 1',
 | 
			
		||||
                                  type_name='Document')
 | 
			
		||||
 | 
			
		||||
    def test_tool_indexing(self):
 | 
			
		||||
        # Create a conversation. In this case we doesn't assign it to an
 | 
			
		||||
        # object, as we just want to check the Conversation object API.
 | 
			
		||||
        conversation = IConversation(self.portal.doc1)
 | 
			
		||||
 | 
			
		||||
        # Add a comment.
 | 
			
		||||
        comment = createObject('plone.Comment')
 | 
			
		||||
        comment.creator = 'jim'
 | 
			
		||||
        comment.author_name = "Jim"
 | 
			
		||||
        comment.text = 'Comment text'
 | 
			
		||||
 | 
			
		||||
        conversation.addComment(comment)
 | 
			
		||||
 | 
			
		||||
        # Check that the comment got indexed in the tool:
 | 
			
		||||
        tool = queryUtility(ICommentingTool)
 | 
			
		||||
        comment = list(tool.searchResults())
 | 
			
		||||
        self.assertTrue(
 | 
			
		||||
            len(comment) == 1,
 | 
			
		||||
            "There is only one comment, but we got"
 | 
			
		||||
            " %s results in the search" % len(comment)
 | 
			
		||||
        )
 | 
			
		||||
        self.assertEqual(comment[0].Title, 'Jim on Document 1')
 | 
			
		||||
 | 
			
		||||
    def test_unindexing(self):
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
    def test_search(self):
 | 
			
		||||
        # search returns only comments
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_suite():
 | 
			
		||||
    return unittest.defaultTestLoader.loadTestsFromName(__name__)
 | 
			
		||||
@ -32,7 +32,6 @@ class WorkflowSetupTest(unittest.TestCase):
 | 
			
		||||
        self.portal.invokeFactory('Folder', 'test-folder')
 | 
			
		||||
        self.folder = self.portal['test-folder']
 | 
			
		||||
        self.portal.portal_types['Document'].allow_discussion = True
 | 
			
		||||
        self.portal_discussion = self.portal.portal_discussion
 | 
			
		||||
        self.folder.invokeFactory('Document', 'doc1')
 | 
			
		||||
        self.doc = self.folder.doc1
 | 
			
		||||
 | 
			
		||||
@ -190,7 +189,6 @@ class CommentReviewWorkflowTest(unittest.TestCase):
 | 
			
		||||
 | 
			
		||||
        # Create a Document
 | 
			
		||||
        self.portal.invokeFactory('Document', 'doc1')
 | 
			
		||||
        self.portal_discussion = self.portal.portal_discussion
 | 
			
		||||
 | 
			
		||||
        # Create a conversation for this Document
 | 
			
		||||
        conversation = IConversation(self.portal.doc1)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user