~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/http_utils.py

(spiv) Fix a regression in bzr+http:// where http wasn't implementing
        a necessary function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from bzrlib import (
29
29
    errors,
30
30
    tests,
31
 
    transport,
32
31
    )
33
32
from bzrlib.smart import medium, protocol
34
33
from bzrlib.tests import http_server
 
34
from bzrlib.transport import (
 
35
    chroot,
 
36
    get_transport,
 
37
    )
35
38
 
36
39
 
37
40
class HTTPServerWithSmarts(http_server.HttpServer):
46
49
 
47
50
 
48
51
class SmartRequestHandler(http_server.TestingHTTPRequestHandler):
49
 
    """Extend TestingHTTPRequestHandler to support smart client POSTs."""
 
52
    """Extend TestingHTTPRequestHandler to support smart client POSTs.
 
53
    
 
54
    XXX: This duplicates a fair bit of the logic in bzrlib.transport.http.wsgi.
 
55
    """
50
56
 
51
57
    def do_POST(self):
52
58
        """Hand the request off to a smart server instance."""
 
59
        backing = get_transport(self.server.test_case_server._home_dir)
 
60
        chroot_server = chroot.ChrootServer(backing)
 
61
        chroot_server.setUp()
 
62
        try:
 
63
            t = get_transport(chroot_server.get_url())
 
64
            self.do_POST_inner(t)
 
65
        finally:
 
66
            chroot_server.tearDown()
 
67
 
 
68
    def do_POST_inner(self, chrooted_transport):
53
69
        self.send_response(200)
54
70
        self.send_header("Content-type", "application/octet-stream")
55
 
        t = transport.get_transport(self.server.test_case_server._home_dir)
 
71
        if not self.path.endswith('.bzr/smart'):
 
72
            raise AssertionError(
 
73
                'POST to path not ending in .bzr/smart: %r' % (self.path,))
 
74
        t = chrooted_transport.clone(self.path[:-len('.bzr/smart')])
56
75
        # if this fails, we should return 400 bad request, but failure is
57
76
        # failure for now - RBC 20060919
58
77
        data_length = int(self.headers['Content-Length'])