Пример #1
0
 def test_updateindexes(self):
     """Test a full refresh."""
     self._frob_intidutil()
     catalog = Catalog()
     catalog['author'] = StubIndex('author', None)
     catalog['title'] = StubIndex('author', None)
     catalog.updateIndexes()
     for index in catalog.values():
         checkNotifies = index.doc
         self.assertEqual(len(checkNotifies), 18)
Пример #2
0
 def test_updateindex(self):
     """Test a full refresh."""
     self._frob_intidutil()
     catalog = Catalog()
     catalog['author'] = StubIndex('author', None)
     catalog['title'] = StubIndex('author', None)
     catalog.updateIndex(catalog['author'])
     checkNotifies = catalog['author'].doc
     self.assertEqual(len(checkNotifies), 18)
     checkNotifies = catalog['title'].doc
     self.assertEqual(len(checkNotifies), 0)
Пример #3
0
 def test_catalog_add_del_indexes(self):
     catalog = Catalog()
     verifyObject(ICatalog, catalog)
     index = StubIndex('author', None)
     catalog['author'] = index
     self.assertEqual(list(catalog.keys()), ['author'])
     index = StubIndex('title', None)
     catalog['title'] = index
     indexes = list(catalog.keys())
     indexes.sort()
     self.assertEqual(indexes, ['author', 'title'])
     del catalog['author']
     self.assertEqual(list(catalog.keys()), ['title'])
Пример #4
0
    def test_basicsearch(self):
        """Test the simple search results interface."""
        self._frob_intidutil(ints=0)
        catalog = Catalog()
        catalog['simiantype'] = StubIndex('simiantype', None)
        catalog['name'] = StubIndex('name', None)
        catalog.updateIndexes()

        res = catalog.searchResults(simiantype='monkey')
        names = [x.name for x in res]
        names.sort()
        self.assertEqual(len(names), 3)
        self.assertEqual(names, ['bobo', 'bubbles', 'ginger'])

        res = catalog.searchResults(name='bobo')
        names = [x.simiantype for x in res]
        names.sort()
        self.assertEqual(len(names), 2)
        self.assertEqual(names, ['bonobo', 'monkey'])

        res = catalog.searchResults(simiantype='punyhuman', name='anthony')
        self.assertEqual(len(res), 1)
        ob = iter(res).next()
        self.assertEqual((ob.name, ob.simiantype), ('anthony', 'punyhuman'))

        res = catalog.searchResults(simiantype='ape', name='bobo')
        self.assertEqual(len(res), 0)

        res = catalog.searchResults(simiantype='ape', name='mwumi')
        self.assertEqual(len(res), 0)
        self.assertRaises(KeyError, catalog.searchResults,
                          simiantype='monkey', hat='beret')
Пример #5
0
 def setUp(self):
     """emulate the doctest fixtures"""
     self.intid = DummyIntId()
     provideUtility(self.intid, zope.intid.interfaces.IIntIds)
     self.catalog = Catalog()
     provideUtility(self.catalog, ICatalog, 'catalog1')
     self.catalog['f1'] = FieldIndex('f1', IContent)
     self.catalog['f2'] = FieldIndex('f2', IContent)
     self.catalog['f3'] = FieldIndex('f3', IContent)
     self.catalog['f4'] = FieldIndex('f4', IContent)
     self.catalog['t1'] = TextIndex('t1', IContent)
     self.catalog['t2'] = TextIndex('t2', IContent)
     provideUtility(query.Query(), IQuery)
     self.setup_content()
Пример #6
0
 def create_catalog(self):
     catalog = Catalog()
     catalog[u'user'] = FieldIndex(field_name='user', field_callable=False)
     catalog[u'text'] = TextIndex(field_name='text', field_callable=False)
     catalog[u'keywords'] = KeywordIndex(field_name='keywords',
                                         field_callable=False)
     return catalog
Пример #7
0
def setup_catalog():
    catalog = Catalog()
    catalog['date'] = FieldIndex('date', IBooking, False)
    catalog['text'] = TextIndex('text', IBooking, False)
    catalog['owner'] = FieldIndex('owner', IBooking, False)
    catalog['references'] = KeywordIndex('index_references', IBooking, True)
    catalog['tags'] = KeywordIndex('tags', IBooking, False)
    return catalog
Пример #8
0
    def test_updateIndexFromCallableWithNone(self):
        uidutil = IntIdsStub()
        provideUtility(uidutil, IIntIds)

        catalog = Catalog()
        index = FieldIndex('getAuthor', None, field_callable=True)
        catalog['author'] = index

        ob1 = stoopidCallable(author = "joe")

        ob1id = uidutil.register(ob1)
        catalog.index_doc(ob1id, ob1)

        res = catalog.searchResults(author=('joe','joe'))
        names = [x.author for x in res]
        names.sort()
        self.assertEqual(len(names), 1)
        self.assertEqual(names, ['joe'])

        ob1.author = None
        catalog.index_doc(ob1id, ob1)

        #the index must be empty now because None values are never indexed
        res = catalog.searchResults(author=(None, None))
        self.assertEqual(len(res), 0)
