Commit 63c7b495 authored by Yusei Tahara's avatar Yusei Tahara

Merge branch 'for_testrunner_1'

parents c803a430 98601acc
......@@ -45,6 +45,7 @@ from Products.ERP5Type.tests.utils import reindex
from Products.ERP5Type.tests.backportUnittest import expectedFailure
from Products.DCWorkflow.DCWorkflow import ValidationFailed
from Products.ERP5Type.Base import _aq_reset
from Products.ERP5Type.tests.utils import createZODBPythonScript
class InventoryAPITestCase(ERP5TypeTestCase):
"""Base class for Inventory API Tests {{{
......@@ -132,6 +133,8 @@ class InventoryAPITestCase(ERP5TypeTestCase):
self.folder.getId() ]:
folder = self.portal[module]
folder.manage_delObjects(list(folder.objectIds()))
self.portal.portal_skins.custom.manage_delObjects(list(self.portal.portal_skins.custom.objectIds()))
self.tic()
def login(self, quiet=0, run=1):
......@@ -2739,6 +2742,125 @@ class TestInventoryDocument(InventoryAPITestCase):
optimisation__=False,
mirror_uid=self.mirror_node.getUid())])
def test_MultipleSectionAndFullInventory(self):
"""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.
self.portal.inventory_module.manage_delObjects(list(self.portal.inventory_module.objectIds()))
self.folder.manage_delObjects(list(self.folder.objectIds()))
self.commit()
self.tic()
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()
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})
class BaseTestUnitConversion(InventoryAPITestCase):
QUANTITY_UNIT_DICT = {}
......
......@@ -53,7 +53,7 @@ def _DateTime(*args, **kw):
return DateTime(*args, **kw)
@profiler_decorator
def castDate(value):
def castDate(value, change_timezone=True):
if value is None:
return None
date_kw = {'datefmt': 'international'}
......@@ -69,6 +69,17 @@ def castDate(value):
pass
elif isinstance(value, basestring):
try:
# This is needed because DateTime(2012) ignores timezone.
# >>> DateTime()
# DateTime('2012/01/30 19:06:34.216686 GMT+9')
# >>> DateTime('2012')
# DateTime('2012/01/01 00:00:00 GMT+0')
# Timezone changed from GMT+9 to GMT+0!
# Then document at "2012/01/01 00:00:00 GMT+9" cannot be found by
# query of '2012'.
# Because "2012/01/01 00:00:00 GMT+9" < "2012/01/01 00:00:00 GMT+0".
if value.isdigit():
raise DateTimeError
value = _DateTime(value, **date_kw)
except DateTimeError:
delimiter_count = countDelimiters(value)
......@@ -83,7 +94,14 @@ def castDate(value):
raise
else:
raise TypeError, 'Unknown date type: %r' % (value)
return value.toZone('UTC')
if change_timezone:
return value.toZone('UTC')
else:
# This is needed. Because if you call toZone('UTC'),
# 2012/12/01 can become 2012/11/30 and then month
# is changed! Month must not be changed. Otherwise
# getMonthLen returns wrong value.
return value
# (strongly) inspired from DateTime.DateTime.py
delimiter_list = ' -/.:,+'
......@@ -114,7 +132,7 @@ def countDelimiters(value):
@profiler_decorator
def getPeriodBoundaries(value):
first_date = castDate(value)
first_date = castDate(value, change_timezone=False)
if isinstance(value, dict):
value = value['query']
# Try to guess how much was given in query.
......@@ -127,7 +145,7 @@ def getPeriodBoundaries(value):
delta = delta_list[delimiter_count]
if callable(delta):
delta = delta(first_date)
return first_date, first_date + delta
return first_date.toZone('UTC'), (first_date + delta).toZone('UTC')
@profiler_decorator
def wholePeriod(search_key, group, column, value_list, exclude=False):
......
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