Commit b98f0d67 authored by Romain Courteaud's avatar Romain Courteaud Committed by Rafael Monnerat

slapos_cloud: allow to test alarm on document without workflow

parent 963d2549
...@@ -83,21 +83,27 @@ class TemporaryAlarmScript(object): ...@@ -83,21 +83,27 @@ class TemporaryAlarmScript(object):
""" """
Context manager for temporary python scripts Context manager for temporary python scripts
""" """
def __init__(self, portal, script_name, fake_return=""): def __init__(self, portal, script_name, fake_return="", attribute=None):
self.script_name = script_name self.script_name = script_name
self.portal = portal self.portal = portal
self.fake_return = fake_return self.fake_return = fake_return
self.attribute = attribute
def __enter__(self): def __enter__(self):
if self.script_name in self.portal.portal_skins.custom.objectIds(): if self.script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % self.script_name) raise ValueError('Precondition failed: %s exists in custom' % self.script_name)
if self.attribute is None:
content = """portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by %s')
return %s""" % (self.script_name, self.fake_return)
else:
content = """portal_workflow = context.portal_workflow
context.edit(%s='Visited by %s')
return %s""" % (self.attribute, self.script_name, self.fake_return)
createZODBPythonScript(self.portal.portal_skins.custom, createZODBPythonScript(self.portal.portal_skins.custom,
self.script_name, self.script_name,
'*args, **kwargs', '*args, **kwargs',
'# Script body\n' '# Script body\n' + content)
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by %s')
return %s""" % (self.script_name, self.fake_return ))
transaction.commit() transaction.commit()
def __exit__(self, exc_type, exc_value, traceback): def __exit__(self, exc_type, exc_value, traceback):
...@@ -648,23 +654,31 @@ class SlapOSTestCaseMixin(testSlapOSMixin): ...@@ -648,23 +654,31 @@ class SlapOSTestCaseMixin(testSlapOSMixin):
resource='foo/bar', resource='foo/bar',
) )
def _test_alarm(self, alarm, document, script_name): def _test_alarm(self, alarm, document, script_name, attribute=None):
self.tic() self.tic()
with TemporaryAlarmScript(self.portal, script_name): with TemporaryAlarmScript(self.portal, script_name, attribute=attribute):
alarm.activeSense() alarm.activeSense()
self.tic() self.tic()
if attribute is None:
content = document.workflow_history['edit_workflow'][-1]['comment']
else:
content = document.getProperty(attribute)
self.assertEqual( self.assertEqual(
'Visited by %s' % script_name, 'Visited by %s' % script_name,
document.workflow_history['edit_workflow'][-1]['comment']) content)
def _test_alarm_not_visited(self, alarm, document, script_name): def _test_alarm_not_visited(self, alarm, document, script_name, attribute=None):
self.tic() self.tic()
with TemporaryAlarmScript(self.portal, script_name): with TemporaryAlarmScript(self.portal, script_name, attribute=attribute):
alarm.activeSense() alarm.activeSense()
self.tic() self.tic()
if attribute is None:
content = document.workflow_history['edit_workflow'][-1]['comment']
else:
content = document.getProperty(attribute)
self.assertNotEqual( self.assertNotEqual(
'Visited by %s' % script_name, 'Visited by %s' % script_name,
document.workflow_history['edit_workflow'][-1]['comment']) content)
def restoreAccountingTemplatesOnPreferences(self): def restoreAccountingTemplatesOnPreferences(self):
self.login() self.login()
......
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