[Zope-CVS] CVS: Packages3/workflow/stateful/tests - test_instance.py:1.2
Ulrich Eck
ueck@net-labs.de
Wed, 5 Feb 2003 20:21:01 -0500
Update of /cvs-repository/Packages3/workflow/stateful/tests
In directory cvs.zope.org:/tmp/cvs-serv31928/stateful/tests
Modified Files:
test_instance.py
Log Message:
removed m$ line-endings ..
=== Packages3/workflow/stateful/tests/test_instance.py 1.1 => 1.2 ===
--- Packages3/workflow/stateful/tests/test_instance.py:1.1 Wed Feb 5 20:09:33 2003
+++ Packages3/workflow/stateful/tests/test_instance.py Wed Feb 5 20:20:58 2003
@@ -1,162 +1,162 @@
-##############################################################################
-#
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""
-
-Revision information:
-$Id$
-"""
-
-import unittest
-
-from zope.interface import Interface
-from zope.interface.verify import verifyClass
-
-from zope.proxy.context import ContextWrapper
-from zope.app.traversing import traverse
-from zope.app.container.zopecontainer import ZopeContainerAdapter
-from zope.app.services.service import ServiceManager
-from zope.app.services.service import ServiceConfiguration
-from zope.app.interfaces.dependable import IDependable
-from zope.app.services.tests.placefulsetup \
- import PlacefulSetup
-from zope.app.interfaces.annotation import IAnnotatable
-from zope.app.interfaces.annotation import IAttributeAnnotatable
-from zope.app.attributeannotations import AttributeAnnotations
-from zope.app.interfaces.annotation import IAnnotations
-from zope.app.interfaces.dependable import IDependable
-from zope.app.dependable import Dependable
-from zope.component.adapter import provideAdapter
-from zope.app.interfaces.services.configuration \
- import Active, Unregistered, Registered
-
-from zope.app.workflow.service import WorkflowService
-from zope.app.workflow.service import ProcessDefinitionConfiguration
-from zope.app.interfaces.workflow.stateful \
- import IStatefulProcessInstance
-from zope.app.workflow.stateful.definition \
- import StatefulProcessDefinition, State, Transition
-from zope.app.workflow.stateful.instance \
- import StatefulProcessInstance
-
-
-class WorkflowServiceForTests(WorkflowService):
-
- __implements__ = WorkflowService.__implements__, IAttributeAnnotatable
-
-
-# define and create ProcessDefinition (PD) for tests
-class TestProcessDefinition(StatefulProcessDefinition):
- __implements__ = IAttributeAnnotatable, StatefulProcessDefinition.__implements__
-
-
-def sort(l):
- l.sort()
- return l
-
-class SimpleProcessInstanceTests(PlacefulSetup, unittest.TestCase):
-
- def setUp(self):
- PlacefulSetup.setUp(self)
-
- provideAdapter(IAttributeAnnotatable,
- IAnnotations, AttributeAnnotations)
- provideAdapter(IAnnotatable, IDependable, Dependable)
-
- # Set up a local workflow service
- self.buildFolders()
- self.rootFolder.setServiceManager(ServiceManager())
-
- self.default = traverse(self.rootFolder,
- '++etc++Services/Packages/default')
- self.default.setObject('workflow_srv', WorkflowServiceForTests())
- self.service = traverse(self.default, 'workflow_srv')
-
- self.cm = ZopeContainerAdapter(traverse(self.default, "configure"))
- self.cm.setObject('', ServiceConfiguration('Workflows',
- '/++etc++Services/Packages/default/workflow_srv'))
- traverse(self.default, 'configure/1').status = Active
-
- pd = TestProcessDefinition()
-
- pd.states.setObject('private', State())
- pd.states.setObject('published', State())
- pd.states.setObject('pending', State())
-
- pd.transitions.setObject('show',
- Transition('INITIAL', 'private', None))
- pd.transitions.setObject('publish_direct',
- Transition('private', 'published', None))
- pd.transitions.setObject('publish_pending',
- Transition('pending', 'published', None))
- pd.transitions.setObject('submit_pending',
- Transition('private', 'pending', None))
- pd.transitions.setObject('retract_published',
- Transition('published', 'private', None))
- pd.transitions.setObject('retract_pending',
- Transition('pending', 'private', None))
-
- self.default.setObject('pd1', pd )
-
- self.cm.setObject('', ProcessDefinitionConfiguration('definition1',
- '/++etc++Services/Packages/default/pd1'))
- traverse(self.default, 'configure/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 testInterface(self):
- verifyClass(IStatefulProcessInstance, StatefulProcessInstance)
-
- def testSimpleTranstitions(self):
- pi = self.pi
- pd = self.pd
- self.assertEqual(pi.status, pd.getInitialStateName())
- self.assertEqual(pi.getOutgoingTransitions(), ['show'])
-
- pi.fireTransition('show')
- self.assertEqual(pi.status, 'private')
- self.assertEqual(sort(pi.getOutgoingTransitions()),
- ['publish_direct', 'submit_pending'])
-
- pi.fireTransition('submit_pending')
- self.assertEqual(pi.status, 'pending')
- self.assertEqual(sort(pi.getOutgoingTransitions()),
- ['publish_pending', 'retract_pending'])
-
- pi.fireTransition('publish_pending')
- self.assertEqual(pi.status, 'published')
- self.assertEqual(sort(pi.getOutgoingTransitions()),
- ['retract_published'])
-
- pi.fireTransition('retract_published')
- self.assertEqual(pi.status, 'private')
-
- pi.fireTransition('submit_pending')
- self.assertEqual(pi.status, 'pending')
-
- pi.fireTransition('retract_pending')
- self.assertEqual(pi.status, 'private')
-
-
-def test_suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(
- SimpleProcessInstanceTests))
- return suite
-
-if __name__ == '__main__':
- unittest.main()
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+Revision information:
+$Id$
+"""
+
+import unittest
+
+from zope.interface import Interface
+from zope.interface.verify import verifyClass
+
+from zope.proxy.context import ContextWrapper
+from zope.app.traversing import traverse
+from zope.app.container.zopecontainer import ZopeContainerAdapter
+from zope.app.services.service import ServiceManager
+from zope.app.services.service import ServiceConfiguration
+from zope.app.interfaces.dependable import IDependable
+from zope.app.services.tests.placefulsetup \
+ import PlacefulSetup
+from zope.app.interfaces.annotation import IAnnotatable
+from zope.app.interfaces.annotation import IAttributeAnnotatable
+from zope.app.attributeannotations import AttributeAnnotations
+from zope.app.interfaces.annotation import IAnnotations
+from zope.app.interfaces.dependable import IDependable
+from zope.app.dependable import Dependable
+from zope.component.adapter import provideAdapter
+from zope.app.interfaces.services.configuration \
+ import Active, Unregistered, Registered
+
+from zope.app.workflow.service import WorkflowService
+from zope.app.workflow.service import ProcessDefinitionConfiguration
+from zope.app.interfaces.workflow.stateful \
+ import IStatefulProcessInstance
+from zope.app.workflow.stateful.definition \
+ import StatefulProcessDefinition, State, Transition
+from zope.app.workflow.stateful.instance \
+ import StatefulProcessInstance
+
+
+class WorkflowServiceForTests(WorkflowService):
+
+ __implements__ = WorkflowService.__implements__, IAttributeAnnotatable
+
+
+# define and create ProcessDefinition (PD) for tests
+class TestProcessDefinition(StatefulProcessDefinition):
+ __implements__ = IAttributeAnnotatable, StatefulProcessDefinition.__implements__
+
+
+def sort(l):
+ l.sort()
+ return l
+
+class SimpleProcessInstanceTests(PlacefulSetup, unittest.TestCase):
+
+ def setUp(self):
+ PlacefulSetup.setUp(self)
+
+ provideAdapter(IAttributeAnnotatable,
+ IAnnotations, AttributeAnnotations)
+ provideAdapter(IAnnotatable, IDependable, Dependable)
+
+ # Set up a local workflow service
+ self.buildFolders()
+ self.rootFolder.setServiceManager(ServiceManager())
+
+ self.default = traverse(self.rootFolder,
+ '++etc++Services/Packages/default')
+ self.default.setObject('workflow_srv', WorkflowServiceForTests())
+ self.service = traverse(self.default, 'workflow_srv')
+
+ self.cm = ZopeContainerAdapter(traverse(self.default, "configure"))
+ self.cm.setObject('', ServiceConfiguration('Workflows',
+ '/++etc++Services/Packages/default/workflow_srv'))
+ traverse(self.default, 'configure/1').status = Active
+
+ pd = TestProcessDefinition()
+
+ pd.states.setObject('private', State())
+ pd.states.setObject('published', State())
+ pd.states.setObject('pending', State())
+
+ pd.transitions.setObject('show',
+ Transition('INITIAL', 'private', None))
+ pd.transitions.setObject('publish_direct',
+ Transition('private', 'published', None))
+ pd.transitions.setObject('publish_pending',
+ Transition('pending', 'published', None))
+ pd.transitions.setObject('submit_pending',
+ Transition('private', 'pending', None))
+ pd.transitions.setObject('retract_published',
+ Transition('published', 'private', None))
+ pd.transitions.setObject('retract_pending',
+ Transition('pending', 'private', None))
+
+ self.default.setObject('pd1', pd )
+
+ self.cm.setObject('', ProcessDefinitionConfiguration('definition1',
+ '/++etc++Services/Packages/default/pd1'))
+ traverse(self.default, 'configure/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 testInterface(self):
+ verifyClass(IStatefulProcessInstance, StatefulProcessInstance)
+
+ def testSimpleTranstitions(self):
+ pi = self.pi
+ pd = self.pd
+ self.assertEqual(pi.status, pd.getInitialStateName())
+ self.assertEqual(pi.getOutgoingTransitions(), ['show'])
+
+ pi.fireTransition('show')
+ self.assertEqual(pi.status, 'private')
+ self.assertEqual(sort(pi.getOutgoingTransitions()),
+ ['publish_direct', 'submit_pending'])
+
+ pi.fireTransition('submit_pending')
+ self.assertEqual(pi.status, 'pending')
+ self.assertEqual(sort(pi.getOutgoingTransitions()),
+ ['publish_pending', 'retract_pending'])
+
+ pi.fireTransition('publish_pending')
+ self.assertEqual(pi.status, 'published')
+ self.assertEqual(sort(pi.getOutgoingTransitions()),
+ ['retract_published'])
+
+ pi.fireTransition('retract_published')
+ self.assertEqual(pi.status, 'private')
+
+ pi.fireTransition('submit_pending')
+ self.assertEqual(pi.status, 'pending')
+
+ pi.fireTransition('retract_pending')
+ self.assertEqual(pi.status, 'private')
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(
+ SimpleProcessInstanceTests))
+ return suite
+
+if __name__ == '__main__':
+ unittest.main()