Skip to content

Commit

Permalink
fixup! make tests work for servers where it's not possible to delete …
Browse files Browse the repository at this point in the history
…calendars
  • Loading branch information
tobixen committed Nov 1, 2024
1 parent a7f50ad commit 4f9b95e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
10 changes: 5 additions & 5 deletions caldav/lib/vcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ def create_ical(ical_fragment=None, objtype=None, language="en_DK", **props):
ical_fragment = None

## Populate with mandatory fields, if missing
if not my_instance.get('prodid'):
if not my_instance.get("prodid"):
my_instance.add("prodid", "-//python-caldav//caldav//" + language)
if not my_instance.get('version'):
if not my_instance.get("version"):
my_instance.add("version", "2.0")
if not component.get('dtstamp') and not props.get('dtstamp'):
if not component.get("dtstamp") and not props.get("dtstamp"):
component.add("dtstamp", datetime.datetime.now(tz=datetime.timezone.utc))
if not component.get('uid') and not props.get("uid"):
if not component.get("uid") and not props.get("uid"):
component.add("uid", uuid.uuid1())

for prop in props:
if props[prop] is not None:
if isinstance(props[prop], datetime.datetime) and not props[prop].tzinfo:
Expand Down
27 changes: 17 additions & 10 deletions tests/test_caldav.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,15 @@ def setup_method(self):

self.caldav = client(**self.server_params)

if self.check_compatibility_flag('rate_limited'):
if self.check_compatibility_flag("rate_limited"):

def delay_decorator(f):
def foo(*a, **kwa):
time.sleep(5)
return f(*a, **kwa)

return foo

self.caldav.request = delay_decorator(self.caldav.request)

if False and self.check_compatibility_flag("no-current-user-principal"):
Expand Down Expand Up @@ -679,7 +682,9 @@ def _cleanup(self, mode=None):
def _teardownCalendar(self, name=None, cal_id=None):
try:
cal = self.principal.calendar(name=name, cal_id=cal_id)
if self.check_compatibility_flag("sticky_events") or self.check_compatibility_flag('no_delete_calendar'):
if self.check_compatibility_flag(
"sticky_events"
) or self.check_compatibility_flag("no_delete_calendar"):
try:
for goo in cal.objects():
goo.delete()
Expand Down Expand Up @@ -714,23 +719,23 @@ def _fixCalendar(self, **kwargs):
self._default_calendar = calendars[0]
return self._default_calendar
else:
if not 'name' in kwargs:
if not "name" in kwargs:
if not self.check_compatibility_flag(
"unique_calendar_ids"
) and self.cleanup_regime in ("light", "pre"):
self._teardownCalendar(cal_id=self.testcal_id)
if self.check_compatibility_flag("no_displayname"):
kwargs['name'] = None
kwargs["name"] = None
else:
kwargs['name'] = "Yep"
if not 'cal_id' in kwargs:
kwargs['cal_id'] = self.testcal_id
kwargs["name"] = "Yep"
if not "cal_id" in kwargs:
kwargs["cal_id"] = self.testcal_id
try:
ret = self.principal.make_calendar(**kwargs)
except error.MkcalendarError:
## "calendar already exists" can be ignored (at least
## if no_delete_calendar flag is set)
ret = self.principal.calendar(cal_id = kwargs['cal_id'])
ret = self.principal.calendar(cal_id=kwargs["cal_id"])
if self.check_compatibility_flag("search_always_needs_comptype"):
ret.objects = lambda load_objects: ret.events()
if self.cleanup_regime == "post":
Expand Down Expand Up @@ -960,7 +965,7 @@ def testCreateEvent(self):
# We should be able to access the calender through the name
c2 = self.principal.calendar(name="Yep")
## may break if we have multiple calendars with the same name
if not self.check_compatibility_flag('no_delete_calendar'):
if not self.check_compatibility_flag("no_delete_calendar"):
assert c2.url == c.url
events2 = c2.events()
assert len(events2) == 1
Expand Down Expand Up @@ -2274,7 +2279,9 @@ def testSetCalendarProperties(self):
try:
cc.delete()
except error.DeleteError:
if not self.check_compatibility_flag('no_delete_calendar') or self.check_compatibility_flag('unique_calendar_ids'):
if not self.check_compatibility_flag(
"no_delete_calendar"
) or self.check_compatibility_flag("unique_calendar_ids"):
raise

c.set_properties(
Expand Down

0 comments on commit 4f9b95e

Please sign in to comment.