[Zope-Checkins] CVS: Zope2 - testCatalog.py:1.1.6.5

chrism@serenade.digicool.com chrism@serenade.digicool.com
Tue, 17 Apr 2001 13:01:21 -0400


Update of /cvs-repository/Zope2/lib/python/Products/ZCatalog/tests
In directory serenade.digicool.com:/home/chrism/sandboxes/2_3Branch/lib/python/Products/ZCatalog/tests

Modified Files:
      Tag: zope-2_3-branch
	testCatalog.py 
Log Message:
More tests.


--- Updated File testCatalog.py in package Zope2 --
--- testCatalog.py	2001/04/05 16:18:05	1.1.6.4
+++ testCatalog.py	2001/04/17 17:01:21	1.1.6.5
@@ -7,6 +7,12 @@
     Andreas Jung, andreas@digicool.com
     
     $Log$
+    Revision 1.1.6.5  2001/04/17 17:01:21  chrism
+    More tests.
+
+    Revision 1.1.6.4.2.1  2001/04/17 06:39:45  chrism
+    added further tests for catalog object in test_suite.
+
     Revision 1.1.6.4  2001/04/05 16:18:05  chrism
     Added test for empty mapping returns all.
 
@@ -94,6 +100,7 @@
 import Zope
 import ZODB, ZODB.FileStorage
 from Products.ZCatalog import Catalog,ZCatalog,Vocabulary
+from Products.ZCatalog.Catalog import CatalogError
 import Persistence
 import ExtensionClass
 from Testing import dispatcher
@@ -124,9 +131,8 @@
 
 # input mailbox file
 mbox   = os.environ.get("TESTCATALOG_MBOX","/usr/home/andreas/zope.mbox")
-mbox2  = "/usr/home/andreas/python.mbox"
+mbox2  = os.environ.get("TESTCATALOG_MBOX2", "/usr/home/andreas/python.mbox")
 
-
 dataDir = ""
 
 
@@ -723,11 +729,15 @@
         self._catalog.delIndex('id')
         assert self._catalog.indexes.has_key('id') != 1, 'del index failed'
 
-class TestSimultaneousAddAndRead(CatalogBase, unittest.TestCase):
-    def checkMultiThread(self):
-        pass
-
 class TestZCatalogObject(unittest.TestCase):
+    def setUp(self):
+        class dummy(ExtensionClass.Base):
+            pass
+        self.dummy = dummy()
+
+    def tearDown(self):
+        self.dummy = None
+
     def checkInstantiateWithoutVocab(self):
         v = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary', globbing=1)
         zc = ZCatalog.ZCatalog('acatalog')
@@ -735,15 +745,19 @@
         assert zc.getVocabulary().__class__ == v.__class__
 
     def checkInstantiateWithGlobbingVocab(self):
+        dummy = self.dummy
         v = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary', globbing=1)
-        zc = ZCatalog.ZCatalog('acatalog', vocab_id='vocab')
-        zc._setObject('vocab', v)
+        dummy.v = v
+        zc = ZCatalog.ZCatalog('acatalog', vocab_id='v', container=dummy)
+        zc = zc.__of__(dummy)
         assert zc.getVocabulary() == v
 
     def checkInstantiateWithNormalVocab(self):
+        dummy = self.dummy
         v = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary', globbing=0)
-        zc = ZCatalog.ZCatalog('acatalog', vocab_id='vocab')
-        zc._setObject('vocab', v)
+        dummy.v = v
+        zc = ZCatalog.ZCatalog('acatalog', vocab_id='v', container=dummy)
+        zc = zc.__of__(dummy)
         assert zc.getVocabulary() == v
 
 class TestCatalogObject(unittest.TestCase):
@@ -761,11 +775,12 @@
         self._catalog.addIndex('att1', 'FieldIndex')
         self._catalog.addIndex('att2', 'TextIndex')
         self._catalog.addIndex('att3', 'KeywordIndex')
+        self._catalog.addIndex('num', 'FieldIndex')
         self._catalog.addColumn('att1') 
         self._catalog.addColumn('att2')
         self._catalog.addColumn('att3')
-
         self._catalog.addColumn('num')
+
         self.upper = 1000
         class dummy(ExtensionClass.Base):
             att1 = 'att1'
@@ -782,6 +797,8 @@
 
             def col3(self):
                 return ['col3']
+
+            
         for x in range(0, self.upper):
             self._catalog.catalogObject(dummy(x), `x`)
         self._catalog.aq_parent = dummy('foo') # fake out acquisition
@@ -858,6 +875,60 @@
         for x in range(0, self.upper):
             self._catalog.uncatalogObject(`x`)
 
+    def checkGoodSortIndex(self):
+        upper = self.upper
+        a = self._catalog(sort_on='num')
+        assert len(a) == upper, 'length should be %s, its %s'%(upper, len(a))
+        for x in range(self.upper):
+            assert a[x].num == x, x
+            
+    def checkBadSortIndex(self):
+        self.assertRaises(CatalogError, self.badsortindex)
+
+    def badsortindex(self):
+        a = self._catalog(sort_on='foofaraw')
+
+    def checkWrongKindOfIndexForSort(self):
+        self.assertRaises(CatalogError, self.wrongsortindex)
+
+    def wrongsortindex(self):
+        a = self._catalog(sort_on='att2')
+
+    def checkTextIndexQWithSortOn(self):
+        upper = self.upper
+        a = self._catalog(sort_on='num', att2='att2')
+        assert len(a) == upper, 'length should be %s, its %s'%(upper, len(a))
+        for x in range(self.upper):
+            assert a[x].num == x, x
+
+    def checkTextIndexQWithoutSortOn(self):
+        upper = self.upper
+        a = self._catalog(att2='att2')
+        assert len(a) == upper, 'length should be %s, its %s'%(upper, len(a))
+        for x in range(self.upper):
+            assert a[x].data_record_score_ == 1, a[x].data_record_score_
+
+    def checkKeywordIndexWithMinRange(self):
+        a = self._catalog(att3='att', att3_usage='range:min')
+        assert len(a) == self.upper
+
+    def checkKeywordIndexWithMaxRange(self):
+        a = self._catalog(att3='att35', att3_usage='range:max')
+        assert len(a) == self.upper
+
+    def checkKeywordIndexWithMinMaxRangeCorrectSyntax(self):
+        a = self._catalog(att3=['att', 'att35'], att3_usage='range:min:max')
+        assert len(a) == self.upper
+
+    def checkKeywordIndexWithMinMaxRangeWrongSyntax(self):
+        "checkKeywordIndex with min/max range wrong syntax - known to fail"
+        a = self._catalog(att3=['att'], att3_usage='range:min:max')
+        assert len(a) == self.upper
+
+    def checkCombinedTextandKeywordQuery(self):
+        a = self._catalog(att3='att3', att2='att2')
+        assert len(a) == self.upper
+
 class objRS(ExtensionClass.Base):
 
     def __init__(self,num):
@@ -1000,7 +1071,7 @@
 
     if what=='basic':    
         ts = unittest.TestSuite(ts_cm)
-        for x in t_aj: ts.addTest(x)
+#        for x in t_aj: ts.addTest(x)
         return ts
 
     else: