Use plone.app.testing in test_catalog.
svn path=/plone.app.discussion/trunk/; revision=48897
This commit is contained in:
parent
4110b41ae6
commit
e5d45dbd78
@ -1,6 +1,6 @@
|
|||||||
"""Test the plone.app.discussion catalog indexes
|
"""Test the plone.app.discussion catalog indexes
|
||||||
"""
|
"""
|
||||||
import unittest
|
import unittest2 as unittest
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
@ -9,17 +9,20 @@ from zope.annotation.interfaces import IAnnotations
|
|||||||
|
|
||||||
from Products.CMFCore.utils import getToolByName
|
from Products.CMFCore.utils import getToolByName
|
||||||
|
|
||||||
from Products.PloneTestCase.ptc import PloneTestCase
|
from plone.app.testing import TEST_USER_ID, setRoles
|
||||||
|
|
||||||
from plone.app.discussion.tests.layer import DiscussionLayer
|
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
|
||||||
|
|
||||||
|
|
||||||
class CatalogSetupTest(PloneTestCase):
|
class CatalogSetupTest(unittest.TestCase):
|
||||||
|
|
||||||
layer = DiscussionLayer
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
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())
|
||||||
@ -29,7 +32,7 @@ class CatalogSetupTest(PloneTestCase):
|
|||||||
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')
|
||||||
@ -39,21 +42,19 @@ class CatalogSetupTest(PloneTestCase):
|
|||||||
self.fail()
|
self.fail()
|
||||||
|
|
||||||
|
|
||||||
class ConversationCatalogTest(PloneTestCase):
|
class ConversationCatalogTest(unittest.TestCase):
|
||||||
|
|
||||||
layer = DiscussionLayer
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||||
|
|
||||||
def afterSetUp(self):
|
def setUp(self):
|
||||||
# First we need to create some content.
|
self.portal = self.layer['portal']
|
||||||
self.loginAsPortalOwner()
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
||||||
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')
|
||||||
comment1.title = 'Comment 1'
|
comment1.title = 'Comment 1'
|
||||||
comment1.text = 'Comment text'
|
comment1.text = 'Comment text'
|
||||||
@ -75,17 +76,17 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
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()
|
||||||
@ -96,12 +97,12 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
))
|
))
|
||||||
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'
|
||||||
@ -110,7 +111,7 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
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()
|
||||||
@ -122,20 +123,19 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
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()) },
|
||||||
portal_type="Document"
|
portal_type="Document"
|
||||||
))
|
))
|
||||||
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(
|
||||||
@ -145,11 +145,11 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
))
|
))
|
||||||
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'
|
||||||
@ -157,20 +157,20 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
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(
|
||||||
@ -180,7 +180,7 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
))
|
))
|
||||||
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(
|
||||||
@ -190,7 +190,7 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
))
|
))
|
||||||
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':
|
||||||
@ -203,28 +203,27 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
self.assertEqual(comment1_brain.total_comments, None)
|
self.assertEqual(comment1_brain.total_comments, None)
|
||||||
|
|
||||||
|
|
||||||
class CommentCatalogTest(PloneTestCase):
|
class CommentCatalogTest(unittest.TestCase):
|
||||||
|
|
||||||
layer = DiscussionLayer
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||||
|
|
||||||
def afterSetUp(self):
|
def setUp(self):
|
||||||
"""Create a document with a comment.
|
self.portal = self.layer['portal']
|
||||||
"""
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
||||||
self.loginAsPortalOwner()
|
|
||||||
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)
|
||||||
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)
|
||||||
@ -368,13 +367,13 @@ class CommentCatalogTest(PloneTestCase):
|
|||||||
self.assertEqual(len(topic.queryCatalog()), 1)
|
self.assertEqual(len(topic.queryCatalog()), 1)
|
||||||
|
|
||||||
|
|
||||||
class NoConversationCatalogTest(PloneTestCase):
|
class NoConversationCatalogTest(unittest.TestCase):
|
||||||
|
|
||||||
layer = DiscussionLayer
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||||
|
|
||||||
def afterSetUp(self):
|
def setUp(self):
|
||||||
# First we need to create some content.
|
self.portal = self.layer['portal']
|
||||||
self.loginAsPortalOwner()
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
||||||
self.portal.invokeFactory(id='doc1',
|
self.portal.invokeFactory(id='doc1',
|
||||||
Title='Document 1',
|
Title='Document 1',
|
||||||
type_name='Document')
|
type_name='Document')
|
||||||
|
Loading…
Reference in New Issue
Block a user