[Zope3-checkins] CVS: Zope3/src/zope/app/workflow/stateful/tests - test_contentworkflow.py:1.1.4.1 test_definition.py:1.1.4.1 test_instance.py:1.1.4.1 test_xmlimportexport.py:1.2.2.1
Grégoire Weber
zope@i-con.ch
Sun, 22 Jun 2003 10:24:07 -0400
Update of /cvs-repository/Zope3/src/zope/app/workflow/stateful/tests
In directory cvs.zope.org:/tmp/cvs-serv24874/src/zope/app/workflow/stateful/tests
Modified Files:
Tag: cw-mail-branch
test_contentworkflow.py test_definition.py test_instance.py
test_xmlimportexport.py
Log Message:
Synced up with HEAD
=== Zope3/src/zope/app/workflow/stateful/tests/test_contentworkflow.py 1.1 => 1.1.4.1 ===
--- Zope3/src/zope/app/workflow/stateful/tests/test_contentworkflow.py:1.1 Thu May 8 13:27:20 2003
+++ Zope3/src/zope/app/workflow/stateful/tests/test_contentworkflow.py Sun Jun 22 10:23:35 2003
@@ -18,7 +18,6 @@
"""
import unittest
-from zope.interface import Interface
from zope.interface.verify import verifyClass
from zope.app.interfaces.workflow.stateful import IContentWorkflowsUtility
=== Zope3/src/zope/app/workflow/stateful/tests/test_definition.py 1.1 => 1.1.4.1 ===
--- Zope3/src/zope/app/workflow/stateful/tests/test_definition.py:1.1 Thu May 8 13:27:20 2003
+++ Zope3/src/zope/app/workflow/stateful/tests/test_definition.py Sun Jun 22 10:23:35 2003
@@ -18,7 +18,7 @@
"""
import unittest
-from zope.interface import Interface
+from zope.interface import Interface, implements
from zope.interface.verify import verifyClass
from zope.schema import TextLine
@@ -30,14 +30,14 @@
"""A really dummy state"""
class DummyState:
- __implements__ = IDummyState
+ implements(IDummyState)
class IDummyTransition(Interface):
"""A really dummy transition"""
class DummyTransition:
- __implements__ = IDummyTransition
+ implements(IDummyTransition)
class IDummyDataSchema(Interface):
=== Zope3/src/zope/app/workflow/stateful/tests/test_instance.py 1.1 => 1.1.4.1 ===
--- Zope3/src/zope/app/workflow/stateful/tests/test_instance.py:1.1 Thu May 8 13:27:20 2003
+++ Zope3/src/zope/app/workflow/stateful/tests/test_instance.py Sun Jun 22 10:23:35 2003
@@ -19,7 +19,7 @@
import unittest
-from zope.interface import Interface
+from zope.interface import Interface, implements
from zope.interface.verify import verifyClass
from zope.schema import Text, Int
@@ -30,38 +30,32 @@
from zope.app.services.servicenames import Permissions
from zope.security.checker import CheckerPublic
from zope.security.management import newSecurityManager
-from zope.security.management import system_user
-from zope.proxy.context import ContextWrapper
-from zope.app.traversing import traverse
+from zope.app.context import ContextWrapper
-from zope.app.container.zopecontainer import ZopeContainerAdapter
-
-from zope.app.interfaces.services.configuration \
- import IUseConfigurable
+from zope.app.interfaces.services.registration import IRegisterable
+from zope.app.interfaces.services.registration import IRegistered
from zope.app.interfaces.annotation import IAttributeAnnotatable
-from zope.app.interfaces.services.configuration \
- import Active, Unregistered, Registered
+from zope.app.interfaces.services.registration import ActiveStatus
from zope.app.workflow.tests.workflowsetup import WorkflowSetup
-from zope.app.workflow.service import WorkflowService
-from zope.app.workflow.service import ProcessDefinitionConfiguration
+from zope.app.workflow.service import ProcessDefinitionRegistration
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, StateChangeInfo
-
-
+from zope.app import zapi
# define and create ProcessDefinition (PD) for tests
class TestProcessDefinition(StatefulProcessDefinition):
- __implements__ = IAttributeAnnotatable, IUseConfigurable, \
- StatefulProcessDefinition.__implements__
-
+ implements(IAttributeAnnotatable, IRegisterable, IRegistered)
+ # Incompletely implementing IRegistered
+ def addUsage(self, location):
+ pass
class ITestDataSchema(Interface):
@@ -75,7 +69,6 @@
return l
-
class SimpleProcessInstanceTests(WorkflowSetup, unittest.TestCase):
def setUp(self):
@@ -88,7 +81,7 @@
pd.states.setObject('private', State())
pd.states.setObject('published', State())
pd.states.setObject('pending', State())
-
+
pd.transitions.setObject('show',
Transition('INITIAL', 'private'))
pd.transitions.setObject('publish_direct',
@@ -104,20 +97,20 @@
self.default.setObject('pd1', pd )
- self.cm.setObject('', ProcessDefinitionConfiguration('definition1',
+ self.cm.setObject('', ProcessDefinitionRegistration('definition1',
'/++etc++site/default/pd1'))
- traverse(self.default.getConfigurationManager(), '2').status = Active
+ zapi.traverse(self.default.getRegistrationManager(),
+ '2').status = ActiveStatus
self.pd = self.service.getProcessDefinition('definition1')
# give the pi some context to find a service
- self.pi = ContextWrapper(self.service.createProcessInstance('definition1'),
- self.rootFolder)
-
+ self.pi = ContextWrapper(
+ self.service.createProcessInstance('definition1'),
+ self.rootFolder)
def testInterface(self):
verifyClass(IStatefulProcessInstance, StatefulProcessInstance)
-
def testRelevantData(self):
pi = self.pi
data = pi.data
@@ -132,15 +125,14 @@
self.assertEqual(data.text, 'another text')
self.assertEqual(data.value, 10)
-
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()),
@@ -166,9 +158,6 @@
self.assertEqual(pi.status, 'private')
-
-
-
class ConditionProcessInstanceTests(WorkflowSetup, unittest.TestCase):
def setUp(self):
@@ -180,19 +169,21 @@
pd.states.setObject('state1', State())
pd.states.setObject('state2', State())
-
+
pd.transitions.setObject('initial_state1',
Transition('INITIAL', 'state1',
condition='data/value'))
pd.transitions.setObject('initial_state2',
Transition('INITIAL', 'state2',
condition='not: data/value'))
- pd.transitions.setObject('state1_state2',
- Transition('state1', 'state2',
- condition='python: data.text == "some text"'))
- pd.transitions.setObject('state2_state1',
- Transition('state2', 'state1',
- condition='python: data.text == "no text"'))
+ pd.transitions.setObject(
+ 'state1_state2',
+ Transition('state1', 'state2',
+ condition='python: data.text == "some text"'))
+ pd.transitions.setObject(
+ 'state2_state1',
+ Transition('state2', 'state1',
+ condition='python: data.text == "no text"'))
pd.transitions.setObject('state1_initial',
Transition('state1', 'INITIAL'))
pd.transitions.setObject('state2_initial',
@@ -200,23 +191,22 @@
self.default.setObject('pd1', pd )
- self.cm.setObject('', ProcessDefinitionConfiguration('definition1',
+ self.cm.setObject('', ProcessDefinitionRegistration('definition1',
'/++etc++site/default/pd1'))
- traverse(self.default.getConfigurationManager(), '2').status = Active
+ zapi.traverse(self.default.getRegistrationManager(), '2').status = ActiveStatus
self.pd = self.service.getProcessDefinition('definition1')
# give the pi some context to find a service
- self.pi = ContextWrapper(self.service.createProcessInstance('definition1'),
- self.rootFolder)
-
-
+ 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)
@@ -229,7 +219,7 @@
self.assertEqual(pi.getOutgoingTransitions(), ['state1_initial'])
data.text = 'some text'
-
+
self.assertEqual(sort(pi.getOutgoingTransitions()),
['state1_initial', 'state1_state2'])
@@ -247,17 +237,13 @@
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'])
-
-
-
-
def transition_script1(contexts):
return contexts['data'].text == "some text"
@@ -275,13 +261,14 @@
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(
+ 'initial_state2',
+ Transition('INITIAL', 'state2',
+ script=lambda c: not c['data'].value))
pd.transitions.setObject('state1_state2',
Transition('state1', 'state2',
script=transition_script1))
@@ -295,23 +282,23 @@
self.default.setObject('pd1', pd )
- self.cm.setObject('', ProcessDefinitionConfiguration('definition1',
+ k = self.cm.setObject('', ProcessDefinitionRegistration('definition1',
'/++etc++site/default/pd1'))
- traverse(self.default.getConfigurationManager(), '2').status = Active
+ zapi.traverse(self.default.getRegistrationManager(),
+ k).status = ActiveStatus
self.pd = self.service.getProcessDefinition('definition1')
# give the pi some context to find a service
- self.pi = ContextWrapper(self.service.createProcessInstance('definition1'),
- self.rootFolder)
-
-
+ 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)
@@ -324,7 +311,7 @@
self.assertEqual(pi.getOutgoingTransitions(), ['state1_initial'])
data.text = 'some text'
-
+
self.assertEqual(sort(pi.getOutgoingTransitions()),
['state1_initial', 'state1_state2'])
@@ -342,15 +329,13 @@
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):
def setUp(self):
@@ -369,32 +354,37 @@
pd.states.setObject('state1', State())
pd.states.setObject('state2', State())
-
+
pd.transitions.setObject('initial_state1',
- Transition('INITIAL', 'state1', permission=CheckerPublic))
+ Transition('INITIAL', 'state1',
+ permission=CheckerPublic))
pd.transitions.setObject('initial_state2',
- Transition('INITIAL', 'state2', permission='deny'))
+ Transition('INITIAL', 'state2',
+ permission='deny'))
pd.transitions.setObject('state1_state2',
- Transition('state1', 'state2', permission=CheckerPublic))
+ Transition('state1', 'state2',
+ permission=CheckerPublic))
pd.transitions.setObject('state2_state1',
Transition('state2', 'state1'))
pd.transitions.setObject('state1_initial',
- Transition('state1', 'INITIAL', permission='deny'))
+ Transition('state1', 'INITIAL',
+ permission='deny'))
pd.transitions.setObject('state2_initial',
- Transition('state2', 'INITIAL', permission=CheckerPublic))
+ Transition('state2', 'INITIAL',
+ permission=CheckerPublic))
self.default.setObject('pd1', pd )
- self.cm.setObject('', ProcessDefinitionConfiguration('definition1',
+ k = self.cm.setObject('', ProcessDefinitionRegistration('definition1',
'/++etc++site/default/pd1'))
- traverse(self.default.getConfigurationManager(), '2').status = Active
+ zapi.traverse(self.default.getRegistrationManager(),
+ k).status = ActiveStatus
self.pd = self.service.getProcessDefinition('definition1')
# give the pi some context to find a service
- self.pi = ContextWrapper(self.service.createProcessInstance('definition1'),
- self.rootFolder)
-
-
+ self.pi = ContextWrapper(
+ self.service.createProcessInstance('definition1'),
+ self.rootFolder)
def testPermissionedTranstitions(self):
pi = self.pi
@@ -410,7 +400,6 @@
self.assertEqual(pi.getOutgoingTransitions(), ['state1_state2'])
-
class DummyTransition:
def __init__(self, source, destination):
self.sourceState = source
@@ -424,9 +413,6 @@
sci = StateChangeInfo(t)
self.assertEqual(sci.old_state, 1)
self.assertEqual(sci.new_state, 2)
-
-
-
def test_suite():
=== Zope3/src/zope/app/workflow/stateful/tests/test_xmlimportexport.py 1.2 => 1.2.2.1 ===
--- Zope3/src/zope/app/workflow/stateful/tests/test_xmlimportexport.py:1.2 Wed May 21 16:27:42 2003
+++ Zope3/src/zope/app/workflow/stateful/tests/test_xmlimportexport.py Sun Jun 22 10:23:35 2003
@@ -11,37 +11,27 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-import unittest
-from StringIO import StringIO
-
-from zope.interface.verify import verifyClass
-from zope.interface.implements import implements
+from StringIO import StringIO
+from zope.app.attributeannotations import AttributeAnnotations
+from zope.app.dublincore.annotatableadapter import ZDCAnnotatableAdapter
+from zope.app.interfaces.annotation import IAnnotatable, IAnnotations
+from zope.app.interfaces.annotation import IAttributeAnnotatable
+from zope.app.interfaces.dublincore import IZopeDublinCore
+from zope.app.interfaces.services.registration import IRegisterable
+from zope.app.interfaces.workflow import IProcessDefinitionExportHandler
+from zope.app.interfaces.workflow import IProcessDefinitionImportHandler
from zope.app.services.tests.placefulsetup import PlacefulSetup
+from zope.app.workflow.stateful.definition import StatefulProcessDefinition
+from zope.app.workflow.stateful.definition import State, Transition
+from zope.app.workflow.stateful.xmlimportexport import XMLExportHandler
+from zope.app.workflow.stateful.xmlimportexport import XMLImportHandler
from zope.component.adapter import provideAdapter
from zope.component import getAdapter
-
+from zope.interface import implements, classImplements
+from zope.interface.verify import verifyClass
from zope.security.checker import CheckerPublic
-
-from zope.app.dublincore.annotatableadapter \
- import ZDCAnnotatableAdapter
-from zope.app.attributeannotations import AttributeAnnotations
-from zope.app.interfaces.dublincore import IZopeDublinCore
-from zope.app.interfaces.annotation \
- import IAnnotatable, IAnnotations, IAttributeAnnotatable
-
-from zope.app.interfaces.services.configuration \
- import IUseConfigurable
-
-from zope.app.workflow.stateful.definition \
- import StatefulProcessDefinition, State, Transition
-
-from zope.app.interfaces.workflow import IProcessDefinitionImportHandler
-from zope.app.interfaces.workflow import IProcessDefinitionExportHandler
-from zope.app.workflow.stateful.xmlimportexport \
- import XMLImportHandler, XMLExportHandler
-
-
+import unittest
xml_text = """<?xml version="1.0"?>
@@ -57,7 +47,6 @@
</states>
<transitions>
-
<transition sourceState="state2"
destinationState="INITIAL"
script="some.path.to.some.script"
@@ -65,16 +54,14 @@
triggerMode="Manual"
title="State2toINITIAL"
name="state2_initial"/>
-
-
+
<transition sourceState="INITIAL"
destinationState="state1"
permission="zope.Public"
triggerMode="Automatic"
title="INITIALtoState1"
name="initial_state1"/>
-
-
+
<transition sourceState="state1"
destinationState="state2"
condition="python: 1==1"
@@ -82,22 +69,20 @@
triggerMode="Manual"
title="State1toState2"
name="state1_state2"/>
-
+
</transitions>
-
+
</workflow>
"""
class TestProcessDefinition(StatefulProcessDefinition):
- __implements__ = IAttributeAnnotatable, IUseConfigurable, \
- StatefulProcessDefinition.__implements__
+ implements(IAttributeAnnotatable, IRegisterable)
# need to patch this cause these classes are used directly
# in the import/export classes
-implements(State, IAttributeAnnotatable)
-implements(Transition, IAttributeAnnotatable)
-
+classImplements(State, IAttributeAnnotatable)
+classImplements(Transition, IAttributeAnnotatable)
class Test(PlacefulSetup, unittest.TestCase):
@@ -115,7 +100,7 @@
def testImport(self):
testpd = TestProcessDefinition()
handler = XMLImportHandler()
-
+
self.assertEqual(handler.canImport(testpd, StringIO(xml_text)), True)
self.assertEqual(handler.canImport(None, StringIO(xml_text)), False)
self.assertEqual(
@@ -128,14 +113,14 @@
self.assertEqual(testpd.getRelevantDataSchema(),
'Some.path.to.an.ISchemaClass')
self.assertEqual(getAdapter(testpd, IZopeDublinCore).title, 'TestPD')
-
+
self.assertEqual(len(testpd.states), 3)
self.assertEqual(len(testpd.transitions), 3)
st = testpd.states['INITIAL']
self.assert_(isinstance(st, State))
self.assertEqual(getAdapter(st, IZopeDublinCore).title, 'initial')
-
+
st = testpd.states['state1']
self.assert_(isinstance(st, State))
self.assertEqual(getAdapter(st, IZopeDublinCore).title, 'State1')
@@ -155,7 +140,7 @@
self.assertEqual(tr.script, None)
self.assertEqual(tr.permission, CheckerPublic)
self.assertEqual(tr.triggerMode, 'Automatic')
-
+
tr = testpd.transitions['state1_state2']
self.assert_(isinstance(tr, Transition))
self.assertEqual(getAdapter(tr, IZopeDublinCore).title,
@@ -166,7 +151,7 @@
self.assertEqual(tr.script, None)
self.assertEqual(tr.permission, CheckerPublic)
self.assertEqual(tr.triggerMode, 'Manual')
-
+
tr = testpd.transitions['state2_initial']
self.assert_(isinstance(tr, Transition))
self.assertEqual(getAdapter(tr, IZopeDublinCore).title,
@@ -181,9 +166,7 @@
def testExport(self):
# XXX TBD before Merge into HEAD !!!!
pass
-
-
def test_suite():
loader=unittest.TestLoader()