Rev 54: All bzr tests passing with an apache2-dav local test server. in http://bazaar.launchpad.net/%7Ebzr/bzr.webdav/webdav

Vincent Ladeuil v.ladeuil+lp at free.fr
Sun Jun 8 23:35:45 BST 2008


At http://bazaar.launchpad.net/%7Ebzr/bzr.webdav/webdav

------------------------------------------------------------
revno: 54
revision-id: v.ladeuil+lp at free.fr-20080608223542-c47y2fmxuj9jngyy
parent: v.ladeuil+lp at free.fr-20080608214822-eu52arzzoah6qz57
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: webdav
timestamp: Mon 2008-06-09 00:35:42 +0200
message:
  All bzr tests passing with an apache2-dav local test server.
  
  * test_webdav.py:
  (_get_list_dir_apache2_depth_1_allprop): Tweak the the example by
  putting non-zero lengths.
  (TestDavSaxParser.test_list_dir_apache2_dir_depth_1_example):
  <cough> add the forgotten test, we need to test for correct
  behaviour and we re-factored two commits ago to do that don't we ?
  (TestDavSaxParser.test_stat_apache2_dir_depth_0_example): Update
  test '-1' for directory size is as good as None.
  
  * webdav.py:
  (DavStatHandler._init_response_attrs): Use '-1' for default length
  value instead of None.
  (DavStatHandler.endElement): Convert the length to int.
  (_extract_dir_content): Return the full tuple instead of just the
  name.
  (HttpDavTransport.list_dir): Delegate to _list_tree and filter the
  result.
  (HttpDavTransport._list_tree): Was list_dir but now accept an
  additional depth parameter.
  (HttpDavTransport.iter_files_recursive): New function.
modified:
  NOTES                          notes-20060816232542-enpjxth2743ttqpq-1
  test_webdav.py                 test_webdav.py-20060823130244-qvg4wqdodnmf5nhs-1
  webdav.py                      webdav.py-20060816232542-enpjxth2743ttqpq-3
-------------- next part --------------
=== modified file 'NOTES'
--- a/NOTES	2008-06-04 19:52:25 +0000
+++ b/NOTES	2008-06-08 22:35:42 +0000
@@ -10,23 +10,10 @@
 user	1m15.280s
 sys	0m20.060s
 
+The above measure is imprecise and certainly out-of-date.
 
 Tests:
 
-The plugin pass the bzr selftest except for:
-
-- lock_write: We  can implement  that, but it  seems it  has been
-  abandoned in the existing code already in favor of a global lock
-  valid for all transports.
-
-- test_rmdir_not_empty: We have cheated there. That's bad.
-
-Extensions:
-
-- Looking  at Apache  sources  it appears  that  PATCH have  been
-  introduced  in  Apache 1.3.4,  but  only  the  request name  is
-  reserved, there is no code to implement it.
-
 Installation example:
 
 <IfModule mod_dav.c>
@@ -38,10 +25,18 @@
 	# bzr (to they the least) and provide no benefits in our
 	# case. So just turn it off.
 	DirectorySlash Off
+        # We need to activate the following which is off by
+        # default. For good security reasons which don't apply to
+        # bzr directories ;)
+        DavDepthInfinity on
+        # The simplest auth scheme is basic, just given as an
+        # example, using https is recommanded with it, or at
+        # least digest if https is not possible.
 	AuthType Basic
 	AuthName bzr
 	AuthUserFile /etc/apache2/dav.users
 	<LimitExcept GET OPTIONS>
+                # Write access requires authentication
 		Require valid-user
 	</LimitExcept>
 </Directory>

=== modified file 'test_webdav.py'
--- a/test_webdav.py	2008-06-08 21:48:22 +0000
+++ b/test_webdav.py	2008-06-08 22:35:42 +0000
@@ -483,7 +483,7 @@
             <D:prop>
                 <lp1:resourcetype/>
                 <lp1:creationdate>2008-06-08T09:50:15Z</lp1:creationdate>
-                <lp1:getcontentlength>0</lp1:getcontentlength>
+                <lp1:getcontentlength>14</lp1:getcontentlength>
                 <lp1:getlastmodified>Sun, 08 Jun 2008 09:50:11 GMT</lp1:getlastmodified>
                 <lp1:getetag>"da9f81-0-9ef33ac0"</lp1:getetag>
                 <lp2:executable>T</lp2:executable>
