[Zope3-checkins] CVS: Packages3/workflow/stateful/tests - test_definition.py:1.6 test_instance.py:1.10
Ulrich Eck
ueck@net-labs.de
Fri, 28 Mar 2003 13:16:38 -0500
Update of /cvs-repository/Packages3/workflow/stateful/tests
In directory cvs.zope.org:/tmp/cvs-serv4403/stateful/tests
Modified Files:
test_definition.py test_instance.py
Log Message:
added script support for Transitions (condition and script need to evaluate
to True that the transition can be fired)
cleaned up some parts of the import/export (unittests will follow next week)
added unittest for transition-script-support
=== Packages3/workflow/stateful/tests/test_definition.py 1.5 => 1.6 ===
--- Packages3/workflow/stateful/tests/test_definition.py:1.5 Sat Feb 8 11:57:03 2003
+++ Packages3/workflow/stateful/tests/test_definition.py Fri Mar 28 13:16:37 2003
@@ -45,6 +45,10 @@
text = TextLine(title=u'a text', default=u'no text')
+# XXX Tests missing for:
+# State Class/Interface
+# Transition Class/Interface
+
class StatefulProcessDefinitionTests(unittest.TestCase):
=== Packages3/workflow/stateful/tests/test_instance.py 1.9 => 1.10 ===
--- Packages3/workflow/stateful/tests/test_instance.py:1.9 Mon Mar 24 09:53:00 2003
+++ Packages3/workflow/stateful/tests/test_instance.py Fri Mar 28 13:16:37 2003
@@ -164,7 +164,6 @@
pi.fireTransition('retract_pending')
self.assertEqual(pi.status, 'private')
-
class ConditionProcessInstanceTests(WorkflowSetup, unittest.TestCase):
def setUp(self):
@@ -250,6 +249,97 @@
['state2_initial', 'state2_state1'])
+def transition_script1(contexts):
+ return contexts['data'].text == "some text"
+
+def transition_script2(contexts):
+ return contexts['data'].text == "no text"
+
+class ScriptProcessInstanceTests(WorkflowSetup, unittest.TestCase):
+
+ def setUp(self):
+ WorkflowSetup.setUp(self)
+
+ pd = TestProcessDefinition()
+
+ pd.setRelevantDataSchema(ITestDataSchema)
+
+ pd.states.setObject('state1', State())
+ pd.states.setObject('state2', State())
+
+ pd.transitions.setObject('initial_state1',
+ Transition('INITIAL', 'state1',
+ script=lambda c: c['data'].value))
+ pd.transitions.setObject('initial_state2',
+ Transition('INITIAL', 'state2',
+ script=lambda c: not c['data'].value))
+ pd.transitions.setObject('state1_state2',
+ Transition('state1', 'state2',
+ script=transition_script1))
+ pd.transitions.setObject('state2_state1',
+ Transition('state2', 'state1',
+ script=transition_script2))
+ pd.transitions.setObject('state1_initial',
+ Transition('state1', 'INITIAL'))
+ pd.transitions.setObject('state2_initial',
+ Transition('state2', 'INITIAL'))
+
+ self.default.setObject('pd1', pd )
+
+ self.cm.setObject('', ProcessDefinitionConfiguration('definition1',
+ '/++etc++site/default/pd1'))
+ traverse(self.default.getConfigurationManager(), '2').status = Active
+
+ self.pd = self.service.getProcessDefinition('definition1')
+ # give the pi some context to find a service
+ self.pi = ContextWrapper(self.service.createProcessInstance('definition1'),
+ self.rootFolder)
+
+
+
+ def testConditionalTranstitions(self):
+ pi = self.pi
+ pd = self.pd
+
+ data = pi.data
+
+ self.assertEqual(pi.status, pd.getInitialStateName())
+ self.assertEqual(data.text, 'no text')
+ self.assertEqual(data.value, 1)
+
+ self.assertEqual(pi.getOutgoingTransitions(), ['initial_state1'])
+ self.assertRaises(KeyError, pi.fireTransition, 'initial_state2')
+
+ pi.fireTransition('initial_state1')
+ self.assertEqual(pi.status, 'state1')
+ self.assertEqual(pi.getOutgoingTransitions(), ['state1_initial'])
+
+ data.text = 'some text'
+
+ self.assertEqual(sort(pi.getOutgoingTransitions()),
+ ['state1_initial', 'state1_state2'])
+
+ pi.fireTransition('state1_state2')
+ self.assertEqual(pi.status, 'state2')
+ self.assertEqual(pi.getOutgoingTransitions(), ['state2_initial'])
+ self.assertRaises(KeyError, pi.fireTransition, 'state2_state1')
+
+ data.text = 'no text'
+
+ pi.fireTransition('state2_initial')
+ self.assertEqual(pi.status, 'INITIAL')
+ self.assertEqual(pi.getOutgoingTransitions(), ['initial_state1'])
+
+ data.value = 0
+
+ self.assertEqual(pi.getOutgoingTransitions(), ['initial_state2'])
+
+ pi.fireTransition('initial_state2')
+ self.assertEqual(pi.status, 'state2')
+ self.assertEqual(pi.getOutgoingTransitions(),
+ ['state2_initial', 'state2_state1'])
+
+
class PermissionProcessInstanceTests(WorkflowSetup, unittest.TestCase):
@@ -334,6 +424,7 @@
return unittest.TestSuite((
unittest.makeSuite(SimpleProcessInstanceTests),
unittest.makeSuite(ConditionProcessInstanceTests),
+ unittest.makeSuite(ScriptProcessInstanceTests),
unittest.makeSuite(PermissionProcessInstanceTests),
unittest.makeSuite(TestStateChangeInfo),
))