Commit 7d9f7f8d authored by Vincent Pelletier's avatar Vincent Pelletier

Add a test to verify that CMFActivity SQL connection is not blindly commited...

Add a test to verify that CMFActivity SQL connection is not blindly commited when activity failed: it needs to be commited for internal activity handling, but it must not commit whan activity might have done.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18500 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent daebbadf
...@@ -39,6 +39,7 @@ from Products.ERP5Type.Document.Organisation import Organisation ...@@ -39,6 +39,7 @@ from Products.ERP5Type.Document.Organisation import Organisation
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from zLOG import LOG from zLOG import LOG
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from DateTime import DateTime
try: try:
from transaction import get as get_transaction from transaction import get as get_transaction
...@@ -1926,6 +1927,61 @@ class TestCMFActivity(ERP5TypeTestCase): ...@@ -1926,6 +1927,61 @@ class TestCMFActivity(ERP5TypeTestCase):
message_list = activity_tool.getMessageList() message_list = activity_tool.getMessageList()
self.assertEquals(len(message_list), 2) self.assertEquals(len(message_list), 2)
def activityModificationsViaCMFActivityConnectionRolledBackOnError(self, activity):
activity_tool = self.getActivityTool()
def modifySQLAndFail(self, connection_id):
# Add a dumy activity which will not be executed
# Modified table does not matter
self.SQLDict_writeMessageList(
uid_list=[0], # This uid is never automaticaly assigned (starts at 1)
date_list=[DateTime().Date()],
path_list=['dummy_activity'],
method_id_list=['dummy_activity'],
message_list=['dummy_message'],
priority_list=[1],
processing_node_list=[-4],
group_method_id_list=[''],
tag_list=[''],
order_validation_text_list=['']
)
# Fail
raise ValueError, 'This method always fail'
Organisation.modifySQLAndFail = modifySQLAndFail
obj = self.getPortal().organisation_module.newContent(portal_type='Organisation')
obj.activate(activity=activity).modifySQLAndFail()
get_transaction().commit()
self.flushAllActivities(silent=1, loop_size=100)
self.assertEquals(activity_tool.countMessage(path='dummy_activity'), 0)
def test_83_ActivityModificationsViaCMFActivityConnectionRolledBackOnErrorSQLDict(self, quiet=0, run=run_all_test):
"""
When an activity modifies tables through CMFActivity SQL connection and
raises, check that its changes are correctly rolled back.
"""
if not run: return
if not quiet:
message = '\nCheck activity modifications via CMFActivity connection are rolled back on error (SQLDict)'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
get_transaction().commit()
self.tic()
self.activityModificationsViaCMFActivityConnectionRolledBackOnError('SQLDict')
def test_84_ActivityModificationsViaCMFActivityConnectionRolledBackOnErrorSQLQeue(self, quiet=0, run=run_all_test):
"""
When an activity modifies tables through CMFActivity SQL connection and
raises, check that its changes are correctly rolled back.
"""
if not run: return
if not quiet:
message = '\nCheck activity modifications via CMFActivity connection are rolled back on error (SQLQueue)'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
get_transaction().commit()
self.tic()
self.activityModificationsViaCMFActivityConnectionRolledBackOnError('SQLQueue')
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestCMFActivity)) suite.addTest(unittest.makeSuite(TestCMFActivity))
......
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