Rev 53: Fix more failing tests. in http://bazaar.launchpad.net/%7Ebzr/bzr.webdav/webdav
Vincent Ladeuil
v.ladeuil+lp at free.fr
Sun Jun 8 22:48:25 BST 2008
At http://bazaar.launchpad.net/%7Ebzr/bzr.webdav/webdav
------------------------------------------------------------
revno: 53
revision-id: v.ladeuil+lp at free.fr-20080608214822-eu52arzzoah6qz57
parent: v.ladeuil+lp at free.fr-20080608210605-qxz1v5ryh9l7n0qw
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: webdav
timestamp: Sun 2008-06-08 23:48:22 +0200
message:
Fix more failing tests.
* webdav.py:
(DavStatHandler.endElement): Recognize directories via the
collection property.
(_extract_stat_info): Don't guess directories anymore (the guess
was wrong for some cases anyway).
(_extract_dir_content): Raise NotADirectory when needed.
(HttpDavTransport.delete): Finally getting rid of the horrible
workaround.
(HttpDavTransport.rmdir): Detect non-empty directories.
* test_webdav.py:
(TestingDAVRequestHandler.do_DELETE): Finally ! One FIXME less.
(TestDavSaxParser.test_list_dir_incomplete_format_response,
TestDavSaxParser.test_list_dir_apache2_example,
TestDavSaxParser.test_list_dir_lighttpd_example): Update tests, we
have more requirements now.
modified:
test_webdav.py test_webdav.py-20060823130244-qvg4wqdodnmf5nhs-1
webdav.py webdav.py-20060816232542-enpjxth2743ttqpq-3
-------------- next part --------------
=== modified file 'test_webdav.py'
--- a/test_webdav.py 2008-06-08 21:06:05 +0000
+++ b/test_webdav.py 2008-06-08 21:48:22 +0000
@@ -284,13 +284,6 @@
except (IOError, OSError),e:
if e.errno in (errno.ENOENT, ):
self.send_error(404, "File not found")
- elif e.errno in (errno.ENOTEMPTY, ):
- # FIXME: Really gray area, we are not supposed to
- # fail here :-/ If we act as a conforming DAV
- # server we should delete the directory content,
- # but bzr may want to test that we don't. So, as
- # we want to conform to bzr, we don't.
- self.send_error(999, "Directory not empty")
else:
# Ok we fail for an unnkown reason :-/
raise
@@ -612,12 +605,7 @@
self._extract_dir_content_from_str, example)
def test_list_dir_incomplete_format_response(self):
- # The minimal information is present but doesn't conform to RFC 2518
- # (well, as I understand it since the reference servers disagree on
- # more than details).
-
- # The last href below is not enclosed in a response element and is
- # therefore ignored.
+ # The information we need is not present
example = """<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:" xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/">
<D:response>
@@ -628,12 +616,13 @@
</D:response>
<D:href>http://localhost/toto</D:href>
</D:multistatus>"""
- self.assertEqual(['titi'], self._extract_dir_content_from_str(example))
+ self.assertRaises(errors.NotADirectory,
+ self._extract_dir_content_from_str, example)
def test_list_dir_apache2_example(self):
example = _get_list_dir_apache2_depth_1_prop()
- self.assertEqual(['a', 'b', 'c'],
- self._extract_dir_content_from_str(example))
+ self.assertRaises(errors.NotADirectory,
+ self._extract_dir_content_from_str, example)
def test_list_dir_lighttpd_example(self):
example = """<?xml version="1.0" encoding="utf-8"?>
@@ -648,8 +637,8 @@
<D:href>http://localhost/toto</D:href>
</D:response>
</D:multistatus>"""
- self.assertEqual(['titi', 'toto'],
- self._extract_dir_content_from_str(example))
+ self.assertRaises(errors.NotADirectory,
+ self._extract_dir_content_from_str, example)
def test_stat_malformed_response(self):
# Invalid xml, neither multistatus nor response are properly closed
=== modified file 'webdav.py'
--- a/webdav.py 2008-06-08 21:06:05 +0000
+++ b/webdav.py 2008-06-08 21:48:22 +0000
@@ -162,15 +162,21 @@
- a prop element containing at least (other are ignored)
- a getcontentlength element (for files only)
- an executable element (for files only)
+ - a resourcetype element containing
+ - a collection element (for directories only)
"""
def __init__(self):
DavResponseHandler.__init__(self)
- self.href = None
- self.length = None
- self.executable = None
# Flags defining the context for the actions
self._response_seen = False
+ self._init_response_attrs()
+
+ def _init_response_attrs(self):
+ self.href = None
+ self.length = None
+ self.executable = None
+ self.is_dir = False
def _validate_handling(self):
if self.href is not None:
@@ -191,6 +197,8 @@
self.length = self.chars
elif self._executable_end():
self.executable = self.chars
+ elif self._collection_end():
+ self.is_dir = True
if self._strip_ns(name) == 'response':
self._response_seen = True
@@ -234,6 +242,16 @@
and stack[3] == 'prop'
and stack[4] == 'executable')
+ def _collection_end(self):
+ stack = self.elt_stack
+ return (len(stack) == 6
+ and stack[0] == 'multistatus'
+ and stack[1] == 'response'
+ and stack[2] == 'propstat'
+ and stack[3] == 'prop'
+ and stack[4] == 'resourcetype'
+ and stack[5] == 'collection')
+
class _DAVStat(object):
"""The stat info as it can be acquired with DAV."""
@@ -270,16 +288,13 @@
except xml.sax.SAXParseException, e:
raise errors.InvalidHttpResponse(
url, msg='Malformed xml response: %s' % e)
- is_dir = (handler.href is not None
- and handler.length is None
- and handler.executable is None)
- if is_dir:
+ if handler.is_dir:
size = None # directory sizes are meaningless for bzr
is_exec = True
else:
size = int(handler.length)
is_exec = (handler.executable == 'T')
- return _DAVStat(size, is_dir, is_exec)
+ return _DAVStat(size, handler.is_dir, is_exec)
class DavListDirHandler(DavStatHandler):
@@ -293,7 +308,11 @@
self.expected_content_handled = True
def _make_response_tuple(self):
- return (self.href, self.length, self.executable)
+ if self.executable == 'T':
+ is_exec = True
+ else:
+ is_exec = False
+ return (self.href, self.is_dir, self.length, is_exec)
def _response_handled(self):
"""A response element inside a multistatus have been parsed."""
@@ -301,9 +320,7 @@
self.dir_content = []
self.dir_content.append(self._make_response_tuple())
# Resest the attributes for the next response if any
- self.href = None
- self.length = None
- self.executable = None
+ self._init_response_attrs()
def _additional_response_starting(self, name):
"""A additional response element inside a multistatus begins."""
@@ -328,11 +345,13 @@
url, msg='Malformed xml response: %s' % e)
# Reformat for bzr needs
dir_content = handler.dir_content
- dir = dir_content[0][0]
- dir_len = len(dir)
+ (dir_name, is_dir) = dir_content[0][:2]
+ if not is_dir:
+ raise errors.NotADirectory(url)
+ dir_len = len(dir_name)
elements = []
- for (href, size, is_exec) in dir_content[1:]: # Ignore first element
- if href.startswith(dir):
+ for (href, is_dir, size, is_exec) in dir_content[1:]: # Ignore first element
+ if href.startswith(dir_name):
name = href[dir_len:]
if name.endswith('/'):
# Get rid of final '/'
@@ -690,13 +709,6 @@
code = response.code
if code == 404:
raise errors.NoSuchFile(abs_path)
- # FIXME: This is an hoooooorible workaround to pass the
- # tests, what we really should do is test that the
- # directory is not empty *because bzr do not want to
- # remove non-empty dirs*.
- # Which requires implementing list_dir, hi Robert ;)
- if code == 999:
- raise errors.DirectoryNotEmpty(abs_path)
if code != 204:
self._raise_curl_http_error(curl, 'unable to delete')
@@ -779,7 +791,10 @@
def rmdir(self, relpath):
"""See Transport.rmdir."""
- self.delete(relpath) # That was easy thanks DAV
+ content = self.list_dir(relpath)
+ if len(content) > 0:
+ raise errors.DirectoryNotEmpty(self._remote_path(relpath))
+ self.delete(relpath)
def stat(self, relpath):
"""See Transport.stat.
More information about the bazaar-commits
mailing list