Add managed cron editing and bump version to 0.4.0
This commit is contained in:
11 files changed
+488
-23
No files matched your search
@@ -9,6 +9,7 @@ from schedls.errors import ConfirmationRequiredError, InvalidScheduleError
|
||||
from schedls.models import (
|
||||
Backend,
|
||||
Command,
|
||||
CronDetails,
|
||||
JobSource,
|
||||
Schedule,
|
||||
ScheduledJob,
|
||||
@@ -60,6 +61,20 @@ def _systemd_job() -> ScheduledJob:
|
||||
)
|
||||
|
||||
|
||||
def _cron_job() -> ScheduledJob:
|
||||
return ScheduledJob(
|
||||
name="cleanup",
|
||||
backend=Backend.CRON,
|
||||
scope=Scope.USER,
|
||||
managed=True,
|
||||
enabled=None,
|
||||
schedule=Schedule(ScheduleKind.CRON, "0 2 * * *"),
|
||||
command=Command(raw="/usr/local/bin/cleanup"),
|
||||
source=JobSource(detail="current user's crontab"),
|
||||
cron=CronDetails(expression="0 2 * * *"),
|
||||
)
|
||||
|
||||
|
||||
def test_text_requires_a_value() -> None:
|
||||
prompter, fake = make_prompter(["", "backup"])
|
||||
assert prompter.text("Name") == "backup"
|
||||
@@ -260,6 +275,16 @@ def test_wizard_edit_changes_schedule(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
assert spec.calendar == ("*-*-* 03:00:00",)
|
||||
|
||||
|
||||
def test_wizard_edit_changes_cron_schedule(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr("sys.stdin", FakeStdin(isatty=True))
|
||||
args = build_parser().parse_args(["edit", "cleanup", "-i"])
|
||||
prompter, _ = make_prompter(["n", "y", "", "03:00"])
|
||||
args, tail = _wizard_edit(_cron_job(), args, [], prompter)
|
||||
spec = _spec_for_edit(_cron_job(), args, tail)
|
||||
|
||||
assert spec.cron_expression == "0 3 * * *"
|
||||
|
||||
|
||||
def test_wizard_edit_keeps_changes_optional(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr("sys.stdin", FakeStdin(isatty=True))
|
||||
job = _systemd_job()
|
||||
|
||||
Reference in new issue
Block a user