Rev 3108: Add test. in file:///v/home/vila/src/bzr/bugs/175886/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu Dec 13 15:40:47 GMT 2007
At file:///v/home/vila/src/bzr/bugs/175886/
------------------------------------------------------------
revno: 3108
revision-id:v.ladeuil+lp at free.fr-20071213154042-77h01zei40qptsuv
parent: v.ladeuil+lp at free.fr-20071212210605-utjudvizj5v9qotc
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 175886
timestamp: Thu 2007-12-13 16:40:42 +0100
message:
Add test.
* bzrlib/transport/http/_urllib2_wrappers.py :
Some cleanup.
* bzrlib/tests/test_http_response.py:
(TestHTTPConnection): Test the warning emission.
modified:
bzrlib/tests/test_http_response.py test_http_response.py-20060628233143-950b2a482a32505d
bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
-------------- next part --------------
=== modified file 'bzrlib/tests/test_http_response.py'
--- a/bzrlib/tests/test_http_response.py 2007-12-10 10:41:24 +0000
+++ b/bzrlib/tests/test_http_response.py 2007-12-13 15:40:42 +0000
@@ -44,7 +44,56 @@
errors,
tests,
)
-from bzrlib.transport.http import response
+from bzrlib.transport.http import (
+ response,
+ _urllib2_wrappers,
+ )
+
+
+class ReadSocket(object):
+ """A socket-like object that can be given a predefined content."""
+
+ def __init__(self, data):
+ self.readfile = StringIO(data)
+
+ def makefile(self, mode='r', bufsize=None):
+ return self.readfile
+
+class FakeHTTPConnection(_urllib2_wrappers.HTTPConnection):
+
+ def __init__(self, sock):
+ _urllib2_wrappers.HTTPConnection.__init__(self, 'localhost')
+ # Set the socket to bypass the connection
+ self.sock = sock
+
+ def send(self, str):
+ """Ignores the writes on the socket."""
+ pass
+
+
+class TestHTTPConnection(tests.TestCase):
+
+ def test_cleanup_pipe(self):
+ sock = ReadSocket("""HTTP/1.1 200 OK\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Length: 18
+\r
+0123456789
+garbage""")
+ conn = FakeHTTPConnection(sock)
+ # Simulate the request sending so that the connection will be able to
+ # read the response.
+ conn.putrequest('GET', 'http://localhost/fictious')
+ conn.endheaders()
+ # Now, get the response
+ resp = conn.getresponse()
+ # Read part of the response
+ self.assertEquals('0123456789\n', resp.read(11))
+ # Override the thresold to force the warning emission
+ conn._range_warning_thresold = 6 # There are 7 bytes pending
+ conn.cleanup_pipe()
+ self.assertContainsRe(self._get_log(keep_log_file=True),
+ 'Got a 200 response when asking')
class TestRangeFileMixin(object):
=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
--- a/bzrlib/transport/http/_urllib2_wrappers.py 2007-12-12 21:06:05 +0000
+++ b/bzrlib/transport/http/_urllib2_wrappers.py 2007-12-13 15:40:42 +0000
@@ -78,9 +78,6 @@
# Some responses have bodies in which we have no interest
_body_ignored_responses = [301,302, 303, 307, 401, 403, 404]
- def __init__(self, *args, **kwargs):
- httplib.HTTPResponse.__init__(self, *args, **kwargs)
-
def begin(self):
"""Begin to read the response from the server.
@@ -175,9 +172,7 @@
self._ranges_received_whole_file = None
def _mutter_connect(self):
- netloc = self.host
- if self.port is not None:
- netloc += ':%d' % self.port
+ netloc = '%s:%s' % (self.host, self.port)
if self.proxied_host is not None:
netloc += '(proxy for %s)' % self.proxied_host
trace.mutter('* About to connect() to %s' % netloc)
@@ -188,10 +183,7 @@
return self._response
def cleanup_pipe(self):
- """Make the connection believes the response have been fully handled.
-
- That makes the httplib.HTTPConnection happy
- """
+ """Make the connection believe the response has been fully processed."""
if self._response is not None:
pending = self._response.finish()
# Warn the user (once) that
More information about the bazaar-commits
mailing list