def setUp(self): from Products.PluginIndexes.DateRangeIndex.DateRangeIndex \ import DateRangeIndex NodeAdapterTestCase.setUp(self) self._obj = DateRangeIndex('foo_daterange') self._XML = _DATERANGE_XML
def test_DateRangeIndex(self): from xml.dom.minidom import parseString from Products.PluginIndexes.DateRangeIndex.DateRangeIndex \ import DateRangeIndex from Products.GenericSetup.testing import DummySetupEnviron from Products.GenericSetup.PluginIndexes.exportimport \ import DateRangeIndexNodeAdapter environ = DummySetupEnviron() def _no_clear(*a): raise AssertionError("Don't clear me!") index = DateRangeIndex('foo_daterange') index._since_field = 'bar' index._until_field = 'baz' index.clear = _no_clear adapted = DateRangeIndexNodeAdapter(index, environ) adapted.node = parseString(_DATERANGE_XML).documentElement # no raise
def setUp(self): from Products.PluginIndexes.DateRangeIndex.DateRangeIndex \ import DateRangeIndex PlacelessSetup.setUp(self) zcml.load_config('meta.zcml', Products.Five) zcml.load_config('configure.zcml', Products.GenericSetup.PluginIndexes) self._obj = DateRangeIndex('foo_daterange') self._XML = _DATERANGE_XML
def setUp(self): import Products.GenericSetup.PluginIndexes from Products.PluginIndexes.DateRangeIndex.DateRangeIndex \ import DateRangeIndex NodeAdapterTestCase.setUp(self) zcml.load_config('configure.zcml', Products.GenericSetup.PluginIndexes) self._obj = DateRangeIndex('foo_daterange') self._XML = _DATERANGE_XML
def _make_catalog(self): zcat = ZCatalog('catalog') zcat._catalog.addIndex('big', BooleanIndex('big')) zcat._catalog.addIndex('date', DateRangeIndex('date', 'start', 'end')) zcat._catalog.addIndex('num', FieldIndex('num')) zcat._catalog.addIndex('numbers', KeywordIndex('numbers')) zcat._catalog.addIndex('path', PathIndex('getPhysicalPath')) zcat._catalog.addIndex('uuid', UUIDIndex('num')) for i in range(9): obj = Dummy(i) zcat.catalog_object(obj, str(i)) return zcat
def test_empty( self ): empty = DateRangeIndex( 'empty' ) assert empty.getEntryForObject( 1234 ) is None empty.unindex_object( 1234 ) # shouldn't throw assert not empty.uniqueValues( 'foo' ) assert not empty.uniqueValues( 'foo', 1 ) assert empty._apply_index( { 'zed' : 12345 } ) is None result, used = empty._apply_index( { 'empty' : 12345 } ) assert not result assert used == ( None, None )
def _make_catalog(self): from Products.PluginIndexes.BooleanIndex.BooleanIndex import \ BooleanIndex from Products.PluginIndexes.DateRangeIndex.DateRangeIndex import \ DateRangeIndex from Products.PluginIndexes.FieldIndex.FieldIndex import FieldIndex from Products.PluginIndexes.KeywordIndex.KeywordIndex import \ KeywordIndex from Products.PluginIndexes.PathIndex.PathIndex import PathIndex from Products.PluginIndexes.UUIDIndex.UUIDIndex import UUIDIndex from Products.ZCatalog.ZCatalog import ZCatalog zcat = ZCatalog('catalog') zcat._catalog.addIndex('big', BooleanIndex('big')) zcat._catalog.addIndex('date', DateRangeIndex('date', 'start', 'end')) zcat._catalog.addIndex('num', FieldIndex('num')) zcat._catalog.addIndex('numbers', KeywordIndex('numbers')) zcat._catalog.addIndex('path', PathIndex('getPhysicalPath')) zcat._catalog.addIndex('uuid', UUIDIndex('num')) for i in range(9): obj = dummy(i) zcat.catalog_object(obj, str(i)) return zcat
def test_retrieval( self ): work = DateRangeIndex( 'work', 'start', 'stop' ) for i in range( len( dummies ) ): work.index_object( i, dummies[i] ) for i in range( len( dummies ) ): assert work.getEntryForObject( i ) == dummies[i].datum() for value in range( -1, 15 ): matches = matchingDummies( value ) results, used = work._apply_index( { 'work' : value } ) assert used == ( 'start', 'stop' ) assert len( matches ) == len( results ), ( '%s: %s == %s' % ( value, map( lambda x: x.name(), matches ), results ) ) matches.sort( lambda x, y: cmp( x.name(), y.name() ) ) for result, match in map( None, results, matches ): assert work.getEntryForObject( result ) == match.datum()
def unindex_object( self, documentId ): for lang in self.languages: self._v_lang = lang DateRangeIndex.unindex_object(self, documentId) self._v_lang = None
def setUp(self): from Products.PluginIndexes.DateRangeIndex.DateRangeIndex import \ DateRangeIndex self._obj = DateRangeIndex('foo_daterange') self._XML = _DATERANGE_XML
def _badlong(self): work = DateRangeIndex ('work', 'start', 'stop' ) bad = Dummy( 'bad', long(sys.maxint) + 1, long(sys.maxint) + 1 ) work.index_object( 0, bad )
def unindex_object(self, documentId): for lang in self.languages: self._v_lang = lang DateRangeIndex.unindex_object(self, documentId) self._v_lang = None