From 78a4cd0f1c32477d42f14e4c48daedb24be44ebf Mon Sep 17 00:00:00 2001 From: Mikhail Korobov Date: Tue, 1 Sep 2015 04:00:26 +0500 Subject: [PATCH] PY3 fix HttpAuthMiddleware tests --- scrapy/downloadermiddlewares/httpauth.py | 4 ++-- tests/py3-ignores.txt | 1 - tests/test_downloadermiddleware_httpauth.py | 13 ++++++------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/scrapy/downloadermiddlewares/httpauth.py b/scrapy/downloadermiddlewares/httpauth.py index 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'] = auth diff --git a/tests/py3-ignores.txt b/tests/py3-ignores.txt index 4fedc48e6..793f0c6cd 100644 --- a/tests/py3-ignores.txt +++ b/tests/py3-ignores.txt @@ -6,7 +6,6 @@ tests/test_exporters.py tests/test_linkextractors_deprecated.py tests/test_crawl.py tests/test_downloader_handlers.py -tests/test_downloadermiddleware_httpauth.py tests/test_downloadermiddleware_httpcache.py tests/test_downloadermiddleware_httpcompression.py tests/test_downloadermiddleware_httpproxy.py diff --git a/tests/test_downloadermiddleware_httpauth.py b/tests/test_downloadermiddleware_httpauth.py index c30fa97c6..425a5cc79 100644 --- a/tests/test_downloadermiddleware_httpauth.py +++ b/tests/test_downloadermiddleware_httpauth.py @@ -4,10 +4,12 @@ from scrapy.http import Request from scrapy.downloadermiddlewares.httpauth import HttpAuthMiddleware from 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')