Commit 6694b3d6 authored by Jérome Perrin's avatar Jérome Perrin

pass group_by_expression to buildSQLQuery

add a new getInventoryList test


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12003 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3a59776d
......@@ -454,7 +454,7 @@ class SimulationTool (BaseTool):
if len(group_by_expression_list):
# Always group by resource
group_by_expression_list.append('%s.resource_uid' % table)
sql_kw['group_by_expression'] = ', '.join(group_by_expression_list)
new_kw['group_by_expression'] = ', '.join(group_by_expression_list)
sql_kw.update(self.portal_catalog.buildSQLQuery(**new_kw))
return sql_kw
......
......@@ -77,6 +77,7 @@ class InventoryAPITestCase(ERP5TypeTestCase):
self.section = self._makeOrganisation(title='Section')
self.node = self._makeOrganisation(title='Node')
self.other_node = self._makeOrganisation(title='Other Node')
self.payment_node = self.section.newContent(
title='Payment Node',
portal_type='Bank Account')
......@@ -497,6 +498,34 @@ class TestInventory(InventoryAPITestCase):
class TestInventoryList(InventoryAPITestCase):
"""Tests getInventoryList methods.
"""
def test_ReturnedTypeIsList(self):
"""Inventory List returns a sequence object"""
getInventoryList = self.getSimulationTool().getInventoryList
inventory_list = getInventoryList()
self.assertEquals(str(inventory_list.__class__),
'Shared.DC.ZRDB.Results.Results')
# the brain is InventoryListBrain
self.assert_('InventoryListBrain' in
[c.__name__ for c in inventory_list._class.__bases__])
# default is an empty list
self.assertEquals(0, len(inventory_list))
def test_GroupByNode(self):
getInventoryList = self.getSimulationTool().getInventoryList
self._makeMovement(quantity=100)
self._makeMovement(destination_value=self.other_node, quantity=100)
self._makeMovement(destination_value=None, quantity=100)
inventory_list = getInventoryList(group_by_node=1)
self.assertEquals(3, len(inventory_list))
self.assertEquals([r for r in inventory_list if r.node_relative_url ==
self.node.getRelativeUrl()][0].inventory, 100)
self.assertEquals([r for r in inventory_list if r.node_relative_url ==
self.other_node.getRelativeUrl()][0].inventory, 100)
self.assertEquals([r for r in inventory_list if r.node_relative_url ==
self.mirror_node.getRelativeUrl()][0].inventory, -300)
# TODO group by mirror_node, section, mirror_section, payment, resource
# ? and maybe project, function, portal_type ?
class TestMovementHistoryList(InventoryAPITestCase):
"""Tests Movement history list methods.
......
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