(bugfix) Preserve existing schedule values in the edit form

Only apply default schedule initial values when creating a new schedule.

Avoid passing default initial data while editing an existing ScheduleConfig,
so the form renders the active cron-style expression, user, and retention
settings from the database.

Add a regression test that reopens an existing schedule and verifies the
stored values are shown instead of defaults.
This commit is contained in:
2026-05-19 23:13:53 +02:00
parent 39b6cf3469
commit 1e04da9de8
2 changed files with 25 additions and 1 deletions

View File

@@ -1203,6 +1203,26 @@ class ViewTests(TestCase):
self.assertFalse(schedule.prune)
self.assertEqual(schedule.prune_max_delete, 8)
def test_schedule_form_renders_existing_schedule_values(self) -> None:
self.client.force_login(self.staff_user)
host = HostConfig.objects.create(host="web-01", address="web-01.example.test")
ScheduleConfig.objects.create(
host=host,
cron_expr="45 4 * * 1",
user="backup",
enabled=True,
prune_max_delete=8,
)
response = self.client.get(reverse("edit_host_schedule", args=[host.host]))
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Edit Schedule")
self.assertContains(response, 'value="45 4 * * 1"', html=False)
self.assertContains(response, 'value="backup"', html=False)
self.assertContains(response, 'value="8"', html=False)
self.assertNotContains(response, 'value="15 2 * * *"', html=False)
def test_schedule_form_rejects_invalid_cron(self) -> None:
self.client.force_login(self.staff_user)
host = HostConfig.objects.create(host="web-01", address="web-01.example.test")