diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Component_view.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Component_view.xml index 491ce56894b1d7addfbe500c0996624b49709807..aeb33550febaa463b3ba7a55e0938763de99865e 100644 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Component_view.xml +++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Component_view.xml @@ -106,7 +106,7 @@ <value> <list> <string>my_description</string> - <string>my_translated_validation_state_title</string> + <string>my_translated_validation_state_title_with_error_message</string> </list> </value> </item> diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Component_view/my_translated_validation_state_title.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Component_view/my_translated_validation_state_title_with_error_message.xml similarity index 98% rename from product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Component_view/my_translated_validation_state_title.xml rename to product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Component_view/my_translated_validation_state_title_with_error_message.xml index f8bf5216b58f242f89e84c2b71a6fa143dfe5460..864a295d7f30ec960f55a6087ba79ba2ae4fa28a 100644 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Component_view/my_translated_validation_state_title.xml +++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Component_view/my_translated_validation_state_title_with_error_message.xml @@ -14,7 +14,7 @@ </item> <item> <key> <string>id</string> </key> - <value> <string>my_translated_validation_state_title</string> </value> + <value> <string>my_translated_validation_state_title_with_error_message</string> </value> </item> <item> <key> <string>message_values</string> </key> diff --git a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_interaction_workflow/interactions/Component_reset.xml b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_interaction_workflow/interactions/Component_reset.xml index 8215e15dcb3520bc533f99d43baca7e853fe0821..5a7f0c8023b85a51e3735b6a8d13bb8a5e828f03 100644 --- a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_interaction_workflow/interactions/Component_reset.xml +++ b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_interaction_workflow/interactions/Component_reset.xml @@ -58,7 +58,6 @@ <list> <string>validate</string> <string>invalidate</string> - <string>revalidate</string> </list> </value> </item> diff --git a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_interaction_workflow/interactions/Component_revalidate.xml b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_interaction_workflow/interactions/Component_revalidate.xml deleted file mode 100644 index 74aecd086ba8d6e9c3e7a9946ccc5ea6cb502d75..0000000000000000000000000000000000000000 --- a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_interaction_workflow/interactions/Component_revalidate.xml +++ /dev/null @@ -1,97 +0,0 @@ -<?xml version="1.0"?> -<ZopeData> - <record id="1" aka="AAAAAAAAAAE="> - <pickle> - <global name="InteractionDefinition" module="Products.ERP5.Interaction"/> - </pickle> - <pickle> - <dictionary> - <item> - <key> <string>actbox_category</string> </key> - <value> <string>workflow</string> </value> - </item> - <item> - <key> <string>actbox_name</string> </key> - <value> <string></string> </value> - </item> - <item> - <key> <string>actbox_url</string> </key> - <value> <string></string> </value> - </item> - <item> - <key> <string>activate_script_name</string> </key> - <value> - <tuple/> - </value> - </item> - <item> - <key> <string>after_script_name</string> </key> - <value> - <tuple/> - </value> - </item> - <item> - <key> <string>before_commit_script_name</string> </key> - <value> - <tuple/> - </value> - </item> - <item> - <key> <string>description</string> </key> - <value> <string></string> </value> - </item> - <item> - <key> <string>guard</string> </key> - <value> - <none/> - </value> - </item> - <item> - <key> <string>id</string> </key> - <value> <string>Component_revalidate</string> </value> - </item> - <item> - <key> <string>method_id</string> </key> - <value> - <list> - <string>revalidate</string> - </list> - </value> - </item> - <item> - <key> <string>once_per_transaction</string> </key> - <value> <int>1</int> </value> - </item> - <item> - <key> <string>portal_type_filter</string> </key> - <value> - <list> - <string>Document Component</string> - <string>Extension Component</string> - </list> - </value> - </item> - <item> - <key> <string>script_name</string> </key> - <value> - <list> - <string>revalidate</string> - </list> - </value> - </item> - <item> - <key> <string>temporary_document_disallowed</string> </key> - <value> <int>0</int> </value> - </item> - <item> - <key> <string>title</string> </key> - <value> <string></string> </value> - </item> - <item> - <key> <string>trigger_type</string> </key> - <value> <int>2</int> </value> - </item> - </dictionary> - </pickle> - </record> -</ZopeData> diff --git a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_interaction_workflow/scripts/revalidate.xml b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_interaction_workflow/scripts/revalidate.xml deleted file mode 100644 index a2388de3fc63160eaa6a31390088cbbe92869134..0000000000000000000000000000000000000000 --- a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_interaction_workflow/scripts/revalidate.xml +++ /dev/null @@ -1,67 +0,0 @@ -<?xml version="1.0"?> -<ZopeData> - <record id="1" aka="AAAAAAAAAAE="> - <pickle> - <global name="PythonScript" module="Products.PythonScripts.PythonScript"/> - </pickle> - <pickle> - <dictionary> - <item> - <key> <string>Script_magic</string> </key> - <value> <int>3</int> </value> - </item> - <item> - <key> <string>_bind_names</string> </key> - <value> - <object> - <klass> - <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/> - </klass> - <tuple/> - <state> - <dictionary> - <item> - <key> <string>_asgns</string> </key> - <value> - <dictionary> - <item> - <key> <string>name_container</string> </key> - <value> <string>container</string> </value> - </item> - <item> - <key> <string>name_context</string> </key> - <value> <string>context</string> </value> - </item> - <item> - <key> <string>name_m_self</string> </key> - <value> <string>script</string> </value> - </item> - <item> - <key> <string>name_subpath</string> </key> - <value> <string>traverse_subpath</string> </value> - </item> - </dictionary> - </value> - </item> - </dictionary> - </state> - </object> - </value> - </item> - <item> - <key> <string>_body</string> </key> - <value> <string>state_change[\'object\'].setTextContentAfterRevalidation()\n -</string> </value> - </item> - <item> - <key> <string>_params</string> </key> - <value> <string>state_change</string> </value> - </item> - <item> - <key> <string>id</string> </key> - <value> <string>revalidate</string> </value> - </item> - </dictionary> - </pickle> - </record> -</ZopeData> diff --git a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/states/modified.xml b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/states/modified.xml new file mode 100644 index 0000000000000000000000000000000000000000..a93b0a2f7de5ace36edbca9bbc8899a8bf344bee --- /dev/null +++ b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/states/modified.xml @@ -0,0 +1,41 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="StateDefinition" module="Products.DCWorkflow.States"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>description</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>modified</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string>Modified</string> </value> + </item> + <item> + <key> <string>transitions</string> </key> + <value> + <tuple> + <string>invalidate</string> + <string>invalidate_action</string> + <string>modified</string> + <string>validate</string> + </tuple> + </value> + </item> + <item> + <key> <string>type_list</string> </key> + <value> + <tuple/> + </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/states/validated.xml b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/states/validated.xml index e13554c40e6c5ece5d11ad81fcd71d35445471aa..219f67c4173fc21fe807b337e9eae95d17d098aa 100644 --- a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/states/validated.xml +++ b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/states/validated.xml @@ -30,8 +30,8 @@ <tuple> <string>invalidate</string> <string>invalidate_action</string> - <string>revalidate</string> - <string>revalidate_action</string> + <string>modified</string> + <string>validate</string> </tuple> </value> </item> diff --git a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/revalidate.xml b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/modified.xml similarity index 94% rename from product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/revalidate.xml rename to product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/modified.xml index 3ca764fb2bf43a52c09ab2ee2857ffbe954eabaa..94ab3bb0979b5337a4fc2de76bdd4192ad70c967 100644 --- a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/revalidate.xml +++ b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/modified.xml @@ -38,11 +38,11 @@ </item> <item> <key> <string>id</string> </key> - <value> <string>revalidate</string> </value> + <value> <string>modified</string> </value> </item> <item> <key> <string>new_state_id</string> </key> - <value> <string></string> </value> + <value> <string>modified</string> </value> </item> <item> <key> <string>script_name</string> </key> diff --git a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/revalidate_action.xml b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/revalidate_action.xml deleted file mode 100644 index f7b38f57e5fc9b70a6e0af357eb19e42e9c5ab81..0000000000000000000000000000000000000000 --- a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/revalidate_action.xml +++ /dev/null @@ -1,81 +0,0 @@ -<?xml version="1.0"?> -<ZopeData> - <record id="1" aka="AAAAAAAAAAE="> - <pickle> - <global name="TransitionDefinition" module="Products.DCWorkflow.Transitions"/> - </pickle> - <pickle> - <dictionary> - <item> - <key> <string>actbox_category</string> </key> - <value> <string>workflow</string> </value> - </item> - <item> - <key> <string>actbox_icon</string> </key> - <value> <string></string> </value> - </item> - <item> - <key> <string>actbox_name</string> </key> - <value> <string>Revalidate</string> </value> - </item> - <item> - <key> <string>actbox_url</string> </key> - <value> <string>%(content_url)s/Base_viewWorkflowActionDialog?workflow_action=revalidate_action</string> </value> - </item> - <item> - <key> <string>after_script_name</string> </key> - <value> <string>revalidate</string> </value> - </item> - <item> - <key> <string>description</string> </key> - <value> <string>Revalidate a Component, until then the code previously validated/revalidated is used.</string> </value> - </item> - <item> - <key> <string>guard</string> </key> - <value> - <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> - </value> - </item> - <item> - <key> <string>id</string> </key> - <value> <string>revalidate_action</string> </value> - </item> - <item> - <key> <string>new_state_id</string> </key> - <value> <string></string> </value> - </item> - <item> - <key> <string>script_name</string> </key> - <value> <string>checkConsistency</string> </value> - </item> - <item> - <key> <string>title</string> </key> - <value> <string>Revalidate Action</string> </value> - </item> - <item> - <key> <string>trigger_type</string> </key> - <value> <int>1</int> </value> - </item> - </dictionary> - </pickle> - </record> - <record id="2" aka="AAAAAAAAAAI="> - <pickle> - <global name="Guard" module="Products.DCWorkflow.Guard"/> - </pickle> - <pickle> - <dictionary> - <item> - <key> <string>roles</string> </key> - <value> - <tuple> - <string>Assignee</string> - <string>Assignor</string> - <string>Manager</string> - </tuple> - </value> - </item> - </dictionary> - </pickle> - </record> -</ZopeData> diff --git a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/variables/text_content.xml b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/variables/text_content.xml new file mode 100644 index 0000000000000000000000000000000000000000..8ff402c78c93a2ab496a9ba754a901e6c7fe61a6 --- /dev/null +++ b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/variables/text_content.xml @@ -0,0 +1,48 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="VariableDefinition" module="Products.DCWorkflow.Variables"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>default_expr</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>default_value</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>description</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>for_catalog</string> </key> + <value> <int>0</int> </value> + </item> + <item> + <key> <string>for_status</string> </key> + <value> <int>1</int> </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>text_content</string> </value> + </item> + <item> + <key> <string>info_guard</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>update_always</string> </key> + <value> <int>1</int> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/product/ERP5/bootstrap/erp5_core/bt/change_log b/product/ERP5/bootstrap/erp5_core/bt/change_log index 1a9365c9852782ae42d67065264cc2c459077401..734bb25ac8c7ecbd7abc7709f36ae5f2d89af39e 100644 --- a/product/ERP5/bootstrap/erp5_core/bt/change_log +++ b/product/ERP5/bootstrap/erp5_core/bt/change_log @@ -1,3 +1,6 @@ +2012-02-02 arnaud.fontaine +* Perform revalidate automatically rather than requiring a manual action. + 2012-02-01 arnaud.fontaine * Replace comments by description field in Component_view. diff --git a/product/ERP5/bootstrap/erp5_core/bt/revision b/product/ERP5/bootstrap/erp5_core/bt/revision index 5e5bef8b9badd2d791b1b0d12eca6c4a8a7e3786..77256e4b7a61ee7c2f3bdfe8c5766ba8950abadb 100644 --- a/product/ERP5/bootstrap/erp5_core/bt/revision +++ b/product/ERP5/bootstrap/erp5_core/bt/revision @@ -1 +1 @@ -40998 \ No newline at end of file +40999 \ No newline at end of file diff --git a/product/ERP5Type/Core/Component.py b/product/ERP5Type/Core/Component.py index cd59499a62d59743d72ea558025fb2ff72b89208..e6c2823195fc4e1bfa7608a1c4804bbe02561df3 100644 --- a/product/ERP5Type/Core/Component.py +++ b/product/ERP5Type/Core/Component.py @@ -58,11 +58,14 @@ class Component(Base): 'Reference', 'TextDocument') - def checkConsistency(self, *args, **kw): + def checkConsistency(self, text_content=None, *args, **kw): """ XXX-arnau: should probably in a separate Constraint class """ - if not self.getTextContent(): + if text_content is None: + text_content = self.getTextContent() + + if not text_content: return [ConsistencyMessage(self, object_relative_url=self.getRelativeUrl(), message="No source code", @@ -70,7 +73,7 @@ class Component(Base): message = None try: - self.load() + self.load(text_content=text_content) except SyntaxError, e: message = "%s (line: %d, column: %d)" % (e.msg, e.lineno, e.offset) except Exception, e: @@ -99,21 +102,36 @@ class Component(Base): Then, when the user revalidates the Component through a workflow action, 'text_content_non_validated' property is copied back to 'text_content'. - XXX-arnau: having a separate property would require hackish code when - exporting the bt5, perhaps a workflow variable would be better? + XXX-arnau: the workflow history bit is really ugly and should be moved to + an interaction workflow instead """ - if self.getValidationState() == 'validated': - return self.setProperty('text_content_non_validated', text_content) - - return super(Component, self)._setTextContent(text_content) + validation_state = self.getValidationState() + if validation_state in ('validated', 'modified'): + error_message_list = self.checkConsistency(text_content=text_content) + if error_message_list: + self.modified() - def setTextContentAfterRevalidation(self): - """ - Call upon revalidate on an already validated Component to set the source - code from text_content_non_validated property - """ - super(Component, self)._setTextContent(self.getTextContent()) - self.setProperty('text_content_non_validated', None) + validation_workflow = self.workflow_history['component_validation_workflow'] + + last_validation_workflow = validation_workflow[-1] + last_validation_workflow['error_message'] = error_message_list[0] + last_validation_workflow['text_content'] = text_content + + previous_validation_workflow = validation_workflow[-2] + previous_validation_workflow['error_message'] = '' + previous_validation_workflow['text_content'] = '' + else: + super(Component, self)._setTextContent(text_content) + self.validate() + + if validation_state == 'modified': + # XXX-arnau: copy/paste + validation_workflow = self.workflow_history['component_validation_workflow'] + previous_validation_workflow = validation_workflow[-2] + previous_validation_workflow['error_message'] = '' + previous_validation_workflow['text_content'] = '' + else: + return super(Component, self)._setTextContent(text_content) def getTextContent(self, validated_only=False): """ @@ -123,13 +141,29 @@ class Component(Base): validated), meaningful when editing a Component or checking consistency """ if not validated_only: - text_content_non_validated = self.getProperty('text_content_non_validated') + text_content_non_validated = \ + self.workflow_history['component_validation_workflow'][-1].get('text_content', + None) + if text_content_non_validated: return text_content_non_validated return super(Component, self).getTextContent() - def load(self, namespace_dict={}, validated_only=False): + def _getErrorMessage(self): + current_workflow = self.workflow_history['component_validation_workflow'][-1] + return current_workflow['error_message'] + + def getTranslatedValidationStateTitleWithErrorMessage(self): + validation_state_title = self.getTranslatedValidationStateTitle() + error_message = self._getErrorMessage() + if error_message: + return "%s (%s)" % (validation_state_title, + str(error_message.getTranslatedMessage())) + + return validation_state_title + + def load(self, namespace_dict={}, validated_only=False, text_content=None): """ Load the source code into the given dict. Using exec() rather than imp.load_source() as the latter would required creating an intermediary @@ -138,7 +172,10 @@ class Component(Base): it. By default namespace_dict is an empty dict to allow checking the source code before validate. """ - exec self.getTextContent(validated_only=validated_only) in namespace_dict + if text_content is None: + text_content = self.getTextContent(validated_only=validated_only) + + exec text_content in namespace_dict @staticmethod def _getFilesystemPath(): diff --git a/product/ERP5Type/tests/testDynamicClassGeneration.py b/product/ERP5Type/tests/testDynamicClassGeneration.py index 973f5acae794799e151f45e3fa6be01da6d9f39c..577fb4ca344c0bdd0a120781829393189744f047 100644 --- a/product/ERP5Type/tests/testDynamicClassGeneration.py +++ b/product/ERP5Type/tests/testDynamicClassGeneration.py @@ -1204,6 +1204,18 @@ class TestZodbPropertySheet(ERP5TypeTestCase): self.fail("Creating a Category Expression with syntax error raises "\ "an error") +from Products.ERP5Type.Tool.ComponentTool import ComponentTool +ComponentTool._original_reset = ComponentTool.reset +ComponentTool._reset_performed = False + +def assertResetNotCalled(*args, **kwargs): + raise AssertionError("reset should only be called once revalidating") + +def assertResetCalled(self, *args, **kwargs): + from Products.ERP5Type.Tool.ComponentTool import ComponentTool + ComponentTool._reset_performed = True + return ComponentTool._original_reset(self, *args, **kwargs) + import abc class _TestZodbComponent(ERP5TypeTestCase): @@ -1255,74 +1267,54 @@ class _TestZodbComponent(ERP5TypeTestCase): self.assertHasAttribute(self._module, 'TestValidateInvalidateComponent') - def testRevalidate(self): - """ - Check whether revalidate is performed properly - """ - validated_code = 'def foobar(*args, **kwargs):\n return "Validated"' - component = self._newComponent('TestRevalidateComponent', validated_code) - - component.validate() - transaction.commit() - self.tic() - - self.assertHasAttribute(self._module, 'TestRevalidateComponent') - self.assertEquals(component.getTextContent(), validated_code) - self.assertEquals(component.getTextContent(validated_only=True), - validated_code) - - from Products.ERP5Type.Tool.ComponentTool import ComponentTool - old_reset_function = ComponentTool.reset - def assertResetNotCalled(*args, **kwargs): - raise AssertionError("reset should only be called once revalidating") - - def assertResetCalled(self, *args, **kwargs): - from Products.ERP5Type.Tool.ComponentTool import ComponentTool - ComponentTool._reset_performed = True - return old_reset_function(self, *args, **kwargs) - - revalidated_code = 'def foobar(*args, **kwargs):\n return "Revalidated"' - + def testSourceCodeWithSyntaxError(self): + valid_code = 'def foobar(*args, **kwargs):\n return 42' + ComponentTool.reset = assertResetCalled try: - ComponentTool.reset = assertResetNotCalled - component.setTextContent(revalidated_code) + component = self._newComponent('TestComponentWithSyntaxError', valid_code) + component.validate() transaction.commit() self.tic() + finally: + ComponentTool.reset = ComponentTool._original_reset - self.assertEquals(component.getTextContent(), revalidated_code) - self.assertEquals(component.getTextContent(validated_only=True), - validated_code) + self.assertEquals(component.getValidationState(), 'validated') + self.assertEquals(component.getTextContent(), valid_code) + self.assertEquals(component.getTextContent(validated_only=True), valid_code) + self.assertHasAttribute(self._module, 'TestComponentWithSyntaxError') - ComponentTool.reset = assertResetCalled - component.revalidate() + invalid_code = 'def foobar(*args, **kwargs)\n return 42' + ComponentTool.reset = assertResetNotCalled + try: + component.setTextContent(invalid_code) transaction.commit() self.tic() - - self.assertTrue(ComponentTool._reset_performed) - self.assertEquals(component.getTextContent(), revalidated_code) - self.assertEquals(component.getTextContent(validated_only=True), - revalidated_code) - finally: - self._component_tool.reset = old_reset_function - - def testSourceCodeWithSyntaxError(self): - test_component = self._newComponent( - 'TestComponentWithSyntaxError', - 'def foobar(*args, **kwargs):\n return 42') + ComponentTool.reset = ComponentTool._original_reset - self.assertEqual(test_component.checkConsistency(), []) - test_component.validate() - transaction.commit() - self.tic() - self.assertHasAttribute(self._module, - 'TestComponentWithSyntaxError') + self.assertEquals(component.getValidationState(), 'modified') + self.assertNotEqual(component._getErrorMessage(), '') + self.assertEquals(component.getTextContent(), invalid_code) + self.assertEquals(component.getTextContent(validated_only=True), valid_code) + self._component_tool.reset() + self.assertHasAttribute(self._module, 'TestComponentWithSyntaxError') - test_component.setTextContent('def foobar(*args, **kwargs)\n return 42') - transaction.commit() - self.tic() + ComponentTool.reset = assertResetCalled + try: + component.setTextContent(valid_code) + transaction.commit() + self.tic() - self.assertNotEqual(test_component.checkConsistency(), []) + self.assertEquals(ComponentTool._reset_performed, True) + finally: + ComponentTool.reset = ComponentTool._original_reset + ComponentTool._reset_performed = False + + self.assertEquals(component.getValidationState(), 'validated') + self.assertEquals(component._getErrorMessage(), '') + self.assertEquals(component.getTextContent(), valid_code) + self.assertEquals(component.getTextContent(validated_only=True), valid_code) + self.assertHasAttribute(self._module, 'TestComponentWithSyntaxError') from Products.ERP5Type.Core.ExtensionComponent import ExtensionComponent