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

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

  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.ace import ACE 
 18  from xml.etree.ElementTree import XML 
 19  from caldavclientlibrary.protocol.webdav.definitions import davxml 
 20  from xml.etree.ElementTree import Element 
 21  from caldavclientlibrary.protocol.utils.xmlhelpers import BetterElementTree 
 22  from StringIO import StringIO 
 23   
 24  import unittest 
 25   
26 -class TestRequest(unittest.TestCase):
27
28 - def verifyXML(self, x, y=None):
29 30 x = x.replace("\n", "\r\n") 31 if y: 32 y = y.replace("\n", "\r\n") 33 34 # Parse the XML data 35 a = ACE() 36 a.parseACE(XML(x)) 37 38 # Generate the XML data 39 aclnode = Element(davxml.acl) 40 a.generateACE(aclnode) 41 os = StringIO() 42 xmldoc = BetterElementTree(aclnode.getchildren()[0]) 43 xmldoc.writeUTF8(os) 44 45 # Verify data 46 self.assertEqual(os.getvalue(), y if y else x)
47
48 - def test_XML1(self):
49 50 self.verifyXML("""<?xml version='1.0' encoding='utf-8'?> 51 <ns0:ace xmlns:ns0="DAV:"> 52 <ns0:principal> 53 <ns0:href>/principals/users/a</ns0:href> 54 </ns0:principal> 55 <ns0:grant> 56 <ns0:privilege> 57 <ns0:read /> 58 </ns0:privilege> 59 </ns0:grant> 60 </ns0:ace> 61 """)
62
63 - def test_XML2(self):
64 65 self.verifyXML("""<?xml version='1.0' encoding='utf-8'?> 66 <ns0:ace xmlns:ns0="DAV:"> 67 <ns0:principal> 68 <ns0:unauthenticated /> 69 </ns0:principal> 70 <ns0:deny> 71 <ns0:privilege> 72 <ns0:read /> 73 </ns0:privilege> 74 <ns0:privilege> 75 <ns0:write /> 76 </ns0:privilege> 77 </ns0:deny> 78 </ns0:ace> 79 """)
80
81 - def test_XML3(self):
82 83 self.verifyXML("""<?xml version='1.0' encoding='utf-8'?> 84 <ns0:ace xmlns:ns0="DAV:"> 85 <ns0:principal> 86 <ns0:href>/principals/users/a</ns0:href> 87 </ns0:principal> 88 <ns0:grant> 89 <ns0:privilege> 90 <ns0:read /> 91 </ns0:privilege> 92 </ns0:grant> 93 <ns0:protected /> 94 <ns0:inherited /> 95 </ns0:ace> 96 """)
97
98 - def test_XML4(self):
99 100 self.verifyXML("""<?xml version='1.0' encoding='utf-8'?> 101 <ns0:ace xmlns:ns0="DAV:"> 102 <ns0:invert> 103 <ns0:principal> 104 <ns0:self /> 105 </ns0:principal> 106 </ns0:invert> 107 <ns0:grant> 108 <ns0:privilege> 109 <ns0:read /> 110 </ns0:privilege> 111 </ns0:grant> 112 <ns0:protected /> 113 <ns0:inherited /> 114 </ns0:ace> 115 """)
116
117 - def test_XML5(self):
118 119 self.verifyXML("""<?xml version='1.0' encoding='utf-8'?> 120 <ns0:ace xmlns:ns0="DAV:"> 121 <ns0:principal> 122 <ns0:property> 123 <ns0:owner /> 124 </ns0:property> 125 </ns0:principal> 126 <ns0:grant> 127 <ns0:privilege> 128 <ns0:read /> 129 </ns0:privilege> 130 </ns0:grant> 131 </ns0:ace> 132 """)
133