Skip to content
Snippets Groups Projects
Commit 1e6b86fa authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Correctly handle the last stage in the Workflow

parent d9fea539
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,10 @@ class TestWorkflowCreation(SimpleTestCase): ...@@ -28,6 +28,10 @@ class TestWorkflowCreation(SimpleTestCase):
workflow = WorkflowFactory(num_stages=1) workflow = WorkflowFactory(num_stages=1)
self.assertEqual(workflow.next(), workflow.stages[0]) self.assertEqual(workflow.next(), workflow.stages[0])
def test_returns_none_if_no_next(self):
workflow = WorkflowFactory(num_stages=1)
self.assertEqual(workflow.next(workflow.stages[0]), None)
class TestStageCreation(SimpleTestCase): class TestStageCreation(SimpleTestCase):
def test_can_create_stage(self): def test_can_create_stage(self):
......
from typing import Iterator, Iterable from typing import Iterator, Iterable, Union
from django.forms import Form from django.forms import Form
...@@ -13,8 +13,11 @@ class Workflow(Iterable['Stage']): ...@@ -13,8 +13,11 @@ class Workflow(Iterable['Stage']):
def __iter__(self) -> Iterator['Stage']: def __iter__(self) -> Iterator['Stage']:
yield from self.stages yield from self.stages
def next(self): def next(self, current_stage: Union['Stage', None]=None) -> Union['Stage', None]:
return self.stages[0] if not current_stage:
return self.stages[0]
return None
class Stage: class Stage:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment