Commit 05a7bebe authored by Sebastien Robin's avatar Sebastien Robin

ERP5Catalog: fixed parameter propagation when using searchAndActivate and grouping

parent fef6cdfb
......@@ -1031,7 +1031,8 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
next_kw['priority'] = 1 + next_kw.get('priority', 1)
self.activate(activity='SQLQueue', **next_kw) \
._searchAndActivate(method_id,method_args, method_kw,
activate_kw, r[-1].getUid(), **kw)
activate_kw, r[-1].getUid(),
group_kw=group_kw, **kw)
if select_method_id:
portal_activities = self.getPortalObject().portal_activities
active_portal_activities = portal_activities.activate(
......
......@@ -4059,6 +4059,51 @@ VALUES
self.assertEqual([x.getObject() for x in catalog.searchResults(**query_lj)],
[org_a.default_address])
def testSearchAndActivateWithGroupMethodId(self):
"""
Make sure searchAndActivate method could be used with a grouping method,
and in particular make sure sure searchAndActivate can calls himself
properly.
We create 300 organisations and use a group method cost of 0.5.
So this means searchAndActivate should first create 200 activities
that will be grouped by 2. Then searchAndActivate will call himself
another time to activate the last 100 organisations, and in their turn
they will be grouped by 2.
"""
group_method_call_list = []
def doSomething(self, message_list):
r = []
for m in message_list:
m.result = r.append(m.object.getPath())
r.sort()
group_method_call_list.append(r)
self.portal.portal_activities.__class__.doSomething = doSomething
now = DateTime()
try:
organisation_list = []
for x in xrange(0,300):
organisation_list.append(
self.portal.organisation_module.newContent().getPath())
self.tic()
self.portal.portal_catalog.searchAndActivate(
creation_date={'query': now, 'range': 'min'},
method_id="dummyDoSomething",
group_kw = {"group_method_id" : "portal_activities/doSomething",
"group_method_cost": 0.5},
)
self.tic()
self.assertEqual(150, len(group_method_call_list))
organisation_call_list = []
for call_path_list in group_method_call_list:
self.assertEqual(2, len(call_path_list))
organisation_call_list.extend(call_path_list)
organisation_call_list.sort()
organisation_list.sort()
self.assertEqual(organisation_call_list, organisation_list)
finally:
del self.portal.portal_activities.__class__.doSomething
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestERP5Catalog))
......
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