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

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

  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.http.session import Session 
 18  from caldavclientlibrary.protocol.webdav.lock import Lock 
 19  from caldavclientlibrary.protocol.webdav.definitions import headers 
 20  from StringIO import StringIO 
 21   
 22  import unittest 
 23   
24 -class TestRequest(unittest.TestCase):
25
26 - def test_Method(self):
27 28 server = Session("www.example.com") 29 request = Lock(server, "/", headers.Depth0, Lock.eExclusive, "user@example.com", -1) 30 self.assertEqual(request.getMethod(), "LOCK")
31
32 -class TestRequestHeaders(unittest.TestCase):
33
34 - def test_NoSpecialHeaders(self):
35 36 server = Session("www.example.com") 37 request = Lock(server, "/", headers.Depth0, Lock.eExclusive, "user@example.com", -1, exists=Lock.eResourceMayExist) 38 hdrs = request.generateRequestHeader() 39 self.assertFalse("If-None-Match:" in hdrs) 40 self.assertFalse("If-Match:" in hdrs)
41
42 - def test_IfMatchHeader(self):
43 44 server = Session("www.example.com") 45 request = Lock(server, "/", headers.Depth0, Lock.eExclusive, "user@example.com", -1, exists=Lock.eResourceMustExist) 46 hdrs = request.generateRequestHeader() 47 self.assertFalse("If-None-Match:" in hdrs) 48 self.assertTrue("If-Match: *" in hdrs)
49
50 - def test_IfNoneMatchHeader(self):
51 52 server = Session("www.example.com") 53 request = Lock(server, "/", headers.Depth0, Lock.eExclusive, "user@example.com", -1, exists=Lock.eResourceMustNotExist) 54 hdrs = request.generateRequestHeader() 55 self.assertTrue("If-None-Match: *" in hdrs) 56 self.assertFalse("If-Match:" in hdrs)
57
58 - def test_Depth0Headers(self):
59 60 server = Session("www.example.com") 61 request = Lock(server, "/", headers.Depth0, Lock.eExclusive, "user@example.com", -1, exists=Lock.eResourceMustNotExist) 62 hdrs = request.generateRequestHeader() 63 self.assertTrue("Depth: 0" in hdrs) 64 self.assertFalse("Depth: 1" in hdrs) 65 self.assertFalse("Depth: infinity" in hdrs)
66
67 - def test_Depth1Headers(self):
68 69 server = Session("www.example.com") 70 request = Lock(server, "/", headers.Depth1, Lock.eExclusive, "user@example.com", -1, exists=Lock.eResourceMustNotExist) 71 hdrs = request.generateRequestHeader() 72 self.assertFalse("Depth: 0" in hdrs) 73 self.assertTrue("Depth: 1" in hdrs) 74 self.assertFalse("Depth: infinity" in hdrs)
75
77 78 server = Session("www.example.com") 79 request = Lock(server, "/", headers.DepthInfinity, Lock.eExclusive, "user@example.com", -1, exists=Lock.eResourceMustNotExist) 80 hdrs = request.generateRequestHeader() 81 self.assertFalse("Depth: 0" in hdrs) 82 self.assertFalse("Depth: 1" in hdrs) 83 self.assertTrue("Depth: infinity" in hdrs)
84 85
86 -class TestRequestBody(unittest.TestCase):
87
88 - def test_GenerateXML(self):
89 90 server = Session("www.example.com") 91 request = Lock(server, "/", headers.Depth0, Lock.eExclusive, "user@example.com", -1) 92 os = StringIO() 93 request.generateXML(os) 94 self.assertEqual(os.getvalue(), """<?xml version='1.0' encoding='utf-8'?> 95 <ns0:lockinfo xmlns:ns0="DAV:"> 96 <ns0:lockscope> 97 <ns0:exclusive /> 98 </ns0:lockscope> 99 <ns0:locktype> 100 <ns0:write /> 101 </ns0:locktype> 102 <ns0:owner>user@example.com</ns0:owner> 103 </ns0:lockinfo> 104 """.replace("\n", "\r\n") 105 )
106
107 -class TestResponse(unittest.TestCase):
108 pass
109
110 -class TestResponseHeaders(unittest.TestCase):
111
112 - def test_OneHeader(self):
113 114 server = Session("www.example.com") 115 request = Lock(server, "/", headers.Depth0, Lock.eExclusive, "user@example.com", -1) 116 request.getResponseHeaders().update({ 117 "Lock-Token": ("<user@example.com>",), 118 }) 119 self.assertEqual(request.getLockToken(), "user@example.com")
120