Skip to content

Commit d91c412

Browse files
committed
test code for multiget
1 parent 69997c9 commit d91c412

3 files changed

Lines changed: 37 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Python 3.7 is no longer tested - but it should work. Please file a bug report i
4646
* By now `calendar.search(..., sort_keys=("DTSTART")` will work. Sort keys expects a list or a tuple, but it's easy to send an attribute by mistake. https://github.com/python-caldav/caldav/issues/448 https://github.com/python-caldav/caldav/pull/449
4747
* Compatibility workaround: If `event.load()` fails, it will retry the load by doing a multiget - https://github.com/python-caldav/caldav/pull/475 - https://github.com/python-caldav/caldav/issues/459
4848
* The `class_`-parameter now works when sending data to `save_event()` etc.
49+
* Search method now takes parameter `journal=True`. ref https://github.com/python-caldav/caldav/issues/237 and https://github.com/python-caldav/caldav/pull/486
4950

5051
### Fixed
5152

caldav/collection.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,10 @@ def search(
868868
raise
869869

870870
obj2 = []
871+
871872
for o in objects:
872873
## This would not be needed if the servers would follow the standard ...
874+
## TODO: use self.calendar_multiget - see https://github.com/python-caldav/caldav/issues/487
873875
try:
874876
o.load(only_if_unloaded=True)
875877
obj2.append(o)
@@ -1050,12 +1052,15 @@ def build_search_xml_query(
10501052

10511053
## Deal with event, todo, journal or comp_class
10521054
for flagged, comp_name, comp_class_ in (
1053-
(event, 'VEVENT', Event),
1054-
(todo, 'VTODO', Todo),
1055-
(journal, 'VJOURNAL', Journal)):
1055+
(event, "VEVENT", Event),
1056+
(todo, "VTODO", Todo),
1057+
(journal, "VJOURNAL", Journal),
1058+
):
10561059
if flagged is not None:
10571060
if not flagged:
1058-
raise NotImplementedError(f"Negated search for {comp_name} not supported yet")
1061+
raise NotImplementedError(
1062+
f"Negated search for {comp_name} not supported yet"
1063+
)
10591064
if flagged:
10601065
## event/journal/todo is set, we adjust comp_class accordingly
10611066
if comp_class is not None and comp_class is not comp_class:

tests/test_caldav.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,31 @@ def testChangeAttendeeStatusWithEmailGiven(self):
937937
event = c.event_by_uid("test1")
938938
## TODO: work in progress ... see https://github.com/python-caldav/caldav/issues/399
939939

940+
def testMultiGet(self):
941+
self.skip_on_compatibility_flag("read_only")
942+
c = self._fixCalendar()
943+
944+
event1 = c.save_event(
945+
uid="test1",
946+
dtstart=datetime(2015, 10, 10, 8, 7, 6),
947+
dtend=datetime(2015, 10, 10, 9, 7, 6),
948+
summary="test1",
949+
)
950+
951+
event2 = c.save_event(
952+
uid="test2",
953+
dtstart=datetime(2015, 10, 10, 8, 7, 6),
954+
dtend=datetime(2015, 10, 10, 9, 7, 6),
955+
summary="test2",
956+
)
957+
958+
results = c.calendar_multiget([event1.url, event2.url])
959+
assert len(results) == 2
960+
assert set([x.icalendar_component["uid"] for x in results]) == {
961+
"test1",
962+
"test2",
963+
}
964+
940965
def testCreateEvent(self):
941966
self.skip_on_compatibility_flag("read_only")
942967
c = self._fixCalendar()
@@ -1278,12 +1303,10 @@ def testLoadEvent(self):
12781303
c2 = self._fixCalendar(name="Yapp", cal_id=self.testcal_id2)
12791304

12801305
e1_ = c1.save_event(ev1)
1281-
if not self.check_compatibility_flag("event_by_url_is_broken"):
1282-
e1_.load()
1306+
e1_.load()
12831307
e1 = c1.events()[0]
12841308
assert e1.url == e1_.url
1285-
if not self.check_compatibility_flag("event_by_url_is_broken"):
1286-
e1.load()
1309+
e1.load()
12871310
if (
12881311
not self.check_compatibility_flag("unique_calendar_ids")
12891312
and self.cleanup_regime == "post"

0 commit comments

Comments
 (0)