Package caldavclientlibrary :: Package protocol :: Package webdav :: Package tests :: Module test_propfindparser
[hide private]
[frames] | no frames]

Source Code for Module caldavclientlibrary.protocol.webdav.tests.test_propfindparser

  1  ## 
  2  # Copyright (c) 2007-2016 Apple Inc. All rights reserved. 
  3  # 
  4  # Licensed under the Apache License, Version 2.0 (the "License"); 
  5  # you may not use this file except in compliance with the License. 
  6  # You may obtain a copy of the License at 
  7  # 
  8  # http://www.apache.org/licenses/LICENSE-2.0 
  9  # 
 10  # Unless required by applicable law or agreed to in writing, software 
 11  # distributed under the License is distributed on an "AS IS" BASIS, 
 12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 13  # See the License for the specific language governing permissions and 
 14  # limitations under the License. 
 15  ## 
 16   
 17  from caldavclientlibrary.protocol.webdav.propfindparser import PropFindParser 
 18  from xml.etree.ElementTree import XML 
 19  from caldavclientlibrary.protocol.webdav.definitions import davxml 
 20  import unittest 
 21   
22 -class TestRequest(unittest.TestCase):
23
24 - def parseXML(self, x):
25 26 x = x.replace("\n", "\r\n") 27 28 # Parse the XML data 29 p = PropFindParser() 30 p.parse(XML(x)) 31 return p
32
33 - def checkResource(self, parser, resource, properties):
34 result = parser.getResults().get(resource, None) 35 self.assertTrue(result is not None) 36 for prop, value in properties: 37 self.assertEqual(result.getTextProperties().get(prop, None), value)
38
40 41 parser = self.parseXML("""<?xml version='1.0' encoding='utf-8'?> 42 <ns0:multistatus xmlns:ns0="DAV:"> 43 <ns0:response> 44 <ns0:href>/principals/users/a</ns0:href> 45 <ns0:propstat> 46 <ns0:prop> 47 <ns0:getetag>12345</ns0:getetag> 48 </ns0:prop> 49 <ns0:status>HTTP/1.1 200 OK</ns0:status> 50 </ns0:propstat> 51 </ns0:response> 52 </ns0:multistatus> 53 """) 54 55 self.checkResource(parser, "/principals/users/a", ( 56 (davxml.getetag, "12345",), 57 ))
58
60 61 parser = self.parseXML("""<?xml version='1.0' encoding='utf-8'?> 62 <ns0:multistatus xmlns:ns0="DAV:"> 63 <ns0:response> 64 <ns0:href>/principals/users/a</ns0:href> 65 <ns0:propstat> 66 <ns0:prop> 67 <ns0:displayname>Name</ns0:displayname> 68 <ns0:getetag>12345</ns0:getetag> 69 </ns0:prop> 70 <ns0:status>HTTP/1.1 200 OK</ns0:status> 71 </ns0:propstat> 72 </ns0:response> 73 </ns0:multistatus> 74 """) 75 76 result = parser.getResults().get("/principals/users/a", None) 77 self.assertTrue(result is not None) 78 self.assertEqual(result.getTextProperties().get(davxml.getetag, None), "12345") 79 self.assertEqual(result.getTextProperties().get(davxml.displayname, None), "Name") 80 81 self.checkResource(parser, "/principals/users/a", ( 82 (davxml.getetag, "12345",), 83 (davxml.displayname, "Name",), 84 ))
85
87 88 parser = self.parseXML("""<?xml version='1.0' encoding='utf-8'?> 89 <ns0:multistatus xmlns:ns0="DAV:"> 90 <ns0:response> 91 <ns0:href>/principals/users/a</ns0:href> 92 <ns0:propstat> 93 <ns0:prop> 94 <ns0:displayname>Name1</ns0:displayname> 95 <ns0:getetag>1</ns0:getetag> 96 </ns0:prop> 97 <ns0:status>HTTP/1.1 200 OK</ns0:status> 98 </ns0:propstat> 99 </ns0:response> 100 <ns0:response> 101 <ns0:href>/principals/users/b</ns0:href> 102 <ns0:propstat> 103 <ns0:prop> 104 <ns0:displayname>Name2</ns0:displayname> 105 <ns0:getetag>2</ns0:getetag> 106 </ns0:prop> 107 <ns0:status>HTTP/1.1 200 OK</ns0:status> 108 </ns0:propstat> 109 </ns0:response> 110 </ns0:multistatus> 111 """) 112 113 self.checkResource(parser, "/principals/users/a", ( 114 (davxml.getetag, "1",), 115 (davxml.displayname, "Name1",), 116 )) 117 118 self.checkResource(parser, "/principals/users/b", ( 119 (davxml.getetag, "2",), 120 (davxml.displayname, "Name2",), 121 ))
122 123
124 - def test_ResourceNotFound(self):
125 parser = self.parseXML("""<?xml version='1.0' encoding='UTF-8'?> 126 <multistatus xmlns='DAV:'> 127 <response> 128 <href>/calendars/__uids__/user01/inbox/event.ics</href> 129 <status>HTTP/1.1 404 Not Found</status> 130 </response> 131 </multistatus> 132 """) 133 results = parser.getResults() 134 result = results["/calendars/__uids__/user01/inbox/event.ics"] 135 self.assertEqual("HTTP/1.1 404 Not Found", result.getStatus())
136