summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Warsaw2015-04-07 15:32:30 -0400
committerBarry Warsaw2015-04-07 15:32:30 -0400
commit3a0c1191d8c12a8f4d4e5acb1f167331dfabc7d8 (patch)
treebbf03ce44866ea2ba49ae7db30b3a675062a4f08
parent89f8cd6c2bc7d38c2478d87d81b4b729169b3d80 (diff)
downloadmailman-3a0c1191d8c12a8f4d4e5acb1f167331dfabc7d8.tar.gz
mailman-3a0c1191d8c12a8f4d4e5acb1f167331dfabc7d8.tar.zst
mailman-3a0c1191d8c12a8f4d4e5acb1f167331dfabc7d8.zip
-rw-r--r--src/mailman/app/tests/test_workflow.py6
-rw-r--r--src/mailman/app/workflow.py42
2 files changed, 46 insertions, 2 deletions
diff --git a/src/mailman/app/tests/test_workflow.py b/src/mailman/app/tests/test_workflow.py
index 0f70042af..51beceb86 100644
--- a/src/mailman/app/tests/test_workflow.py
+++ b/src/mailman/app/tests/test_workflow.py
@@ -119,8 +119,10 @@ class TestWorkflow(unittest.TestCase):
def test_run_thru(self):
# Run all steps through the given one.
- results = self._workflow.run_thru(second)
+ results = self._workflow.run_thru('second')
self.assertEqual(results, ['one', 'two'])
def test_run_until(self):
- # Run until (but not including
+ # Run until (but not including) the given step.
+ results = self._workflow.run_until('second')
+ self.assertEqual(results, ['one'])
diff --git a/src/mailman/app/workflow.py b/src/mailman/app/workflow.py
index f9a951157..8275addc0 100644
--- a/src/mailman/app/workflow.py
+++ b/src/mailman/app/workflow.py
@@ -67,6 +67,48 @@ class Workflow:
log.exception('deque: {}'.format(COMMASPACE.join(self._next)))
raise
+ def run_thru(self, stop_after):
+ """Run the state machine through and including the given step.
+
+ :param stop_after: Name of method, sans prefix to run the
+ state machine through. In other words, the state machine runs
+ until the named method completes.
+ """
+ results = []
+ while True:
+ try:
+ name, step = self._pop()
+ except (StopIteration, IndexError):
+ # We're done.
+ break
+ results.append(step())
+ if name == stop_after:
+ break
+ return results
+
+ def run_until(self, stop_before):
+ """Trun the state machine until (not including) the given step.
+
+ :param stop_before: Name of method, sans prefix that the
+ state machine is run until the method is reached. Unlike
+ `run_thru()` the named method is not run.
+ """
+ results = []
+ while True:
+ try:
+ name, step = self._pop()
+ except (StopIteration, IndexError):
+ # We're done.
+ break
+ if name == stop_before:
+ # Stop executing, but not before we push the last state back
+ # onto the deque. Otherwise, resuming the state machine would
+ # skip this step.
+ self._next.appendleft(step)
+ break
+ results.append(step())
+ return results
+
def save(self):
assert self.token, 'Workflow token must be set'
state_manager = getUtility(IWorkflowStateManager)