@@ -508,7 +508,7 @@
             <D:prop>
                 <lp1:resourcetype/>
                 <lp1:creationdate>2008-06-08T09:50:11Z</lp1:creationdate>
-                <lp1:getcontentlength>0</lp1:getcontentlength>
+                <lp1:getcontentlength>42</lp1:getcontentlength>
                 <lp1:getlastmodified>Sun, 08 Jun 2008 09:50:11 GMT</lp1:getlastmodified>
                 <lp1:getetag>"da9f80-0-9ef33ac0"</lp1:getetag>
                 <lp2:executable>F</lp2:executable>
@@ -640,6 +640,14 @@
         self.assertRaises(errors.NotADirectory,
                          self._extract_dir_content_from_str, example)
 
+    def test_list_dir_apache2_dir_depth_1_example(self):
+        example = _get_list_dir_apache2_depth_1_allprop()
+        self.assertEquals([('executable', False, 14, True),
+                           ('read-only', False, 42, False),
+                           ('titi', False, 6, False),
+                           ('toto', True, -1, False)],
+                          self._extract_dir_content_from_str(example))
+
     def test_stat_malformed_response(self):
         # Invalid xml, neither multistatus nor response are properly closed
         example = """<?xml version="1.0" encoding="utf-8"?>
@@ -732,6 +740,6 @@
 </D:multistatus>
 """
         st = self._extract_stat_from_str(example)
-        self.assertEquals(None, st.st_size)
+        self.assertEquals(-1, st.st_size)
         self.assertTrue(stat.S_ISDIR(st.st_mode))
         self.assertTrue(st.st_mode & stat.S_IXUSR)

=== modified file 'webdav.py'
--- a/webdav.py	2008-06-08 21:48:22 +0000
+++ b/webdav.py	2008-06-08 22:35:42 +0000
@@ -174,7 +174,7 @@
 
     def _init_response_attrs(self):
         self.href = None
-        self.length = None
+        self.length = -1
         self.executable = None
         self.is_dir = False
 
@@ -194,7 +194,7 @@
         if self._href_end():
             self.href = self.chars
         elif self._getcontentlength_end():
-            self.length = self.chars
+            self.length = int(self.chars)
         elif self._executable_end():
             self.executable = self.chars
         elif self._collection_end():
@@ -289,10 +289,10 @@
         raise errors.InvalidHttpResponse(
             url, msg='Malformed xml response: %s' % e)
     if handler.is_dir:
-        size = None # directory sizes are meaningless for bzr
+        size = -1 # directory sizes are meaningless for bzr
         is_exec = True
     else:
-        size = int(handler.length)
+        size = handler.length
         is_exec = (handler.executable == 'T')
     return _DAVStat(size, handler.is_dir, is_exec)
 
@@ -358,7 +358,7 @@
                 name = name[0:-1]
             # We receive already url-encoded strings so down-casting is
             # safe. And bzr insists on getting strings not unicode strings.
-            elements.append(str(name))
+            elements.append((str(name), is_dir, size, is_exec))
     return elements
 
 
@@ -754,6 +754,9 @@
         """
         Return a list of all files at the given location.
         """
+        return [elt[0] for elt in self._list_tree(relpath, 1)]
+
+    def _list_tree(self, relpath, depth):
         abspath = self._remote_path(relpath)
         propfind = """<?xml version="1.0" encoding="utf-8" ?>
    <D:propfind xmlns:D="DAV:">
@@ -761,7 +764,7 @@
    </D:propfind>
 """
         request = _urllib2_wrappers.Request('PROPFIND', abspath, propfind,
-                                            {'Depth': 1},
+                                            {'Depth': depth},
                                             accepted_errors=[207, 404, 409,])
         response = self._perform(request)
 
@@ -823,6 +826,15 @@
                                    'unable to list  %r directory' % (abspath))
         return _extract_stat_info(abspath, response)
 
+    def iter_files_recursive(self):
+        """Walk the relative paths of all files in this transport."""
+        # We get the whole tree with a single request
+        tree = self._list_tree('.', 'Infinity')
+        # Now filter out the directories
+        for (name, is_dir, size, is_exex) in tree:
+            if not is_dir:
+                yield name
+
     # TODO: Before
     # www.ietf.org/internet-drafts/draft-suma-append-patch-00.txt
     # becomes  a real  RFC and  gets implemented,  we can  try to



More information about the bazaar-commits mailing list