def test_DepthInfinityHeaders(self): server = Session("www.example.com") request = PropFind(server, "/", headers.DepthInfinity, (davxml.getetag, QName("http://example.com/ns/", "taggy"))) hdrs = request.generateRequestHeader() self.assertFalse("Depth: 0" in hdrs) self.assertFalse("Depth: 1" in hdrs) self.assertTrue("Depth: infinity" in hdrs)
def test_Depth0Headers(self): server = Session("www.example.com") request = PrincipalMatch(server, "/", ()) hdrs = request.generateRequestHeader() self.assertTrue("Depth: 0" in hdrs) self.assertFalse("Depth: 1" in hdrs) self.assertFalse("Depth: infinity" in hdrs)
def test_GenerateXMLOneHrefOnly(self): server = Session("www.example.com") request = Multiget(server, "/", ("/a", )) os = StringIO() request.generateXML(os) self.assertEqual( os.getvalue(), """<?xml version='1.0' encoding='utf-8'?> <ns0:addressbook-multiget xmlns:ns0="urn:ietf:params:xml:ns:carddav"> <ns1:href xmlns:ns1="DAV:">/a</ns1:href> </ns0:addressbook-multiget> """.replace("\n", "\r\n"))
def test_GenerateXML(self): server = Session("www.example.com") request = PropFind(server, "/", headers.Depth0, (davxml.getetag, QName("http://example.com/ns/", "taggy"))) os = StringIO() request.generateXML(os) self.assertEqual(os.getvalue(), """<?xml version='1.0' encoding='utf-8'?> <ns0:propfind xmlns:ns0="DAV:"> <ns0:prop> <ns0:getetag /> <ns1:taggy xmlns:ns1="http://example.com/ns/" /> </ns0:prop> </ns0:propfind> """.replace("\n", "\r\n") )
def test_GenerateXMLOneProperty(self): server = Session("www.example.com") request = PrincipalMatch(server, "/", (davxml.getetag, )) os = StringIO() request.generateXML(os) self.assertEqual( os.getvalue(), """<?xml version='1.0' encoding='utf-8'?> <ns0:principal-match xmlns:ns0="DAV:"> <ns0:self /> <ns0:prop> <ns0:getetag /> </ns0:prop> </ns0:principal-match> """.replace("\n", "\r\n"))
def test_GenerateXMLDisplayname(self): server = Session("www.example.com") request = MakeCalendar(server, "/", "home") os = StringIO() request.generateXML(os) self.assertEqual( os.getvalue(), """<?xml version='1.0' encoding='utf-8'?> <ns0:mkcalendar xmlns:ns0="urn:ietf:params:xml:ns:caldav"> <ns1:set xmlns:ns1="DAV:"> <ns1:prop> <ns1:displayname>home</ns1:displayname> </ns1:prop> </ns1:set> </ns0:mkcalendar> """.replace("\n", "\r\n"))
def test_GenerateXMLMultipleHrefsOneProperty(self): server = Session("www.example.com") request = Multiget(server, "/", ("/a", "/b",), (davxml.getetag,)) os = StringIO() request.generateXML(os) self.assertEqual( os.getvalue(), """<?xml version='1.0' encoding='utf-8'?> <ns0:calendar-multiget xmlns:ns0="urn:ietf:params:xml:ns:caldav"> <ns1:prop xmlns:ns1="DAV:"> <ns1:getetag /> </ns1:prop> <ns1:href xmlns:ns1="DAV:">/a</ns1:href> <ns1:href xmlns:ns1="DAV:">/b</ns1:href> </ns0:calendar-multiget> """.replace("\n", "\r\n") )
def test_GenerateXMLDisplayname(self): server = Session("www.example.com") request = MakeAddressBook(server, "/", "home") os = StringIO() request.generateXML(os) self.assertEqual( os.getvalue(), """<?xml version='1.0' encoding='utf-8'?> <ns0:mkcol xmlns:ns0="DAV:"> <ns0:set> <ns0:prop> <ns0:resourcetype> <ns0:collection /> <ns1:addressbook xmlns:ns1="urn:ietf:params:xml:ns:carddav" /> </ns0:resourcetype> <ns0:displayname>home</ns0:displayname> </ns0:prop> </ns0:set> </ns0:mkcol> """.replace("\n", "\r\n"))
def test_GenerateXMLCDATAProperty(self): server = Session("www.example.com") timezone = """BEGIN:VCALENDAR PRODID:-//Example Corp.//CalDAV Client//EN VERSION:2.0 BEGIN:VTIMEZONE TZID:US-Eastern LAST-MODIFIED:19870101T000000Z BEGIN:STANDARD DTSTART:19671029T020000 RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10 TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:Eastern Standard Time (US & Canada) END:STANDARD BEGIN:DAYLIGHT DTSTART:19870405T020000 RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4 TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:Eastern Daylight Time (US & Canada) END:DAYLIGHT END:VTIMEZONE END:VCALENDAR """.replace("\n", "\r\n") request = MakeCalendar(server, "/", timezone=timezone) os = StringIO() request.generateXML(os) self.assertEqual( os.getvalue(), """<?xml version='1.0' encoding='utf-8'?> <ns0:mkcalendar xmlns:ns0="urn:ietf:params:xml:ns:caldav"> <ns1:set xmlns:ns1="DAV:"> <ns1:prop> <ns0:calendar-timezone>%s</ns0:calendar-timezone> </ns1:prop> </ns1:set> </ns0:mkcalendar> """.replace("\n", "\r\n") % (timezone.replace("&", "&"), ))
def test_Method(self): server = Session("www.example.com") request = Multiget(server, "/", ()) self.assertEqual(request.getMethod(), "REPORT")
def test_Method(self): server = Session("www.example.com") request = MakeCalendar(server, "/") self.assertEqual(request.getMethod(), "MKCALENDAR")
def test_Method(self): server = Session("www.example.com") request = MakeAddressBook(server, "/") self.assertEqual(request.getMethod(), "MKCOL")
def test_Method(self): server = Session("www.example.com") request = PropFind(server, "/", headers.Depth0, (davxml.getetag, QName("http://example.com/ns/", "taggy"))) self.assertEqual(request.getMethod(), "PROPFIND")
for header, value in hdrs.iteritems(): connect.putheader(header, value) connect.endheaders() # Do request body stream = request.getRequestDataStream() if stream: stream.start() more = True while more: data, more = stream.read() if data: connect.send(data) stream.stop() # Get response response = connect.getresponse() # Get response headers request.setResponseStatus(response.version, response.status, response.reason) request.setResponseHeaders(response.getheaders()) # Get response body if __name__ == '__main__': session = Session("www.mulberrymail.com") request = Options(session, "/") run(session, request)