Commit c560771f authored by Julien Muchembled's avatar Julien Muchembled

Fix unit tests of ERP5 Product so that they don't call unsupported workflow...

Fix unit tests of ERP5 Product so that they don't call unsupported workflow methods. Transitions of the following workflows were not considered:
* amortisation_transaction_causality_workflow
* event_workflow
* processing_status_workflow
* publication_workflow

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27822 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3f6e0b81
...@@ -177,6 +177,7 @@ class AccountingTestCase(ERP5TypeTestCase): ...@@ -177,6 +177,7 @@ class AccountingTestCase(ERP5TypeTestCase):
for module in (self.account_module, self.organisation_module, for module in (self.account_module, self.organisation_module,
self.person_module): self.person_module):
for doc in module.objectValues(): for doc in module.objectValues():
if doc.getValidationState() != 'validated':
doc.validate() doc.validate()
# and the preference enabled # and the preference enabled
...@@ -184,9 +185,7 @@ class AccountingTestCase(ERP5TypeTestCase): ...@@ -184,9 +185,7 @@ class AccountingTestCase(ERP5TypeTestCase):
'accounting_zuite_preference', None) 'accounting_zuite_preference', None)
if pref is not None: if pref is not None:
pref.manage_addLocalRoles(self.username, ('Auditor', )) pref.manage_addLocalRoles(self.username, ('Auditor', ))
# Make sure _aq_dynamic is called before calling the workflow method if pref.getPreferenceState() != 'enabled':
# otherwise .enable might not been wrapped yet. This happen in --load
pref._aq_dynamic('hack')
pref.enable() pref.enable()
self.validateRules() self.validateRules()
......
...@@ -204,6 +204,10 @@ class TestAccountingRules(TestAccountingRulesMixin, ERP5TypeTestCase): ...@@ -204,6 +204,10 @@ class TestAccountingRules(TestAccountingRulesMixin, ERP5TypeTestCase):
""" """
invoice_transaction_rule = getattr(self.getRuleTool(), invoice_transaction_rule = getattr(self.getRuleTool(),
'default_invoice_transaction_rule') 'default_invoice_transaction_rule')
if invoice_transaction_rule.getValidationState() == 'validated':
invoice_transaction_rule.invalidate()
transaction.commit()
# delete anything inside the rule first # delete anything inside the rule first
# clear the message queue, so that it does not contains unexistant paths # clear the message queue, so that it does not contains unexistant paths
self.tic() self.tic()
......
...@@ -76,7 +76,6 @@ class TestBPMMixin(ERP5TypeTestCase): ...@@ -76,7 +76,6 @@ class TestBPMMixin(ERP5TypeTestCase):
invoicing_resource_use_category_list = ['discount', 'tax'] invoicing_resource_use_category_list = ['discount', 'tax']
def setUpOnce(self): def setUpOnce(self):
self.portal = self.getPortalObject()
self.validateRules() self.validateRules()
def createCategoriesInCategory(self, category, category_id_list): def createCategoriesInCategory(self, category, category_id_list):
......
...@@ -621,6 +621,7 @@ class TestCRMMailSend(ERP5TypeTestCase): ...@@ -621,6 +621,7 @@ class TestCRMMailSend(ERP5TypeTestCase):
default_pref.setPreferredOoodocServerPortNumber(conversion_server_host[1]) default_pref.setPreferredOoodocServerPortNumber(conversion_server_host[1])
default_pref.setPreferredDocumentFileNameRegularExpression(FILE_NAME_REGULAR_EXPRESSION) default_pref.setPreferredDocumentFileNameRegularExpression(FILE_NAME_REGULAR_EXPRESSION)
default_pref.setPreferredDocumentReferenceRegularExpression(REFERENCE_REGULAR_EXPRESSION) default_pref.setPreferredDocumentReferenceRegularExpression(REFERENCE_REGULAR_EXPRESSION)
if default_pref.getPreferenceState() == 'disabled':
default_pref.enable() default_pref.enable()
# add a dummy mailhost not to send real messages # add a dummy mailhost not to send real messages
...@@ -947,6 +948,7 @@ class TestCRMMailSend(ERP5TypeTestCase): ...@@ -947,6 +948,7 @@ class TestCRMMailSend(ERP5TypeTestCase):
aggregate=document_zip.getRelativeUrl(), aggregate=document_zip.getRelativeUrl(),
text_content='This is an advertisement mail.') text_content='This is an advertisement mail.')
event.pdb()
mail_text = event.send(download=True) mail_text = event.send(download=True)
# Check mail text. # Check mail text.
......
...@@ -205,8 +205,9 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase): ...@@ -205,8 +205,9 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
portal.portal_workflow.doActionFor(account, 'validate_action') portal.portal_workflow.doActionFor(account, 'validate_action')
invoice_rule = portal.portal_rules.default_invoice_transaction_rule invoice_rule = portal.portal_rules.default_invoice_transaction_rule
invoice_rule.deleteContent([x.getId() if invoice_rule.getValidationState() == 'validated':
for x in invoice_rule.objectValues()]) invoice_rule.invalidate()
invoice_rule.deleteContent(list(invoice_rule.objectIds()))
transaction.commit() transaction.commit()
self.tic() self.tic()
region_predicate = invoice_rule.newContent(portal_type = 'Predicate') region_predicate = invoice_rule.newContent(portal_type = 'Predicate')
......
...@@ -184,35 +184,30 @@ class CrmTestCase(ERP5ReportTestCase): ...@@ -184,35 +184,30 @@ class CrmTestCase(ERP5ReportTestCase):
reference='Person_1', reference='Person_1',
title='Person_1', title='Person_1',
id='Person_1') id='Person_1')
user.validate()
if not self.person_module.has_key('Person_2'): if not self.person_module.has_key('Person_2'):
user = self.portal.person_module.newContent( user = self.portal.person_module.newContent(
portal_type='Person', portal_type='Person',
reference='Person_2', reference='Person_2',
title='Person_2', title='Person_2',
id='Person_2') id='Person_2')
user.validate()
if not self.person_module.has_key('Person_3'): if not self.person_module.has_key('Person_3'):
user = self.portal.person_module.newContent( user = self.portal.person_module.newContent(
portal_type='Person', portal_type='Person',
reference='Person_3', reference='Person_3',
title='Person_3', title='Person_3',
id='Person_3') id='Person_3')
user.validate()
if not self.organisation_module.has_key('Organisation_1'): if not self.organisation_module.has_key('Organisation_1'):
org = self.portal.organisation_module.newContent( org = self.portal.organisation_module.newContent(
portal_type='Organisation', portal_type='Organisation',
reference='Organisation_1', reference='Organisation_1',
title='Organisation_1', title='Organisation_1',
id='Organisation_1') id='Organisation_1')
org.validate()
if not self.organisation_module.has_key('Organisation_2'): if not self.organisation_module.has_key('Organisation_2'):
org = self.portal.organisation_module.newContent( org = self.portal.organisation_module.newContent(
portal_type='Organisation', portal_type='Organisation',
reference='Organisation_2', reference='Organisation_2',
title='Organisation_2', title='Organisation_2',
id='Organisation_2') id='Organisation_2')
org.validate()
if not self.organisation_module.has_key('My_organisation'): if not self.organisation_module.has_key('My_organisation'):
org = self.portal.organisation_module.newContent( org = self.portal.organisation_module.newContent(
portal_type='Organisation', portal_type='Organisation',
...@@ -220,7 +215,6 @@ class CrmTestCase(ERP5ReportTestCase): ...@@ -220,7 +215,6 @@ class CrmTestCase(ERP5ReportTestCase):
title='My_organisation', title='My_organisation',
group_value=self.portal_categories['group'].demo_group, group_value=self.portal_categories['group'].demo_group,
id='My_organisation') id='My_organisation')
org.validate()
# make sure documents are validated # make sure documents are validated
for module in (self.organisation_module, for module in (self.organisation_module,
...@@ -237,22 +231,15 @@ class CrmTestCase(ERP5ReportTestCase): ...@@ -237,22 +231,15 @@ class CrmTestCase(ERP5ReportTestCase):
"""Remove all documents. """Remove all documents.
""" """
transaction.abort() transaction.abort()
self.campaign_module.manage_delObjects( for module in (self.campaign_module,
list(self.campaign_module.objectIds())) self.meeting_module,
self.meeting_module.manage_delObjects( self.sale_opportunity_module,
list(self.meeting_module.objectIds())) self.support_request_module,
self.sale_opportunity_module.manage_delObjects( self.organisation_module,
list(self.sale_opportunity_module.objectIds())) self.person_module,
self.support_request_module.manage_delObjects( self.event_module):
list(self.support_request_module.objectIds())) module.manage_delObjects(list(module.objectIds()))
self.organisation_module.manage_delObjects(
list(self.campaign_module.objectIds()))
self.person_module.manage_delObjects(
list(self.person_module.objectIds()))
self.portal_categories['group'].manage_delObjects((['demo_group',])) self.portal_categories['group'].manage_delObjects((['demo_group',]))
self.event_module.manage_delObjects(
list(self.event_module.objectIds()))
transaction.commit() transaction.commit()
self.tic() self.tic()
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
import unittest import unittest
import transaction import transaction
from Testing import ZopeTestCase from Testing import ZopeTestCase
from zExceptions import Unauthorized
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.Sequence import SequenceList from Products.ERP5Type.tests.Sequence import SequenceList
from DateTime import DateTime from DateTime import DateTime
...@@ -423,9 +424,6 @@ class TestImmobilisationMixin(ERP5TypeTestCase): ...@@ -423,9 +424,6 @@ class TestImmobilisationMixin(ERP5TypeTestCase):
def stepTic(self, sequence=None, sequence_list=None, **kw): def stepTic(self, sequence=None, sequence_list=None, **kw):
self.tic() self.tic()
def stepPdb(self, sequence=None, sequence_list=None, **kw):
import pdb;pdb.set_trace()
def stepCreatePackingList(self, sequence=None, sequence_list=None, **kw): def stepCreatePackingList(self, sequence=None, sequence_list=None, **kw):
property_dict = {} property_dict = {}
for property in ('source_section','destination_section','datetime','destination'): for property in ('source_section','destination_section','datetime','destination'):
...@@ -992,8 +990,9 @@ class TestImmobilisationMixin(ERP5TypeTestCase): ...@@ -992,8 +990,9 @@ class TestImmobilisationMixin(ERP5TypeTestCase):
""" """
Launch adopt_prevision() on each Amortisation Transaction Launch adopt_prevision() on each Amortisation Transaction
""" """
isTransitionPossible = self.portal.portal_workflow.isTransitionPossible
for transaction in self.getAccountingModule().contentValues(): for transaction in self.getAccountingModule().contentValues():
if hasattr(transaction, 'adoptPrevision'): if isTransitionPossible(transaction, 'adopt_prevision'):
transaction.adoptPrevision() transaction.adoptPrevision()
#LOG('Launched adoptPrevision() for transaction', 0, transaction.getRelativeUrl()) #LOG('Launched adoptPrevision() for transaction', 0, transaction.getRelativeUrl())
else: else:
...@@ -1011,7 +1010,7 @@ class TestImmobilisationMixin(ERP5TypeTestCase): ...@@ -1011,7 +1010,7 @@ class TestImmobilisationMixin(ERP5TypeTestCase):
'accept_decision_action', 'accept_decision_action',
'amortisation_transaction_causality_workflow') 'amortisation_transaction_causality_workflow')
#LOG('Launched acceptDecision() for transaction', 0, transaction.getRelativeUrl()) #LOG('Launched acceptDecision() for transaction', 0, transaction.getRelativeUrl())
except: except Unauthorized:
pass pass
#LOG('Cannot launch acceptDecision() for transaction', 0, transaction.getRelativeUrl()) #LOG('Cannot launch acceptDecision() for transaction', 0, transaction.getRelativeUrl())
......
...@@ -172,8 +172,9 @@ class TestInvoiceMixin(TestPackingListMixin, ...@@ -172,8 +172,9 @@ class TestInvoiceMixin(TestPackingListMixin,
portal.portal_workflow.doActionFor(account, 'validate_action') portal.portal_workflow.doActionFor(account, 'validate_action')
invoice_rule = portal.portal_rules.default_invoice_transaction_rule invoice_rule = portal.portal_rules.default_invoice_transaction_rule
invoice_rule.deleteContent([x.getId() if invoice_rule.getValidationState() == 'validated':
for x in invoice_rule.objectValues()]) invoice_rule.invalidate()
invoice_rule.deleteContent(list(invoice_rule.objectIds()))
transaction.commit() transaction.commit()
self.tic() self.tic()
region_predicate = invoice_rule.newContent(portal_type = 'Predicate') region_predicate = invoice_rule.newContent(portal_type = 'Predicate')
......
...@@ -47,9 +47,6 @@ class TestMRPMixin(TestBPMMixin): ...@@ -47,9 +47,6 @@ class TestMRPMixin(TestBPMMixin):
order_portal_type = 'Production Order' order_portal_type = 'Production Order'
order_line_portal_type = 'Production Order Line' order_line_portal_type = 'Production Order Line'
def setUpOnce(self):
self.portal = self.getPortalObject()
def invalidateRules(self): def invalidateRules(self):
""" """
do reversely of validateRules do reversely of validateRules
...@@ -57,6 +54,7 @@ class TestMRPMixin(TestBPMMixin): ...@@ -57,6 +54,7 @@ class TestMRPMixin(TestBPMMixin):
rule_tool = self.getRuleTool() rule_tool = self.getRuleTool()
for rule in rule_tool.contentValues( for rule in rule_tool.contentValues(
portal_type=rule_tool.getPortalRuleTypeList()): portal_type=rule_tool.getPortalRuleTypeList()):
if rule.getValidationState() == 'validated':
rule.invalidate() rule.invalidate()
def _createDocument(self, portal_type, **kw): def _createDocument(self, portal_type, **kw):
......
...@@ -175,37 +175,28 @@ class ResourceVariationTestCase(ERP5TypeTestCase): ...@@ -175,37 +175,28 @@ class ResourceVariationTestCase(ERP5TypeTestCase):
reference='A2',id='a2') reference='A2',id='a2')
#create resource variation preferences #create resource variation preferences
if not self.portal_preferences.hasContent('test_site_preference'): preference = getattr(self.portal_preferences, 'test_site_preference', None)
if preference is None:
preference = self.portal_preferences.newContent(portal_type='Preference', preference = self.portal_preferences.newContent(portal_type='Preference',
title='Default Site Preference', title='Default Site Preference',
id='test_site_preference') id='test_site_preference')
preference.enable() preference.enable()
value='individual_aspect' value='individual_aspect'
self.portal_preferences['test_site_preference' preference.setPreferredProductIndividualVariationBaseCategory(value)
].setPreferredProductIndividualVariationBaseCategory(value) preference.setPreferredServiceIndividualVariationBaseCategory(value)
self.portal_preferences['test_site_preference' preference.setPreferredComponentIndividualVariationBaseCategory(value)
].setPreferredServiceIndividualVariationBaseCategory(value)
self.portal_preferences['test_site_preference'
].setPreferredComponentIndividualVariationBaseCategory(value)
value=('required_size',) value=('required_size',)
self.portal_preferences['test_site_preference' preference.setPreferredProductVariationBaseCategoryList(value)
].setPreferredProductVariationBaseCategoryList(value) preference.setPreferredServiceVariationBaseCategoryList(value)
self.portal_preferences['test_site_preference' preference.setPreferredComponentVariationBaseCategoryList(value)
].setPreferredServiceVariationBaseCategoryList(value)
self.portal_preferences['test_site_preference'
].setPreferredComponentVariationBaseCategoryList(value)
value=('option_colour',) value=('option_colour',)
self.portal_preferences['test_site_preference' preference.setPreferredProductOptionalVariationBaseCategory(value)
].setPreferredProductOptionalVariationBaseCategory(value) preference.setPreferredServiceOptionalVariationBaseCategory(value)
self.portal_preferences['test_site_preference' preference.setPreferredComponentOptionalVariationBaseCategory(value)
].setPreferredServiceOptionalVariationBaseCategory(value)
self.portal_preferences['test_site_preference'
].setPreferredComponentOptionalVariationBaseCategory(value)
self.portal_preferences['test_site_preference'].enable()
# all this available to catalog # all this available to catalog
#adding to base categories of resources #adding to base categories of resources
......
...@@ -41,7 +41,6 @@ class TestRuleMixin(TestOrderMixin): ...@@ -41,7 +41,6 @@ class TestRuleMixin(TestOrderMixin):
""" """
def afterSetUp(self): def afterSetUp(self):
self.test_data = []
# delete rules # delete rules
self.getRuleTool().manage_delObjects( self.getRuleTool().manage_delObjects(
ids=list(list(self.getRuleTool().objectIds()))) ids=list(list(self.getRuleTool().objectIds())))
...@@ -52,14 +51,15 @@ class TestRuleMixin(TestOrderMixin): ...@@ -52,14 +51,15 @@ class TestRuleMixin(TestOrderMixin):
delivery_rule = self.getRuleTool().newContent(portal_type="Delivery Rule", delivery_rule = self.getRuleTool().newContent(portal_type="Delivery Rule",
id='default_delivery_rule', id='default_delivery_rule',
reference='default_delivery_rule', version='1') reference='default_delivery_rule', version='1')
# at least one default_delivery_rule should be validated here to
# confirm Sale Packing List in afterSetUp()
delivery_rule.validate()
# create packing list if necessary # create packing list if necessary
pl_module = self.getPortal().getDefaultModule( pl_module = self.getPortal().getDefaultModule(
self.packing_list_portal_type) self.packing_list_portal_type)
if pl_module.objectCount() == 0: if pl_module.objectCount() == 0:
# at least one default_delivery_rule should be validated here to
# confirm Sale Packing List
delivery_rule.validate()
self.pl = self.createPackingList() self.pl = self.createPackingList()
delivery_rule.invalidate()
else: else:
self.pl = self.getPortal().getDefaultModule( self.pl = self.getPortal().getDefaultModule(
self.packing_list_portal_type).objectValues()[0] self.packing_list_portal_type).objectValues()[0]
...@@ -72,10 +72,8 @@ class TestRuleMixin(TestOrderMixin): ...@@ -72,10 +72,8 @@ class TestRuleMixin(TestOrderMixin):
def beforeTearDown(self): def beforeTearDown(self):
for container, id in self.test_data: for module in self.getRuleTool(), self.getSimulationTool():
container.manage_delObjects(ids=[id]) module.manage_delObjects(list(module.objectIds()))
self.getSimulationTool().manage_delObjects(
ids=list(self.getSimulationTool().objectIds()))
transaction.commit() transaction.commit()
self.tic() self.tic()
...@@ -189,26 +187,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -189,26 +187,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
validation_state="validated")[0][0], 0) validation_state="validated")[0][0], 0)
self.assertEquals(len(self.getRuleTool().searchRuleList(self.pl)), 0) self.assertEquals(len(self.getRuleTool().searchRuleList(self.pl)), 0)
def test_05_ValidatedRule(self, quiet=quiet, run=run_all_test):
"""
test that when a rule is validated, it will apply
"""
if not run: return
skin_folder = self.getPortal().portal_skins.custom
skin = createZODBPythonScript(skin_folder, 'good_script', 'rule',
'return True')
delivery_rule = self.getRuleTool().searchFolder(
reference='default_delivery_rule')[0]
delivery_rule.setTestMethodId('good_script')
delivery_rule.validate()
transaction.commit()
self.tic()
self.assertEquals(self.getRuleTool().countFolder(
validation_state="validated")[0][0], 1)
self.assertEquals(len(self.getRuleTool().searchRuleList(self.pl)), 1)
def test_06_WrongDateRange(self, quiet=quiet, run=run_all_test): def test_06_WrongDateRange(self, quiet=quiet, run=run_all_test):
""" """
test that when a rule is validated but does not have correct date range, test that when a rule is validated but does not have correct date range,
......
...@@ -1627,10 +1627,7 @@ class TestTaxLineInvoiceSimulation(AccountingBuildTestCase): ...@@ -1627,10 +1627,7 @@ class TestTaxLineInvoiceSimulation(AccountingBuildTestCase):
invoice_simulation_movement.getPriceCurrencyValue()) invoice_simulation_movement.getPriceCurrencyValue())
self.assertEquals(self.resource, self.assertEquals(self.resource,
invoice_simulation_movement.getResourceValue()) invoice_simulation_movement.getResourceValue())
invoice.start()
self.assertEquals('started', invoice.getSimulationState())
transaction.commit()
self.tic()
accounting_line_list = invoice.getMovementList( accounting_line_list = invoice.getMovementList(
portal_type=('Sale Invoice Transaction Line', portal_type=('Sale Invoice Transaction Line',
'Purchase Invoice Transaction Line')) 'Purchase Invoice Transaction Line'))
......
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