From 1e6b86fac53fe6ba18340ef7f255fa82b0a533ef Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Wed, 13 Dec 2017 15:57:49 +0000 Subject: [PATCH] Correctly handle the last stage in the Workflow --- opentech/apply/tests.py | 4 ++++ opentech/apply/workflow.py | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/opentech/apply/tests.py b/opentech/apply/tests.py index cc8a68758..fbbf0a099 100644 --- a/opentech/apply/tests.py +++ b/opentech/apply/tests.py @@ -28,6 +28,10 @@ class TestWorkflowCreation(SimpleTestCase): workflow = WorkflowFactory(num_stages=1) 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): def test_can_create_stage(self): diff --git a/opentech/apply/workflow.py b/opentech/apply/workflow.py index 9b624227e..fe2f35860 100644 --- a/opentech/apply/workflow.py +++ b/opentech/apply/workflow.py @@ -1,4 +1,4 @@ -from typing import Iterator, Iterable +from typing import Iterator, Iterable, Union from django.forms import Form @@ -13,8 +13,11 @@ class Workflow(Iterable['Stage']): def __iter__(self) -> Iterator['Stage']: yield from self.stages - def next(self): - return self.stages[0] + def next(self, current_stage: Union['Stage', None]=None) -> Union['Stage', None]: + if not current_stage: + return self.stages[0] + + return None class Stage: -- GitLab