Commit 8a335cca authored by Jérome Perrin's avatar Jérome Perrin

component: fix error_message saved in every line of history

Because error_message variable was missing in component_validation_workflow,
once the validation was refused for an error, every subsequent entry
in workflow history was carrying the same error message.

Adding the missing variable fix this, but it would cause diff every time
we modify and re-export a component, so we also take care of not exporting
it in business template, like we already did for other several variables.
parent 9dadb6dd
......@@ -4253,10 +4253,11 @@ class _ZodbComponentTemplateItem(ObjectTemplateItem):
continue
wf_history = obj.workflow_history[wf_id][-1]
# Remove useless modifcation 'time' and 'actor' (conflicts with VCSs)
wf_history.pop('time', None)
# Remove useless workflow entries that are always different and cause conflicts with VCS
wf_history.pop('actor', None)
wf_history.pop('comment', None)
wf_history.pop('error_message', None)
wf_history.pop('time', None)
obj.workflow_history[wf_id] = WorkflowHistoryList([wf_history])
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Workflow Variable" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>automatic_update</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>for_catalog</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>variable_error_message</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Workflow Variable</string> </value>
</item>
<item>
<key> <string>status_included</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value>
<none/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -1659,6 +1659,38 @@ class TestZodbModuleComponent(SecurityTestCase):
self.tic()
self.assertEqual(component.checkConsistency(), [])
def testWorkflowErrorMessage(self):
"""Check that validation error messages are stored in workflow
"""
component = self._newComponent(self._generateReference('WorkflowErrorMessage'))
valid_id = component.getId()
self.tic()
component.setId('wrong')
from Products.ERP5Type.Core.Workflow import ValidationFailed
with self.assertRaises(ValidationFailed):
self.portal.portal_workflow.doActionFor(component, 'validate_action')
last_error_message = str(
self.portal.portal_workflow.getInfoFor(
component, 'history',
wf_id='component_validation_workflow')[-1]['error_message'][0])
self.assertEqual(
last_error_message,
self.portal.Base_translateString(
ComponentMixin._message_invalid_id,
mapping={'id_prefix': self._document_class.getIdPrefix()}))
self.tic()
# non-regression test: when there is no error the error is no longer
# in workflow history
component.setId(valid_id)
component.validate()
self.tic()
last_error_message = self.portal.portal_workflow.getInfoFor(
component, 'history',
wf_id='component_validation_workflow')[-1]['error_message']
self.assertEqual(last_error_message, '')
def testReferenceWithReservedKeywords(self):
"""
Check whether checkConsistency has been properly implemented for checking
......
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