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

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

 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.session import Session 
18  from caldavclientlibrary.protocol.webdav.propfind import PropFind 
19  from StringIO import StringIO 
20  from caldavclientlibrary.protocol.webdav.definitions import davxml 
21  from xml.etree.ElementTree import QName 
22  from caldavclientlibrary.protocol.webdav.definitions import headers 
23  import unittest 
24   
25 -class TestRequest(unittest.TestCase):
26
27 - def test_Method(self):
28 29 server = Session("www.example.com") 30 request = PropFind(server, "/", headers.Depth0, (davxml.getetag, QName("http://example.com/ns/", "taggy"))) 31 self.assertEqual(request.getMethod(), "PROPFIND")
32
33 -class TestRequestHeaders(unittest.TestCase):
34
35 - def test_Depth0Headers(self):
36 37 server = Session("www.example.com") 38 request = PropFind(server, "/", headers.Depth0, (davxml.getetag, QName("http://example.com/ns/", "taggy"))) 39 hdrs = request.generateRequestHeader() 40 self.assertTrue("Depth: 0" in hdrs) 41 self.assertFalse("Depth: 1" in hdrs) 42 self.assertFalse("Depth: infinity" in hdrs)
43
44 - def test_Depth1Headers(self):
45 46 server = Session("www.example.com") 47 request = PropFind(server, "/", headers.Depth1, (davxml.getetag, QName("http://example.com/ns/", "taggy"))) 48 hdrs = request.generateRequestHeader() 49 self.assertFalse("Depth: 0" in hdrs) 50 self.assertTrue("Depth: 1" in hdrs) 51 self.assertFalse("Depth: infinity" in hdrs)
52
54 55 server = Session("www.example.com") 56 request = PropFind(server, "/", headers.DepthInfinity, (davxml.getetag, QName("http://example.com/ns/", "taggy"))) 57 hdrs = request.generateRequestHeader() 58 self.assertFalse("Depth: 0" in hdrs) 59 self.assertFalse("Depth: 1" in hdrs) 60 self.assertTrue("Depth: infinity" in hdrs)
61
62 -class TestRequestBody(unittest.TestCase):
63
64 - def test_GenerateXML(self):
65 66 server = Session("www.example.com") 67 request = PropFind(server, "/", headers.Depth0, (davxml.getetag, QName("http://example.com/ns/", "taggy"))) 68 os = StringIO() 69 request.generateXML(os) 70 self.assertEqual(os.getvalue(), """<?xml version='1.0' encoding='utf-8'?> 71 <ns0:propfind xmlns:ns0="DAV:"> 72 <ns0:prop> 73 <ns0:getetag /> 74 <ns1:taggy xmlns:ns1="http://example.com/ns/" /> 75 </ns0:prop> 76 </ns0:propfind> 77 """.replace("\n", "\r\n") 78 )
79
80 -class TestResponse(unittest.TestCase):
81 pass
82
83 -class TestResponseHeaders(unittest.TestCase):
84 pass
85
86 -class TestResponseBody(unittest.TestCase):
87 pass
88