Exemplo n.º 1
0
 def setUp(self):
     self._index = UUIDIndex('foo')
     self._marker = []
     self._values = [(0, Dummy('a')), (1, Dummy('ab')), (2, Dummy(123)),
                     (3, Dummy(234)), (4, Dummy(0))]
     self._forward = {}
     self._backward = {}
     for k, v in self._values:
         self._backward[k] = v
         keys = self._forward.get(v, [])
         self._forward[v] = keys
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 def setUp(self):
     self._index = UUIDIndex('foo')
     self._marker = []
     self._values = [
         (0, Dummy('a')),
         (1, Dummy('ab')),
         (2, Dummy(123)),
         (3, Dummy(234)),
         (4, Dummy(0))]
     self._forward = {}
     self._backward = {}
     for k, v in self._values:
         self._backward[k] = v
         keys = self._forward.get(v, [])
         self._forward[v] = keys
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
class UUIDIndexTests(unittest.TestCase):

    def setUp(self):
        self._index = UUIDIndex('foo')
        self._marker = []
        self._values = [
            (0, Dummy('a')),
            (1, Dummy('ab')),
            (2, Dummy(123)),
            (3, Dummy(234)),
            (4, Dummy(0))]
        self._forward = {}
        self._backward = {}
        for k, v in self._values:
            self._backward[k] = v
            keys = self._forward.get(v, [])
            self._forward[v] = keys

    def tearDown(self):
        self._index.clear()

    def _populateIndex(self):
        for k, v in self._values:
            self._index.index_object(k, v)

    def _checkApply(self, req, expectedValues):
        result, used = self._index._apply_index(req)
        if hasattr(result, 'keys'):
            result = result.keys()
        self.assertEqual(used, ('foo', ))
        self.assertEqual(len(result), len(expectedValues))
        for k, v in expectedValues:
            self.assertTrue(k in result)

    def test_interfaces(self):
        from Products.PluginIndexes.interfaces import IPluggableIndex
        from Products.PluginIndexes.interfaces import ISortIndex
        from Products.PluginIndexes.interfaces import IUniqueValueIndex
        from zope.interface.verify import verifyClass

        verifyClass(IPluggableIndex, UUIDIndex)
        verifyClass(ISortIndex, UUIDIndex)
        verifyClass(IUniqueValueIndex, UUIDIndex)

    def test_empty(self):
        self.assertEqual(len(self._index), 0)
        self.assertEqual(len(self._index.referencedObjects()), 0)
        self.assertEqual(self._index.numObjects(), 0)
        self._checkApply({'foo': 'a'}, [])

    def test_populated(self):
        self._populateIndex()
        values = self._values
        self.assertEqual(len(self._index), len(values))
        self.assertEqual(self._index.indexSize(), len(values))
        self.assertTrue(self._index.getEntryForObject(10) is None)
        self._checkApply({'foo': 'not'}, [])

        self._index.unindex_object(10) # nothrow

        for k, v in values:
            self.assertEqual(self._index.getEntryForObject(k), v.foo())

        self._checkApply({'foo': 'a'}, [values[0]])
        self._checkApply({'foo': 0}, [values[4]])
        self._checkApply({'foo': ['a', 'ab']}, values[:2])

    def test_none(self):
        self._index.index_object(10, Dummy(None))
        self._checkApply({'foo': None}, [])
        self.assertFalse(None in self._index.uniqueValues('foo'))

    def test_reindex(self):
        self._populateIndex()
        self._checkApply({'foo': 'a'}, [self._values[0]])
        d = Dummy('world')
        self._index.index_object(0, d)
        self._checkApply({'foo': 'a'}, [])
        self._checkApply({'foo': 'world'}, [(0, d)])
        self.assertEqual(self._index.keyForDocument(0), 'world')
        del d._foo
        self._index.index_object(0, d)
        self._checkApply({'foo': 'world'}, [])
        self.assertRaises(KeyError, self._index.keyForDocument, 0)

    def test_range(self):
        values = []
        for i in range(100):
            obj = (i, Dummy(i))
            self._index.index_object(*obj)
            values.append(obj)

        query = {'foo': {'query': [10, 20], 'range': 'min:max'}}
        self._checkApply(query, values[10:21])

    def test_non_unique(self):
        obj = Dummy('a')
        self._index.index_object(0, obj)
        # second index call fails and logs
        self._index.index_object(1, obj)
        self._checkApply({'foo': 'a'}, [(0, obj)])
