def testCalendar(self): c = Calendar(self.caldav, name="Yep", parent = self.principal, id = testcal_id).save() assert_not_equal(c.url, None) # TODO: fail #props = c.get_properties([dav.DisplayName(),]) #assert_equal("Yep", props[dav.DisplayName.tag]) c.set_properties([dav.DisplayName("hooray"),]) props = c.get_properties([dav.DisplayName(),]) assert_equal(props[dav.DisplayName.tag], "hooray") print c cc = Calendar(self.caldav, name="Yep", parent = self.principal).save() assert_not_equal(cc.url, None) cc.delete() e = Event(self.caldav, data = ev1, parent = c).save() assert_not_equal(e.url, None) print e, e.data ee = Event(self.caldav, url = url.make(e.url), parent = c) ee.load() assert_equal(e.instance.vevent.uid, ee.instance.vevent.uid) r = c.date_search(datetime(2006,7,13,17,00,00), datetime(2006,7,15,17,00,00)) assert_equal(e.instance.vevent.uid, r[0].instance.vevent.uid) for e in r: print e.data assert_equal(len(r), 1) all = c.events() print all assert_equal(len(all), 1) e2 = Event(self.caldav, data = ev2, parent = c).save() assert_not_equal(e.url, None) tmp = c.event("*****@*****.**") assert_equal(e2.instance.vevent.uid, tmp.instance.vevent.uid) r = c.date_search(datetime(2006,7,13,17,00,00), datetime(2006,7,15,17,00,00)) for e in r: print e.data assert_equal(len(r), 1) e.data = ev2 e.save() r = c.date_search(datetime(2006,7,13,17,00,00), datetime(2006,7,15,17,00,00)) for e in r: print e.data assert_equal(len(r), 1) e.instance = e2.instance e.save() r = c.date_search(datetime(2006,7,13,17,00,00), datetime(2006,7,15,17,00,00)) for e in r: print e.data assert_equal(len(r), 1)
def testLookupEvent(self): """ Makes sure we can add events and look them up by URL and ID """ # Create calendar c = self.principal.make_calendar(name="Yep", cal_id=self.testcal_id) assert_not_equal(c.url, None) # add event e1 = c.add_event(ev1) assert_not_equal(e1.url, None) # Verify that we can look it up, both by URL and by ID e2 = c.event_by_url(e1.url) e3 = c.event_by_uid("*****@*****.**") assert_equal(e2.instance.vevent.uid, e1.instance.vevent.uid) assert_equal(e3.instance.vevent.uid, e1.instance.vevent.uid) # Knowing the URL of an event, we should be able to get to it # without going through a calendar object e4 = Event(client=self.caldav, url=e1.url) e4.load() assert_equal(e4.instance.vevent.uid, e1.instance.vevent.uid) assert_raises(error.NotFoundError, c.event_by_uid, "0") c.add_event(evr) assert_raises(error.NotFoundError, c.event_by_uid, "0")
def testBackwardCompatibility(self): """ Tobias Brox has done some API changes - but this thing should still be backward compatible. """ if not 'backwards_compatibility_url' in self.server_params: return caldav = DAVClient(self.server_params['backwards_compatibility_url']) principal = Principal(caldav, self.server_params['backwards_compatibility_url']) c = Calendar(caldav, name="Yep", parent = principal, id = testcal_id).save() assert_not_equal(c.url, None) c.set_properties([dav.DisplayName("hooray"),]) props = c.get_properties([dav.DisplayName(),]) assert_equal(props[dav.DisplayName.tag], "hooray") cc = Calendar(caldav, name="Yep", parent = principal).save() assert_not_equal(cc.url, None) cc.delete() e = Event(caldav, data = ev1, parent = c).save() assert_not_equal(e.url, None) ee = Event(caldav, url = url.make(e.url), parent = c) ee.load() assert_equal(e.instance.vevent.uid, ee.instance.vevent.uid) r = c.date_search(datetime(2006,7,13,17,00,00), datetime(2006,7,15,17,00,00)) assert_equal(e.instance.vevent.uid, r[0].instance.vevent.uid) assert_equal(len(r), 1) all = c.events() assert_equal(len(all), 1) e2 = Event(caldav, data = ev2, parent = c).save() assert_not_equal(e.url, None) tmp = c.event("*****@*****.**") assert_equal(e2.instance.vevent.uid, tmp.instance.vevent.uid) r = c.date_search(datetime(2007,7,13,17,00,00), datetime(2007,7,15,17,00,00)) assert_equal(len(r), 1) e.data = ev2 e.save() r = c.date_search(datetime(2007,7,13,17,00,00), datetime(2007,7,15,17,00,00)) for e in r: print e.data assert_equal(len(r), 1) e.instance = e2.instance e.save() r = c.date_search(datetime(2007,7,13,17,00,00), datetime(2007,7,15,17,00,00)) for e in r: print e.data assert_equal(len(r), 1)
def Caldav(self): # Verbinding maken met CalDav agenda client = caldav.DAVClient(self.config["url"]) principal = client.principal() calendars = principal.calendars() first_all = True # Lus door de beschikbare agenda's heen for calendar in calendars: # Zoek de naam hiervan op calendar_name = calendar.get_properties([ dav.DisplayName(), ])["{DAV:}displayname"] # Alleen doorgaan indien de agenda in de 'calendars' config regel staat if calendar_name in self.config["calendars"]: first = True now = f.Now(self.config_full) # Evenementen voor vandaag zoeken, met een beetje buffer terug in de tijd. results = calendar.date_search(now - timedelta(hours=2), now + timedelta(days=1)) for vevent in results: event = Event(client=client, url=vevent.url) event.load() # Oke.. in de documentatie niks over hoe hier een nette string van te maken # En in het object zelf zit ook niet echt een functie daarvoor, los van __str()__ start = event.instance.vevent.dtstart.__str__() summary = event.instance.vevent.summary.__str__() # Zo kan het ook. summary = summary.replace("<SUMMARY{}", "")[:-1] # Dit komt binnen: <DTSTART{'X-VOBJ-ORIGINAL-TZID': ['Europe/Amsterdam']} # Dus split op } en dan de eerste verwijderen, en het > teken achteraan verwijderen start = parse(''.join(start.split("}")[1:])[:-1]) # Eerste event in deze agenda? Toon de agenda naam if first: # Niet de eerste agenda? Extra witregel if not first_all: self.text += "<br/>" self.text += "<h3>" + calendar_name + "</h3>" first = False first_all = False # Event samenvatting (tijd + omschijving) toevoegen aan de text dt = "%A %H:%M" if (calendar_name.lower().find("birthday") >= 0 or calendar_name.lower().find("verjaardag") >= 0): dt = "%A" self.text += "{0} {1}<br/>".format(start.strftime(dt), summary) if not first_all: self.hasText = True
def _mock_calendar(name): events = [] for idx, event in enumerate(EVENTS): events.append(Event(None, "%d.ics" % idx, event, None, str(idx))) calendar = Mock() calendar.date_search = MagicMock(return_value=events) calendar.name = name return calendar
def testLookupEvent(self): """ Makes sure we can add events and look them up by URL and ID """ ## Create calendar c = self.principal.make_calendar(name="Yep", cal_id=testcal_id) assert_not_equal(c.url, None) ## add event e1 = c.add_event(ev1) assert_not_equal(e1.url, None) ## Verify that we can look it up, both by URL and by ID e2 = c.event_by_url(e1.url) e3 = c.event_by_uid("*****@*****.**") assert_equal(e2.instance.vevent.uid, e1.instance.vevent.uid) assert_equal(e3.instance.vevent.uid, e1.instance.vevent.uid) ## Knowing the URL of an event, we should be able to get to it ## without going through a calendar object e4 = Event(client=self.caldav, url=e1.url) e4.load() assert_equal(e4.instance.vevent.uid, e1.instance.vevent.uid)
def testInstance(self): cal_url = "http://*****:*****@calendar.example:80/" client = DAVClient(url=cal_url) my_event = Event(client, data=ev1) my_event.vobject_instance.vevent.summary.value = 'new summary' assert ('new summary' in my_event.data) icalobj = my_event.icalendar_instance icalobj.subcomponents[0]['SUMMARY'] = 'yet another summary' assert_equal(my_event.vobject_instance.vevent.summary.value, 'yet another summary') ## Now the data has been converted from string to vobject to string to icalendar to string to vobject and ... will the string still match the original? lines_now = my_event.data.split('\r\n') lines_orig = ev1.replace('Bastille Day Party', 'yet another summary').split('\n') lines_now.sort() lines_orig.sort() assert_equal(lines_now, lines_orig)
def testBackwardCompatibility(self): """ Tobias Brox has done some API changes - but this thing should still be backward compatible. """ if not 'backwards_compatibility_url' in self.server_params: return caldav = DAVClient(self.server_params['backwards_compatibility_url']) principal = Principal( caldav, self.server_params['backwards_compatibility_url']) c = Calendar(caldav, name="Yep", parent=principal, id=testcal_id).save() assert_not_equal(c.url, None) c.set_properties([ dav.DisplayName("hooray"), ]) props = c.get_properties([ dav.DisplayName(), ]) assert_equal(props[dav.DisplayName.tag], "hooray") cc = Calendar(caldav, name="Yep", parent=principal).save() assert_not_equal(cc.url, None) cc.delete() e = Event(caldav, data=ev1, parent=c).save() assert_not_equal(e.url, None) ee = Event(caldav, url=url.make(e.url), parent=c) ee.load() assert_equal(e.instance.vevent.uid, ee.instance.vevent.uid) r = c.date_search(datetime(2006, 7, 13, 17, 00, 00), datetime(2006, 7, 15, 17, 00, 00)) assert_equal(e.instance.vevent.uid, r[0].instance.vevent.uid) assert_equal(len(r), 1) all = c.events() assert_equal(len(all), 1) e2 = Event(caldav, data=ev2, parent=c).save() assert_not_equal(e.url, None) tmp = c.event("*****@*****.**") assert_equal(e2.instance.vevent.uid, tmp.instance.vevent.uid) r = c.date_search(datetime(2007, 7, 13, 17, 00, 00), datetime(2007, 7, 15, 17, 00, 00)) assert_equal(len(r), 1) e.data = ev2 e.save() r = c.date_search(datetime(2007, 7, 13, 17, 00, 00), datetime(2007, 7, 15, 17, 00, 00)) for e in r: print(e.data) assert_equal(len(r), 1) e.instance = e2.instance e.save() r = c.date_search(datetime(2007, 7, 13, 17, 00, 00), datetime(2007, 7, 15, 17, 00, 00)) for e in r: print(e.data) assert_equal(len(r), 1)
def testCalendar(self): c = Calendar(self.caldav, name="Yep", parent=self.principal, id=testcal_id).save() assert_not_equal(c.url, None) # TODO: fail #props = c.get_properties([DAVDisplayName(),]) #assert_equal("Yep", props[DAVDisplayName.tag]) c.set_properties([ dav.DisplayName("hooray"), ]) props = c.get_properties([ dav.DisplayName(), ]) assert_equal(props[dav.DisplayName.tag], "hooray") print c cc = Calendar(self.caldav, name="Yep", parent=self.principal).save() assert_not_equal(cc.url, None) cc.delete() e = Event(self.caldav, data=ev1, parent=c).save() assert_not_equal(e.url, None) print e, e.data ee = Event(self.caldav, url=url.make(e.url), parent=c) ee.load() assert_equal(e.instance.vevent.uid, ee.instance.vevent.uid) r = c.date_search(datetime(2006, 7, 13, 17, 00, 00), datetime(2006, 7, 15, 17, 00, 00)) assert_equal(e.instance.vevent.uid, r[0].instance.vevent.uid) for e in r: print e.data assert_equal(len(r), 1) all = c.events() assert_equal(len(all), 1) e2 = Event(self.caldav, data=ev2, parent=c).save() assert_not_equal(e.url, None) tmp = c.event("*****@*****.**") assert_equal(e2.instance.vevent.uid, tmp.instance.vevent.uid) r = c.date_search(datetime(2006, 7, 13, 17, 00, 00), datetime(2006, 7, 15, 17, 00, 00)) for e in r: print e.data assert_equal(len(r), 1) e.data = ev2 e.save() r = c.date_search(datetime(2006, 7, 13, 17, 00, 00), datetime(2006, 7, 15, 17, 00, 00)) for e in r: print e.data assert_equal(len(r), 1)