From 91ae5f32bc3f069b26fc76a72a8885afa74c1518 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Wed, 7 Feb 2018 11:43:03 +0000 Subject: [PATCH] Add the workflow to the round on save --- opentech/apply/funds/models.py | 6 ++++++ opentech/apply/funds/tests/test_models.py | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py index 98b6c0033..fb1d3372f 100644 --- a/opentech/apply/funds/models.py +++ b/opentech/apply/funds/models.py @@ -223,6 +223,12 @@ class Round(SubmittableStreamForm): ], heading="Dates") ] + def save(self, *args, **kwargs): + if hasattr(self, 'parent_page'): + # We attached the parent page as part of the before_create_hook + self.workflow = self.parent_page.workflow + super().save(*args, **kwargs) + def get_submit_meta_data(self, **kwargs): return super().get_submit_meta_data( page=self.get_parent(), diff --git a/opentech/apply/funds/tests/test_models.py b/opentech/apply/funds/tests/test_models.py index 6d4094dac..dab37d083 100644 --- a/opentech/apply/funds/tests/test_models.py +++ b/opentech/apply/funds/tests/test_models.py @@ -68,7 +68,7 @@ class TestFundModel(TestCase): self.assertEqual(self.fund.open_round, None) -class TestRoundModel(TestCase): +class TestRoundModelDates(TestCase): def setUp(self): self.fund = FundTypeFactory(parent=None) @@ -139,6 +139,18 @@ class TestRoundModel(TestCase): new_round.clean() +class TestRoundModelWorkflowAndForms(TestCase): + def setUp(self): + self.fund = FundTypeFactory(parent=None) + # we only add parent_page on create, so if the object exists already this should not affect testing + self.round = RoundFactory() + self.round.parent_page = self.fund + + def test_workflow_is_copied_to_new_rounds(self): + self.round.save() + self.assertEqual(self.round.workflow, self.fund.workflow) + + class TestFormSubmission(TestCase): def setUp(self): self.site = Site.objects.first() -- GitLab