on workflow changes and catalog updates

Héctor Velarde hvelarde at jornada.com.mx
Wed Jul 4 20:14:07 UTC 2007


I am writing a method that returns the number of published items that 
have a particular keyword:

     def getUniqueTags(self):
         """ returns tags in alphabetical order; tags are subjects """

         catalog = getToolByName(self, 'portal_catalog')
         tags = list(catalog.uniqueValuesFor('Subject'))
         if tags:
             tags.sort(lambda x, y: cmp(x.lower(), y.lower()))
         return tuple(tags)

when writing the unit test I found that when I change the object state I 
have to use reindexObject() for the catalog to reflect the change:

     def testGetUniqueTags(self):
         """ test if unique tags are returned """
         self.folder.invokeFactory('Document', 'o1')
         self.o1 = getattr(self.folder, 'o1')
         self.o1.setSubject('one')

         tags = self.tool.getUniqueTags()
         self.assertEqual(len(tags), 0)

         self.setRoles(['Manager', 'Member'])
         self.workflow.doActionFor(self.o1, 'publish')
         #test fails if object is not reindexed
         self.o1.reindexObject()
         tags = self.tool.getUniqueTags()
         self.assertEqual(len(tags), 1)

is this behavior right or not?





More information about the Product-Developers mailing list