[Zope-Checkins] CVS: Zope/lib/python/Products/ZCatalog/tests - testCatalog.py:1.17.4.2
Chris McDonough
chrism@zope.com
Fri, 3 Jan 2003 01:34:03 -0500
Update of /cvs-repository/Zope/lib/python/Products/ZCatalog/tests
In directory cvs.zope.org:/tmp/cvs-serv27194/ZCatalog/tests
Modified Files:
Tag: chrism-install-branch
testCatalog.py
Log Message:
Merging chrism-install-branch with HEAD (hopefully for one of the last
times).
=== Zope/lib/python/Products/ZCatalog/tests/testCatalog.py 1.17.4.1 => 1.17.4.2 ===
--- Zope/lib/python/Products/ZCatalog/tests/testCatalog.py:1.17.4.1 Thu Aug 29 01:31:21 2002
+++ Zope/lib/python/Products/ZCatalog/tests/testCatalog.py Fri Jan 3 01:33:30 2003
@@ -17,7 +17,7 @@
from Products.PluginIndexes.TextIndex.Lexicon import Lexicon
from Products.PluginIndexes.KeywordIndex.KeywordIndex import KeywordIndex
-import whrandom,string, unittest
+import whrandom,string, unittest, random
def createDatabase():
@@ -157,8 +157,25 @@
testNum = str(self.upper - 3)
data = self._catalog.getIndexDataForUID(testNum)
assert data['title'][0] == testNum
+
+ def testSearch(self):
+ query = {'title': ['5','6','7']}
+ sr = self._catalog.searchResults(query)
+ self.assertEqual(len(sr), 3)
+ sr = self._catalog.search(query)
+ self.assertEqual(len(sr), 3)
class TestCatalogObject(unittest.TestCase):
+
+ upper = 1000
+
+ nums = range(upper)
+ for i in range(upper):
+ j = random.randint(0, upper-1)
+ tmp = nums[i]
+ nums[i] = nums[j]
+ nums[j] = tmp
+
def setUp(self):
self._vocabulary = Vocabulary.Vocabulary('Vocabulary','Vocabulary',
globbing=1)
@@ -189,7 +206,6 @@
self._catalog.addColumn('att3')
self._catalog.addColumn('num')
- self.upper = 1000
class dummy(ExtensionClass.Base):
att1 = 'att1'
att2 = 'att2'
@@ -206,9 +222,9 @@
def col3(self):
return ['col3']
-
+
for x in range(0, self.upper):
- self._catalog.catalogObject(dummy(x), `x`)
+ self._catalog.catalogObject(dummy(self.nums[x]), `x`)
self._catalog.aq_parent = dummy('foo') # fake out acquisition
def tearDown(self):
@@ -346,6 +362,33 @@
# set is much larger than the sort index.
a = self._catalog(sort_on='att1')
self.assertEqual(len(a), self.upper)
+
+ def testBadSortLimits(self):
+ self.assertRaises(
+ AssertionError, self._catalog, sort_on='num', sort_limit=0)
+ self.assertRaises(
+ AssertionError, self._catalog, sort_on='num', sort_limit=-10)
+
+ def testSortLimit(self):
+ full = self._catalog(sort_on='num')
+ a = self._catalog(sort_on='num', sort_limit=10)
+ self.assertEqual([r.num for r in a], [r.num for r in full[:10]])
+ self.assertEqual(a.actual_result_count, self.upper)
+ a = self._catalog(sort_on='num', sort_limit=10, sort_order='reverse')
+ rev = [r.num for r in full[-10:]]
+ rev.reverse()
+ self.assertEqual([r.num for r in a], rev)
+ self.assertEqual(a.actual_result_count, self.upper)
+
+ def testBigSortLimit(self):
+ a = self._catalog(sort_on='num', sort_limit=self.upper*3)
+ self.assertEqual(a.actual_result_count, self.upper)
+ self.assertEqual(a[0].num, 0)
+ a = self._catalog(
+ sort_on='num', sort_limit=self.upper*3, sort_order='reverse')
+ self.assertEqual(a.actual_result_count, self.upper)
+ self.assertEqual(a[0].num, self.upper - 1)
+
class objRS(ExtensionClass.Base):