[Zope-Checkins] CVS: Zope/lib/python/Products/ZCatalog/tests - testCatalog.py:1.18.2.2

Chris McDonough chrism at zope.com
Tue Oct 7 15:43:26 EDT 2003


Update of /cvs-repository/Zope/lib/python/Products/ZCatalog/tests
In directory cvs.zope.org:/tmp/cvs-serv7849/tests

Modified Files:
      Tag: Zope-2_6-branch
	testCatalog.py 
Log Message:
Revert feature of never updaing metadata if index is specified in catalog_object.  This broke several applications.  Instead, we provide the catalog_object method (and the Catalog.py's catalogObject method) with an update_metadata keyword argument.  If the update_metadata keyword argument is set false (the default is true), metadata is not updated.



=== Zope/lib/python/Products/ZCatalog/tests/testCatalog.py 1.18.2.1 => 1.18.2.2 ===
--- Zope/lib/python/Products/ZCatalog/tests/testCatalog.py:1.18.2.1	Tue Dec 10 10:55:00 2002
+++ Zope/lib/python/Products/ZCatalog/tests/testCatalog.py	Tue Oct  7 15:43:25 2003
@@ -128,25 +128,31 @@
 
 # Test of the ZCatalog object, as opposed to Catalog
 
+class zdummy(ExtensionClass.Base):
+    def __init__(self, num):
+        self.num = num
+
+    def title(self):
+        return '%d' % self.num
+
 class TestZCatalog(unittest.TestCase):
     def setUp(self):
         self._catalog = ZCatalog.ZCatalog('Catalog')
+        self._catalog.resolve_path = self._resolve_num
         self._catalog.addIndex('title', 'KeywordIndex')
         self._catalog.addColumn('title')
         
         self.upper = 10
 
-        class dummy(ExtensionClass.Base):
-            def __init__(self, num):
-                self.num = num
-    
-            def title(self):
-                return '%d' % self.num
-
+        self.d = {}
         for x in range(0, self.upper):
             # make uid a string of the number
-            self._catalog.catalog_object(dummy(x), str(x))
+            ob = zdummy(x)
+            self.d[str(x)] = ob
+            self._catalog.catalog_object(ob, str(x))
 
+    def _resolve_num(self, num):
+        return self.d[num]
 
     def testGetMetadataForUID(self):
         testNum = str(self.upper - 3) # as good as any..
@@ -163,6 +169,44 @@
         sr = self._catalog.searchResults(query)
         self.assertEqual(len(sr), 3)
 
+    def testUpdateMetadata(self):
+        self._catalog.catalog_object(zdummy(1), '1')
+        data = self._catalog.getMetadataForUID('1')
+        self.assertEqual(data['title'], '1')
+        self._catalog.catalog_object(zdummy(2), '1', update_metadata=0)
+        data = self._catalog.getMetadataForUID('1')
+        self.assertEqual(data['title'], '1')
+        self._catalog.catalog_object(zdummy(2), '1', update_metadata=1)
+        data = self._catalog.getMetadataForUID('1')
+        self.assertEqual(data['title'], '2')
+        # update_metadata defaults to true, test that here
+        self._catalog.catalog_object(zdummy(1), '1')
+        data = self._catalog.getMetadataForUID('1')
+        self.assertEqual(data['title'], '1')
+
+    def testReindexIndexDoesntDoMetadata(self):
+        self.d['0'].num = 9999
+        self._catalog.reindexIndex('title', {})
+        data = self._catalog.getMetadataForUID('0')
+        self.assertEqual(data['title'], '0')
+
+class dummy(ExtensionClass.Base):
+    att1 = 'att1'
+    att2 = 'att2'
+    att3 = ['att3']
+    def __init__(self, num):
+        self.num = num
+
+    def col1(self):
+        return 'col1'
+
+    def col2(self):
+        return 'col2'
+
+    def col3(self):
+        return ['col3']
+
+
 class TestCatalogObject(unittest.TestCase):
     
     upper = 1000
@@ -204,23 +248,6 @@
         self._catalog.addColumn('att3')
         self._catalog.addColumn('num')
 
-        class dummy(ExtensionClass.Base):
-            att1 = 'att1'
-            att2 = 'att2'
-            att3 = ['att3']
-            def __init__(self, num):
-                self.num = num
-
-            def col1(self):
-                return 'col1'
-
-            def col2(self):
-                return 'col2'
-
-            def col3(self):
-                return ['col3']
-
-        
         for x in range(0, self.upper):
             self._catalog.catalogObject(dummy(self.nums[x]), `x`)
         self._catalog.aq_parent = dummy('foo') # fake out acquisition
@@ -386,7 +413,20 @@
             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)
-        
+
+    def testUpdateMetadataFalse(self):
+        ob = dummy(9999)
+        self._catalog.catalogObject(ob, `9999`)
+        brain = self._catalog(num=9999)[0]
+        self.assertEqual(brain.att1, 'att1')
+        ob.att1 = 'foobar'
+        self._catalog.catalogObject(ob, `9999`, update_metadata=0)
+        brain = self._catalog(num=9999)[0]
+        self.assertEqual(brain.att1, 'att1')
+        self._catalog.catalogObject(ob, `9999`)
+        brain = self._catalog(num=9999)[0]
+        self.assertEqual(brain.att1, 'foobar')
+
 
 class objRS(ExtensionClass.Base):
 




More information about the Zope-Checkins mailing list