Пример #9
0
class QueryTestBase(unittest.TestCase):

    tearDown = zope.component.testing.tearDown

    def setUp(self):
        """emulate the doctest fixtures"""
        self.intid = DummyIntId()
        provideUtility(self.intid, zope.intid.interfaces.IIntIds)
        self.catalog = Catalog()
        provideUtility(self.catalog, ICatalog, 'catalog1')
        self.catalog['f1'] = FieldIndex('f1', IContent)
        self.catalog['f2'] = FieldIndex('f2', IContent)
        self.catalog['f3'] = FieldIndex('f3', IContent)
        self.catalog['f4'] = FieldIndex('f4', IContent)
        self.catalog['t1'] = TextIndex('t1', IContent)
        self.catalog['t2'] = TextIndex('t2', IContent)
        provideUtility(query.Query(), IQuery)
        self.setup_content()

    def setup_content(self):
        content = [
            Content(1, 'a', 'b', 'd'),
            Content(2, 'a', 'c'),
            Content(3, 'X', 'c'),
            Content(4, 'a', 'b', 'e'),
            Content(5, 'X', 'b', 'e'),
            Content(6, 'Y', 'Z')]
        for entry in content:
            self.catalog.index_doc(self.intid.register(entry), entry)

    def searchResults(self, q, **kw):
        query = getUtility(IQuery)
        return query.searchResults(q, **kw)

    def displayQuery(self, q, **kw):
        r = self.searchResults(q, **kw)
        return [e.id for e in sorted(list(r))]

    def test_setup(self):
        """verify test fixtures by reproducing first doctest"""
        self.assertEqual(self.displayQuery(
            query.All(f1)),
            [1, 2, 3, 4, 5, 6])
Пример #10
0
class QueryTestBase(unittest.TestCase):

    tearDown = zope.component.testing.tearDown

    def setUp(self):
        """emulate the doctest fixtures"""
        self.intid = DummyIntId()
        provideUtility(self.intid, zope.intid.interfaces.IIntIds)
        self.catalog = Catalog()
        provideUtility(self.catalog, ICatalog, 'catalog1')
        self.catalog['f1'] = FieldIndex('f1', IContent)
        self.catalog['f2'] = FieldIndex('f2', IContent)
        self.catalog['f3'] = FieldIndex('f3', IContent)
        self.catalog['f4'] = FieldIndex('f4', IContent)
        self.catalog['t1'] = TextIndex('t1', IContent)
        self.catalog['t2'] = TextIndex('t2', IContent)
        provideUtility(query.Query(), IQuery)
        self.setup_content()

    def setup_content(self):
        content = [
            Content(1, 'a', 'b', 'd'),
            Content(2, 'a', 'c'),
            Content(3, 'X', 'c'),
            Content(4, 'a', 'b', 'e'),
            Content(5, 'X', 'b', 'e'),
            Content(6, 'Y', 'Z')
        ]
        for entry in content:
            self.catalog.index_doc(self.intid.register(entry), entry)

    def searchResults(self, q, **kw):
        query = getUtility(IQuery)
        return query.searchResults(q, **kw)

    def displayQuery(self, q, **kw):
        r = self.searchResults(q, **kw)
        return [e.id for e in sorted(list(r))]

    def test_setup(self):
        """verify test fixtures by reproducing first doctest"""
        self.assertEqual(self.displayQuery(query.All(f1)), [1, 2, 3, 4, 5, 6])
Пример #11
0
    def test_IndexRaisingValueGetter(self):
        """We can have indexes whose values are determined by callable
        methods.
        Raising an exception in the method should not be silently ignored
        That would cause index corruption -- the index would be out of sync"""
        uidutil = IntIdsStub()
        provideUtility(uidutil, IIntIds)

        catalog = Catalog()
        index = FieldIndex('getAuthor', None, field_callable=True)
        catalog['author'] = index

        ob1 = stoopidCallable(author = "joe")
        ob1id = uidutil.register(ob1)
        catalog.index_doc(ob1id, ob1)

        res = catalog.searchResults(author=('joe','joe'))
        names = [x.author for x in res]
        names.sort()
        self.assertEqual(len(names), 1)
        self.assertEqual(names, ['joe'])

        ob2 = stoopidCallable() # no author here, will raise AttributeError
        ob2id = uidutil.register(ob2)
        try:
            catalog.index_doc(ob2id, ob2)
            self.fail("AttributeError exception should be raised")
        except AttributeError:
            #this is OK, we WANT to have the exception
            pass
Пример #12
0
 def setUp(self):
     """emulate the doctest fixtures"""
     self.intid = DummyIntId()
     provideUtility(self.intid, zope.intid.interfaces.IIntIds)
     self.catalog = Catalog()
     provideUtility(self.catalog, ICatalog, 'catalog1')
     self.catalog['f1'] = FieldIndex('f1', IContent)
     self.catalog['f2'] = FieldIndex('f2', IContent)
     self.catalog['f3'] = FieldIndex('f3', IContent)
     self.catalog['f4'] = FieldIndex('f4', IContent)
     self.catalog['t1'] = TextIndex('t1', IContent)
     self.catalog['t2'] = TextIndex('t2', IContent)
     provideUtility(query.Query(), IQuery)
     self.setup_content()
Пример #13
0
    def _createCatalog(self, site):
        """Create the catalog if needed and return it.

        If the catalog already exists, return that.

        """
        catalog = zope.component.queryUtility(ICatalog,
                                              name=self.catalog_name,
                                              context=site,
                                              default=None)
        if catalog is not None:
            return catalog
        catalog = Catalog()
        setupUtility = zope.component.getUtility(
            grokcore.site.interfaces.IUtilityInstaller)
        setupUtility(site, catalog, ICatalog, name=self.catalog_name)
        return catalog
Пример #14
0
 def __call__(self):
     catalog = Catalog()
     catalog[u'date'] = FieldIndex(field_name='date', field_callable=False)
     return catalog
Пример #15
0
 def create_catalog(self):
     catalog = Catalog()
     catalog[u'ting'] = TingIndex(field_name=('foo', 'bar', 'baz'),
                                  field_callable=False)
     return catalog