Back to index

plone3  3.1.7
test_extensions_utils.py
Go to the documentation of this file.
00001 
00002 from cStringIO import StringIO
00003 
00004 from Products.Archetypes.tests.atsitetestcase import ATSiteTestCase
00005 #from Products.Archetypes.tests.utils import makeContent
00006 from Products.Archetypes.examples.ComplexType import ComplexType
00007 from Products.Archetypes.Extensions import utils
00008 
00009 ComplexType.installMode = ('indexes', )
00010 class InstallIndexesTests(ATSiteTestCase):
00011 
00012     def tearDown(self):
00013         ATSiteTestCase.tearDown(self)
00014         del ComplexType.schema['richtextfield'].index
00015         try:
00016             del ComplexType.schema['richtextfield'].index_method
00017         except (AttributeError, KeyError):
00018             pass
00019         
00020     def test_base_usage(self):
00021         ComplexType.schema['richtextfield'].index = 'TextIndex'
00022         utils.install_indexes(self.portal, StringIO(), (ComplexType,) )
00023         self.failUnless('getRichtextfield' in self.portal.portal_catalog.indexes())
00024 
00025         
00026     def test_index_method(self):
00027         ComplexType.schema['richtextfield'].index = 'TextIndex'
00028         ComplexType.schema['richtextfield'].index_method = 'Whatever'
00029         utils.install_indexes(self.portal, StringIO(), (ComplexType,) )
00030         self.failUnless('Whatever' in self.portal.portal_catalog.indexes())
00031         
00032         ComplexType.schema['richtextfield'].index_method = '_at_accessor'
00033         utils.install_indexes(self.portal, StringIO(), (ComplexType,) )
00034         self.failUnless('getRichtextfield' in self.portal.portal_catalog.indexes())
00035 
00036         ComplexType.schema['richtextfield'].index_method = '_at_edit_accessor'
00037         utils.install_indexes(self.portal, StringIO(), (ComplexType,) )
00038         self.failUnless('getRawRichtextfield' in self.portal.portal_catalog.indexes())
00039 
00040         
00041     def test_bad_index_method(self):
00042         ComplexType.schema['richtextfield'].index = 'TextIndex'
00043         ComplexType.schema['richtextfield'].index_method = lambda x: 'yop'
00044         self.failUnlessRaises(ValueError,
00045                               utils.install_indexes, self.portal, StringIO(), (ComplexType,) )
00046         ComplexType.schema['richtextfield'].index_method = lambda x: 'yop'
00047         self.failUnlessRaises(ValueError,
00048                               utils.install_indexes, self.portal, StringIO(), (ComplexType,) )
00049 
00050         ComplexType.schema['richtextfield'].index_method = ComplexType._get_selection_vocab
00051         self.failUnlessRaises(ValueError,
00052                               utils.install_indexes, self.portal, StringIO(), (ComplexType,) )
00053         
00054 
00055 def test_suite():
00056     from unittest import TestSuite, makeSuite
00057     suite = TestSuite()
00058     suite.addTest(makeSuite(InstallIndexesTests))
00059     return suite