def supportedReports(self): result = super(CalDAVResource, self).supportedReports() result.append(davxml.Report(caldavxml.CalendarQuery(), )) result.append(davxml.Report(caldavxml.CalendarMultiGet(), )) # free-busy report not allowed if config.EnableSyncReport: # Only allowed on calendar/inbox/addressbook collections result.append(davxml.Report(davxml.SyncCollection(), )) return result
def simple_event_multiget(self, cal_uri, okuids, baduids, data=None, no_init=False, withData=True): cal_uri = joinURL("/calendars/users/wsanchez", cal_uri) props = (davxml.GETETag(), ) if withData: props += (caldavxml.CalendarData(), ) children = [] children.append(davxml.PropertyContainer(*props)) okhrefs = [joinURL(cal_uri, x + ".ics") for x in okuids] badhrefs = [joinURL(cal_uri, x + ".ics") for x in baduids] for href in okhrefs + badhrefs: children.append(davxml.HRef.fromString(href)) query = caldavxml.CalendarMultiGet(*children) def got_xml(doc): if not isinstance(doc.root_element, davxml.MultiStatus): self.fail( "REPORT response XML root element is not multistatus: %r" % (doc.root_element, )) for response in doc.root_element.childrenOfType( davxml.PropertyStatusResponse): href = str(response.childOfType(davxml.HRef)) for propstat in response.childrenOfType(davxml.PropertyStatus): status = propstat.childOfType(davxml.Status) if status.code != responsecode.OK: self.fail( "REPORT failed (status %s) to locate properties: %r" % (status.code, href)) properties = propstat.childOfType( davxml.PropertyContainer).children for property in properties: qname = property.qname() if qname == (davxml.dav_namespace, "getetag"): continue if qname != (caldavxml.caldav_namespace, "calendar-data"): self.fail( "Response included unexpected property %r" % (property, )) result_calendar = property.calendar() if result_calendar is None: self.fail( "Invalid response CalDAV:calendar-data: %r" % (property, )) uid = result_calendar.resourceUID() if uid in okuids: okuids.remove(uid) else: self.fail("Got calendar for unexpected UID %r" % (uid, )) if data: original_calendar = ical.Component.fromString( data[uid]) else: original_filename = file( os.path.join(self.holidays_dir, uid + ".ics")) original_calendar = ical.Component.fromStream( original_filename) self.assertEqual(result_calendar, original_calendar) for response in doc.root_element.childrenOfType( davxml.StatusResponse): href = str(response.childOfType(davxml.HRef)) propstatus = response.childOfType(davxml.PropertyStatus) if propstatus is not None: status = propstatus.childOfType(davxml.Status) else: status = response.childOfType(davxml.Status) if status.code != responsecode.OK: if href in okhrefs: self.fail( "REPORT failed (status %s) to locate properties: %r" % (status.code, href)) else: if href in badhrefs: badhrefs.remove(href) continue else: self.fail("Got unexpected href %r" % (href, )) if withData and (len(okuids) + len(badhrefs)): self.fail("Some components were not returned: %r, %r" % (okuids, badhrefs)) return self.calendar_query(cal_uri, query, got_xml, data, no_init)