Rev 3136: Fix the smart server failing test and use it against protocol combinations. in file:///v/home/vila/src/bzr/bugs/175524/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Dec 24 15:29:15 GMT 2007
At file:///v/home/vila/src/bzr/bugs/175524/
------------------------------------------------------------
revno: 3136
revision-id:v.ladeuil+lp at free.fr-20071224152910-mcym6zmmzt9x2es2
parent: v.ladeuil+lp at free.fr-20071224132930-on2606aabyvv5mjj
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 175524
timestamp: Mon 2007-12-24 16:29:10 +0100
message:
Fix the smart server failing test and use it against protocol combinations.
* bzrlib/tests/test_smart_transport.py:
(HTTPTunnellingSmokeTest): Some tests transferred to
test_http (including the previously failing one).
* bzrlib/tests/test_http.py:
(SmartHTTPTunnellingTest): Transferred from test_smart_tranport
since most of the infrastucture for parametrized test is available
here and some combinations were not tested.
* bzrlib/tests/http_utils.py:
(HTTPServerWithSmarts.__init__): Add the protocol_version
parameter.
modified:
bzrlib/tests/http_utils.py HTTPTestUtil.py-20050914180604-247d3aafb7a43343
bzrlib/tests/test_http.py testhttp.py-20051018020158-b2eef6e867c514d9
bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
-------------- next part --------------
=== modified file 'bzrlib/tests/http_utils.py'
--- a/bzrlib/tests/http_utils.py 2007-12-21 21:58:06 +0000
+++ b/bzrlib/tests/http_utils.py 2007-12-24 15:29:10 +0000
@@ -40,8 +40,9 @@
the HTTP server.
"""
- def __init__(self):
- http_server.HttpServer.__init__(self, SmartRequestHandler)
+ def __init__(self, protocol_version=None):
+ http_server.HttpServer.__init__(self, SmartRequestHandler,
+ protocol_version=protocol_version)
class SmartRequestHandler(http_server.TestingHTTPRequestHandler):
=== modified file 'bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py 2007-12-24 13:29:30 +0000
+++ b/bzrlib/tests/test_http.py 2007-12-24 15:29:10 +0000
@@ -46,7 +46,10 @@
http_server,
http_utils,
)
-from bzrlib.transport import http
+from bzrlib.transport import (
+ http,
+ remote,
+ )
from bzrlib.transport.http import (
_urllib,
_urllib2_wrappers,
@@ -120,7 +123,8 @@
# multiplied by one for each protocol version
tp_adapter = TransportProtocolAdapter()
- tp_classes= (TestDoCatchRedirections,
+ tp_classes= (SmartHTTPTunnellingTest,
+ TestDoCatchRedirections,
TestHTTPConnections,
TestHTTPRedirections,
TestHTTPSilentRedirections,
@@ -1413,3 +1417,90 @@
'pycurl < 7.16.0 does not handle empty proxy passwords')
super(TestProxyAuth, self).test_empty_pass()
+
+class SampleSocket(object):
+ """A socket-like object for use in testing the HTTP request handler."""
+
+ def __init__(self, socket_read_content):
+ """Constructs a sample socket.
+
+ :param socket_read_content: a byte sequence
+ """
+ # Use plain python StringIO so we can monkey-patch the close method to
+ # not discard the contents.
+ from StringIO import StringIO
+ self.readfile = StringIO(socket_read_content)
+ self.writefile = StringIO()
+ self.writefile.close = lambda: None
+
+ def makefile(self, mode='r', bufsize=None):
+ if 'r' in mode:
+ return self.readfile
+ else:
+ return self.writefile
+
+
+class SmartHTTPTunnellingTest(tests.TestCaseWithTransport):
+
+ def setUp(self):
+ super(SmartHTTPTunnellingTest, self).setUp()
+ # We use the VFS layer as part of HTTP tunnelling tests.
+ self._captureVar('BZR_NO_SMART_VFS', None)
+ self.transport_readonly_server = http_utils.HTTPServerWithSmarts
+
+ def create_transport_readonly_server(self):
+ return http_utils.HTTPServerWithSmarts(
+ protocol_version=self._protocol_version)
+
+ def test_bulk_data(self):
+ # We should be able to send and receive bulk data in a single message.
+ # The 'readv' command in the smart protocol both sends and receives
+ # bulk data, so we use that.
+ self.build_tree(['data-file'])
+ http_server = self.get_readonly_server()
+ http_transport = self._transport(http_server.get_url())
+ medium = http_transport.get_smart_medium()
+ # Since we provide the medium, the url below will be mostly ignored
+ # during the test, as long as the path is '/'.
+ remote_transport = remote.RemoteTransport('bzr://fake_host/',
+ medium=medium)
+ self.assertEqual(
+ [(0, "c")], list(remote_transport.readv("data-file", [(0,1)])))
+
+ def test_http_send_smart_request(self):
+
+ post_body = 'hello\n'
+ expected_reply_body = 'ok\x012\n'
+
+ http_server = self.get_readonly_server()
+ http_transport = self._transport(http_server.get_url())
+ medium = http_transport.get_smart_medium()
+ response = medium.send_http_smart_request(post_body)
+ reply_body = response.read()
+ self.assertEqual(expected_reply_body, reply_body)
+
+ def test_smart_http_server_post_request_handler(self):
+ httpd = self.get_readonly_server()._get_httpd()
+
+ socket = SampleSocket(
+ 'POST /.bzr/smart %s \r\n' % self._protocol_version
+ # HTTP/1.1 posts must have a Content-Length (but it doesn't hurt
+ # for 1.0)
+ + 'Content-Length: 6\r\n'
+ '\r\n'
+ 'hello\n')
+ # Beware: the ('localhost', 80) below is the
+ # client_address parameter, but we don't have one because
+ # we have defined a socket which is not bound to an
+ # address. The test framework never uses this client
+ # address, so far...
+ request_handler = http_utils.SmartRequestHandler(socket,
+ ('localhost', 80),
+ httpd)
+ response = socket.writefile.getvalue()
+ self.assertStartsWith(response, '%s 200 ' % self._protocol_version)
+ # This includes the end of the HTTP headers, and all the body.
+ expected_end_of_response = '\r\n\r\nok\x012\n'
+ self.assertEndsWith(response, expected_end_of_response)
+
+
=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py 2007-12-11 14:26:18 +0000
+++ b/bzrlib/tests/test_smart_transport.py 2007-12-24 15:29:10 +0000
@@ -2322,38 +2322,13 @@
return None
-class HTTPTunnellingSmokeTest(tests.TestCaseWithTransport):
-
+class HTTPTunnellingSmokeTest(tests.TestCase):
+
def setUp(self):
super(HTTPTunnellingSmokeTest, self).setUp()
# We use the VFS layer as part of HTTP tunnelling tests.
self._captureVar('BZR_NO_SMART_VFS', None)
- def _test_bulk_data(self, url_protocol):
- # We should be able to send and receive bulk data in a single message.
- # The 'readv' command in the smart protocol both sends and receives bulk
- # data, so we use that.
- self.build_tree(['data-file'])
- self.transport_readonly_server = HTTPServerWithSmarts
-
- http_transport = self.get_readonly_transport()
- medium = http_transport.get_smart_medium()
- # Since we provide the medium, the url below will be mostly ignored
- # during the test, as long as the path is '/'.
- remote_transport = remote.RemoteTransport('bzr://fake_host/',
- medium=medium)
- self.assertEqual(
- [(0, "c")], list(remote_transport.readv("data-file", [(0,1)])))
-
- def test_bulk_data_pycurl(self):
- try:
- self._test_bulk_data('http+pycurl')
- except errors.UnsupportedProtocol, e:
- raise tests.TestSkipped(str(e))
-
- def test_bulk_data_urllib(self):
- self._test_bulk_data('http+urllib')
-
def test_smart_http_medium_request_accept_bytes(self):
medium = FakeHTTPMedium()
request = SmartClientHTTPMediumRequest(medium)
@@ -2363,85 +2338,6 @@
request.finished_writing()
self.assertEqual('abcdef', medium.written_request)
- def _test_http_send_smart_request(self, url_protocol):
- http_server = HTTPServerWithSmarts()
- http_server._url_protocol = url_protocol
- http_server.setUp(self.get_vfs_only_server())
- self.addCleanup(http_server.tearDown)
-
- post_body = 'hello\n'
- expected_reply_body = 'ok\x012\n'
-
- http_transport = get_transport(http_server.get_url())
- medium = http_transport.get_smart_medium()
- response = medium.send_http_smart_request(post_body)
- reply_body = response.read()
- self.assertEqual(expected_reply_body, reply_body)
-
- def test_http_send_smart_request_pycurl(self):
- try:
- self._test_http_send_smart_request('http+pycurl')
- except errors.UnsupportedProtocol, e:
- raise tests.TestSkipped(str(e))
-
- def test_http_send_smart_request_urllib(self):
- self._test_http_send_smart_request('http+urllib')
-
- def test_http_server_with_smarts(self):
- self.transport_readonly_server = HTTPServerWithSmarts
-
- post_body = 'hello\n'
- expected_reply_body = 'ok\x012\n'
-
- smart_server_url = self.get_readonly_url('.bzr/smart')
- reply = urllib2.urlopen(smart_server_url, post_body).read()
-
- self.assertEqual(expected_reply_body, reply)
-
- def test_smart_http_server_post_request_handler(self):
- self.transport_readonly_server = HTTPServerWithSmarts
- httpd = self.get_readonly_server()._get_httpd()
-
- socket = SampleSocket(
- 'POST /.bzr/smart HTTP/1.0\r\n'
- # HTTP/1.0 posts must have a Content-Length.
- 'Content-Length: 6\r\n'
- '\r\n'
- 'hello\n')
- # Beware: the ('localhost', 80) below is the
- # client_address parameter, but we don't have one because
- # we have defined a socket which is not bound to an
- # address. The test framework never uses this client
- # address, so far...
- request_handler = SmartRequestHandler(socket, ('localhost', 80), httpd)
- response = socket.writefile.getvalue()
- self.assertStartsWith(response, 'HTTP/1.0 200 ')
- # This includes the end of the HTTP headers, and all the body.
- expected_end_of_response = '\r\n\r\nok\x012\n'
- self.assertEndsWith(response, expected_end_of_response)
-
-
-class SampleSocket(object):
- """A socket-like object for use in testing the HTTP request handler."""
-
- def __init__(self, socket_read_content):
- """Constructs a sample socket.
-
- :param socket_read_content: a byte sequence
- """
- # Use plain python StringIO so we can monkey-patch the close method to
- # not discard the contents.
- from StringIO import StringIO
- self.readfile = StringIO(socket_read_content)
- self.writefile = StringIO()
- self.writefile.close = lambda: None
-
- def makefile(self, mode='r', bufsize=None):
- if 'r' in mode:
- return self.readfile
- else:
- return self.writefile
-
class RemoteHTTPTransportTestCase(tests.TestCase):
More information about the bazaar-commits
mailing list