Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

unskip part of test_download_gzip_response on py3, file a twisted issue for the remaining part

Konstantin Lopuhin81a90c3af65c
diff --git a/tests/mockserver.py b/tests/mockserver.py
index 1ab8e4b8d..02bab0efd 100644
--- a/tests/mockserver.py
+++ b/tests/mockserver.py
@@ -170,12 +170,12 @@ class Root(Resource):
self.putChild(b"raw", Raw())
self.putChild(b"echo", Echo())
- if six.PY2 and twisted_version > (12, 3, 0):
+ if twisted_version > (12, 3, 0):
from twisted.web.test.test_webclient import PayloadResource
from twisted.web.server import GzipEncoderFactory
from twisted.web.resource import EncodingResourceWrapper
- self.putChild('payload', PayloadResource())
- self.putChild("xpayload", EncodingResourceWrapper(PayloadResource(), [GzipEncoderFactory()]))
+ self.putChild(b"payload", PayloadResource())
+ self.putChild(b"xpayload", EncodingResourceWrapper(PayloadResource(), [GzipEncoderFactory()]))
def getChild(self, name, request):
return self
diff --git a/tests/test_downloader_handlers.py b/tests/test_downloader_handlers.py
index b3c1c565f..a8de28d4b 100644
--- a/tests/test_downloader_handlers.py
+++ b/tests/test_downloader_handlers.py
@@ -294,27 +294,30 @@ class Http11MockServerTestCase(unittest.TestCase):
@defer.inlineCallbacks
def test_download_gzip_response(self):
- if six.PY2 and twisted_version > (12, 3, 0):
+ if twisted_version > (12, 3, 0):
crawler = get_crawler(SingleRequestSpider)
- body = '1'*100 # PayloadResource requires body length to be 100
+ body = b'1'*100 # PayloadResource requires body length to be 100
request = Request('http://localhost:8998/payload', method='POST', body=body, meta={'download_maxsize': 50})
yield crawler.crawl(seed=request)
failure = crawler.spider.meta['failure']
# download_maxsize < 100, hence the CancelledError
self.assertIsInstance(failure.value, defer.CancelledError)
- request.headers.setdefault('Accept-Encoding', 'gzip,deflate')
+ request.headers.setdefault(b'Accept-Encoding', b'gzip,deflate')
request = request.replace(url='http://localhost:8998/xpayload')
yield crawler.crawl(seed=request)
- # download_maxsize = 50 is enough for the gzipped response
- failure = crawler.spider.meta.get('failure')
- self.assertTrue(failure == None)
- reason = crawler.spider.meta['close_reason']
- self.assertTrue(reason, 'finished')
+ if six.PY2:
+ # download_maxsize = 50 is enough for the gzipped response
+ # See issue https://twistedmatrix.com/trac/ticket/8175
+ raise unittest.SkipTest("xpayload only enabled for PY2")
+ failure = crawler.spider.meta.get('failure')
+ self.assertTrue(failure == None)
+ reason = crawler.spider.meta['close_reason']
+ self.assertTrue(reason, 'finished')
else:
- raise unittest.SkipTest("xpayload and payload endpoint only enabled for twisted > 12.3.0 and python 2.x")
+ raise unittest.SkipTest("xpayload and payload endpoint only enabled for twisted > 12.3.0")
class UriResource(resource.Resource):