Skip to content

Commit

Permalink
refactoring a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
tobixen committed Nov 18, 2024
1 parent 7a7c071 commit 4d73ec6
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 138 deletions.
4 changes: 2 additions & 2 deletions caldav/lib/vcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ def create_ical(ical_fragment=None, objtype=None, language="en_DK", **props):
I somehow feel this fits more into the icalendar library than here
"""
ical_fragment = to_normal_str(ical_fragment)
if 'class_' in props:
props['class'] = props.pop('class_')
if "class_" in props:
props["class"] = props.pop("class_")
if not ical_fragment or not re.search("^BEGIN:V", ical_fragment, re.MULTILINE):
my_instance = icalendar.Calendar()
if objtype is None:
Expand Down
283 changes: 147 additions & 136 deletions check_server_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,104 +243,9 @@ def check_event(self):
categories=["zoo", "test"],
uid="check_event_2",
)
try: ## try-finally-block covering testing of obj1 and obj2
try:
foo = cal.event_by_uid("check_event_2")
assert foo
self.set_flag("object_by_uid_is_broken", False)
except:
time.sleep(60)
try:
foo = cal.event_by_uid("check_event_2")
assert foo
self.set_flag("search_delay")
self.set_flag("object_by_uid_is_broken", False)
except:
self.set_flag("object_by_uid_is_broken", True)

try:
objcnt = len(cal.objects())
except:
objcnt = 0
if objcnt != 2:
if len(cal.events()) == 2:
self.set_flag("search_always_needs_comptype", True)
else:
import pdb

pdb.set_trace()
pass
## we should not be here
else:
self.set_flag("search_always_needs_comptype", False)

## purelymail writes things to an index as a background thread
## and have delayed search. Let's test for that first.
events = cal.search(summary="Test event 1", event=True)
if len(events) == 0:
events = cal.search(summary="Test event 1", event=True)
if len(events) == 1:
self.set_flag("rate_limited", True)
if len(events) == 1:
self.set_flag("no_search", False)
self.set_flag("text_search_not_working", False)
else:
self.set_flag("text_search_not_working", True)

objs = cal.search(summary="Test event 1")
if len(objs) == 0 and len(events) == 1:
self.set_flag("search_needs_comptype", True)
elif len(objs) == 1:
self.set_flag("search_always_needs_comptype", False)

if not self.flags_checked["text_search_not_working"]:
events = cal.search(summary="test event 1", event=True)
if len(events) == 1:
self.set_flag("text_search_is_case_insensitive", True)
elif len(events) == 0:
self.set_flag("text_search_is_case_insensitive", False)
else:
## we should not be here
import pdb

pdb.set_trace()
pass
events = cal.search(summary="test event", event=True)
if len(events) == 2:
self.set_flag("text_search_is_exact_match_only", False)
elif len(events) == 0:
self.set_flag("text_search_is_exact_match_only", "maybe")
## may also be text_search_is_exact_match_sometimes
events = cal.search(
summary="Test event 1", class_="CONFIDENTIAL", event=True
)
if len(events) == 1:
self.set_flag("combined_search_not_working", False)
elif len(events) == 0:
import pdb; pdb.set_trace()
self.set_flag("combined_search_not_working", True)
else:
import pdb

pdb.set_trace()
## We should not be here
pass
try:
events = cal.search(category="foo", event=True)
except:
events = []
if len(events) == 1:
self.set_flag("category_search_yields_nothing", False)
elif len(events) == 0:
self.set_flag("category_search_yields_nothing", True)
else:
## we should not be here
import pdb

pdb.set_trace()
pass

events = cal.search(summary="test event", class_="CONFIDENTIAL", event=True)
try: ## try-finally-block covering testing of obj1 and obj2
self._check_simple_events(obj1, obj2)
finally:
obj1.delete()
obj2.delete()
Expand All @@ -366,46 +271,150 @@ def check_event(self):
pdb.set_trace()
raise
try:
try:
events = cal.search(
start=datetime.datetime(2001, 4, 1),
end=datetime.datetime(2002, 2, 2),
event=True,
)
assert len(events) == 2
self.set_flag("no_recurring", False)
except:
self.set_flag("no_recurring", True)

if not (self.flags_checked["no_recurring"]):
events = cal.search(
start=datetime.datetime(2001, 4, 1),
end=datetime.datetime(2002, 2, 2),
event=True,
expand="server",
)
assert len(events) == 2
if "RRULE" in events[0].data:
assert "RRULE" in events[1].data
assert not "RECURRENCE-ID" in events[0].data
assert not "RECURRENCE-ID" in events[1].data
self.set_flag("no_expand", True)
else:
assert not "RRULE" in events[1].data
self.set_flag("no_expand", False)
if (
"RECURRENCE-ID" in events[0].data
and "DTSTART:2001" in events[0].data
):
assert "RECURRENCE-ID" in events[1].data
self.set_flag("broken_expand", False)
else:
self.set_flag("broken_expand", True)

self._check_recurring_events(yearly_time, yearly_day)
finally:
yearly_time.delete()
yearly_day.delete()

def _check_simple_events(self, obj1, obj2):
cal = self._default_calendar
try:
foo = cal.event_by_uid("check_event_2")
assert foo
self.set_flag("object_by_uid_is_broken", False)
except:
time.sleep(60)
try:
foo = cal.event_by_uid("check_event_2")
assert foo
self.set_flag("search_delay")
self.set_flag("object_by_uid_is_broken", False)
except:
self.set_flag("object_by_uid_is_broken", True)

try:
objcnt = len(cal.objects())
except:
objcnt = 0
if objcnt != 2:
if len(cal.events()) == 2:
self.set_flag("search_always_needs_comptype", True)
else:
import pdb

pdb.set_trace()
pass
## we should not be here
else:
self.set_flag("search_always_needs_comptype", False)

## purelymail writes things to an index as a background thread
## and have delayed search. Let's test for that first.
events = cal.search(summary="Test event 1", event=True)
if len(events) == 0:
events = cal.search(summary="Test event 1", event=True)
if len(events) == 1:
self.set_flag("rate_limited", True)
if len(events) == 1:
self.set_flag("no_search", False)
self.set_flag("text_search_not_working", False)
else:
self.set_flag("text_search_not_working", True)

objs = cal.search(summary="Test event 1")
if len(objs) == 0 and len(events) == 1:
self.set_flag("search_needs_comptype", True)
elif len(objs) == 1:
self.set_flag("search_always_needs_comptype", False)

if not self.flags_checked["text_search_not_working"]:
events = cal.search(summary="test event 1", event=True)
if len(events) == 1:
self.set_flag("text_search_is_case_insensitive", True)
elif len(events) == 0:
self.set_flag("text_search_is_case_insensitive", False)
else:
## we should not be here
import pdb

pdb.set_trace()
pass
events = cal.search(summary="test event", event=True)
if len(events) == 2:
self.set_flag("text_search_is_exact_match_only", False)
elif len(events) == 0:
self.set_flag("text_search_is_exact_match_only", "maybe")
## may also be text_search_is_exact_match_sometimes
events = cal.search(
summary="Test event 1", class_="CONFIDENTIAL", event=True
)
if len(events) == 1:
self.set_flag("combined_search_not_working", False)
elif len(events) == 0:
import pdb

pdb.set_trace()
self.set_flag("combined_search_not_working", True)
else:
import pdb

pdb.set_trace()
## We should not be here
pass
try:
events = cal.search(category="foo", event=True)
except:
events = []
if len(events) == 1:
self.set_flag("category_search_yields_nothing", False)
elif len(events) == 0:
self.set_flag("category_search_yields_nothing", True)
else:
## we should not be here
import pdb

pdb.set_trace()
pass

events = cal.search(summary="test event", class_="CONFIDENTIAL", event=True)

def _check_recurring_events(self, yearly_time, yearly_day):
cal = self._default_calendar
try:
events = cal.search(
start=datetime.datetime(2001, 4, 1),
end=datetime.datetime(2002, 2, 2),
event=True,
)
assert len(events) == 2
self.set_flag("no_recurring", False)
except:
self.set_flag("no_recurring", True)

if self.flags_checked["no_recurring"]:
return

events = cal.search(
start=datetime.datetime(2001, 4, 1),
end=datetime.datetime(2002, 2, 2),
event=True,
expand="server",
)
assert len(events) == 2
if "RRULE" in events[0].data:
assert "RRULE" in events[1].data
assert not "RECURRENCE-ID" in events[0].data
assert not "RECURRENCE-ID" in events[1].data
self.set_flag("no_expand", True)
else:
assert not "RRULE" in events[1].data
self.set_flag("no_expand", False)
if "RECURRENCE-ID" in events[0].data and "DTSTART:2001" in events[0].data:
assert "RECURRENCE-ID" in events[1].data
self.set_flag("broken_expand", False)
else:
self.set_flag("broken_expand", True)

def check_todo(self):
cal = self._default_calendar

Expand All @@ -415,10 +424,12 @@ def check_todo(self):
summary="This is a summary",
uid="check_todo_1",
)
self.set_flag('no_todo', False)
self.set_flag("no_todo", False)
except:
import pdb; pdb.set_trace()
self.set_flag('no_todo')
import pdb

pdb.set_trace()
self.set_flag("no_todo")
return

def check_all(self):
Expand Down

0 comments on commit 4d73ec6

Please sign in to comment.