Scrapy, a fast high-level web crawling & scraping framework for Python.
PY3 fix HttpAuthMiddleware tests
Mikhail Korobov78a4cd0f1c32
diff --git a/scrapy/downloadermiddlewares/httpauth.py b/scrapy/downloadermiddlewares/httpauth.pyindex 7854e899a..7aa7a62bc 100644--- a/scrapy/downloadermiddlewares/httpauth.py+++ b/scrapy/downloadermiddlewares/httpauth.py@@ -27,5 +27,5 @@ class HttpAuthMiddleware(object):def process_request(self, request, spider):auth = getattr(self, 'auth', None)- if auth and 'Authorization' not in request.headers:- request.headers['Authorization'] = auth+ if auth and b'Authorization' not in request.headers:+ request.headers[b'Authorization'] = authdiff --git a/tests/py3-ignores.txt b/tests/py3-ignores.txtindex 4fedc48e6..793f0c6cd 100644--- a/tests/py3-ignores.txt+++ b/tests/py3-ignores.txt@@ -6,7 +6,6 @@ tests/test_exporters.pytests/test_linkextractors_deprecated.pytests/test_crawl.pytests/test_downloader_handlers.py-tests/test_downloadermiddleware_httpauth.pytests/test_downloadermiddleware_httpcache.pytests/test_downloadermiddleware_httpcompression.pytests/test_downloadermiddleware_httpproxy.pydiff --git a/tests/test_downloadermiddleware_httpauth.py b/tests/test_downloadermiddleware_httpauth.pyindex c30fa97c6..425a5cc79 100644--- a/tests/test_downloadermiddleware_httpauth.py+++ b/tests/test_downloadermiddleware_httpauth.py@@ -4,10 +4,12 @@ from scrapy.http import Requestfrom scrapy.downloadermiddlewares.httpauth import HttpAuthMiddlewarefrom scrapy.spiders import Spider+class TestSpider(Spider):http_user = 'foo'http_pass = 'bar'+class HttpAuthMiddlewareTest(unittest.TestCase):def setUp(self):@@ -21,13 +23,10 @@ class HttpAuthMiddlewareTest(unittest.TestCase):def test_auth(self):req = Request('http://scrapytest.org/')assert self.mw.process_request(req, self.spider) is None- self.assertEquals(req.headers['Authorization'], 'Basic Zm9vOmJhcg==')+ self.assertEquals(req.headers['Authorization'], b'Basic Zm9vOmJhcg==')def test_auth_already_set(self):- req = Request('http://scrapytest.org/', headers=dict(Authorization='Digest 123'))+ req = Request('http://scrapytest.org/',+ headers=dict(Authorization='Digest 123'))assert self.mw.process_request(req, self.spider) is None- self.assertEquals(req.headers['Authorization'], 'Digest 123')---if __name__ == '__main__':- unittest.main()+ self.assertEquals(req.headers['Authorization'], b'Digest 123')