2010-08-28 19:06:53 +02:00
|
|
|
"""Test for the plone.app.discussion indexers
|
|
|
|
"""
|
|
|
|
|
2011-04-16 11:35:34 +02:00
|
|
|
import unittest2 as unittest
|
2009-05-18 17:15:36 +02:00
|
|
|
|
2010-07-13 12:45:53 +02:00
|
|
|
from datetime import datetime
|
2009-06-02 01:17:13 +02:00
|
|
|
from DateTime import DateTime
|
|
|
|
|
2009-05-31 19:55:46 +02:00
|
|
|
from zope.component import createObject
|
|
|
|
|
2011-04-16 11:35:34 +02:00
|
|
|
from plone.app.testing import TEST_USER_ID, setRoles
|
|
|
|
|
|
|
|
from plone.app.discussion.testing import \
|
|
|
|
PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
2009-05-18 17:15:36 +02:00
|
|
|
|
2009-05-31 19:55:46 +02:00
|
|
|
from plone.app.discussion.interfaces import IConversation
|
2009-05-31 21:07:35 +02:00
|
|
|
|
|
|
|
from plone.indexer.delegate import DelegatingIndexerFactory
|
2009-05-31 19:55:46 +02:00
|
|
|
|
2009-06-02 01:17:13 +02:00
|
|
|
from plone.app.discussion import catalog
|
2009-05-31 19:55:46 +02:00
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
LONG_TEXT = """Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
|
|
|
|
diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
|
|
|
|
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
|
|
|
|
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit
|
2010-08-28 19:06:53 +02:00
|
|
|
amet."""
|
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
LONG_TEXT_CUT = """Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
|
|
|
|
diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
|
2010-08-28 19:06:53 +02:00
|
|
|
sed diam voluptua. At [...]"""
|
|
|
|
|
2009-07-01 22:57:55 +02:00
|
|
|
|
2011-04-16 11:35:34 +02:00
|
|
|
class ConversationIndexersTest(unittest.TestCase):
|
2010-08-28 19:06:53 +02:00
|
|
|
"""Conversation Indexer Tests
|
|
|
|
"""
|
2009-07-01 22:57:55 +02:00
|
|
|
|
2011-04-16 11:35:34 +02:00
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.portal = self.layer['portal']
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
2009-07-01 22:57:55 +02:00
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
self.portal.invokeFactory(id='doc1',
|
|
|
|
title='Document 1',
|
2010-09-29 09:56:36 +02:00
|
|
|
type_name='Document')
|
2009-07-01 22:57:55 +02:00
|
|
|
|
|
|
|
# Create a conversation.
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
|
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
comment1.text = 'Comment Text'
|
|
|
|
comment1.creator = "Jim"
|
|
|
|
comment1.author_username = "Jim"
|
|
|
|
comment1.creation_date = datetime(2006, 9, 17, 14, 18, 12)
|
|
|
|
comment1.modification_date = datetime(2006, 9, 17, 14, 18, 12)
|
|
|
|
self.new_id1 = conversation.addComment(comment1)
|
|
|
|
|
|
|
|
comment2 = createObject('plone.Comment')
|
|
|
|
comment2.text = 'Comment Text'
|
|
|
|
comment2.creator = "Emma"
|
|
|
|
comment2.author_username = "Emma"
|
|
|
|
comment2.creation_date = datetime(2007, 12, 13, 4, 18, 12)
|
|
|
|
comment2.modification_date = datetime(2007, 12, 13, 4, 18, 12)
|
|
|
|
self.new_id2 = conversation.addComment(comment2)
|
|
|
|
|
|
|
|
comment3 = createObject('plone.Comment')
|
|
|
|
comment3.text = 'Comment Text'
|
|
|
|
comment3.creator = "Lukas"
|
|
|
|
comment3.author_username = "Lukas"
|
|
|
|
comment3.creation_date = datetime(2009, 4, 12, 11, 12, 12)
|
|
|
|
comment3.modification_date = datetime(2009, 4, 12, 11, 12, 12)
|
|
|
|
self.new_id3 = conversation.addComment(comment3)
|
|
|
|
|
|
|
|
self.conversation = conversation
|
|
|
|
|
|
|
|
def test_conversation_total_comments(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(isinstance(catalog.total_comments,
|
2010-08-28 19:06:53 +02:00
|
|
|
DelegatingIndexerFactory))
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(catalog.total_comments(self.portal.doc1)(), 3)
|
2009-07-01 22:57:55 +02:00
|
|
|
del self.conversation[self.new_id1]
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(catalog.total_comments(self.portal.doc1)(), 2)
|
2009-07-01 22:57:55 +02:00
|
|
|
del self.conversation[self.new_id2]
|
|
|
|
del self.conversation[self.new_id3]
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(catalog.total_comments(self.portal.doc1)(), 0)
|
2009-07-01 22:57:55 +02:00
|
|
|
|
|
|
|
def test_conversation_last_comment_date(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(isinstance(catalog.last_comment_date,
|
2010-08-28 19:06:53 +02:00
|
|
|
DelegatingIndexerFactory))
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(catalog.last_comment_date(self.portal.doc1)(),
|
2010-08-28 19:06:53 +02:00
|
|
|
datetime(2009, 4, 12, 11, 12, 12))
|
2009-07-01 22:57:55 +02:00
|
|
|
del self.conversation[self.new_id3]
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(catalog.last_comment_date(self.portal.doc1)(),
|
2010-08-28 19:06:53 +02:00
|
|
|
datetime(2007, 12, 13, 4, 18, 12))
|
2009-07-01 22:57:55 +02:00
|
|
|
del self.conversation[self.new_id2]
|
|
|
|
del self.conversation[self.new_id1]
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(catalog.last_comment_date(self.portal.doc1)(), None)
|
2009-07-01 22:57:55 +02:00
|
|
|
|
|
|
|
def test_conversation_commentators(self):
|
|
|
|
pass
|
2011-04-15 18:23:38 +02:00
|
|
|
#self.assertEqual(catalog.commentators(self.portal.doc1)(),
|
2010-08-28 19:06:53 +02:00
|
|
|
# ('Jim', 'Emma', 'Lukas'))
|
2011-04-15 18:23:38 +02:00
|
|
|
#self.assertTrue(isinstance(catalog.commentators,
|
2010-08-28 19:06:53 +02:00
|
|
|
# DelegatingIndexerFactory))
|
2009-07-01 22:57:55 +02:00
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2011-04-16 11:35:34 +02:00
|
|
|
class CommentIndexersTest(unittest.TestCase):
|
|
|
|
|
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.portal = self.layer['portal']
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
2009-05-18 17:15:36 +02:00
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
self.portal.invokeFactory(id='doc1',
|
|
|
|
title='Document 1',
|
|
|
|
type_name='Document')
|
2009-05-31 19:55:46 +02:00
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
# Add a comment. Note: in real life, we always create comments via the
|
2010-08-28 19:06:53 +02:00
|
|
|
# factory to allow different factories to be swapped in
|
2009-05-31 19:55:46 +02:00
|
|
|
|
|
|
|
comment = createObject('plone.Comment')
|
2009-07-01 12:01:37 +02:00
|
|
|
comment.text = 'Lorem ipsum dolor sit amet.'
|
2009-06-02 01:45:49 +02:00
|
|
|
comment.creator = "Jim"
|
|
|
|
comment.creation_date = datetime(2006, 9, 17, 14, 18, 12)
|
|
|
|
comment.modification_date = datetime(2008, 3, 12, 7, 32, 52)
|
2009-05-31 19:55:46 +02:00
|
|
|
|
2010-08-28 19:06:53 +02:00
|
|
|
self.comment_id = conversation.addComment(comment)
|
2009-10-16 14:11:58 +02:00
|
|
|
self.comment = comment.__of__(conversation)
|
2009-07-01 12:01:37 +02:00
|
|
|
self.conversation = conversation
|
2009-05-31 21:07:35 +02:00
|
|
|
|
2009-06-02 01:45:49 +02:00
|
|
|
def test_title(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(catalog.title(self.comment)(), 'Jim on Document 1')
|
|
|
|
self.assertTrue(isinstance(catalog.title, DelegatingIndexerFactory))
|
2009-06-02 01:45:49 +02:00
|
|
|
|
|
|
|
def test_description(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(catalog.description(self.comment)(),
|
2010-08-28 19:06:53 +02:00
|
|
|
'Lorem ipsum dolor sit amet.')
|
2012-01-14 07:13:39 +01:00
|
|
|
self.assertTrue(
|
|
|
|
isinstance(catalog.description, DelegatingIndexerFactory))
|
2009-07-01 12:01:37 +02:00
|
|
|
|
|
|
|
def test_description_long(self):
|
2009-06-01 11:59:07 +02:00
|
|
|
# Create a 50 word comment and make sure the description returns
|
|
|
|
# only the first 25 words
|
2009-07-01 12:01:37 +02:00
|
|
|
comment_long = createObject('plone.Comment')
|
|
|
|
comment_long.title = 'Long Comment'
|
2010-08-28 19:06:53 +02:00
|
|
|
comment_long.text = LONG_TEXT
|
2009-07-01 12:01:37 +02:00
|
|
|
|
2010-07-13 12:45:53 +02:00
|
|
|
self.conversation.addComment(comment_long)
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(catalog.description(comment_long)(),
|
2010-12-16 00:52:56 +01:00
|
|
|
LONG_TEXT_CUT.replace("\n", " "))
|
2009-05-31 19:55:46 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_dates(self):
|
2009-06-02 01:17:13 +02:00
|
|
|
# Test if created, modified, effective etc. are set correctly
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(catalog.created(self.comment)(),
|
2011-04-02 23:26:36 +02:00
|
|
|
DateTime(2006, 9, 17, 14, 18, 12, 'GMT'))
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(catalog.effective(self.comment)(),
|
2011-04-02 23:26:36 +02:00
|
|
|
DateTime(2006, 9, 17, 14, 18, 12, 'GMT'))
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(catalog.modified(self.comment)(),
|
2011-04-02 23:26:36 +02:00
|
|
|
DateTime(2008, 3, 12, 7, 32, 52, 'GMT'))
|
2009-05-18 17:15:36 +02:00
|
|
|
|
|
|
|
def test_searchable_text(self):
|
2009-06-02 01:45:49 +02:00
|
|
|
# Test if searchable text is a concatenation of title and comment text
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(catalog.searchable_text(self.comment)(),
|
2010-09-29 09:56:36 +02:00
|
|
|
('Lorem ipsum dolor sit amet.'))
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(isinstance(catalog.searchable_text,
|
2010-08-28 19:06:53 +02:00
|
|
|
DelegatingIndexerFactory))
|
2009-05-18 17:15:36 +02:00
|
|
|
|
|
|
|
def test_creator(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(catalog.creator(self.comment)(), ('Jim'))
|
2009-05-31 19:55:46 +02:00
|
|
|
|
2009-07-03 10:03:09 +02:00
|
|
|
def test_in_response_to(self):
|
|
|
|
# make sure in_response_to returns the title or id of the content
|
|
|
|
# object the comment was added to
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(catalog.in_response_to(self.comment)(), 'Document 1')
|
2009-05-31 19:55:46 +02:00
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_suite():
|
2010-08-28 19:06:53 +02:00
|
|
|
return unittest.defaultTestLoader.loadTestsFromName(__name__)
|