From: Cameron Dale Date: Wed, 12 Dec 2007 21:31:57 +0000 (-0800) Subject: Read the response in the unit tests to prevent RST packets. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=385f35d33b0c47a55fac7250d2d9933f33c11dfd;p=quix0rs-apt-p2p.git Read the response in the unit tests to prevent RST packets. --- diff --git a/HTTPDownloader.py b/HTTPDownloader.py index 290c7f9..a7c5044 100644 --- a/HTTPDownloader.py +++ b/HTTPDownloader.py @@ -5,6 +5,7 @@ from twisted.web2.client.interfaces import IHTTPClientManager from twisted.web2.client.http import ProtocolError, ClientRequest, HTTPClientProtocol from twisted.trial import unittest from zope.interface import implements +from twisted.web2 import stream as stream_mod, http, http_headers, responsecode class HTTPClientManager(ClientFactory): """A manager for all HTTP requests to a single site. @@ -129,8 +130,13 @@ class TestClientManager(unittest.TestCase): def gotResp(self, resp, num, expect): self.failUnless(resp.code >= 200 and resp.code < 300, "Got a non-200 response: %r" % resp.code) - self.failUnless(resp.stream.length == expect, "Length was incorrect, got %r, expected %r" % (resp.stream.length, expect)) - resp.stream.close() + if expect is not None: + self.failUnless(resp.stream.length == expect, "Length was incorrect, got %r, expected %r" % (resp.stream.length, expect)) + def print_(n): + pass + def printdone(n): + pass + stream_mod.readStream(resp.stream, print_).addCallback(printdone) def test_download(self): host = 'www.camrdale.org' @@ -208,7 +214,11 @@ class TestDownloader(unittest.TestCase): self.failUnless(resp.code >= 200 and resp.code < 300, "Got a non-200 response: %r" % resp.code) if expect is not None: self.failUnless(resp.stream.length == expect, "Length was incorrect, got %r, expected %r" % (resp.stream.length, expect)) - resp.stream.close() + def print_(n): + pass + def printdone(n): + pass + stream_mod.readStream(resp.stream, print_).addCallback(printdone) def test_download(self): self.manager = HTTPDownloader()