Commit c5e35d7a authored by 's avatar

- added test to verify the interface

- synced interface and help file with implementation
parent 41e836ec
...@@ -228,25 +228,25 @@ class IZCatalog(Interface): ...@@ -228,25 +228,25 @@ class IZCatalog(Interface):
queries (even across catalogs) and merge and sort the combined results. queries (even across catalogs) and merge and sort the combined results.
""" """
def refreshCatalog(clear=0, REQUEST=None, pghandler=None): def refreshCatalog(clear=0, pghandler=None):
"""Reindex every object we can find, removing the unreachable """Reindex every object we can find, removing the unreachable
ones from the index. ones from the index.
clear -- values: 1|0 clear the catalog before reindexing clear -- values: 1|0 clear the catalog before reindexing
REQUEST -- optional REQUEST object pghandler -- optional Progresshandler as defined in ProgressHandler.py
(see also README.txt)
pghandler -- optional Progresshandler as defined in ProgressHandler.py
(see also README.txt)
""" """
def reindexIndex(name, pghandler=None): def reindexIndex(name, REQUEST, pghandler=None):
"""Reindex a single index. """Reindex a single index.
name -- id of index name -- id of index
pghandler -- optional Progresshandler as defined in ProgressHandler.py REQUEST -- REQUEST object
(see also README.txt)
pghandler -- optional Progresshandler as defined in ProgressHandler.py
(see also README.txt)
""" """
__doc__ = IZCatalog.__doc__ + __doc__ __doc__ = IZCatalog.__doc__ + __doc__
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
...@@ -229,7 +229,23 @@ class ZCatalog: ...@@ -229,7 +229,23 @@ class ZCatalog:
queries (even across catalogs) and merge and sort the combined results. queries (even across catalogs) and merge and sort the combined results.
""" """
def refreshCatalog(): def refreshCatalog(clear=0, pghandler=None):
"""Reindex every object we can find, removing the unreachable """Reindex every object we can find, removing the unreachable
ones from the index. ones from the index.
clear -- values: 1|0 clear the catalog before reindexing
pghandler -- optional Progresshandler as defined in ProgressHandler.py
(see also README.txt)
"""
def reindexIndex(name, REQUEST, pghandler=None):
"""Reindex a single index.
name -- id of index
REQUEST -- REQUEST object
pghandler -- optional Progresshandler as defined in ProgressHandler.py
(see also README.txt)
""" """
#!/usr/bin/env python, unittest ##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
""" Unittests for Catalog.
$Id:$
"""
# Unittests for Catalog
import os
import random
import unittest import unittest
import Testing
import Zope
Zope.startup()
from Interface.Verify import verifyClass
from itertools import chain from itertools import chain
import random
import ZODB, OFS.Application
from ZODB.DemoStorage import DemoStorage
from ZODB.DB import DB
from Products import ZCatalog
from Products.ZCatalog import ZCatalog,Vocabulary
from Products.ZCatalog.Catalog import Catalog, CatalogError
import ExtensionClass import ExtensionClass
import OFS.Application
from Products.ZCatalog import Vocabulary
from Products.ZCatalog.Catalog import Catalog
from Products.ZCatalog.Catalog import CatalogError
from ZODB.DB import DB
from ZODB.DemoStorage import DemoStorage
from Products.PluginIndexes.FieldIndex.FieldIndex import FieldIndex from Products.PluginIndexes.FieldIndex.FieldIndex import FieldIndex
from Products.PluginIndexes.TextIndex.TextIndex import TextIndex
from Products.PluginIndexes.TextIndex.Lexicon import Lexicon
from Products.PluginIndexes.KeywordIndex.KeywordIndex import KeywordIndex from Products.PluginIndexes.KeywordIndex.KeywordIndex import KeywordIndex
from Products.PluginIndexes.TextIndex.Lexicon import Lexicon
from Products.PluginIndexes.TextIndex.TextIndex import TextIndex
def createDatabase(): def createDatabase():
...@@ -129,7 +146,8 @@ class zdummy(ExtensionClass.Base): ...@@ -129,7 +146,8 @@ class zdummy(ExtensionClass.Base):
class TestZCatalog(unittest.TestCase): class TestZCatalog(unittest.TestCase):
def setUp(self): def setUp(self):
self._catalog = ZCatalog.ZCatalog('Catalog') from Products.ZCatalog.ZCatalog import ZCatalog
self._catalog = ZCatalog('Catalog')
self._catalog.resolve_path = self._resolve_num self._catalog.resolve_path = self._resolve_num
self._catalog.addIndex('title', 'KeywordIndex') self._catalog.addIndex('title', 'KeywordIndex')
self._catalog.addColumn('title') self._catalog.addColumn('title')
...@@ -184,6 +202,13 @@ class TestZCatalog(unittest.TestCase): ...@@ -184,6 +202,13 @@ class TestZCatalog(unittest.TestCase):
data = self._catalog.getMetadataForUID('0') data = self._catalog.getMetadataForUID('0')
self.assertEqual(data['title'], '0') self.assertEqual(data['title'], '0')
def test_interface(self):
from Products.ZCatalog.IZCatalog import IZCatalog
from Products.ZCatalog.ZCatalog import ZCatalog
verifyClass(IZCatalog, ZCatalog)
class dummy(ExtensionClass.Base): class dummy(ExtensionClass.Base):
att1 = 'att1' att1 = 'att1'
att2 = 'att2' att2 = 'att2'
...@@ -425,7 +450,7 @@ class TestCatalogObject(unittest.TestCase): ...@@ -425,7 +450,7 @@ class TestCatalogObject(unittest.TestCase):
self._catalog.catalogObject(ob, `9999`) self._catalog.catalogObject(ob, `9999`)
brain = self._catalog(num=9999)[0] brain = self._catalog(num=9999)[0]
self.assertEqual(brain.att1, 'foobar') self.assertEqual(brain.att1, 'foobar')
class objRS(ExtensionClass.Base): class objRS(ExtensionClass.Base):
...@@ -461,7 +486,7 @@ class TestRS(unittest.TestCase): ...@@ -461,7 +486,7 @@ class TestRS(unittest.TestCase):
class TestMerge(unittest.TestCase): class TestMerge(unittest.TestCase):
# Test merging results from multiple catalogs # Test merging results from multiple catalogs
def setUp(self): def setUp(self):
vocabulary = Vocabulary.Vocabulary( vocabulary = Vocabulary.Vocabulary(
'Vocabulary','Vocabulary', globbing=1) 'Vocabulary','Vocabulary', globbing=1)
...@@ -478,7 +503,7 @@ class TestMerge(unittest.TestCase): ...@@ -478,7 +503,7 @@ class TestMerge(unittest.TestCase):
obj.big = i > 5 obj.big = i > 5
cat.catalogObject(obj, str(i)) cat.catalogObject(obj, str(i))
self.catalogs.append(cat) self.catalogs.append(cat)
def testNoFilterOrSort(self): def testNoFilterOrSort(self):
from Products.ZCatalog.Catalog import mergeResults from Products.ZCatalog.Catalog import mergeResults
results = [cat.searchResults(_merge=0) for cat in self.catalogs] results = [cat.searchResults(_merge=0) for cat in self.catalogs]
...@@ -486,20 +511,20 @@ class TestMerge(unittest.TestCase): ...@@ -486,20 +511,20 @@ class TestMerge(unittest.TestCase):
results, has_sort_keys=False, reverse=False)] results, has_sort_keys=False, reverse=False)]
expected = [r.getRID() for r in chain(*results)] expected = [r.getRID() for r in chain(*results)]
self.assertEqual(sort(merged_rids), sort(expected)) self.assertEqual(sort(merged_rids), sort(expected))
def testSortedOnly(self): def testSortedOnly(self):
from Products.ZCatalog.Catalog import mergeResults from Products.ZCatalog.Catalog import mergeResults
results = [cat.searchResults(sort_on='num', _merge=0) results = [cat.searchResults(sort_on='num', _merge=0)
for cat in self.catalogs] for cat in self.catalogs]
merged_rids = [r.getRID() for r in mergeResults( merged_rids = [r.getRID() for r in mergeResults(
results, has_sort_keys=True, reverse=False)] results, has_sort_keys=True, reverse=False)]
expected = sort(chain(*results)) expected = sort(chain(*results))
expected = [rid for sortkey, rid, getitem in expected] expected = [rid for sortkey, rid, getitem in expected]
self.assertEqual(merged_rids, expected) self.assertEqual(merged_rids, expected)
def testSortReverse(self): def testSortReverse(self):
from Products.ZCatalog.Catalog import mergeResults from Products.ZCatalog.Catalog import mergeResults
results = [cat.searchResults(sort_on='num', _merge=0) results = [cat.searchResults(sort_on='num', _merge=0)
for cat in self.catalogs] for cat in self.catalogs]
merged_rids = [r.getRID() for r in mergeResults( merged_rids = [r.getRID() for r in mergeResults(
results, has_sort_keys=True, reverse=True)] results, has_sort_keys=True, reverse=True)]
...@@ -507,38 +532,39 @@ class TestMerge(unittest.TestCase): ...@@ -507,38 +532,39 @@ class TestMerge(unittest.TestCase):
expected.reverse() expected.reverse()
expected = [rid for sortkey, rid, getitem in expected] expected = [rid for sortkey, rid, getitem in expected]
self.assertEqual(merged_rids, expected) self.assertEqual(merged_rids, expected)
def testLimitSort(self): def testLimitSort(self):
from Products.ZCatalog.Catalog import mergeResults from Products.ZCatalog.Catalog import mergeResults
results = [cat.searchResults(sort_on='num', sort_limit=2, _merge=0) results = [cat.searchResults(sort_on='num', sort_limit=2, _merge=0)
for cat in self.catalogs] for cat in self.catalogs]
merged_rids = [r.getRID() for r in mergeResults( merged_rids = [r.getRID() for r in mergeResults(
results, has_sort_keys=True, reverse=False)] results, has_sort_keys=True, reverse=False)]
expected = sort(chain(*results)) expected = sort(chain(*results))
expected = [rid for sortkey, rid, getitem in expected] expected = [rid for sortkey, rid, getitem in expected]
self.assertEqual(merged_rids, expected) self.assertEqual(merged_rids, expected)
def testScored(self): def testScored(self):
from Products.ZCatalog.Catalog import mergeResults from Products.ZCatalog.Catalog import mergeResults
results = [cat.searchResults(title='4 or 5 or 6', _merge=0) results = [cat.searchResults(title='4 or 5 or 6', _merge=0)
for cat in self.catalogs] for cat in self.catalogs]
merged_rids = [r.getRID() for r in mergeResults( merged_rids = [r.getRID() for r in mergeResults(
results, has_sort_keys=True, reverse=False)] results, has_sort_keys=True, reverse=False)]
expected = sort(chain(*results)) expected = sort(chain(*results))
expected = [rid for sortkey, (nscore, score, rid), getitem in expected] expected = [rid for sortkey, (nscore, score, rid), getitem in expected]
self.assertEqual(merged_rids, expected) self.assertEqual(merged_rids, expected)
def testSmallIndexSort(self): def testSmallIndexSort(self):
# Test that small index sort optimization is not used for merging # Test that small index sort optimization is not used for merging
from Products.ZCatalog.Catalog import mergeResults from Products.ZCatalog.Catalog import mergeResults
results = [cat.searchResults(sort_on='big', _merge=0) results = [cat.searchResults(sort_on='big', _merge=0)
for cat in self.catalogs] for cat in self.catalogs]
merged_rids = [r.getRID() for r in mergeResults( merged_rids = [r.getRID() for r in mergeResults(
results, has_sort_keys=True, reverse=False)] results, has_sort_keys=True, reverse=False)]
expected = sort(chain(*results)) expected = sort(chain(*results))
expected = [rid for sortkey, rid, getitem in expected] expected = [rid for sortkey, rid, getitem in expected]
self.assertEqual(merged_rids, expected) self.assertEqual(merged_rids, expected)
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite( TestAddDelColumn ) ) suite.addTest( unittest.makeSuite( TestAddDelColumn ) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment