/mirrors/bzr.webdav

To get this branch, use:
bzr branch bzr+ssh://bazaar.launchpad.net/+branch/bzr.webdav/

« back to all changes in this revision

Viewing changes to tests/dav_server.py

  • Committer: Vincent Ladeuil
  • Date: 2013-08-10 14:20:13 UTC
  • mfrom: (74.1.5 bzr-webdav)
  • Revision ID: v.ladeuil+lp@free.fr-20130810142013-puu3icldhuz891l4
Merge fixes from Reagan Sanders

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2011 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2011, 2013 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
23
23
 
24
24
import errno
25
25
import os
26
 
import os.path # FIXME: Can't we use bzrlib.osutils ?
27
26
import re
28
27
import shutil # FIXME: Can't we use bzrlib.osutils ?
29
28
import stat
32
31
 
33
32
 
34
33
from bzrlib import (
35
 
    tests,
36
34
    trace,
37
35
    urlutils,
38
36
    )
50
48
    _RANGE_HEADER_RE = re.compile(
51
49
        r'bytes (?P<begin>\d+)-(?P<end>\d+)/(?P<size>\d+|\*)')
52
50
 
 
51
    delete_success_code = 204
 
52
    move_default_overwrite = True
 
53
 
53
54
 
54
55
    def date_time_string(self, timestamp=None):
55
56
        """Return the current date and time formatted for a message header."""
281
282
                # Ok we fail for an unnkown reason :-/
282
283
                raise
283
284
        else:
284
 
            self.send_response(204) # Default success code
 
285
            self.send_response(self.delete_success_code)
285
286
            self.end_headers()
286
287
 
287
288
    def do_MOVE(self):
292
293
            self.send_error(400, "Destination header missing")
293
294
            return
294
295
        overwrite_header = self.headers.get('Overwrite')
 
296
        should_overwrite = self.move_default_overwrite
295
297
        if overwrite_header == 'F':
296
298
            should_overwrite = False
297
 
        else:
 
299
        elif overwrite_header == 'T':
298
300
            should_overwrite = True
299
301
        (scheme, netloc, rel_to,
300
302
         params, query, fragment) = urlparse.urlparse(url_to)
303
305
                                                               rel_to))
304
306
        abs_from = self.translate_path(self.path)
305
307
        abs_to = self.translate_path(rel_to)
306
 
        if should_overwrite is False and os.access(abs_to, os.F_OK):
 
308
        if not should_overwrite and os.access(abs_to, os.F_OK):
307
309
            self.send_error(412, "Precondition Failed")
308
310
            return
309
311
        try:
394
396
            self.send_error(400, "Bad Depth")
395
397
            return
396
398
 
397
 
        path = self.translate_path(self.path)
398
399
        # Don't bother parsing the body, we handle only allprop anyway.
399
400
        # FIXME: Handle the body :)
400
 
        data = self.read_body()
 
401
        self.read_body()
401
402
 
402
403
        try:
403
404
            response, st = self._generate_response(self.path)
425
426
        self.end_headers()
426
427
        self.wfile.write(response)
427
428
 
 
429
 
428
430
class DAVServer(http_server.HttpServer):
429
431
    """Subclass of HttpServer that gives http+webdav urls.
430
432
 
441
443
    _url_protocol = 'http+webdav'
442
444
 
443
445
 
444
 
class TestCaseWithDAVServer(tests.TestCaseWithTransport):
445
 
    """A support class that provides urls that are http+webdav://.
446
 
 
447
 
    This is done by forcing the server to be an http DAV one.
448
 
    """
449
 
    def setUp(self):
450
 
        super(TestCaseWithDAVServer, self).setUp()
451
 
        self.transport_server = DAVServer
 
446
class QuirkyTestingDAVRequestHandler(TestingDAVRequestHandler):
 
447
    """Various quirky/slightly off-spec behaviors.
 
448
 
 
449
    Used to test how gracefully we handle them.
 
450
    """
 
451
 
 
452
    delete_success_code = 200
 
453
    move_default_overwrite = False
 
454
 
 
455
 
 
456
class QuirkyDAVServer(http_server.HttpServer):
 
457
    """DAVServer implementing various quirky/slightly off-spec behaviors.
 
458
 
 
459
    Used to test how gracefully we handle them.
 
460
    """
 
461
 
 
462
    def __init__(self):
 
463
        # We    have   special    requests    to   handle    that
 
464
        # HttpServer_urllib doesn't know about
 
465
        super(QuirkyDAVServer,self).__init__(QuirkyTestingDAVRequestHandler)
 
466
 
 
467
    # urls returned by this server should require the webdav client impl
 
468
    _url_protocol = 'http+webdav'
452
469