From f5d7cb7676f2f0a835a12d47887133d506d824f8 Mon Sep 17 00:00:00 2001 From: Tobias Brox Date: Mon, 24 Oct 2022 15:41:28 +0200 Subject: [PATCH] search for alarms, with test code --- caldav/objects.py | 7 +++++++ tests/test_caldav.py | 26 ++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/caldav/objects.py b/caldav/objects.py index 0d1338a7..bb626b1e 100644 --- a/caldav/objects.py +++ b/caldav/objects.py @@ -1107,6 +1107,8 @@ def build_search_xml_query( expand=None, start=None, end=None, + alarm_start=None, + alarm_end=None, **kwargs ): """This method will produce a caldav search query as an etree object. @@ -1165,6 +1167,11 @@ def build_search_xml_query( if start or end: filters.append(cdav.TimeRange(start, end)) + if alarm_start or alarm_end: + filters.append( + cdav.CompFilter("VALARM") + cdav.TimeRange(alarm_start, alarm_end) + ) + if todo is not None: if not todo: raise NotImplementedError() diff --git a/tests/test_caldav.py b/tests/test_caldav.py index b46ec05c..386eddcf 100644 --- a/tests/test_caldav.py +++ b/tests/test_caldav.py @@ -767,7 +767,8 @@ def testCreateEvent(self): events = c.events() assert len(events) == len(existing_events) + 2 - def testCreateAlarm(self): + def testAlarm(self): + ## Ref https://github.com/python-caldav/caldav/issues/132 c = self._fixCalendar() ev = c.save_event( dtstart=datetime(2015, 10, 10, 8, 7, 6), @@ -776,7 +777,28 @@ def testCreateAlarm(self): alarm_trigger=timedelta(minutes=-15), alarm_action="AUDIO", ) - pass + + ## Search for the alarm (procrastinated - see https://github.com/python-caldav/caldav/issues/132) + assert ( + len( + c.search( + event=True, + alarm_start=datetime(2015, 10, 10, 8, 1), + alarm_end=datetime(2015, 10, 10, 8, 7), + ) + ) + == 0 + ) + assert ( + len( + c.search( + event=True, + alarm_start=datetime(2015, 10, 10, 7, 44), + alarm_end=datetime(2015, 10, 10, 8, 7), + ) + ) + == 1 + ) def testCalendarByFullURL(self): """