Commit 62b17262 authored by Yusei Tahara's avatar Yusei Tahara

Move full inventory related test to TestInventoryDocument and add more tests to it.

parent d2189e27
...@@ -457,67 +457,6 @@ class TestInventory(InventoryAPITestCase): ...@@ -457,67 +457,6 @@ class TestInventory(InventoryAPITestCase):
self.assertInventoryEquals(100, self.assertInventoryEquals(100,
resource_category_strict_membership=['product_line/level1']) resource_category_strict_membership=['product_line/level1'])
def test_ResourceCategoryWithFullInventory(self):
"""Make sure that resource category works when full inventory exists."""
self.resource.setProductLine('level1/level2')
self.other_resource.setProductLine('anotherlevel')
full_inventory1 = self.portal.inventory_module.newContent(portal_type='Inventory')
full_inventory1.edit(destination_section_value=self.section,
destination_value=self.node,
full_inventory=1,
start_date=DateTime('2012/05/18 00:00:00 GMT+9'))
line11 = full_inventory1.newContent(portal_type='Inventory Line')
line11.setResourceValue(self.resource)
line11.setQuantity(17)
line12 = full_inventory1.newContent(portal_type='Inventory Line')
line12.setResourceValue(self.other_resource)
line12.setQuantity(13)
full_inventory1.deliver()
self.commit()
self.tic()
self.assertInventoryEquals(17,
resource_uid=self.resource.getUid()
)
self.assertInventoryEquals(13,
resource_uid=self.other_resource.getUid()
)
self.assertInventoryEquals(17,
section_uid=self.section.getUid(),
node_uid=self.node.getUid(),
resource_uid=self.resource.getUid()
)
self.assertInventoryEquals(13,
section_uid=self.section.getUid(),
node_uid=self.node.getUid(),
resource_uid=self.other_resource.getUid()
)
self.assertInventoryEquals(17,
resource_category='product_line/level1'
)
self.assertInventoryEquals(13,
resource_category='product_line/anotherlevel'
)
# In reality this is not an expected failure, I will remove this very soon.(Yusei)
expectedFailure(self.assertInventoryEquals)(17,
section_uid=self.section.getUid(),
node_uid=self.node.getUid(),
resource_category='product_line/level1'
)
self.assertInventoryEquals(13,
section_uid=self.section.getUid(),
node_uid=self.node.getUid(),
resource_category='product_line/anotherlevel'
)
def test_PaymentCategory(self): def test_PaymentCategory(self):
"""Tests inventory on payment_category """ """Tests inventory on payment_category """
# for now, BankAccount have a product_line category, so we can use this for # for now, BankAccount have a product_line category, so we can use this for
...@@ -2428,6 +2367,90 @@ class TestInventoryDocument(InventoryAPITestCase): ...@@ -2428,6 +2367,90 @@ class TestInventoryDocument(InventoryAPITestCase):
self.getInventory(optimisation__=False, self.getInventory(optimisation__=False,
**inventory_kw)) **inventory_kw))
def setUpDefaultInventoryCalculationList(self):
createZODBPythonScript(self.portal.portal_skins.custom,
'Inventory_getDefaultInventoryCalculationList', '',
'''return ({
'inventory_params':{
'section_uid':context.getDestinationSectionUid(),
'node_uid':context.getDestinationUid(),
'group_by_variation':1,
'group_by_resource':1},
'list_method':'getMovementList',
'first_level':({'key':'resource_relative_url',
'getter':'getResource',
'setter':('appendToCategoryList', 'resource')},
{'key':'variation_text',
'getter':'getVariationText',
'setter':'splitAndExtendToCategoryList'},
),
},)
''')
self.commit()
def clearAllInventoryAndSetUpTwoInventory(self):
self.portal.inventory_module.manage_delObjects(list(self.portal.inventory_module.objectIds()))
self.folder.manage_delObjects(list(self.folder.objectIds()))
self.resource.setProductLine('level1/level2')
self.other_resource.setProductLine('anotherlevel')
self.section.setGroup('level1/level2')
self.other_section.setGroup('anotherlevel')
self.node.setRegion('level1')
self.other_node.setGroup('anotherlevel')
full_inventory = self.portal.inventory_module.newContent(portal_type='Inventory')
full_inventory.edit(destination_section_value=self.section,
destination_value=self.node,
full_inventory=1,
start_date=DateTime('2012/05/18 00:00:00 GMT+9'))
line = full_inventory.newContent(portal_type='Inventory Line')
line.setResourceValue(self.resource)
line.setQuantity(1)
line = full_inventory.newContent(portal_type='Inventory Line')
line.setResourceValue(self.other_resource)
line.setQuantity(10)
full_inventory.deliver()
full_inventory = self.portal.inventory_module.newContent(portal_type='Inventory')
full_inventory.edit(destination_section_value=self.other_section,
destination_value=self.node,
full_inventory=1,
start_date=DateTime('2012/05/18 00:00:00 GMT+9'))
line = full_inventory.newContent(portal_type='Inventory Line')
line.setResourceValue(self.resource)
line.setQuantity(100)
line = full_inventory.newContent(portal_type='Inventory Line')
line.setResourceValue(self.other_resource)
line.setQuantity(1000)
full_inventory.deliver()
full_inventory = self.portal.inventory_module.newContent(portal_type='Inventory')
full_inventory.edit(destination_section_value=self.section,
destination_value=self.other_node,
full_inventory=1,
start_date=DateTime('2012/05/18 00:00:00 GMT+9'))
line = full_inventory.newContent(portal_type='Inventory Line')
line.setResourceValue(self.resource)
line.setQuantity(10000)
line = full_inventory.newContent(portal_type='Inventory Line')
line.setResourceValue(self.other_resource)
line.setQuantity(100000)
full_inventory.deliver()
full_inventory = self.portal.inventory_module.newContent(portal_type='Inventory')
full_inventory.edit(destination_section_value=self.other_section,
destination_value=self.other_node,
full_inventory=1,
start_date=DateTime('2012/05/18 00:00:00 GMT+9'))
line = full_inventory.newContent(portal_type='Inventory Line')
line.setResourceValue(self.resource)
line.setQuantity(1000000)
line = full_inventory.newContent(portal_type='Inventory Line')
line.setResourceValue(self.other_resource)
line.setQuantity(10000000)
full_inventory.deliver()
self.commit()
self.tic()
def test_01_CurrentInventoryWithFullInventory(self): def test_01_CurrentInventoryWithFullInventory(self):
""" """
Check that inventory optimisation is executed when querying current Check that inventory optimisation is executed when querying current
...@@ -2742,126 +2765,46 @@ class TestInventoryDocument(InventoryAPITestCase): ...@@ -2742,126 +2765,46 @@ class TestInventoryDocument(InventoryAPITestCase):
optimisation__=False, optimisation__=False,
mirror_uid=self.mirror_node.getUid())]) mirror_uid=self.mirror_node.getUid())])
@expectedFailure def test_ResourceCategory(self):
def test_MultipleSectionAndFullInventory(self): """Make sure that resource category works when full inventory exists."""
"""Make sure that getInventoryList works in the situation which
two sections use the same node and one section has full inventory for
the node.
"""
# In this test we do not need doucments made by afterSetUp. # In this test we do not need doucments made by afterSetUp.
self.portal.inventory_module.manage_delObjects(list(self.portal.inventory_module.objectIds())) self.setUpDefaultInventoryCalculationList()
self.folder.manage_delObjects(list(self.folder.objectIds())) self.clearAllInventoryAndSetUpTwoInventory()
self.assertEquals(1,
self.commit() self.getInventory(section_uid=self.section.getUid(),
self.tic() node_uid=self.node.getUid(),
resource_category='product_line/level1',
optimisation__=False))
self.assertEquals(1,
self.getInventory(section_uid=self.section.getUid(),
node_uid=self.node.getUid(),
resource_category='product_line/level1',
optimisation__=True))
createZODBPythonScript(self.portal.portal_skins.custom, def test_SectionCategory(self):
'Inventory_getDefaultInventoryCalculationList', '', """Make sure that section category works when full inventory exists."""
'''return ({ # In this test we do not need doucments made by afterSetUp.
'inventory_params':{ self.clearAllInventoryAndSetUpTwoInventory()
'section_uid':context.getDestinationSectionUid(), self.assertEquals(11,
'node_uid':context.getDestinationUid(), self.getInventory(node_uid=self.node.getUid(),
'group_by_variation':1, section_category='group/level1/level2',
'group_by_resource':1}, optimisation__=False))
'list_method':'getMovementList', self.assertEquals(11,
'first_level':({'key':'resource_relative_url', self.getInventory(node_uid=self.node.getUid(),
'getter':'getResource', section_category='group/level1/level2',
'setter':('appendToCategoryList', 'resource')}, optimisation__=True))
{'key':'variation_text',
'getter':'getVariationText',
'setter':'splitAndExtendToCategoryList'},
),
},)
''')
self.commit()
getCurrentInventoryList = self.getSimulationTool().getCurrentInventoryList
# Add movements for section
self._makeMovement(source_section_value=None,
source_value=None,
destination_section_value=self.section,
destination_value=self.node,
start_date=DateTime('2012/07/18 00:00:00 GMT+9'),
simulation_state='delivered',
resource_value=self.resource,
quantity=1)
self._makeMovement(source_section_value=None,
source_value=None,
destination_section_value=self.section,
destination_value=self.node,
start_date=DateTime('2012/07/21 00:00:00 GMT+9'),
simulation_state='delivered',
resource_value=self.resource,
quantity=2)
# Add movemnets for other section
self._makeMovement(source_section_value=None,
source_value=None,
destination_section_value=self.other_section,
destination_value=self.node,
start_date=DateTime('2012/07/19 00:00:00 GMT+9'),
simulation_state='delivered',
resource_value=self.resource,
quantity=3)
self._makeMovement(source_section_value=None,
source_value=None,
destination_section_value=self.other_section,
destination_value=self.node,
start_date=DateTime('2012/07/20 00:00:00 GMT+9'),
simulation_state='delivered',
resource_value=self.resource,
quantity=4)
self.commit()
self.tic()
# Check inventory
result = {}
for brain in getCurrentInventoryList(node_uid=self.node.getUid(),
group_by_resource=1,
group_by_node=1,
group_by_section=1):
key = (brain.section_uid, brain.node_uid, brain.resource_uid)
if not key in result:
result[key] = 0
result[key] = result[key] + brain.inventory
self.assertEqual(result,
{(self.section.getUid(), self.node.getUid(), self.resource.getUid()):3,
(self.other_section.getUid(), self.node.getUid(), self.resource.getUid()):7})
# Add full inventory for section, not for other section
full_inventory1 = self.portal.inventory_module.newContent(portal_type='Inventory')
full_inventory1.edit(destination_section_value=self.section,
destination_value=self.node,
full_inventory=1,
start_date=DateTime('2012/07/20 00:00:00 GMT+9'))
line = full_inventory1.newContent(portal_type='Inventory Line')
line.setResourceValue(self.resource)
line.setQuantity(100)
full_inventory1.deliver()
self.commit()
self.tic()
# Check inventory again. This time, full inventory should change
# section's inventory. It should not change other section's inventory.
result = {}
for brain in getCurrentInventoryList(node_uid=self.node.getUid(),
group_by_resource=1,
group_by_node=1,
group_by_section=1):
key = (brain.section_uid, brain.node_uid, brain.resource_uid)
if not key in result:
result[key] = 0
result[key] = result[key] + brain.inventory
self.assertEqual(result,
{(self.section.getUid(), self.node.getUid(), self.resource.getUid()):102,
(self.other_section.getUid(), self.node.getUid(), self.resource.getUid()):7})
def test_NodeCategory(self):
# In this test we do not need doucments made by afterSetUp.
self.clearAllInventoryAndSetUpTwoInventory()
self.assertEquals(11,
self.getInventory(section_uid=self.section.getUid(),
node_category='region/level1',
optimisation__=False))
self.assertEquals(11,
self.getInventory(section_uid=self.section.getUid(),
node_category='region/level1',
optimisation__=True))
class BaseTestUnitConversion(InventoryAPITestCase): class BaseTestUnitConversion(InventoryAPITestCase):
QUANTITY_UNIT_DICT = {} QUANTITY_UNIT_DICT = {}
......
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