2009-05-18 17:15:36 +02:00
import unittest
2009-06-02 01:17:13 +02:00
from datetime import datetime , timedelta
from DateTime import DateTime
2009-05-31 19:55:46 +02:00
from zope . component import createObject
2009-05-18 17:15:36 +02:00
from Products . PloneTestCase . ptc import PloneTestCase
from plone . app . discussion . tests . layer import DiscussionLayer
2009-05-31 19:55:46 +02:00
from plone . app . discussion . interfaces import IConversation
2009-05-31 21:07:35 +02:00
2009-05-31 19:55:46 +02:00
from plone . indexer import indexer
2009-05-31 21:07:35 +02:00
from plone . indexer . delegate import DelegatingIndexerFactory
2009-05-31 19:55:46 +02:00
from zope . component import provideAdapter
2009-06-02 01:17:13 +02:00
from plone . app . discussion import catalog
2009-05-31 19:55:46 +02:00
class IndexersTest ( PloneTestCase ) :
2009-05-18 17:15:36 +02:00
layer = DiscussionLayer
2009-05-31 19:55:46 +02:00
def afterSetUp ( self ) :
# First we need to create some content.
self . loginAsPortalOwner ( )
typetool = self . portal . portal_types
typetool . constructContent ( ' Document ' , self . portal , ' doc1 ' )
# 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 )
# Pretend that we have traversed to the comment by aq wrapping it.
conversation = conversation . __of__ ( self . portal . doc1 )
# Add a comment. Note: in real life, we always create comments via the factory
# to allow different factories to be swapped in
comment = createObject ( ' plone.Comment ' )
comment . title = ' Comment 1 '
2009-06-02 01:45:49 +02:00
comment . 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 amet. '
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
new_id = conversation . addComment ( comment )
2009-05-31 21:07:35 +02:00
2009-06-02 01:45:49 +02:00
self . comment_id = new_id
self . comment = comment
2009-05-31 21:07:35 +02:00
2009-06-02 01:45:49 +02:00
def test_title ( self ) :
self . assertEquals ( catalog . title ( self . comment ) ( ) , ' Comment 1 ' )
self . assert_ ( isinstance ( catalog . title , DelegatingIndexerFactory ) )
def test_description ( 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-06-02 01:45:49 +02:00
self . assertEquals ( catalog . description ( self . comment ) ( ) , ' 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... ' )
self . assert_ ( isinstance ( catalog . description , DelegatingIndexerFactory ) )
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
2009-06-02 01:45:49 +02:00
self . assertEquals ( catalog . created ( self . comment ) ( ) , DateTime ( 2006 , 9 , 17 , 14 , 18 , 12 ) )
self . assertEquals ( catalog . modified ( self . comment ) ( ) , DateTime ( 2008 , 3 , 12 , 7 , 32 , 52 ) )
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
self . assertEquals ( catalog . searchable_text ( self . comment ) ( ) , ( ' Comment 1 ' , ' 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 amet. ' ) )
self . assert_ ( isinstance ( catalog . searchable_text , DelegatingIndexerFactory ) )
2009-05-18 17:15:36 +02:00
def test_creator ( self ) :
2009-06-02 01:45:49 +02:00
self . assertEquals ( catalog . creator ( self . comment ) ( ) , ( ' Jim ' ) )
2009-05-31 19:55:46 +02:00
2009-05-18 17:15:36 +02:00
def test_in_reply_to ( self ) :
pass
2009-05-31 19:55:46 +02:00
2009-05-18 17:15:36 +02:00
def test_review_state ( self ) :
pass
2009-05-31 19:55:46 +02:00
2009-05-18 17:15:36 +02:00
def test_object_provides ( self ) :
pass
2009-05-31 19:55:46 +02:00
2009-05-18 17:15:36 +02:00
def test_suite ( ) :
return unittest . defaultTestLoader . loadTestsFromName ( __name__ )