afterhours-shift-manager/tests/scripts/test_recreate_holiday_schedules.py
Adam Moussa 45b30e9e30
ci(workflows): call org reusable CI and Fargate CD
Local CI and the image deploy duplicated the org workflows and still required ci / ci. Pin the callers to those workflows and trust the reusable deploy ref.
2026-09-24 12:05:24 -04:00

57 lines
1.6 KiB
Python

"""recreate_holiday_schedules skips past at() expressions, not only EndDate."""
from datetime import datetime, timezone
from zoneinfo import ZoneInfo
import importlib.util
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
def _load():
spec = importlib.util.spec_from_file_location(
"recreate_holiday_schedules",
ROOT / "scripts" / "cutover" / "recreate_holiday_schedules.py",
)
mod = importlib.util.module_from_spec(spec)
sys.modules["recreate_holiday_schedules"] = mod
spec.loader.exec_module(mod)
return mod
mod = _load()
def test_schedule_when_parses_at_expression_in_eastern():
detail = {
"ScheduleExpression": "at(2026-07-04T08:00:00)",
"ScheduleExpressionTimezone": "America/New_York",
}
when = mod.schedule_when(detail)
expected = datetime(
2026, 7, 4, 8, 0, 0, tzinfo=ZoneInfo("America/New_York")
).astimezone(timezone.utc)
assert when == expected
def test_past_at_expression_is_before_now_without_end_date():
detail = {
"ScheduleExpression": "at(2020-01-01T08:00:00)",
"ScheduleExpressionTimezone": "America/New_York",
}
when = mod.schedule_when(detail)
assert when is not None
assert when < datetime.now(timezone.utc)
assert "EndDate" not in detail
assert "StartDate" not in detail
def test_future_at_expression_is_kept():
detail = {
"ScheduleExpression": "at(2099-12-25T17:00:00)",
"ScheduleExpressionTimezone": "America/New_York",
}
when = mod.schedule_when(detail)
assert when is not None
assert when > datetime.now(timezone.utc)