Commit 39ad71e2 authored by Łukasz Nowak's avatar Łukasz Nowak

- allow to pass full import path and test class

 - rewrite current lists to use full paths, optimise a bit
 - remove no more needed real methods
 - cleanup imports


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29318 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4436e229
......@@ -27,74 +27,59 @@
##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.testERP5TypeInterfaces import makeTestMethod, \
addTestMethodDynamically
from zope.interface.verify import verifyClass
from Products.ERP5Type.tests.testERP5TypeInterfaces import addTestMethodDynamically
import unittest
# this list can be generated automatically using introspection or can be set
# manually and treated as reference to what implements what
implements_tuple_list = [
('BusinessPath', 'IArrowBase'),
('BusinessPath', 'IBusinessPath'),
('BusinessPath', 'ICategoryAccessProvider'),
('DeliveryLine', 'IDivergenceSolver'),
('TradeCondition', 'ITransformation'),
('TradeModelCell', 'ITransformation'),
('TradeModelCell', 'IVariated'),
('TradeModelLine', 'ITransformation'),
('TradeModelLine', 'IVariated'),
('TradeModelRule', 'IPredicate'),
('TradeModelRule', 'IRule'),
('Transformation', 'ITransformation'),
('Transformation', 'IVariated'),
('TransformationRule', 'IPredicate'),
('TransformationRule', 'IRule'),
('TransformedResource', 'IVariated'),
(('Products.ERP5Type.Document.BusinessPath','BusinessPath'), 'IArrowBase'),
(('Products.ERP5Type.Document.BusinessPath','BusinessPath'), 'IBusinessPath'),
(('Products.ERP5Type.Document.BusinessPath','BusinessPath'), 'ICategoryAccessProvider'),
(('Products.ERP5Type.Document.DeliveryLine', 'DeliveryLine'), 'IDivergenceSolver'),
(('Products.ERP5Type.Document.TradeCondition','TradeCondition'), 'ITransformation'),
(('Products.ERP5Type.Document.TradeModelCell','TradeModelCell'), 'ITransformation'),
(('Products.ERP5Type.Document.TradeModelCell','TradeModelCell'), 'IVariated'),
(('Products.ERP5Type.Document.TradeModelLine','TradeModelLine'), 'ITransformation'),
(('Products.ERP5Type.Document.TradeModelLine','TradeModelLine'), 'IVariated'),
(('Products.ERP5Type.Document.TradeModelRule','TradeModelRule'), 'IPredicate'),
(('Products.ERP5Type.Document.TradeModelRule','TradeModelRule'), 'IRule'),
(('Products.ERP5Type.Document.Transformation','Transformation'), 'ITransformation'),
(('Products.ERP5Type.Document.Transformation','Transformation'), 'IVariated'),
(('Products.ERP5Type.Document.TransformationRule','TransformationRule'), 'IPredicate'),
(('Products.ERP5Type.Document.TransformationRule','TransformationRule'), 'IRule'),
(('Products.ERP5Type.Document.TransformedResource','TransformedResource'), 'IVariated'),
#IDocument
('Document', 'IDocument'),
('Image', 'IDocument'),
('File', 'IDocument'),
('OOoDocument', 'IDocument'),
('TextDocument', 'IDocument'),
('EmailDocument', 'IDocument'),
('Event', 'IDocument'),
#IMovementGroup
('MovementGroup', 'IMovementGroup'),
('BaseVariantMovementGroup', 'IMovementGroup'),
('CategoryMovementGroup', 'IMovementGroup'),
('CausalityAssignmentMovementGroup', 'IMovementGroup'),
('CausalityMovementGroup', 'IMovementGroup'),
('DayMovementGroup', 'IMovementGroup'),
('DeliveryCausalityAssignmentMovementGroup', 'IMovementGroup'),
('FirstCausalityMovementGroup', 'IMovementGroup'),
('MonthlyRangeMovementGroup', 'IMovementGroup'),
('NestedLineMovementGroup', 'IMovementGroup'),
('OrderMovementGroup', 'IMovementGroup'),
('ParentExplanationMovementGroup', 'IMovementGroup'),
('PropertyAssignmentMovementGroup', 'IMovementGroup'),
('PropertyMovementGroup', 'IMovementGroup'),
('QuantitySignMovementGroup', 'IMovementGroup'),
('RequirementMovementGroup', 'IMovementGroup'),
('RootAppliedRuleCausalityMovementGroup', 'IMovementGroup'),
('SplitMovementGroup', 'IMovementGroup'),
('TaxLineDeliveryMovementGroup', 'IMovementGroup'),
('TitleMovementGroup', 'IMovementGroup'),
('VariantMovementGroup', 'IMovementGroup'),
('VariationPropertyMovementGroup', 'IMovementGroup'),
(('Products.ERP5Type.Document.Document', 'Document'), 'IDocument'),
(('Products.ERP5Type.Document.Image', 'Image'), 'IDocument'),
(('Products.ERP5Type.Document.File', 'File'), 'IDocument'),
(('Products.ERP5Type.Document.OOoDocument', 'OOoDocument'), 'IDocument'),
(('Products.ERP5Type.Document.TextDocument', 'TextDocument'), 'IDocument'),
(('Products.ERP5Type.Document.EmailDocument', 'EmailDocument'), 'IDocument'),
(('Products.ERP5Type.Document.Event', 'Event'), 'IDocument'),
# IAggregatedAmountList
(('Products.ERP5.AggregatedAmountList', 'AggregatedAmountList'), 'IAggregatedAmountList'),
]
# IMovementGroup
for movement_group_class_name in ['MovementGroup', 'BaseVariantMovementGroup',
'CategoryMovementGroup', 'CausalityAssignmentMovementGroup',
'CausalityMovementGroup', 'DayMovementGroup',
'DeliveryCausalityAssignmentMovementGroup', 'FirstCausalityMovementGroup',
'MonthlyRangeMovementGroup', 'NestedLineMovementGroup',
'OrderMovementGroup', 'ParentExplanationMovementGroup',
'PropertyAssignmentMovementGroup', 'PropertyMovementGroup',
'QuantitySignMovementGroup', 'RequirementMovementGroup',
'RootAppliedRuleCausalityMovementGroup', 'SplitMovementGroup',
'TaxLineDeliveryMovementGroup', 'TitleMovementGroup',
'VariantMovementGroup', 'VariationPropertyMovementGroup']:
implements_tuple_list.append((('Products.ERP5Type.Document.%s' % \
movement_group_class_name, movement_group_class_name),
'IMovementGroup'))
class TestERP5Interfaces(ERP5TypeTestCase):
"""Tests implementation of interfaces"""
def test_AggregatedAmountList_implements_IAggregatedAmountList(self):
# AggregatedAmountList is not a document
from Products.ERP5.interfaces.aggregated_amount_list \
import IAggregatedAmountList
from Products.ERP5.AggregatedAmountList import AggregatedAmountList
verifyClass(IAggregatedAmountList, AggregatedAmountList)
addTestMethodDynamically()
addTestMethodDynamically(TestERP5Interfaces, implements_tuple_list)
def test_suite():
suite = unittest.TestSuite()
......
......@@ -30,61 +30,51 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from zope.interface.verify import verifyClass
import unittest
implements_tuple_list = [
(('Products.ERP5Type.ObjectMessage', 'ObjectMessage'), 'IObjectMessage'),
(('Products.ERP5Type.ConsistencyMessage', 'ConsistencyMessage'),
'IObjectMessage'),
(('Products.ERP5Type.DivergenceMessage', 'DivergenceMessage'),
'IObjectMessage'),
(('Products.ERP5Type.ConsistencyMessage', 'ConsistencyMessage'),
'IConsistencyMessage'),
(('Products.ERP5Type.DivergenceMessage', 'DivergenceMessage'),
'IDivergenceMessage'),
]
class TestERP5TypeInterfaces(ERP5TypeTestCase):
"""Tests implementation of interfaces"""
def test_ObjectMessage_implements_IObjectMessage(self):
from Products.ERP5Type.interfaces.object_message import IObjectMessage
from Products.ERP5Type.ObjectMessage import ObjectMessage
verifyClass(IObjectMessage, ObjectMessage)
def test_ConsistencyMessage_implements_IObjectMessage(self):
from Products.ERP5Type.interfaces.object_message import IObjectMessage
from Products.ERP5Type.ConsistencyMessage import ConsistencyMessage
verifyClass(IObjectMessage, ConsistencyMessage)
def test_ConsistencyMessage_implements_IConsistencyMessage(self):
from Products.ERP5Type.interfaces.consistency_message \
import IConsistencyMessage
from Products.ERP5Type.ConsistencyMessage import ConsistencyMessage
verifyClass(IConsistencyMessage, ConsistencyMessage)
def test_DivergenceMessage_implements_IObjectMessage(self):
from Products.ERP5Type.interfaces.object_message import IObjectMessage
from Products.ERP5Type.DivergenceMessage import DivergenceMessage
verifyClass(IObjectMessage, DivergenceMessage)
def test_DivergenceMessage_implements_IDivergenceMessage(self):
from Products.ERP5Type.interfaces.divergence_message import IDivergenceMessage
from Products.ERP5Type.DivergenceMessage import DivergenceMessage
verifyClass(IDivergenceMessage, DivergenceMessage)
def makeTestMethod(document, interface):
def makeTestMethod(import_tuple, interface):
"""Common method which checks if documents implements interface"""
def testMethod(self):
_temp = __import__('Products.ERP5Type.Document.%s' % document, globals(),
locals(), ['%s' % document])
Document = getattr(_temp, document)
_temp = __import__(import_tuple[0], globals(), locals(),
['%s' % import_tuple[1]])
Klass = getattr(_temp, import_tuple[1])
_temp = __import__('Products.ERP5Type.interfaces', globals(), locals(),
['%s' % interface])
Interface = getattr(_temp, interface)
verifyClass(Interface, Document)
verifyClass(Interface, Klass)
return testMethod
def addTestMethodDynamically():
def addTestMethodDynamically(test_class, implements_tuple_list):
"""Creates test methods on the fly
Uses naming test_<DocumentClass>_implements_<InterfaceClass>
Uses naming
test_<ImportPathOfClass>_<ImplementationClass>_implements_<InterfaceClass>
It is possible to use --run_only on those dynamically generated methods"""
for document, interface in implements_tuple_list:
method_name = 'test_%s_implements_%s' % (document, interface)
method = makeTestMethod(document, interface)
setattr(TestERP5Interfaces, method_name, method)
for import_tuple, interface in implements_tuple_list:
method_name = '_'.join(
('test',) + import_tuple + ('implements',) + (interface, )
)
method = makeTestMethod(import_tuple, interface)
setattr(test_class, method_name, method)
# Note: Enable this method when implements_tuple_list will be filled
#addTestMethodDynamically()
addTestMethodDynamically(TestERP5TypeInterfaces, implements_tuple_list)
def test_suite():
suite = unittest.TestSuite()
......
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