From 5ebc43d80dd992fadafe83734c75980377c5189f Mon Sep 17 00:00:00 2001 From: maykin Date: Thu, 20 Feb 2025 17:43:20 +0100 Subject: [PATCH] fixup! [#3049] Fix end-date of plan can precede that of action templates --- src/open_inwoner/plans/tests/test_views.py | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/open_inwoner/plans/tests/test_views.py b/src/open_inwoner/plans/tests/test_views.py index e288c12ba1..9130298ab7 100644 --- a/src/open_inwoner/plans/tests/test_views.py +++ b/src/open_inwoner/plans/tests/test_views.py @@ -491,6 +491,38 @@ def test_plan_create_plan_validation_error_reselects_template_and_contact(self): elem = response.pyquery("#id_plan_contacts_1")[0] self.assertEqual(elem.attrib.get("checked"), "checked") + def test_plan_create_plan_end_date_cannot_precede_action_end_dates(self): + plan_template = PlanTemplateFactory(file=None) + ActionTemplateFactory(plan_template=plan_template) + # make sure we have only one plan + self.assertEqual(Plan.objects.count(), 1) + + # Purposely make the dates of the actions much higher + # than the date of the plan + for actionTemplate in plan_template.actiontemplates.all(): + actionTemplate.end_in_days = 10000 + actionTemplate.save() + + response = self.app.get(self.create_url, user=self.user) + form = response.forms["plan-form"] + form["title"] = "Plan" + form["end_date"] = "2025-02-23" + form["plan_contacts"] = [self.contact.pk] + form["template"] = plan_template.pk + response = form.submit() + self.assertEqual(response.status_code, 200) + + # Confirm the mistake was caught + self.assertContains( + response, + _( + "The end date of the plan cannot precede the end dates of the actions in the selected template." + ), + ) + + # nothing was created + self.assertEqual(Plan.objects.count(), 1) + def test_plan_create_contains_contact_create_link_when_no_contacts_exist(self): self.user.user_contacts.remove(self.contact) response = self.app.get(self.create_url, user=self.user)