Conversation indexers won't work on old discussion items. Fix tests.
svn path=/plone.app.discussion/trunk/; revision=30658
This commit is contained in:
parent
d8d57d3b7a
commit
1ea36d7d82
@ -22,16 +22,26 @@ MAX_DESCRIPTION=25
|
|||||||
|
|
||||||
@indexer(IContentish, IZCatalog)
|
@indexer(IContentish, IZCatalog)
|
||||||
def total_comments(object):
|
def total_comments(object):
|
||||||
|
# Total number of comments on a conversation
|
||||||
|
# Indexers won't work on old discussion items
|
||||||
|
if object.meta_type != 'Discussion Item':
|
||||||
|
|
||||||
conversation = IConversation(object)
|
conversation = IConversation(object)
|
||||||
return conversation.total_comments
|
return conversation.total_comments
|
||||||
|
|
||||||
@indexer(IContentish, IZCatalog)
|
@indexer(IContentish, IZCatalog)
|
||||||
def last_comment_date(object):
|
def last_comment_date(object):
|
||||||
|
# Date of the latest comment on a conversation
|
||||||
|
# Indexers won't work on old discussion items
|
||||||
|
if object.meta_type != 'Discussion Item':
|
||||||
conversation = IConversation(object)
|
conversation = IConversation(object)
|
||||||
return conversation.last_comment_date
|
return conversation.last_comment_date
|
||||||
|
|
||||||
@indexer(IContentish, IZCatalog)
|
@indexer(IContentish, IZCatalog)
|
||||||
def commentators(object):
|
def commentators(object):
|
||||||
|
# List of commentators on a conversation
|
||||||
|
# Indexers won't work on old discussion items
|
||||||
|
if object.meta_type != 'Discussion Item':
|
||||||
conversation = IConversation(object)
|
conversation = IConversation(object)
|
||||||
return tuple(conversation.commentators.keys())
|
return tuple(conversation.commentators.keys())
|
||||||
|
|
||||||
|
@ -57,22 +57,19 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
new_comment1_id = conversation.addComment(comment1)
|
new_comment1_id = conversation.addComment(comment1)
|
||||||
self.comment_id = new_comment1_id
|
self.comment_id = new_comment1_id
|
||||||
|
|
||||||
comment1 = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_comment1_id)
|
|
||||||
comment1.reindexObject()
|
|
||||||
|
|
||||||
brains = self.catalog.searchResults(
|
brains = self.catalog.searchResults(
|
||||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||||
portal_type = "Document"
|
portal_type = "Document"
|
||||||
)
|
)
|
||||||
self.brains = brains
|
|
||||||
self.conversation = conversation
|
self.conversation = conversation
|
||||||
self.conversation_brain = brains[0]
|
self.brains = brains
|
||||||
|
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.failUnless(self.conversation_brain.has_key('total_comments'))
|
self.failUnless(self.doc1_brain.has_key('total_comments'))
|
||||||
self.assertEquals(self.conversation_brain.total_comments, 1)
|
self.assertEquals(self.doc1_brain.total_comments, 1)
|
||||||
|
|
||||||
comment2 = createObject('plone.Comment')
|
comment2 = createObject('plone.Comment')
|
||||||
comment2.title = 'Comment 2'
|
comment2.title = 'Comment 2'
|
||||||
@ -86,12 +83,12 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||||
portal_type = "Document"
|
portal_type = "Document"
|
||||||
)
|
)
|
||||||
conversation_brain = brains[0]
|
doc1_brain = brains[0]
|
||||||
self.assertEquals(conversation_brain.total_comments, 2)
|
self.assertEquals(doc1_brain.total_comments, 2)
|
||||||
|
|
||||||
def test_last_comment_date(self):
|
def test_last_comment_date(self):
|
||||||
self.failUnless(self.conversation_brain.has_key('last_comment_date'))
|
self.failUnless(self.doc1_brain.has_key('last_comment_date'))
|
||||||
self.assertEquals(self.conversation_brain.last_comment_date, datetime(2006, 9, 17, 14, 18, 12))
|
self.assertEquals(self.doc1_brain.last_comment_date, 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')
|
||||||
@ -108,8 +105,8 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||||
portal_type = "Document"
|
portal_type = "Document"
|
||||||
)
|
)
|
||||||
conversation_brain = brains[0]
|
doc1_brain = brains[0]
|
||||||
self.assertEquals(conversation_brain.last_comment_date, datetime(2009, 9, 17, 14, 18, 12))
|
self.assertEquals(doc1_brain.last_comment_date, 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]
|
||||||
@ -118,9 +115,9 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||||
portal_type = "Document"
|
portal_type = "Document"
|
||||||
)
|
)
|
||||||
conversation_brain = brains[0]
|
doc1_brain = brains[0]
|
||||||
|
|
||||||
self.assertEquals(conversation_brain.last_comment_date, datetime(2006, 9, 17, 14, 18, 12))
|
self.assertEquals(doc1_brain.last_comment_date, 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]
|
||||||
@ -128,12 +125,12 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||||
portal_type = "Document"
|
portal_type = "Document"
|
||||||
)
|
)
|
||||||
conversation_brain = brains[0]
|
doc1_brain = brains[0]
|
||||||
self.assertEquals(conversation_brain.last_comment_date, None)
|
self.assertEquals(doc1_brain.last_comment_date, None)
|
||||||
|
|
||||||
def test_commentators(self):
|
def test_commentators(self):
|
||||||
self.failUnless(self.conversation_brain.has_key('commentators'))
|
self.failUnless(self.doc1_brain.has_key('commentators'))
|
||||||
self.assertEquals(self.conversation_brain.commentators, ('Jim',))
|
self.assertEquals(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')
|
||||||
@ -150,9 +147,9 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||||
portal_type = "Document"
|
portal_type = "Document"
|
||||||
)
|
)
|
||||||
conversation_brain = brains[0]
|
doc1_brain = brains[0]
|
||||||
|
|
||||||
self.assertEquals(conversation_brain.commentators, ('Emma', 'Jim'))
|
self.assertEquals(doc1_brain.commentators, ('Emma', 'Jim'))
|
||||||
|
|
||||||
# remove one comments
|
# remove one comments
|
||||||
del self.conversation[new_comment2_id]
|
del self.conversation[new_comment2_id]
|
||||||
@ -160,8 +157,8 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||||
portal_type = "Document"
|
portal_type = "Document"
|
||||||
)
|
)
|
||||||
conversation_brain = brains[0]
|
doc1_brain = brains[0]
|
||||||
self.assertEquals(conversation_brain.commentators, ('Jim',))
|
self.assertEquals(doc1_brain.commentators, ('Jim',))
|
||||||
|
|
||||||
# remove all comments
|
# remove all comments
|
||||||
del self.conversation[self.new_comment1_id]
|
del self.conversation[self.new_comment1_id]
|
||||||
@ -169,8 +166,8 @@ class ConversationCatalogTest(PloneTestCase):
|
|||||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||||
portal_type = "Document"
|
portal_type = "Document"
|
||||||
)
|
)
|
||||||
conversation_brain = brains[0]
|
doc1_brain = brains[0]
|
||||||
self.assertEquals(conversation_brain.commentators, ())
|
self.assertEquals(doc1_brain.commentators, ())
|
||||||
|
|
||||||
def test_conversation_indexes_not_in_comments(self):
|
def test_conversation_indexes_not_in_comments(self):
|
||||||
brains = self.catalog.searchResults(
|
brains = self.catalog.searchResults(
|
||||||
|
Loading…
Reference in New Issue
Block a user