From 087620336d1c9523e31d41142197bfaaa2854bc1 Mon Sep 17 00:00:00 2001 From: Tobias Brox Date: Sat, 19 Oct 2024 06:46:16 +0200 Subject: [PATCH] Make tests ignore broken server-side expand for radicale - updates https://github.com/python-caldav/caldav/issues/439 --- caldav/objects.py | 14 +++++++++----- tests/compatibility_issues.py | 14 +++++--------- tests/test_caldav.py | 18 ++++++++---------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/caldav/objects.py b/caldav/objects.py index 0e78b0b..64f93f6 100644 --- a/caldav/objects.py +++ b/caldav/objects.py @@ -1228,14 +1228,13 @@ def search( objects = [o for o in objects if o.has_component()] if kwargs.get("expand", False): - ## expand can only be used together with start and end. - ## Error checking is done in build_search_xml_query. If - ## search is fed with an XML query together with expand, - ## then it's considered a "search option", and an error is - ## raised above. + ## expand can only be used together with start and end (and not + ## with xml). Error checking has already been done in + ## build_search_xml_query above. start = kwargs["start"] end = kwargs["end"] + ## Verify that any recurring objects returned are already expanded for o in objects: component = o.icalendar_component if component is None: @@ -1243,6 +1242,11 @@ def search( recurrence_properties = ["exdate", "exrule", "rdate", "rrule"] if any(key in component for key in recurrence_properties): o.expand_rrule(start, end) + + ## An expanded recurring object comes as one Event() with + ## icalendar data containing multiple objects. The caller may + ## expect multiple Event()s. This code splits events into + ## separate objects: if split_expanded: objects_ = objects objects = [] diff --git a/tests/compatibility_issues.py b/tests/compatibility_issues.py index dce6986..01f9172 100644 --- a/tests/compatibility_issues.py +++ b/tests/compatibility_issues.py @@ -12,17 +12,14 @@ ## * Perhaps some more readable format should be considered (yaml?). ## * Consider how to get this into the documentation incompatibility_description = { - 'no_expand': - """Server may throw errors when asked to do an expanded date search (this is ignored by the tests now, as we're doing client-side expansion)""", + 'broken_expand': + """Server-side expand seems to work, but delivers wrong data""", 'no_recurring': """Server is having issues with recurring events and/or todos. """ """date searches covering recurrances may yield no results, """ """and events/todos may not be expanded with recurrances""", - 'no_recurring_expandation': - """Server will not expand recurring events (this is ignored by the tests now, as we're doing client-side expansion)""", - 'no_recurring_todo': """Recurring events are supported, but not recurring todos""", @@ -203,7 +200,7 @@ xandikos = [ ## https://github.com/jelmer/xandikos/issues/8 - "no_expand", "no_recurring", + "no_recurring", 'text_search_is_exact_match_only', @@ -217,6 +214,7 @@ radicale = [ ## calendar listings and calendar creation works a bit ## "weird" on radicale + "broken_expand", "no_default_calendar", "non_existing_calendar_found", @@ -227,6 +225,7 @@ "radicale_breaks_on_category_search", 'no_scheduling', + 'no_todo_datesearch', 'text_search_is_case_insensitive', 'text_search_is_exact_match_sometimes', @@ -290,7 +289,6 @@ ## (TODO: do some research on this) 'sync_breaks_on_delete', 'no_recurring_todo', - 'no_recurring_todo_expand', 'non_existing_calendar_found', 'combined_search_not_working', 'text_search_is_exact_match_sometimes', @@ -324,7 +322,6 @@ 'no_mkcalendar', 'no_overwrite', 'no_todo', - 'no_recurring_expandation' ] ## https://www.sogo.nu/bugs/view.php?id=3065 @@ -345,7 +342,6 @@ nextcloud = [ 'sync_breaks_on_delete', 'no_recurring_todo', - 'no_recurring_todo_expand', 'combined_search_not_working', 'text_search_is_exact_match_sometimes', ] diff --git a/tests/test_caldav.py b/tests/test_caldav.py index 24cc0c0..9d663b6 100644 --- a/tests/test_caldav.py +++ b/tests/test_caldav.py @@ -1848,18 +1848,17 @@ def testTodoDatesearch(self): # t5 has dtstart and due set prior to the search window # t6 has dtstart and due set prior to the search window, but is yearly recurring. # What will a date search yield? - noexpand = self.check_compatibility_flag("no_expand") todos1 = c.date_search( start=datetime(1997, 4, 14), end=datetime(2015, 5, 14), compfilter="VTODO", - expand=not noexpand, + expand=True, ) todos2 = c.search( start=datetime(1997, 4, 14), end=datetime(2015, 5, 14), todo=True, - expand=not noexpand, + expand=True, split_expanded=False, include_completed=True, ) @@ -1893,11 +1892,9 @@ def testTodoDatesearch(self): assert len(todos2) == foo ## verify that "expand" works - if ( - not self.check_compatibility_flag("no_expand") - and not self.check_compatibility_flag("no_recurring") - and not self.check_compatibility_flag("no_recurring_todo") - ): + if not self.check_compatibility_flag( + "broken_expand" + ) and not self.check_compatibility_flag("no_recurring"): assert len([x for x in todos1 if "DTSTART:20020415T1330" in x.data]) == 1 assert len([x for x in todos2 if "DTSTART:20020415T1330" in x.data]) == 1 @@ -2444,8 +2441,9 @@ def testRecurringDateSearch(self): assert r1[0].data.count("END:VEVENT") == 1 assert r2[0].data.count("END:VEVENT") == 1 ## due to expandation, the DTSTART should be in 2008 - assert r1[0].data.count("DTSTART;VALUE=DATE:2008") == 1 - assert r2[0].data.count("DTSTART;VALUE=DATE:2008") == 1 + if not self.check_compatibility_flag("broken_expand"): + assert r1[0].data.count("DTSTART;VALUE=DATE:2008") == 1 + assert r2[0].data.count("DTSTART;VALUE=DATE:2008") == 1 ## With expand=True and searching over two recurrences ... r1 = c.date_search(