OffGridSchedula / tests /test_cal_env.py
ParetoOptimal's picture
Initial Commit
0366d65
Raw
History Blame Contribute Delete
1.31 kB
"""CAL_ICS_PATH: a locally hosted install can auto-complete the conflict-check
step — _load_busy falls back to the env-pointed .ics when nothing is uploaded."""
from calendar_out.ics import events_to_ics
from server.schema import Event
from ui import blocks
def _sample_ics_bytes() -> bytes:
return events_to_ics([
Event(title="Dentist", start="2026-06-18T09:00:00", end="2026-06-18T10:00:00"),
])
def test_load_busy_env_fallback(tmp_path, monkeypatch):
ics = tmp_path / "cal.ics"
ics.write_bytes(_sample_ics_bytes())
monkeypatch.setenv("CAL_ICS_PATH", str(ics))
busy = blocks._load_busy(None)
assert len(busy) == 1
assert busy[0].title == "Dentist"
def test_load_busy_upload_overrides_env(tmp_path, monkeypatch):
env_ics = tmp_path / "env.ics"
env_ics.write_bytes(_sample_ics_bytes())
upload = tmp_path / "upload.ics"
upload.write_bytes(events_to_ics([
Event(title="Soccer", start="2026-06-19T17:00:00", end="2026-06-19T18:00:00"),
]))
monkeypatch.setenv("CAL_ICS_PATH", str(env_ics))
busy = blocks._load_busy(str(upload))
assert [b.title for b in busy] == ["Soccer"]
def test_load_busy_unset_env_is_empty(monkeypatch):
monkeypatch.delenv("CAL_ICS_PATH", raising=False)
assert blocks._load_busy(None) == []