Commit 92c8c0fa authored by Martijn Pieters's avatar Martijn Pieters

Simplify and cleanup the tests, including removing a double definition of the same test.

parent 1fda5504
...@@ -24,20 +24,12 @@ from Products.PluginIndexes.PathIndex.PathIndex import PathIndex ...@@ -24,20 +24,12 @@ from Products.PluginIndexes.PathIndex.PathIndex import PathIndex
class Dummy: class Dummy:
meta_type="foo"
def __init__( self, path): def __init__( self, path):
self.path = path self.path = path
def getPhysicalPath(self): def getPhysicalPath(self):
return self.path.split('/') return self.path.split('/')
def __str__( self ):
return '<Dummy: %s>' % self.path
__repr__ = __str__
class PathIndexTests(unittest.TestCase): class PathIndexTests(unittest.TestCase):
""" Test PathIndex objects """ """ Test PathIndex objects """
...@@ -81,7 +73,7 @@ class PathIndexTests(unittest.TestCase): ...@@ -81,7 +73,7 @@ class PathIndexTests(unittest.TestCase):
self.assertEqual(self._index.numObjects() ,0) self.assertEqual(self._index.numObjects() ,0)
self.assertEqual(self._index.getEntryForObject(1234), None) self.assertEqual(self._index.getEntryForObject(1234), None)
self._index.unindex_object( 1234 ) # nothrow self._index.unindex_object( 1234 ) # nothrow
self.assertEqual(self._index._apply_index({"suxpath":"xxx"}), None) self.assertEqual(self._index._apply_index(dict(suxpath="xxx")), None)
def testUnIndex(self): def testUnIndex(self):
self._populateIndex() self._populateIndex()
...@@ -114,79 +106,49 @@ class PathIndexTests(unittest.TestCase): ...@@ -114,79 +106,49 @@ class PathIndexTests(unittest.TestCase):
self._index.unindex_object(1) self._index.unindex_object(1)
def testRoot(self): def testRoot(self):
self._populateIndex() self._populateIndex()
tests = ( ("/",0, range(1,19)), )
for comp,level,results in tests:
for path in [comp,"/"+comp,"/"+comp+"/"]:
res = self._index._apply_index(
{"path":{'query':path,"level":level}})
lst = list(res[0].keys())
self.assertEqual(lst,results)
for comp,level,results in tests:
for path in [comp,"/"+comp,"/"+comp+"/"]:
res = self._index._apply_index(
{"path":{'query':( (path,level),)}})
lst = list(res[0].keys())
self.assertEqual(lst,results)
def testRoot(self): queries = (
dict(path=dict(query='/', level=0)),
self._populateIndex() dict(path=(('/', 0),)),
tests = ( ("/",0, range(1,19)), ) )
for q in queries:
for comp,level,results in tests: res = self._index._apply_index(q)
for path in [comp,"/"+comp,"/"+comp+"/"]: self.assertEqual(list(res[0].keys()), range(1,19))
res = self._index._apply_index(
{"path":{'query':path,"level":level}})
lst = list(res[0].keys())
self.assertEqual(lst,results)
for comp,level,results in tests:
for path in [comp,"/"+comp,"/"+comp+"/"]:
res = self._index._apply_index(
{"path":{'query':( (path,level),)}})
lst = list(res[0].keys())
self.assertEqual(lst,results)
def testSimpleTests(self): def testSimpleTests(self):
self._populateIndex() self._populateIndex()
tests = [ tests = [
# component, level, expected results
("aa", 0, [1,2,3,4,5,6,7,8,9]), ("aa", 0, [1,2,3,4,5,6,7,8,9]),
("aa", 1, [1,2,3,10,11,12] ), ("aa", 1, [1,2,3,10,11,12] ),
("bb", 0, [10,11,12,13,14,15,16,17,18]), ("bb", 0, [10,11,12,13,14,15,16,17,18]),
("bb", 1, [4,5,6,13,14,15] ), ("bb", 1, [4,5,6,13,14,15]),
("bb/cc", 0, [16,17,18] ), ("bb/cc", 0, [16,17,18]),
("bb/cc", 1, [6,15] ), ("bb/cc", 1, [6,15]),
("bb/aa", 0, [10,11,12] ), ("bb/aa", 0, [10,11,12]),
("bb/aa", 1, [4,13] ), ("bb/aa", 1, [4,13]),
("aa/cc", -1, [3,7,8,9,12] ), ("aa/cc", -1, [3,7,8,9,12]),
("bb/bb", -1, [5,13,14,15] ), ("bb/bb", -1, [5,13,14,15]),
("18.html", 3, [18] ), ("18.html", 3, [18]),
("18.html", -1, [18] ), ("18.html", -1, [18]),
("cc/18.html", -1, [18] ), ("cc/18.html", -1, [18]),
("cc/18.html", 2, [18] ), ("cc/18.html", 2, [18]),
] ]
for comp,level,results in tests: for comp, level, results in tests:
for path in [comp,"/"+comp,"/"+comp+"/"]: for path in [comp, "/"+comp, "/"+comp+"/"]:
res = self._index._apply_index( # Test with the level passed in as separate parameter
{"path":{'query':path,"level":level}}) res = self._index._apply_index(dict(path=
lst = list(res[0].keys()) dict(query=path, level=level)))
self.assertEqual(lst,results) self.assertEqual(list(res[0].keys()), results)
for comp,level,results in tests: # Test with the level passed in as part of the path parameter
for path in [comp,"/"+comp,"/"+comp+"/"]: res = self._index._apply_index(dict(path=
res = self._index._apply_index( dict(query=((path, level),))))
{"path":{'query':( (path,level),)}}) self.assertEqual(list(res[0].keys()), results)
lst = list(res[0].keys())
self.assertEqual(lst,results)
def testComplexOrTests(self): def testComplexOrTests(self):
self._populateIndex() self._populateIndex()
tests = [ tests = [
(['aa','bb'],1,[1,2,3,4,5,6,10,11,12,13,14,15]), (['aa','bb'],1,[1,2,3,4,5,6,10,11,12,13,14,15]),
...@@ -194,36 +156,34 @@ class PathIndexTests(unittest.TestCase): ...@@ -194,36 +156,34 @@ class PathIndexTests(unittest.TestCase):
([('cc',1),('cc',2)],0,[3,6,7,8,9,12,15,16,17,18]), ([('cc',1),('cc',2)],0,[3,6,7,8,9,12,15,16,17,18]),
] ]
for lst ,level,results in tests: for lst, level, results in tests:
res = self._index._apply_index(dict(path=
res = self._index._apply_index( dict(query=lst, level=level, operator='or')))
{"path":{'query':lst,"level":level,"operator":"or"}})
lst = list(res[0].keys()) lst = list(res[0].keys())
self.assertEqual(lst,results) self.assertEqual(lst, results)
def testComplexANDTests(self): def testComplexANDTests(self):
self._populateIndex() self._populateIndex()
tests = [ tests = [
(['aa','bb'],1,[]), # Path query (as list or (path, level) tuple), level, expected
([('aa',0),('bb',1)],0,[4,5,6]), (['aa','bb'], 1, []),
([('aa',0),('cc',2)],0,[3,6,9]), ([('aa',0), ('bb',1)], 0, [4,5,6]),
([('aa',0), ('cc',2)], 0, [3,6,9]),
] ]
for lst ,level,results in tests: for lst, level, results in tests:
res = self._index._apply_index( res = self._index._apply_index(dict(path=
{"path":{'query':lst,"level":level,"operator":"and"}}) dict(query=lst, level=level, operator='and')))
lst = list(res[0].keys()) lst = list(res[0].keys())
self.assertEqual(lst,results) self.assertEqual(lst, results)
def testQueryPathReturnedInResult(self): def testQueryPathReturnedInResult(self):
index = self._index index = self._index
index.index_object(1, Dummy("/ff")) index.index_object(1, Dummy("/ff"))
index.index_object(2, Dummy("/ff/gg")) index.index_object(2, Dummy("/ff/gg"))
index.index_object(3, Dummy("/ff/gg/3.html")) index.index_object(3, Dummy("/ff/gg/3.html"))
index.index_object(4, Dummy("/ff/gg/4.html")) index.index_object(4, Dummy("/ff/gg/4.html"))
res = index._apply_index({'path': {'query': '/ff/gg'}}) res = index._apply_index(dict(path=dict(query='/ff/gg')))
lst = list(res[0].keys()) lst = list(res[0].keys())
self.assertEqual(lst, [2, 3, 4]) self.assertEqual(lst, [2, 3, 4])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment