Skip to content
Browse files

Merge branch 'dnouri-master'

  • Loading branch information...
2 parents 225b15e + e47bdb4 commit a57e53af3e27efbbee64d6f85ea3a61f4744b5cf @tseaver tseaver committed Mar 24, 2012
Showing with 75 additions and 4 deletions.
  1. +3 −0 CHANGES.txt
  2. +65 −0 repoze/workflow/tests/test_workflow.py
  3. +7 −4 repoze/workflow/workflow.py
View
3 CHANGES.txt
@@ -9,6 +9,9 @@ Next release
- 100% test coverage
+- With multiple transitions between two states, try all transitions
+ instead of only the first.
+
0.5 (2009-08-27)
----------------
View
65 repoze/workflow/tests/test_workflow.py
@@ -38,6 +38,71 @@ def _makePopulated(self, state_callback=None, transition_callback=None):
sm._transition_order = ['publish', 'reject', 'retract', 'submit']
return sm
+ def _makePopulatedOverlappingTransitions(
+ self, state_callback=None, transition_callback=None,
+ permission_checker=None):
+ sm = self._makePopulated(state_callback, transition_callback)
+ sm.permission_checker = permission_checker
+
+ sm._transition_data['submit2'] = dict(
+ name='submit2',
+ from_state='private',
+ to_state='pending',
+ callback=transition_callback,
+ )
+ sm._transition_order.append('submit2')
+ return sm
+
+ def test_transition_to_state_two_transitions_second_works(self):
+ args = []
+ def dummy(content, info):
+ args.append((content, info))
+
+ def checker(permission, context, request):
+ return permission == 'allowed'
+
+ sm = self._makePopulatedOverlappingTransitions(
+ transition_callback=dummy,
+ permission_checker=checker,
+ )
+
+ sm._transition_data['submit']['permission'] = 'forbidden'
+ sm._transition_data['submit2']['permission'] = 'allowed'
+
+ ob = DummyContent()
+ ob.state = 'private'
+ sm.transition_to_state(ob, object(), 'pending')
+ self.assertEqual(len(args), 1)
+ self.assertEqual(args[0][1].transition['name'], 'submit2')
+
+ def test_transition_to_state_two_transitions_none_works(self):
+ callback_args = []
+ def dummy(content, info):
+ callback_args.append((content, info))
+
+ checker_args = []
+ def checker(permission, context, request):
+ checker_args.append((permission, context, request))
+ return permission == 'allowed'
+
+ sm = self._makePopulatedOverlappingTransitions(
+ transition_callback=dummy,
+ permission_checker=checker,
+ )
+
+ sm._transition_data['submit']['permission'] = 'forbidden1'
+ sm._transition_data['submit2']['permission'] = 'forbidden2'
+
+ ob = DummyContent()
+ ob.state = 'private'
+ from repoze.workflow import WorkflowError
+ self.assertRaises(WorkflowError, sm.transition_to_state,
+ ob, object(), 'pending')
+ self.assertEqual(len(callback_args), 0)
+ self.assertEqual(len(checker_args), 2)
+ self.assertEqual([a[0] for a in checker_args],
+ ['forbidden1', 'forbidden2'])
+
def test_class_conforms_to_IWorkflow(self):
from zope.interface.verify import verifyClass
from repoze.workflow.interfaces import IWorkflow
View
11 repoze/workflow/workflow.py
@@ -230,10 +230,13 @@ def _transition_to_state(self, content, to_state, context=None, guards=(),
if info['name'] == to_state:
transitions = info['transitions']
if transitions:
- transition = transitions[0]
- self._transition(content, transition['name'], context,
- guards)
- return
+ for transition in transitions:
+ try:
+ return self._transition(
+ content, transition['name'], context, guards)
+ except WorkflowError, e:
+ exc = e
+ raise exc
raise WorkflowError('No transition from state %r to state %r'
% (from_state, to_state))

0 comments on commit a57e53a

Please sign in to comment.
Something went wrong with that request. Please try again.