Commit c4e467d6 authored by Arnaud Fontaine's avatar Arnaud Fontaine Committed by Cédric Le Ninivin

BusinessTemplate: Refactor *TemplateItem Unit Tests classes.

One Mixin to handle {Document,Interface,Mixin,Test,Extension} code from:
  * deprecated local (instancehome/XXX).
  * ZODB Components.
  * Products migration (in a later commit).
parent fb78dd1a
...@@ -7555,10 +7555,10 @@ class TestBusinessTemplate(BusinessTemplateMixin): ...@@ -7555,10 +7555,10 @@ class TestBusinessTemplate(BusinessTemplateMixin):
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
class _ZodbComponentTemplateItemMixin(BusinessTemplateMixin):
from Products.ERP5Type.Core.DocumentComponent import DocumentComponent """
Test cases for all Test*TemplateItem test classes.
class _TestZodbOnlyComponentTemplateItemMixin: """
def stepCreateZodbDocument(self, sequence=None, **kw): def stepCreateZodbDocument(self, sequence=None, **kw):
document_id = self.component_id_prefix + '.erp5.' + self.document_title document_id = self.component_id_prefix + '.erp5.' + self.document_title
component = self.portal.portal_components.newContent( component = self.portal.portal_components.newContent(
...@@ -7758,20 +7758,12 @@ class _TestZodbOnlyComponentTemplateItemMixin: ...@@ -7758,20 +7758,12 @@ class _TestZodbOnlyComponentTemplateItemMixin:
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
class TestDocumentTemplateItem(BusinessTemplateMixin, # bt5 (instancehome and ZODB Component)
_TestZodbOnlyComponentTemplateItemMixin): class _LocalTemplateItemMixin:
document_title = 'UnitTest' """
document_data = """class UnitTest: Test Cases for (legacy) local documents (eg instancehome/{Document,Test,
meta_type = 'ERP5 Unit Test' Constraint,Extensions}) and their migration to ZODB Components.
portal_type = 'Unit Test'""" """
document_data_updated = """class UnitTest:
meta_type = 'ERP5 Unit Test'
portal_type = 'Unit Test'
def updated(self):
pass"""
document_base_path = os.path.join(getConfiguration().instancehome, 'Document')
template_property = 'template_document_id_list'
def stepCreateDocument(self, sequence=None, **kw): def stepCreateDocument(self, sequence=None, **kw):
file_path = os.path.join(self.document_base_path, self.document_title+'.py') file_path = os.path.join(self.document_base_path, self.document_title+'.py')
if os.path.exists(file_path): if os.path.exists(file_path):
...@@ -8091,9 +8083,6 @@ class TestDocumentTemplateItem(BusinessTemplateMixin, ...@@ -8091,9 +8083,6 @@ class TestDocumentTemplateItem(BusinessTemplateMixin,
self.assertEqual(component.getPortalType(), self.component_portal_type) self.assertEqual(component.getPortalType(), self.component_portal_type)
sequence.edit(document_id=component_id) sequence.edit(document_id=component_id)
component_id_prefix = DocumentComponent.getIdPrefix()
component_portal_type = DocumentComponent.portal_type
def test_BusinessTemplateWithZodbDocumentMigrated(self): def test_BusinessTemplateWithZodbDocumentMigrated(self):
""" """
Checks that if Business Template defines filesystem Document, they are Checks that if Business Template defines filesystem Document, they are
...@@ -8316,9 +8305,27 @@ class TestDocumentTemplateItem(BusinessTemplateMixin, ...@@ -8316,9 +8305,27 @@ class TestDocumentTemplateItem(BusinessTemplateMixin,
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
from Products.ERP5Type.Core.DocumentComponent import DocumentComponent
# bt5 (instancehome and ZODB Component) and Products
class TestDocumentTemplateItem(_LocalTemplateItemMixin,
_ZodbComponentTemplateItemMixin):
document_title = 'UnitTest'
document_data = """class UnitTest:
meta_type = 'ERP5 Unit Test'
portal_type = 'Unit Test'"""
document_data_updated = """class UnitTest:
meta_type = 'ERP5 Unit Test'
portal_type = 'Unit Test'
def updated(self):
pass"""
document_base_path = os.path.join(getConfiguration().instancehome, 'Document')
template_property = 'template_document_id_list'
component_id_prefix = DocumentComponent.getIdPrefix()
component_portal_type = DocumentComponent.portal_type
from Products.ERP5Type.Core.InterfaceComponent import InterfaceComponent from Products.ERP5Type.Core.InterfaceComponent import InterfaceComponent
class TestInterfaceTemplateItem(BusinessTemplateMixin, # bt5 (ZODB Component only) and Products
_TestZodbOnlyComponentTemplateItemMixin): class TestInterfaceTemplateItem(_ZodbComponentTemplateItemMixin):
document_title = 'IUnitTest' document_title = 'IUnitTest'
document_data = '''from zope.interface import Interface document_data = '''from zope.interface import Interface
...@@ -8333,8 +8340,8 @@ class IUnitTest(Interface): ...@@ -8333,8 +8340,8 @@ class IUnitTest(Interface):
component_portal_type = InterfaceComponent.portal_type component_portal_type = InterfaceComponent.portal_type
from Products.ERP5Type.Core.MixinComponent import MixinComponent from Products.ERP5Type.Core.MixinComponent import MixinComponent
class TestMixinTemplateItem(BusinessTemplateMixin, # bt5 (ZODB Component only) and Products
_TestZodbOnlyComponentTemplateItemMixin): class TestMixinTemplateItem(_ZodbComponentTemplateItemMixin):
document_title = 'UnitTestMixin' document_title = 'UnitTestMixin'
document_data = '''class UnitTestMixin: document_data = '''class UnitTestMixin:
def foo(self): def foo(self):
...@@ -8347,7 +8354,9 @@ class TestMixinTemplateItem(BusinessTemplateMixin, ...@@ -8347,7 +8354,9 @@ class TestMixinTemplateItem(BusinessTemplateMixin,
component_id_prefix = MixinComponent.getIdPrefix() component_id_prefix = MixinComponent.getIdPrefix()
component_portal_type = MixinComponent.portal_type component_portal_type = MixinComponent.portal_type
class TestConstraintTemplateItem(TestDocumentTemplateItem): # bt5 (instancehome (legacy) and ZODB Component) and Products
class TestConstraintTemplateItem(_LocalTemplateItemMixin,
_ZodbComponentTemplateItemMixin):
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 \
""" \n _properties = ( \n ) \n _categories = ( \n ) \n\n' """ \n _properties = ( \n ) \n _categories = ( \n ) \n\n'
...@@ -8357,8 +8366,9 @@ class TestConstraintTemplateItem(TestDocumentTemplateItem): ...@@ -8357,8 +8366,9 @@ class TestConstraintTemplateItem(TestDocumentTemplateItem):
template_property = 'template_constraint_id_list' template_property = 'template_constraint_id_list'
from Products.ERP5Type.Core.ExtensionComponent import ExtensionComponent from Products.ERP5Type.Core.ExtensionComponent import ExtensionComponent
# bt5 (instancehome (legacy) and ZODB Component)
class TestExtensionTemplateItem(TestDocumentTemplateItem): class TestExtensionTemplateItem(_LocalTemplateItemMixin,
_ZodbComponentTemplateItemMixin):
document_title = 'UnitTest' document_title = 'UnitTest'
document_data = """class UnitTest: document_data = """class UnitTest:
meta_type = 'ERP5 Unit Test' meta_type = 'ERP5 Unit Test'
...@@ -8376,8 +8386,9 @@ class TestExtensionTemplateItem(TestDocumentTemplateItem): ...@@ -8376,8 +8386,9 @@ class TestExtensionTemplateItem(TestDocumentTemplateItem):
component_portal_type = ExtensionComponent.portal_type component_portal_type = ExtensionComponent.portal_type
from Products.ERP5Type.Core.TestComponent import TestComponent from Products.ERP5Type.Core.TestComponent import TestComponent
# bt5 (instancehome (legacy) and ZODB Component) and Products
class TestTestTemplateItem(TestDocumentTemplateItem): class TestTestTemplateItem(_LocalTemplateItemMixin,
_ZodbComponentTemplateItemMixin):
document_title = 'UnitTest' document_title = 'UnitTest'
document_data = """class UnitTest: document_data = """class UnitTest:
meta_type = 'ERP5 Unit Test' meta_type = 'ERP5 Unit Test'
......
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