Commit 15805d6c authored by Arnaud Fontaine's avatar Arnaud Fontaine

simulation: Variation Equivalence Tester tested property name should not be hardcoded.

Instead, define default values if not set (same as previously hardcoded
ones) and get the value(s) define on the Tester instead as we may want
to check only variation_category_list and not variation_property_dict
for example...

Followup of: "simulation: improve equivalence testers explanations messages".
parent a5f15bff
......@@ -37,14 +37,17 @@ class VariationEquivalenceTester(Predicate, EquivalenceTesterMixin):
consistency between delivery movement and simulation movement
for a specific property.
"""
meta_type = 'ERP5 Dict Equivalence Tester'
portal_type = 'Dict Equivalence Tester'
meta_type = 'ERP5 Variation Divergence Tester'
portal_type = 'Variation Divergence Tester'
add_permission = Permissions.AddPortalContent
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
tested_property = ('variation_category_list',
'variation_property_dict')
# Declarative properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
......@@ -59,8 +62,7 @@ class VariationEquivalenceTester(Predicate, EquivalenceTesterMixin):
If prevision_movement and decision_movement don't match, it returns a
list : (prevision_value, decision_value, message, mapping)
"""
for tested_property in ('variation_category_list',
'variation_property_dict'):
for tested_property_index, tested_property in enumerate(self.getTestedPropertyList()):
if getattr(decision_movement, 'isPropertyRecorded',
lambda x:False)(tested_property):
decision_value = decision_movement.getRecordedProperty(tested_property)
......@@ -79,15 +81,12 @@ class VariationEquivalenceTester(Predicate, EquivalenceTesterMixin):
# should not happen
raise AttributeError, 'prevision and decision values of this divergence tester should be list, tuple or dict.'
if not result:
property_name = tested_property
try:
# Get the property label to display to user
property_title_index = self.getTestedPropertyList().index(tested_property)
# XXX We should use "getTranslatedTestedPropertyTitleList", but it seems to
# not exist for accessors having multiple possible values
property_name = self.getTestedPropertyTitleList()[property_title_index]
pass
except (ValueError, IndexError):
property_name = self.getTestedPropertyTitleList()[tested_property_index]
except IndexError:
property_name = tested_property
return (
prevision_value, decision_value,
'The value of ${property_name} is different between decision and prevision.',
......@@ -106,8 +105,7 @@ class VariationEquivalenceTester(Predicate, EquivalenceTesterMixin):
the recorded properties instead of the native ones.
"""
value_list = []
for tested_property in ('variation_category_list',
'variation_property_dict'):
for tested_property in self.getTestedPropertyList():
if movement.isPropertyRecorded(tested_property):
value_list.append(movement.getRecordedProperty(tested_property))
else:
......@@ -126,5 +124,4 @@ class VariationEquivalenceTester(Predicate, EquivalenceTesterMixin):
"""
get = self._getTestedPropertyValue
return {tested_property: get(prevision_movement, tested_property)
for tested_property in ('variation_category_list',
'variation_property_dict')}
for tested_property in self.getTestedPropertyList()}
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