Commit 7091bad6 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: Source code and consistency were not checked during import from FS.

These are done through 'validate_action' not at 'validate' Workflow transition.

text_content_{error,warning}_message_list was properly set through
Component_modify Interaction (used for editing Component) which checks the
source code without raising an exception.
parent 7f64d2e4
...@@ -8225,6 +8225,95 @@ class TestDocumentTemplateItem(BusinessTemplateMixin): ...@@ -8225,6 +8225,95 @@ class TestDocumentTemplateItem(BusinessTemplateMixin):
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
def stepCheckDocumentMigrationFailWithConsistencyError(self, sequence=None, **kw):
current_bt = sequence['current_bt']
self.assertRaises(RuntimeError,
current_bt.migrateSourceCodeFromFilesystem,
# version must not start with '_'
version='_invalid_version')
def test_BusinessTemplateUpgradeDocumentFromFilesystemToZodbWithConsistencyError(self):
"""
Check that component.checkConsistency() (called before "validating" a ZODB
Component) is done when migrating Document from filesystem to ZODB
"""
sequence_list = SequenceList()
sequence_string = """
CreateDocument
CreateNewBusinessTemplate
UseExportBusinessTemplate
AddDocumentToBusinessTemplate
CheckModifiedBuildingState
CheckNotInstalledInstallationState
BuildBusinessTemplate
CheckBuiltBuildingState
CheckNotInstalledInstallationState
CheckObjectPropertiesInBusinessTemplate
UseCurrentBusinessTemplateForInstall
InstallWithoutForceBusinessTemplate
Tic
CheckInstalledInstallationState
CheckBuiltBuildingState
CheckSkinsLayers
CheckDocumentExists
CopyBusinessTemplate
CheckDocumentMigrationFailWithConsistencyError
"""
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def stepCheckDocumentMigrationFailWithSourceCodeError(self, sequence=None, **kw):
current_bt = sequence['current_bt']
from Products.ERP5Type.mixin.component import ComponentMixin
orig_checkSourceCode = ComponentMixin.checkSourceCode
try:
ComponentMixin.checkSourceCode = lambda *args, **kwargs: [
{'type': 'E', 'row': 1, 'column': 1,
'text': 'Source Code Error for Unit Test'}]
self.assertRaises(RuntimeError, current_bt.migrateSourceCodeFromFilesystem,
version='erp5')
ComponentMixin.checkSourceCode = lambda *args, **kwargs: [
{'type': 'F', 'row': 1, 'column': 1,
'text': 'Source Code Error for Unit Test'}]
self.assertRaises(RuntimeError, current_bt.migrateSourceCodeFromFilesystem,
version='erp5')
finally:
ComponentMixin.checkSourceCode = orig_checkSourceCode
def test_BusinessTemplateUpgradeDocumentFromFilesystemToZodbWithSyntaxError(self):
"""
Check that component.checkSourceCode() (called before "validating" a ZODB
Component) is done when migrating Document from filesystem to ZODB
"""
sequence_list = SequenceList()
sequence_string = """
CreateDocument
CreateNewBusinessTemplate
UseExportBusinessTemplate
AddDocumentToBusinessTemplate
CheckModifiedBuildingState
CheckNotInstalledInstallationState
BuildBusinessTemplate
CheckBuiltBuildingState
CheckNotInstalledInstallationState
CheckObjectPropertiesInBusinessTemplate
UseCurrentBusinessTemplateForInstall
InstallWithoutForceBusinessTemplate
Tic
CheckInstalledInstallationState
CheckBuiltBuildingState
CheckSkinsLayers
CheckDocumentExists
CopyBusinessTemplate
CheckDocumentMigrationFailWithSourceCodeError
"""
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
class TestConstraintTemplateItem(TestDocumentTemplateItem): class TestConstraintTemplateItem(TestDocumentTemplateItem):
document_title = 'UnitTest' document_title = 'UnitTest'
document_data = ' \nclass UnitTest: \n """ \n Fake constraint for unit test \n \ document_data = ' \nclass UnitTest: \n """ \n Fake constraint for unit test \n \
...@@ -8369,6 +8458,12 @@ TestConstraintTemplateItem.test_BusinessTemplateWithZodbDocumentMigrated = \ ...@@ -8369,6 +8458,12 @@ TestConstraintTemplateItem.test_BusinessTemplateWithZodbDocumentMigrated = \
TestConstraintTemplateItem.test_BusinessTemplateUpgradeDocumentFromFilesystemToZodb = \ TestConstraintTemplateItem.test_BusinessTemplateUpgradeDocumentFromFilesystemToZodb = \
skip('Not implemented yet')(TestConstraintTemplateItem.test_BusinessTemplateUpgradeDocumentFromFilesystemToZodb) skip('Not implemented yet')(TestConstraintTemplateItem.test_BusinessTemplateUpgradeDocumentFromFilesystemToZodb)
TestConstraintTemplateItem.test_BusinessTemplateUpgradeDocumentFromFilesystemToZodbWithConsistencyError = \
skip('Not implemented yet')(TestConstraintTemplateItem.test_BusinessTemplateUpgradeDocumentFromFilesystemToZodbWithConsistencyError)
TestConstraintTemplateItem.test_BusinessTemplateUpgradeDocumentFromFilesystemToZodbWithSyntaxError = \
skip('Not implemented yet')(TestConstraintTemplateItem.test_BusinessTemplateUpgradeDocumentFromFilesystemToZodbWithSyntaxError)
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestBusinessTemplate)) suite.addTest(unittest.makeSuite(TestBusinessTemplate))
......
...@@ -367,10 +367,20 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -367,10 +367,20 @@ class ComponentMixin(PropertyRecordableMixin, Base):
text_content=source_code, text_content=source_code,
portal_type=cls.portal_type) portal_type=cls.portal_type)
# Validate the Component once it is imported so it can be used # XXX-ARNAU: checkConsistency() is also called before commit in
# straightaway as there should be no error # Component_checkSourceCodeAndValidateAfterModified. Also, everything
new_component.validate() # should be done in checkConsistency()...
error_message_list = [ m for m in new_component.checkSourceCode()
if m['type'] in ('F', 'E') ]
if error_message_list:
raise SyntaxError(error_message_list)
consistency_message_list = new_component.checkConsistency()
if consistency_message_list:
from Products.DCWorkflow.DCWorkflow import ValidationFailed
raise ValidationFailed(consistency_message_list)
new_component.validate()
return new_component return new_component
InitializeClass(ComponentMixin) InitializeClass(ComponentMixin)
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