<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[2235] CalendarServer/branches/users/wsanchez/twisted-update/twistedcaldav/
 test/test_root.py</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.macosforge.org/projects/calendarserver/changeset/2235">2235</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2008-03-17 18:14:02 -0700 (Mon, 17 Mar 2008)</dd>
</dl>

<h3>Log Message</h3>
<pre>cosmetic</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserswsancheztwistedupdatetwistedcaldavtesttest_rootpy">CalendarServer/branches/users/wsanchez/twisted-update/twistedcaldav/test/test_root.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserswsancheztwistedupdatetwistedcaldavtesttest_rootpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/wsanchez/twisted-update/twistedcaldav/test/test_root.py (2234 => 2235)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/wsanchez/twisted-update/twistedcaldav/test/test_root.py        2008-03-18 00:23:54 UTC (rev 2234)
+++ CalendarServer/branches/users/wsanchez/twisted-update/twistedcaldav/test/test_root.py        2008-03-18 01:14:02 UTC (rev 2235)
</span><span class="lines">@@ -58,24 +58,23 @@
</span><span class="cx">         return self._docroot
</span><span class="cx"> 
</span><span class="cx">     def setUp(self):
</span><del>-        RootResource.CheckSACL = FakeCheckSACL(sacls={
-                'calendar': ['dreid']})
</del><ins>+        RootResource.CheckSACL = FakeCheckSACL(sacls={&quot;calendar&quot;: [&quot;dreid&quot;]})
</ins><span class="cx"> 
</span><span class="cx">         directory = XMLDirectoryService(xmlFile)
</span><span class="cx"> 
</span><span class="cx">         principals = DirectoryPrincipalProvisioningResource(
</span><del>-            os.path.join(self.docroot, 'principals'),
-            '/principals/',
-            directory)
</del><ins>+            os.path.join(self.docroot, &quot;principals&quot;),
+            &quot;/principals/&quot;,
+            directory
+        )
</ins><span class="cx"> 
</span><span class="cx">         # Otherwise the tests that never touch the root resource will 
</span><span class="cx">         # fail on teardown.
</span><span class="cx">         principals.provision()
</span><span class="cx"> 
</span><del>-        root = RootResource(self.docroot, 
-                            principalCollections=[principals])
</del><ins>+        root = RootResource(self.docroot, principalCollections=[principals])
</ins><span class="cx"> 
</span><del>-        root.putChild('principals',
</del><ins>+        root.putChild(&quot;principals&quot;,
</ins><span class="cx">                       principals)
</span><span class="cx"> 
</span><span class="cx">         portal = Portal(auth.DavRealm())
</span><span class="lines">@@ -92,24 +91,20 @@
</span><span class="cx">     def test_noSacls(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Test the behaviour of locateChild when SACLs are not enabled.
</span><del>-        
-        should return a valid resource
</del><ins>+        Should return a valid resource.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         self.root.resource.useSacls = False
</span><span class="cx"> 
</span><del>-        request = SimpleRequest(self.site,
-                                &quot;GET&quot;,
-                                &quot;/principals/&quot;)
</del><ins>+        request = SimpleRequest(self.site, &quot;GET&quot;, &quot;/principals/&quot;)
</ins><span class="cx"> 
</span><del>-        resrc, segments = self.root.locateChild(request,
-                                         ['principals'])
</del><ins>+        resrc, segments = self.root.locateChild(request, [&quot;principals&quot;])
</ins><span class="cx"> 
</span><del>-        resrc, segments = resrc.locateChild(request, ['principals'])
</del><ins>+        resrc, segments = resrc.locateChild(request, [&quot;principals&quot;])
</ins><span class="cx"> 
</span><span class="cx">         self.failUnless(
</span><del>-            isinstance(resrc,
-                       DirectoryPrincipalProvisioningResource),
-            &quot;Did not get a DirectoryPrincipalProvisioningResource: %s&quot; % (resrc,))
</del><ins>+            isinstance(resrc, DirectoryPrincipalProvisioningResource),
+            &quot;Did not get a DirectoryPrincipalProvisioningResource: %s&quot; % (resrc,)
+        )
</ins><span class="cx"> 
</span><span class="cx">         self.assertEquals(segments, [])
</span><span class="cx"> 
</span><span class="lines">@@ -127,35 +122,34 @@
</span><span class="cx">             &quot;GET&quot;,
</span><span class="cx">             &quot;/principals/&quot;,
</span><span class="cx">             headers=http_headers.Headers({
</span><del>-                    'Authorization': ['basic', '%s' % (
-                            'dreid:dierd'.encode('base64'),)]}))
-        
-        resrc, segments = self.root.locateChild(request,
-                                         ['principals'])
</del><ins>+                &quot;Authorization&quot;: [&quot;basic&quot;, &quot;%s&quot; % (&quot;dreid:dierd&quot;.encode(&quot;base64&quot;),)]
+            })
+        )
</ins><span class="cx"> 
</span><del>-        def _Cb((resrc, segments)):
-            self.failUnless(
-                isinstance(resrc,
-                           DirectoryPrincipalProvisioningResource),
-                &quot;Did not get a DirectoryPrincipalProvisioningResource: %s&quot; % (resrc,))
</del><ins>+        resrc, segments = self.root.locateChild(request, [&quot;principals&quot;])
</ins><span class="cx"> 
</span><ins>+        def gotChild((resrc, segments)):
+            self.failUnless(
+                isinstance(resrc, DirectoryPrincipalProvisioningResource),
+                &quot;Did not get a DirectoryPrincipalProvisioningResource: %s&quot; % (resrc,)
+            )
</ins><span class="cx">             self.assertEquals(segments, [])
</span><del>-
-            self.assertEquals(request.authzUser, 
-                              davxml.Principal(
-                    davxml.HRef('/principals/__uids__/5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1/')))
</del><ins>+            self.assertEquals(
+                request.authzUser, 
+                davxml.Principal(
+                    davxml.HRef(&quot;/principals/__uids__/5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1/&quot;)
+                )
+            )
</ins><span class="cx">             
</span><del>-        d = defer.maybeDeferred(resrc.locateChild, request, ['principals'])
-        d.addCallback(_Cb)
-
</del><ins>+        d = defer.maybeDeferred(resrc.locateChild, request, [&quot;principals&quot;])
+        d.addCallback(gotChild)
</ins><span class="cx">         return d
</span><span class="cx"> 
</span><span class="cx">     def test_notInSacls(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Test the behavior of locateChild when SACLs are enabled and the
</span><del>-        user is not in the SACL group
-        
-        should return a 403 forbidden response
</del><ins>+        user is not in the SACL group.
+        Should return a 403 forbidden response.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         self.root.resource.useSacls = True
</span><span class="cx"> 
</span><span class="lines">@@ -164,50 +158,43 @@
</span><span class="cx">             &quot;GET&quot;,
</span><span class="cx">             &quot;/principals/&quot;,
</span><span class="cx">             headers=http_headers.Headers({
</span><del>-                    'Authorization': ['basic', '%s' % (
-                            'wsanchez:zehcnasw'.encode('base64'),)]}))
</del><ins>+                &quot;Authorization&quot;: [&quot;basic&quot;, &quot;%s&quot; % (&quot;wsanchez:zehcnasw&quot;.encode(&quot;base64&quot;),)]
+            })
+        )
</ins><span class="cx">         
</span><del>-        resrc, segments = self.root.locateChild(request,
-                                         ['principals'])
</del><ins>+        resrc, segments = self.root.locateChild(request, [&quot;principals&quot;])
</ins><span class="cx"> 
</span><del>-        def _Eb(failure):
</del><ins>+        def onError(failure):
</ins><span class="cx">             failure.trap(HTTPError)
</span><span class="cx">             self.assertEquals(failure.value.response.code, 403)
</span><span class="cx">             
</span><del>-        d = defer.maybeDeferred(resrc.locateChild, request, ['principals'])
-        d.addErrback(_Eb)
</del><ins>+        d = defer.maybeDeferred(resrc.locateChild, request, [&quot;principals&quot;])
+        d.addErrback(onError)
</ins><span class="cx"> 
</span><span class="cx">         return d
</span><span class="cx"> 
</span><span class="cx">     def test_unauthenticated(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Test the behavior of locateChild when SACLs are enabled and the request
</span><del>-        is unauthenticated
-        
-        should return a 401 UnauthorizedResponse
</del><ins>+        is unauthenticated.
+        Should return a 401 UnauthorizedResponse.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         self.root.resource.useSacls = True
</span><del>-        request = SimpleRequest(self.site,
-                                &quot;GET&quot;,
-                                &quot;/principals/&quot;)
</del><ins>+        request = SimpleRequest(self.site, &quot;GET&quot;, &quot;/principals/&quot;)
</ins><span class="cx"> 
</span><del>-        resrc, segments = self.root.locateChild(request,
-                                                ['principals'])
</del><ins>+        resrc, segments = self.root.locateChild(request, [&quot;principals&quot;])
</ins><span class="cx"> 
</span><del>-        def _Cb(result):
-            raise AssertionError((&quot;RootResource.locateChild did not return &quot;
-                                  &quot;an error&quot;))
</del><ins>+        def gotChild(child):
+            raise AssertionError(&quot;RootResource.locateChild did not return an error&quot;)
</ins><span class="cx"> 
</span><del>-        def _Eb(failure):
</del><ins>+        def onError(failure):
</ins><span class="cx">             failure.trap(HTTPError)
</span><span class="cx">             self.assertEquals(failure.value.response.code, 401)
</span><span class="cx"> 
</span><del>-        d = defer.maybeDeferred(resrc.locateChild, request, ['principals'])
-
-        d.addCallback(_Cb)
-        d.addErrback(_Eb)
-
</del><ins>+        d = defer.maybeDeferred(resrc.locateChild, request, [&quot;principals&quot;])
+        d.addCallback(gotChild)
+        d.addErrback(onError)
</ins><span class="cx">         return d
</span><span class="cx"> 
</span><span class="cx">     def test_badCredentials(self):
</span><span class="lines">@@ -224,19 +211,18 @@
</span><span class="cx">             &quot;GET&quot;,
</span><span class="cx">             &quot;/principals/&quot;,
</span><span class="cx">             headers=http_headers.Headers({
</span><del>-                    'Authorization': ['basic', '%s' % (
-                            'dreid:dreid'.encode('base64'),)]}))
</del><ins>+                &quot;Authorization&quot;: [&quot;basic&quot;, &quot;%s&quot; % (&quot;dreid:dreid&quot;.encode(&quot;base64&quot;),)]
+            })
+        )
</ins><span class="cx">         
</span><del>-        resrc, segments = self.root.locateChild(request,
-                                         ['principals'])
</del><ins>+        resrc, segments = self.root.locateChild(request, [&quot;principals&quot;])
</ins><span class="cx"> 
</span><del>-        def _Eb(failure):
</del><ins>+        def onError(failure):
</ins><span class="cx">             failure.trap(HTTPError)
</span><span class="cx">             self.assertEquals(failure.value.response.code, 401)
</span><span class="cx">             
</span><del>-        d = defer.maybeDeferred(resrc.locateChild, request, ['principals'])
-        d.addErrback(_Eb)
-
</del><ins>+        d = defer.maybeDeferred(resrc.locateChild, request, [&quot;principals&quot;])
+        d.addErrback(onError)
</ins><span class="cx">         return d
</span><span class="cx"> 
</span><span class="cx">     def test_DELETE(self):
</span></span></pre>
</div>
</div>

</body>
</html>