Skip to content

Commit

Permalink
fixup! [#3049] Fix end-date of plan can precede that of action templates
Browse files Browse the repository at this point in the history
  • Loading branch information
linssen814 committed Feb 20, 2025
1 parent d870687 commit 5ebc43d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/open_inwoner/plans/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5ebc43d

Please sign in to comment.