Adds `_validate_schedule_for_add()` to `CronService.add_job` so that invalid or misplaced `tz` values are rejected before a job is persisted, regardless of which caller (CLI, tool, etc.) invoked the service. Surfaces the resulting `ValueError` in `nanobot cron add` via a `try/except` so the CLI exits cleanly with a readable error message. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
31 lines
936 B
Python
31 lines
936 B
Python
import pytest
|
|
|
|
from nanobot.cron.service import CronService
|
|
from nanobot.cron.types import CronSchedule
|
|
|
|
|
|
def test_add_job_rejects_unknown_timezone(tmp_path) -> None:
|
|
service = CronService(tmp_path / "cron" / "jobs.json")
|
|
|
|
with pytest.raises(ValueError, match="unknown timezone 'America/Vancovuer'"):
|
|
service.add_job(
|
|
name="tz typo",
|
|
schedule=CronSchedule(kind="cron", expr="0 9 * * *", tz="America/Vancovuer"),
|
|
message="hello",
|
|
)
|
|
|
|
assert service.list_jobs(include_disabled=True) == []
|
|
|
|
|
|
def test_add_job_accepts_valid_timezone(tmp_path) -> None:
|
|
service = CronService(tmp_path / "cron" / "jobs.json")
|
|
|
|
job = service.add_job(
|
|
name="tz ok",
|
|
schedule=CronSchedule(kind="cron", expr="0 9 * * *", tz="America/Vancouver"),
|
|
message="hello",
|
|
)
|
|
|
|
assert job.schedule.tz == "America/Vancouver"
|
|
assert job.state.next_run_at_ms is not None
|