Exemplo n.º 6
0
class UUIDIndexTests(unittest.TestCase):
    def setUp(self):
        self._index = UUIDIndex('foo')
        self._marker = []
        self._values = [(0, Dummy('a')), (1, Dummy('ab')), (2, Dummy(123)),
                        (3, Dummy(234)), (4, Dummy(0))]
        self._forward = {}
        self._backward = {}
        for k, v in self._values:
            self._backward[k] = v
            keys = self._forward.get(v, [])
            self._forward[v] = keys

    def tearDown(self):
        self._index.clear()

    def _populateIndex(self):
        for k, v in self._values:
            self._index.index_object(k, v)

    def _checkApply(self, req, expectedValues):
        result, used = self._index._apply_index(req)
        if hasattr(result, 'keys'):
            result = result.keys()
        self.assertEqual(used, ('foo', ))
        self.assertEqual(len(result), len(expectedValues))
        for k, v in expectedValues:
            self.assertTrue(k in result)

    def test_interfaces(self):
        from Products.PluginIndexes.interfaces import IPluggableIndex
        from Products.PluginIndexes.interfaces import ISortIndex
        from Products.PluginIndexes.interfaces import IUniqueValueIndex
        from zope.interface.verify import verifyClass

        verifyClass(IPluggableIndex, UUIDIndex)
        verifyClass(ISortIndex, UUIDIndex)
        verifyClass(IUniqueValueIndex, UUIDIndex)

    def test_empty(self):
        self.assertEqual(len(self._index), 0)
        self.assertEqual(len(self._index.referencedObjects()), 0)
        self.assertEqual(self._index.numObjects(), 0)
        self._checkApply({'foo': 'a'}, [])

    def test_populated(self):
        self._populateIndex()
        values = self._values
        self.assertEqual(len(self._index), len(values))
        self.assertEqual(self._index.indexSize(), len(values))
        self.assertTrue(self._index.getEntryForObject(10) is None)
        self._checkApply({'foo': 'not'}, [])

        self._index.unindex_object(10)  # nothrow

        for k, v in values:
            self.assertEqual(self._index.getEntryForObject(k), v.foo())

        self._checkApply({'foo': 'a'}, [values[0]])
        self._checkApply({'foo': 0}, [values[4]])
        self._checkApply({'foo': ['a', 'ab']}, values[:2])

    def test_none(self):
        self._index.index_object(10, Dummy(None))
        self._checkApply({'foo': None}, [])
        self.assertFalse(None in self._index.uniqueValues('foo'))

    def test_reindex(self):
        self._populateIndex()
        self._checkApply({'foo': 'a'}, [self._values[0]])
        d = Dummy('world')
        self._index.index_object(0, d)
        self._checkApply({'foo': 'a'}, [])
        self._checkApply({'foo': 'world'}, [(0, d)])
        self.assertEqual(self._index.keyForDocument(0), 'world')
        del d._foo
        self._index.index_object(0, d)
        self._checkApply({'foo': 'world'}, [])
        self.assertRaises(KeyError, self._index.keyForDocument, 0)

    def test_range(self):
        values = []
        for i in range(100):
            obj = (i, Dummy(i))
            self._index.index_object(*obj)
            values.append(obj)

        query = {'foo': {'query': [10, 20], 'range': 'min:max'}}
        self._checkApply(query, values[10:21])

    def test_non_unique(self):
        obj = Dummy('a')
        self._index.index_object(0, obj)
        # second index call fails and logs
        self._index.index_object(1, obj)
        self._checkApply({'foo': 'a'}, [(0, obj)])