From afd95f0ac58d80c88ea001586b3dd4576e356e1a Mon Sep 17 00:00:00 2001 From: Tobias Brox Date: Sat, 13 Nov 2021 12:49:44 +0000 Subject: Commented on the discoveries made in https://github.com/python-caldav/caldav/issues/153 in the examples file --- caldav/objects.py | 2 +- examples/basic_usage_examples.py | 9 ++++++++- tests/test_caldav.py | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/caldav/objects.py b/caldav/objects.py index ff4f7ea..1730dca 100644 --- a/caldav/objects.py +++ b/caldav/objects.py @@ -435,7 +435,7 @@ class Principal(DAVObject): def calendar_home_set(self): if not self._calendar_home_set: calendar_home_set_url = self.get_property(cdav.CalendarHomeSet()) - ## owncloud returns remote.php/dav/calendars/tobixen@e.email/ + ## owncloud returns /remote.php/dav/calendars/tobixen@e.email/ ## in that case the @ should be quoted. Perhaps other ## implentations returns already quoted URLs. Hacky workaround: if '@' in calendar_home_set_url and not '://' in calendar_home_set_url: diff --git a/examples/basic_usage_examples.py b/examples/basic_usage_examples.py index 24d7343..baae0cf 100644 --- a/examples/basic_usage_examples.py +++ b/examples/basic_usage_examples.py @@ -86,6 +86,13 @@ event = events_fetched[0] event.vobject_instance.vevent.summary.value = 'Norwegian national day celebrations' event.save() +## Please note that the proper way to save new icalendar data +## to the calendar is calendar.save_event(ics_data), +## while the proper way to update a calendar event is +## event.save(). Doing calendar.save_event(event.data) +## may break. See https://github.com/python-caldav/caldav/issues/153 +## for details. + ## It's possible to access objects such as calendars without going ## through a Principal object if one knows the calendar URL the_same_calendar = client.calendar(url=my_new_calendar.url) @@ -99,7 +106,7 @@ all_objects = the_same_calendar.objects() ## since we have only added events (and neither todos nor journals), those ## should be equal ... except, all_objects is an iterator and not a list. -assert(len(all_events) == len(list(all_objects)) +assert(len(all_events) == len(list(all_objects))) ## Let's check that the summary got right assert all_events[0].vobject_instance.vevent.summary.value.startswith('Norwegian') diff --git a/tests/test_caldav.py b/tests/test_caldav.py index f251b02..30668d9 100644 --- a/tests/test_caldav.py +++ b/tests/test_caldav.py @@ -1043,6 +1043,31 @@ class RepeatedFunctionalTestsBaseClass(object): events = c.events() assert_equal(len(events), 0) + def testTodo153(self): + """ + References issue https://github.com/python-caldav/caldav/issues/153 + If I've understood it correct, an issue is created (through another client) + where the uid and the url does not match. It is then a problem to edit it? + """ + # TODO: should try to add tasks to the default calendar if mkcalendar + # does not work + self.skip_on_compatibility_flag('no_mkcalendar') + # Not all server implementations have support for VTODO + self.skip_on_compatibility_flag('no_todo') + + c = self.principal.make_calendar( + name="Yep", cal_id=self.testcal_id, + supported_calendar_component_set=['VTODO']) + + todo1 = Todo(data=todo, parent=c, url=c.url.join('sometodo.ics')) + todo2 = todo.save() + assert_equal(todo1.id, todo2.id) + assert_equal(todo1.url, todo2.url) + todo3 = c.todo_by_uid(todo1.id) + assert_equal(todo2.id, todo3.id) + todo4 = Todo(url=c.url.join('sometodo.ics')).load() + + def testTodos(self): """ This test will excercise the cal.todos() method, -- cgit v1.2.3