mirror of https://github.com/scrapy/scrapy.git
py3: fix webclient tests after making ScrapyHTTPClientFactory use bytes as in twisted
This commit is contained in:
parent
8df35bcac6
commit
5c2241ccc7
|
|
@ -65,7 +65,7 @@ class ScrapyHTTPPageGetter(HTTPClient):
|
|||
self.factory.noPage(reason)
|
||||
|
||||
def handleResponse(self, response):
|
||||
if self.factory.method.upper() == 'HEAD':
|
||||
if self.factory.method.upper() == b'HEAD':
|
||||
self.factory.page('')
|
||||
elif self.length is not None and self.length > 0:
|
||||
self.factory.noPage(self._connection_lost_reason)
|
||||
|
|
@ -123,7 +123,7 @@ class ScrapyHTTPClientFactory(HTTPClientFactory):
|
|||
# just in case a broken http/1.1 decides to keep connection alive
|
||||
self.headers.setdefault("Connection", "close")
|
||||
# Content-Length must be specified in POST method even with no body
|
||||
elif self.method == 'POST':
|
||||
elif self.method == b'POST':
|
||||
self.headers['Content-Length'] = 0
|
||||
|
||||
def _build_response(self, body, request):
|
||||
|
|
|
|||
|
|
@ -68,6 +68,8 @@ class ParseUrlTestCase(unittest.TestCase):
|
|||
)
|
||||
|
||||
for url, test in tests:
|
||||
test = tuple(
|
||||
to_bytes(x) if not isinstance(x, int) else x for x in test)
|
||||
self.assertEquals(client._parse(url), test, url)
|
||||
|
||||
def test_externalUnicodeInterference(self):
|
||||
|
|
@ -82,10 +84,10 @@ class ParseUrlTestCase(unittest.TestCase):
|
|||
goodInput, badInput = badInput, goodInput
|
||||
urlparse(badInput)
|
||||
scheme, netloc, host, port, path = self._parse(goodInput)
|
||||
self.assertTrue(isinstance(scheme, str))
|
||||
self.assertTrue(isinstance(netloc, str))
|
||||
self.assertTrue(isinstance(host, str))
|
||||
self.assertTrue(isinstance(path, str))
|
||||
self.assertTrue(isinstance(scheme, bytes))
|
||||
self.assertTrue(isinstance(netloc, bytes))
|
||||
self.assertTrue(isinstance(host, bytes))
|
||||
self.assertTrue(isinstance(path, bytes))
|
||||
self.assertTrue(isinstance(port, int))
|
||||
|
||||
|
||||
|
|
@ -317,9 +319,9 @@ class WebClientTestCase(unittest.TestCase):
|
|||
|
||||
def testFactoryInfo(self):
|
||||
url = self.getURL('file')
|
||||
scheme, netloc, host, port, path = client._parse(url)
|
||||
_, _, host, port, _ = client._parse(url)
|
||||
factory = client.ScrapyHTTPClientFactory(Request(url))
|
||||
reactor.connectTCP(host, port, factory)
|
||||
reactor.connectTCP(to_unicode(host), port, factory)
|
||||
return factory.deferred.addCallback(self._cbFactoryInfo, factory)
|
||||
|
||||
def _cbFactoryInfo(self, ignoredResult, factory):
|
||||
|
|
|
|||
Loading…
Reference in New Issue