From: Sidnei da S. <dre...@us...> - 2004-09-11 04:01:32
|
Update of /cvsroot/collective/NavtreeIndexNG/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4349/tests Modified Files: testNavtreeIndexNG.py Log Message: Avoid indexing object as a children of itself if it comes in with weird acquisition context. Index: testNavtreeIndexNG.py =================================================================== RCS file: /cvsroot/collective/NavtreeIndexNG/tests/testNavtreeIndexNG.py,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- testNavtreeIndexNG.py 9 Sep 2004 00:57:03 -0000 1.10 +++ testNavtreeIndexNG.py 10 Sep 2004 21:03:32 -0000 1.11 @@ -12,19 +12,24 @@ ############################################################################## import unittest +from Acquisition import ImplicitAcquisitionWrapper as IAW class Base: def __init__(self, id, docid): self._id = id self._docid = docid - self.aq_parent = None + self._parent = None def setParent(self, parent): - self.aq_parent = parent + self._parent = parent def getParent(self): - return self.aq_parent + p = self._parent + if p is None: + return None + g = p.getParent() + return IAW(p, g) def getId(self): return self._id @@ -69,8 +74,8 @@ return [c.getId() for c in self._childs] def objectValues(self): - return self._childs - + wself = IAW(self, self.getParent()) + return [IAW(c, wself) for c in self._childs] class Document(Base): meta_type = portal_type = 'Document' @@ -109,7 +114,7 @@ from Products.NavtreeIndexNG.NavtreeIndexNG import NavtreeIndexNG self._index = NavtreeIndexNG('navigation') - root = Folder('root', 0) + root = IAW(Folder('root', 0), None) members = Folder('Members', 1) documents = Folder('Documents', 2) @@ -190,6 +195,16 @@ r = self._index.searchChildsDepth('/root', 1) self.assertEqual(list(r[0]), [1,2]) + def testIndexWrappedAvoidSelfRef(self): + self.assertEqual( self._index.numObjects(), 11) + r = self._index.searchChildsDepth('/root', 1) + self.assertEqual(list(r[0]), [1,2]) + wroot = IAW(self.root, self.root) + self._index.index_object(wroot.getDocId(), wroot) + self.assertEqual( self._index.numObjects(), 11) + r = self._index.searchChildsDepth('/root', 1) + self.assertEqual(list(r[0]), [1,2]) + def testQueryChilds(self): r = self._index.search('/root', 'childs') self.assertEqual(list(r[0]), [1,2]) |