From c1338b20e94dff2c4e92ab2903a58506f8065b74 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 17 Apr 2024 11:42:05 +0100 Subject: [PATCH] Add offset note to description --- calmerge/calendars.py | 5 +++++ tests/test_calendar_view.py | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/calmerge/calendars.py b/calmerge/calendars.py index b66ab5d..82f4892 100644 --- a/calmerge/calendars.py +++ b/calmerge/calendars.py @@ -67,6 +67,11 @@ def create_offset_calendar_events( f" ({abs(days)} days {'after' if days > 0 else 'before'})" ) + if "DESCRIPTION" in day_component: + day_component["DESCRIPTION"] += ( + f"\n\nNote: This event has been offset {days} days." + ) + new_components.append(day_component) for component in new_components: diff --git a/tests/test_calendar_view.py b/tests/test_calendar_view.py index 5b1d8b9..7d6d2e5 100644 --- a/tests/test_calendar_view.py +++ b/tests/test_calendar_view.py @@ -55,11 +55,21 @@ async def test_offset_calendar_matches(client: TestClient) -> None: len(offset_calendar.walk("VEVENT")) == len(original_calendar.walk("VEVENT")) * 2 ) + offset_events = [ + event + for event in offset_calendar.walk("VEVENT") + if event["SUMMARY"].endswith("(365 days after)") + ] + + assert len(offset_events) == len(original_calendar.walk("VEVENT")) + original_events_by_summary = { event["SUMMARY"]: event for event in original_calendar.walk("VEVENT") } - for offset_event in offset_calendar.walk("VEVENT"): + for offset_event in offset_events: + assert offset_event["SUMMARY"].endswith(" (365 days after)") + original_event = original_events_by_summary[ offset_event["SUMMARY"].removesuffix(" (365 days after)") ] @@ -76,4 +86,7 @@ async def test_offset_calendar_matches(client: TestClient) -> None: original_event["dtstamp"].dt + timedelta(days=365) ) - assert offset_event["description"] == original_event["description"] + assert offset_event["description"].startswith(original_event["description"]) + assert offset_event["description"].endswith( + "Note: This event has been offset 365 days." + )