[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TopicIndex/test - testTopicIndex.py:1.1.2.1
Andreas Jung
andreas@zope.com
Mon, 15 Oct 2001 14:17:29 -0400
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TopicIndex/test
In directory cvs.zope.org:/tmp/cvs-serv16237/TopicIndex/test
Added Files:
Tag: ajung-topicindex
testTopicIndex.py
Log Message:
=== Added File Zope/lib/python/Products/PluginIndexes/TopicIndex/test/testTopicIndex.py ===
import os,sys,re,unittest
execfile(os.path.join(sys.path[0],'framework.py'))
from Products.PluginIndexes.TopicIndex.TopicIndex import TopicIndex
class Obj:
def __init__(self,meta_type=''):
self.meta_type = meta_type
class TestTopicIndex(unittest.TestCase):
def setUp(self):
self.TI = TopicIndex("topicIndex")
self.TI.addFilteredSet("doc1","meta_type=='doc1'")
self.TI.addFilteredSet("doc2","meta_type=='doc2'")
self.TI.index_object(0 , Obj())
self.TI.index_object(1 , Obj('doc1'))
self.TI.index_object(2 , Obj('doc1'))
self.TI.index_object(3 , Obj('doc2'))
self.TI.index_object(4 , Obj('doc2'))
self.TI.index_object(5 , Obj('doc3'))
self.TI.index_object(6 , Obj('doc3'))
def testOr(self):
""" test 1 """
self._searchOr('doc1')
self._searchOr(['doc1'])
self._searchOr('doc2')
self._searchOr(['doc2'])
self._searchOr('doc2')
self._searchOr(['doc1','doc2'])
def testAnd(self):
""" test 1 """
self._searchAnd('doc1')
self._searchAnd(['doc1'])
self._searchAnd('doc2')
self._searchAnd(['doc2'])
self._searchAnd('doc2')
self._searchAnd(['doc1','doc2'])
def _searchAnd(self,query):
return self._search(query,'and')
def _searchOr(self,query):
return self._search(query,'or')
def _search(self,query,operator):
res = self.TI._apply_index({'topicIndex':{'query':query,'operator':operator}})
print 'query: %s (%s), result: %s' % (query,operator,res)
return res
framework()