Beispiel #1
0
def create_calendar(client, parent, name, id=None):
    """
    Create a new calendar with display name `name` in `parent`.
    """
    path = None
    if id is None:
        id = str(uuid.uuid1())

    name = dav.DisplayName(name)
    cal = cdav.CalendarCollection()
    coll = dav.Collection() + cal
    type = dav.ResourceType() + coll

    prop = dav.Prop() + [type, name]
    set = dav.Set() + prop

    mkcol = dav.Mkcol() + set

    q = etree.tostring(mkcol.xmlelement(),
                       encoding="utf-8",
                       xml_declaration=True)
    path = url.join(parent.url.path, id)

    r = client.mkcol(path, q)
    if r.status == 201:
        path = url.make(parent.url, path)
    else:
        raise error.MkcolError(r.raw)

    return (id, path)
Beispiel #2
0
    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)
Beispiel #3
0
def uid_search(client, calendar, uid):
    """
    Perform a uid search in the `calendar`.
    """
    data = cdav.CalendarData()
    prop = dav.Prop() + data

    match = cdav.TextMatch(uid)
    propf = cdav.PropFilter("UID") + match
    vevent = cdav.CompFilter("VEVENT") + propf
    vcal = cdav.CompFilter("VCALENDAR") + vevent
    filter = cdav.Filter() + vcal

    root = cdav.CalendarQuery() + [prop, filter]

    q = etree.tostring(root.xmlelement(),
                       encoding="utf-8",
                       xml_declaration=True)
    response = client.report(calendar.url.path, q, 1)
    r = response.tree.find(".//" + dav.Response.tag)
    if r is not None:
        href = r.find(".//" + dav.Href.tag).text
        data = r.find(".//" + cdav.CalendarData.tag).text
        info = (url.make(calendar.url, href), data)
    else:
        raise error.NotFoundError(response.raw)

    return info
Beispiel #4
0
    def _create(self, name, id=None):
        """
        Create a new calendar with display name `name` in `parent`.
        """
        path = None
        if id is None:
            id = str(uuid.uuid1())

        name = dav.DisplayName(name)
        cal = cdav.CalendarCollection()
        coll = dav.Collection() + cal
        type = dav.ResourceType() + coll

        prop = dav.Prop() + [type, name]
        set = dav.Set() + prop

        mkcol = dav.Mkcol() + set

        q = etree.tostring(mkcol.xmlelement(), encoding="utf-8", xml_declaration=True)
        path = url.join(self.parent.url.path, id)

        r = self.client.mkcol(path, q)
        if r.status == 201:
            # XXX Should we use self.canonical_url ?
            path = url.make(self.parent.url, path)
        else:
            raise error.MkcolError(r.raw)

        return (id, path)
Beispiel #5
0
def date_search(client, calendar, start, end=None):
    """
    Perform a time-interval search in the `calendar`.
    """
    rc = []

    # build the request
    expand = cdav.Expand(start, end)
    data = cdav.CalendarData() + expand
    prop = dav.Prop() + data

    range = cdav.TimeRange(start, end)
    vevent = cdav.CompFilter("VEVENT") + range
    vcal = cdav.CompFilter("VCALENDAR") + vevent
    filter = cdav.Filter() + vcal

    root = cdav.CalendarQuery() + [prop, filter]

    q = etree.tostring(root.xmlelement(),
                       encoding="utf-8",
                       xml_declaration=True)
    response = client.report(calendar.url.path, q, 1)
    for r in response.tree.findall(".//" + dav.Response.tag):
        status = r.find(".//" + dav.Status.tag)
        if status.text.endswith("200 OK"):
            href = r.find(dav.Href.tag).text
            data = r.find(".//" + cdav.CalendarData.tag).text
            rc.append((url.make(calendar.url, href), data))
        else:
            raise error.ReportError(r.raw)

    return rc
Beispiel #6
0
    def teardown(self):
        p = url.make(self.principal.url)
        path = url.join(p, testcal_id)

        cal = Calendar(self.caldav, name="Yep", parent = self.principal,
                       url = path)
        cal.delete()
Beispiel #7
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 teardown(self):
        p = url.make(self.principal.url)
        path = url.join(p, testcal_id)

        cal = Calendar(self.caldav,
                       name="Yep",
                       parent=self.principal,
                       url=path)
        cal.delete()
Beispiel #9
0
    def _create(self, data, id=None, path=None):
        if id is None:
            id = str(uuid.uuid1())
        if path is None:
            path = url.join(self.parent.url.path, id + ".ics")

        r = self.client.put(path, data, {"Content-Type": 'text/calendar; charset="utf-8"'})
        if r.status == 204 or r.status == 201:
            # XXX Should we use self.canonical_url ?
            path = url.make(self.parent.url, path)
        else:
            raise error.PutError(r.raw)

        return (id, path)
Beispiel #10
0
def create_event(client, calendar, data, id=None):
    path = None
    if id is None:
        id = str(uuid.uuid1())

    path = url.join(calendar.url.path, id + ".ics")
    r = client.put(path, data,
                   {"Content-Type": "text/calendar; charset=\"utf-8\""})
    if r.status == 204 or r.status == 201:
        path = url.make(calendar.url, path)
    else:
        raise error.PutError(r.raw)

    return (id, path)
Beispiel #11
0
def children(client, parent, type=None):
    """
    List children, using a propfind (resourcetype) on the parent object,
    at depth = 1.
    TODO: There should be a better way.
    """
    c = []

    response = get_properties(client, parent, [
        dav.ResourceType(),
    ], 1)
    for path in response.keys():
        if path != parent.url.path:
            resource_type = response[path][dav.ResourceType.tag]
            if resource_type == type or type is None:
                c.append((url.make(parent.url, path), resource_type))

    return c
Beispiel #12
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)
Beispiel #13
0
    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)
Beispiel #14
0
 def __str__(self):
     return "Event: %s" % url.make(self.url)
Beispiel #15
0
 def __str__(self):
     return "Collection: %s" % url.make(self.url)
Beispiel #16
0
    def testPrincipal(self):
        assert_equal(url.make(self.principal.url), principal_url)

        collections = self.principal.calendars()
        for c in collections:
            assert_equal(c.__class__.__name__, "Calendar")
Beispiel #17
0
    def testPrincipal(self):
        assert_equal(url.make(self.principal.url), principal_url)

        collections = self.principal.calendars()
        for c in collections:
            assert_equal(c.__class__.__name__, "Calendar")