Ejemplo n.º 1
0
    def test(self):
        """webdav sync"""
        # missing tests:
        #   invalid tokens: negative, non-numeric, > current timestamp
        #   non-empty collections: token validity, status codes for added,
        #                          modified and removed elements

        # preparation
        mkcol = webdavlib.WebDAVMKCOL(resource)
        self.client.execute(mkcol)
        self.assertEquals(
            mkcol.response["status"], 201,
            "preparation: failure creating collection (code != 201)")

        # test queries:
        #   empty collection:
        #     without a token (query1)
        #     with a token (query2)
        #   (when done, non-empty collection:
        #     without a token (query3)
        #     with a token (query4))

        query1 = webdavlib.WebDAVSyncQuery(resource, None, ["getetag"])
        self.client.execute(query1)
        self.assertEquals(query1.response["status"], 207,
                          ("query1: invalid status code: %d (!= 207)" %
                           query1.response["status"]))
        token_node = query1.response["document"].find("{DAV:}sync-token")
        # Implicit "assertion": we expect SOGo to return a token node, with a
        # non-empty numerical value. Anything else will trigger an exception
        token = int(token_node.text)

        self.assertTrue(token > 0)
        query1EndTime = int(math.ceil(query1.start + query1.duration))
        self.assertTrue(
            token <= query1EndTime,
            "token = %d > query1EndTime = %d" % (token, query1EndTime))

        # we make sure that any token is accepted when the collection is
        # empty, but that the returned token differs
        query2 = webdavlib.WebDAVSyncQuery(resource, "1234", ["getetag"])
        self.client.execute(query2)
        self.assertEquals(query2.response["status"], 207)
        token_node = query2.response["document"].find("{DAV:}sync-token")
        self.assertTrue(token_node is not None, "expected 'sync-token' tag")
        token = int(token_node.text)
        self.assertTrue(token > 0)
Ejemplo n.º 2
0
    def _webdavSyncEvent(self):
        event = None

        sync_query = webdavlib.WebDAVSyncQuery(self.resource, None,
                                               ["{urn:ietf:params:xml:ns:caldav}calendar-data"])
        self.client.execute(sync_query)
        if sync_query.response["status"] != 404:
            event = self._calendarDataInMultistatus(sync_query, "{DAV:}response")

        return event
Ejemplo n.º 3
0
    def _webdavSyncEvent(self, event_class):
        event = None

        icsClass = self.classToICSClass[event_class]
        url = "%s%s-event.ics" % (self.resource, icsClass.lower())
        sync_query = webdavlib.WebDAVSyncQuery(self.resource, None,
                                               ["{urn:ietf:params:xml:ns:caldav}calendar-data"])
        self.subscriber_client.execute(sync_query)
        if sync_query.response["status"] != 404:
            event = self._calendarDataInMultistatus(sync_query, url,
                                                    "{DAV:}response")

        return event
Ejemplo n.º 4
0
 def run(self):
     client = webdavlib.WebDAVClient(hostname, port, self.username,
                                     password)
     resource = "/SOGo/dav/%s/Calendar/personal/" % self.username
     startTime = time.time()
     query = webdavlib.WebDAVSyncQuery(resource, None,
                                       ["getetag", "calendar-data"])
     client.execute(query)
     if query.response["status"] != 207:
         print "*** received unexpected code: %d (%s)" \
               % (query.response["status"], resource)
     endTime = time.time()
     headers = query.response["headers"]
     if headers.has_key(durationHeader):
         self.sogoTime = float(headers[durationHeader])
     self.time = endTime - startTime
Ejemplo n.º 5
0
def changedItemsFromCollection(client, collection, synctoken=None):
  # get all changed hrefs since synctoken
  hrefs = []
  syncquery = webdavlib.WebDAVSyncQuery(collection, synctoken, [ "getcontenttype", "getetag" ])
  client.execute(syncquery)
  client.conn.close()
  if (syncquery.response["status"] != 207):
    raise Exception("Bad http response code: %d" % syncquery.response["status"])
  doc = syncquery.response["document"]

  # extract all hrefs
  for syncResponse in doc.iter("{DAV:}response"):
    href = syncResponse.find("{DAV:}href")
    if href is not None:
      hrefs.append(href.text)

  return hrefs