Skip to content

Commit

Permalink
search for alarms, with test code
Browse files Browse the repository at this point in the history
  • Loading branch information
tobixen committed Nov 30, 2022
1 parent b174c34 commit 9f2e6e0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
7 changes: 7 additions & 0 deletions caldav/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down
26 changes: 24 additions & 2 deletions tests/test_caldav.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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):
"""
Expand Down

0 comments on commit 9f2e6e0

Please sign in to comment.