11#!/usr/bin/env python
2+ import os
23import time
34import uuid
4- import os
55from datetime import date
66from datetime import datetime
77from datetime import timedelta
1010import click
1111
1212import caldav
13- from caldav .elements import dav , ical
13+ from caldav .elements import dav
14+ from caldav .elements import ical
1415from caldav .lib .error import AuthorizationError
1516from caldav .lib .error import DAVError
1617from caldav .lib .error import NotFoundError
2021from tests .conf import client
2122from tests .conf import CONNKEYS
2223
23- ical_with_exception1 = """BEGIN:VCALENDAR
24+ ical_with_exception1 = """BEGIN:VCALENDAR
2425VERSION:2.0
2526PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN
2627BEGIN:VEVENT
4849END:VEVENT
4950END:VCALENDAR"""
5051
51- ical_with_exception2 = """BEGIN:VCALENDAR
52+ ical_with_exception2 = """BEGIN:VCALENDAR
5253VERSION:2.0
5354PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN
5455BEGIN:VEVENT
7879
7980
8081def _debugger ():
81- if os .environ .get (' PYTHON_CALDAV_DEBUGMODE' ) == "DEBUG_PDB" :
82+ if os .environ .get (" PYTHON_CALDAV_DEBUGMODE" ) == "DEBUG_PDB" :
8283 import pdb
84+
8385 pdb .set_trace ()
8486
8587
@@ -88,6 +90,7 @@ def _delay_decorator(f, delay=10):
8890 Sometimes we need to pause between each request, i.e. due to servers
8991 that queues up work, rate-limits requests, etc.
9092 """
93+
9194 def foo (* a , ** kwa ):
9295 time .sleep (delay )
9396 return f (* a , ** kwa )
@@ -97,7 +100,7 @@ def foo(*a, **kwa):
97100
98101class ServerQuirkChecker :
99102 """This class will ...
100-
103+
101104 * Keep the connection details to the server
102105 * Keep the state of what's already checked
103106
@@ -115,6 +118,7 @@ class ServerQuirkChecker:
115118 test, and being able to run multiple tests towards the same data
116119 set.
117120 """
121+
118122 def __init__ (self , client_obj ):
119123 self .client_obj = client_obj
120124 self .flags_checked = {}
@@ -308,14 +312,16 @@ def _fix_cal(self, todo=False):
308312 self ._default_calendar .delete ()
309313 except :
310314 pass
311- if self .flags_checked [' no_mkcalendar' ]:
315+ if self .flags_checked [" no_mkcalendar" ]:
312316 cal = self .principal .calendars ()[0 ]
313317 if cal .events () or cal .todos ():
314- import pdb ; pdb .set_trace ()
318+ import pdb
319+
320+ pdb .set_trace ()
315321 raise "Refusing to run tests on a calendar with content"
316322 self ._default_calendar = cal
317323 return cal
318- if todo and self .flags_checked .get (' no_todo_on_standard_calendar' ):
324+ if todo and self .flags_checked .get (" no_todo_on_standard_calendar" ):
319325 kwargs ["supported_calendar_component_set" ] = ["VTODO" ]
320326 if self .flags_checked ["unique_calendar_ids" ]:
321327 kwargs ["cal_id" ] = "testcalendar-" + str (uuid .uuid4 ())
@@ -375,15 +381,15 @@ def check_calendar_color_and_order(self):
375381 many calendar servers supports it
376382 """
377383 try :
378- self ._check_prop (ical .CalendarColor , ' goldenred' , ' blue' )
379- self .set_flag (' calendar_color' , True )
384+ self ._check_prop (ical .CalendarColor , " goldenred" , " blue" )
385+ self .set_flag (" calendar_color" , True )
380386 except Exception as e :
381- self .set_flag (' calendar_color' , False )
387+ self .set_flag (" calendar_color" , False )
382388 try :
383- self ._check_prop (ical .CalendarOrder , ' -143' , '8' )
384- self .set_flag (' calendar_order' , True )
389+ self ._check_prop (ical .CalendarOrder , " -143" , "8" )
390+ self .set_flag (" calendar_order" , True )
385391 except :
386- self .set_flag (' calendar_order' , False )
392+ self .set_flag (" calendar_order" , False )
387393
388394 def _check_prop (self , propclass , silly_value , test_value ):
389395 cal = self ._default_calendar
@@ -392,7 +398,7 @@ def _check_prop(self, propclass, silly_value, test_value):
392398 cal .set_properties (propclass (test_value ))
393399 props = cal .get_properties ([(propclass ())])
394400 assert props [propclass .tag ] == test_value
395-
401+
396402 def check_event (self ):
397403 cal = self ._default_calendar
398404
@@ -475,7 +481,7 @@ def check_event(self):
475481 assert len (ret ) == 0
476482
477483 def check_exception (self ):
478- if self .flags_checked .get (' broken_expand' ):
484+ if self .flags_checked .get (" broken_expand" ):
479485 return
480486 self ._check_exception (ical_with_exception1 )
481487 self ._check_exception (ical_with_exception2 )
@@ -514,9 +520,9 @@ def _check_freebusy(self):
514520 # TODO: assert something more complex on the return object
515521 assert isinstance (freebusy , FreeBusy )
516522 assert freebusy .instance .vfreebusy
517- self .set_flag (' no_freebusy_rfc4791' , False )
523+ self .set_flag (" no_freebusy_rfc4791" , False )
518524 except Exception as e :
519- self .set_flag (' no_freebusy_rfc4791' )
525+ self .set_flag (" no_freebusy_rfc4791" )
520526
521527 def _check_simple_events (self , obj1 , obj2 ):
522528 cal = self ._default_calendar
@@ -595,11 +601,14 @@ def _check_simple_events(self, obj1, obj2):
595601 )
596602 ## I don't expect this program to be in use by 2055.
597603 events2 = cal .search (
598- start = datetime (2000 ,1 ,1 ), end = datetime (2055 ,1 ,1 ), class_ = "CONFIDENTIAL" , event = True
604+ start = datetime (2000 , 1 , 1 ),
605+ end = datetime (2055 , 1 , 1 ),
606+ class_ = "CONFIDENTIAL" ,
607+ event = True ,
599608 )
600609 if len (events1 ) == 1 and len (events2 ) == 1 :
601610 self .set_flag ("combined_search_not_working" , False )
602- elif len (events1 + events2 ) in (0 ,1 , 3 ):
611+ elif len (events1 + events2 ) in (0 , 1 , 3 ):
603612 self .set_flag ("combined_search_not_working" , True )
604613 else :
605614 _debugger ()
@@ -681,24 +690,24 @@ def _do_date_search(self, assert_found=True, has_duration=True, **kwargs):
681690 during2 = datetime (2000 , 7 , 1 , 12 )
682691 after = datetime (2000 , 7 , 1 , 22 )
683692 longafter = datetime (2000 , 9 , 2 , 10 )
684- if self .flags_checked .get (' inaccurate_datesearch' ):
693+ if self .flags_checked .get (" inaccurate_datesearch" ):
685694 before = before - timedelta (days = 31 )
686695 after = after + timedelta (days = 31 )
687696 one_event_lists = [
688697 ## open-ended searches, should yield object
689- cal .search (end = after , ** kwargs ), ## 0
690- cal .search (start = before , ** kwargs ), ## 1
691- cal .search (start = before , end = after , ** kwargs ), ## 2
698+ cal .search (end = after , ** kwargs ), ## 0
699+ cal .search (start = before , ** kwargs ), ## 1
700+ cal .search (start = before , end = after , ** kwargs ), ## 2
692701 ]
693702 if has_duration :
694703 ## overlapping searches, everything should yield object
695704 one_event_lists .extend (
696705 [
697- cal .search (end = during1 , ** kwargs ), ## 3
698- cal .search (start = during1 , ** kwargs ), ## 4
699- cal .search (start = before , end = during1 , ** kwargs ), ## 5
700- cal .search (start = during1 , end = during2 , ** kwargs ), ## 6
701- cal .search (start = during1 , end = after , ** kwargs ), ## 7
706+ cal .search (end = during1 , ** kwargs ), ## 3
707+ cal .search (start = during1 , ** kwargs ), ## 4
708+ cal .search (start = before , end = during1 , ** kwargs ), ## 5
709+ cal .search (start = during1 , end = during2 , ** kwargs ), ## 6
710+ cal .search (start = during1 , end = after , ** kwargs ), ## 7
702711 ]
703712 )
704713 ret = []
@@ -711,9 +720,9 @@ def _do_date_search(self, assert_found=True, has_duration=True, **kwargs):
711720 if should_be_empty :
712721 assert len (should_be_empty ) == 1
713722 ical = should_be_empty [0 ].icalendar_component
714- assert ( ' due' in ical and not ' dtstart' in ical )
715- self .set_flag (' vtodo_no_dtstart_infinite_duration' )
716-
723+ assert " due" in ical and not " dtstart" in ical
724+ self .set_flag (" vtodo_no_dtstart_infinite_duration" )
725+
717726 if kwargs .get ("todo" ):
718727 if len (cal .search (end = before , ** kwargs )) == 0 :
719728 if (
@@ -735,12 +744,14 @@ def _do_date_search(self, assert_found=True, has_duration=True, **kwargs):
735744 before = before - timedelta (days = 31 )
736745 after = after + timedelta (days = 31 )
737746 else :
738- if not ' inaccurate_Datesearch' in self .flags_checked :
747+ if not " inaccurate_Datesearch" in self .flags_checked :
739748 self .set_flag ("inaccurate_datesearch" , False )
740749
741750 assert len (cal .search (start = after , end = longafter )) == 0
742751 if len (cal .search (start = after , ** kwargs )):
743- import pdb ; pdb .set_trace ()
752+ import pdb
753+
754+ pdb .set_trace ()
744755 assert len (cal .search (start = after , ** kwargs )) == 0
745756 return ret
746757
@@ -804,8 +815,8 @@ def check_todo(self):
804815 todo , assert_found = False , has_duration = False , todo = True
805816 )
806817
807- if not ' vtodo_no_dtstart_infinite_duration' in self .flags_checked :
808- self .set_flag (' vtodo_no_dtstart_infinite_duration' , False )
818+ if not " vtodo_no_dtstart_infinite_duration" in self .flags_checked :
819+ self .set_flag (" vtodo_no_dtstart_infinite_duration" , False )
809820
810821 todo = cal .add_todo (
811822 summary = "This has dtstart and due" ,
@@ -827,11 +838,13 @@ def check_todo(self):
827838 if len (foobar1 + foobar2 + foobar3 + foobar4 ) == 22 :
828839 ## no todos found
829840 self .set_flag ("no_todo_datesearch" )
830- assert self .flags_checked .pop ("vtodo_datesearch_notime_task_is_skipped" ) ## redundant
841+ assert self .flags_checked .pop (
842+ "vtodo_datesearch_notime_task_is_skipped"
843+ ) ## redundant
831844 return
832845
833846 self .set_flag ("no_todo_datesearch" , False )
834- if foobar1 == [1 ,2 ]:
847+ if foobar1 == [1 , 2 ]:
835848 ## dtstart, but no due.
836849 ## open-ended search with end after event: found
837850 ## open-ended search with start before event: not found
0 commit comments