51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""iCalendar-Ausgabe der bestätigten Termine (ohne Datenbank)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime
|
|
from types import SimpleNamespace
|
|
from zoneinfo import ZoneInfo
|
|
|
|
from surveybox.forms import calendar
|
|
|
|
|
|
def poll(confirmed: list[str]) -> SimpleNamespace:
|
|
return SimpleNamespace(
|
|
id=7,
|
|
type="poll",
|
|
config={
|
|
"mode": "dates",
|
|
"confirmed": confirmed,
|
|
"options": [
|
|
{"id": "aaaa0001", "label": "", "date": "2026-07-01", "time": "18:30",
|
|
"duration": 90},
|
|
{"id": "aaaa0002", "label": "Ausweichtermin; mit Grill, bitte",
|
|
"date": "2026-07-08", "time": None, "duration": None},
|
|
{"id": "aaaa0003", "label": "", "date": "2026-07-15", "time": None,
|
|
"duration": None},
|
|
],
|
|
},
|
|
)
|
|
|
|
|
|
def test_only_confirmed_dates_with_utc_and_all_day() -> None:
|
|
events = calendar.confirmed_events([poll(["aaaa0001", "aaaa0002"])])
|
|
text = calendar.build(
|
|
title="Sommerfest", url="https://x/f/t", host="x", events=events,
|
|
tz=ZoneInfo("Europe/Berlin"), now=datetime(2026, 6, 1, tzinfo=UTC),
|
|
)
|
|
assert text.count("BEGIN:VEVENT") == 2
|
|
assert "DTSTART:20260701T163000Z" in text and "DTEND:20260701T180000Z" in text
|
|
assert "DTSTART;VALUE=DATE:20260708" in text and "DTEND;VALUE=DATE:20260709" in text
|
|
assert "SUMMARY:Sommerfest: Ausweichtermin\\; mit Grill\\, bitte" in text
|
|
assert "20260715" not in text
|
|
assert all(len(line.encode()) <= 75 for line in text.split("\r\n"))
|
|
|
|
|
|
def test_folding_keeps_utf8() -> None:
|
|
long = "Ä" * 60
|
|
folded = calendar._fold(f"SUMMARY:{long}")
|
|
assert "\r\n " in folded
|
|
assert folded.replace("\r\n ", "") == f"SUMMARY:{long}"
|