mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-23 04:44:04 +00:00
PY3 fix HttpAuthMiddleware tests
This commit is contained in:
parent
179a4409fb
commit
78a4cd0f1c
@ -27,5 +27,5 @@ class HttpAuthMiddleware(object):
|
|||||||
|
|
||||||
def process_request(self, request, spider):
|
def process_request(self, request, spider):
|
||||||
auth = getattr(self, 'auth', None)
|
auth = getattr(self, 'auth', None)
|
||||||
if auth and 'Authorization' not in request.headers:
|
if auth and b'Authorization' not in request.headers:
|
||||||
request.headers['Authorization'] = auth
|
request.headers[b'Authorization'] = auth
|
||||||
|
@ -6,7 +6,6 @@ tests/test_exporters.py
|
|||||||
tests/test_linkextractors_deprecated.py
|
tests/test_linkextractors_deprecated.py
|
||||||
tests/test_crawl.py
|
tests/test_crawl.py
|
||||||
tests/test_downloader_handlers.py
|
tests/test_downloader_handlers.py
|
||||||
tests/test_downloadermiddleware_httpauth.py
|
|
||||||
tests/test_downloadermiddleware_httpcache.py
|
tests/test_downloadermiddleware_httpcache.py
|
||||||
tests/test_downloadermiddleware_httpcompression.py
|
tests/test_downloadermiddleware_httpcompression.py
|
||||||
tests/test_downloadermiddleware_httpproxy.py
|
tests/test_downloadermiddleware_httpproxy.py
|
||||||
|
@ -4,10 +4,12 @@ from scrapy.http import Request
|
|||||||
from scrapy.downloadermiddlewares.httpauth import HttpAuthMiddleware
|
from scrapy.downloadermiddlewares.httpauth import HttpAuthMiddleware
|
||||||
from scrapy.spiders import Spider
|
from scrapy.spiders import Spider
|
||||||
|
|
||||||
|
|
||||||
class TestSpider(Spider):
|
class TestSpider(Spider):
|
||||||
http_user = 'foo'
|
http_user = 'foo'
|
||||||
http_pass = 'bar'
|
http_pass = 'bar'
|
||||||
|
|
||||||
|
|
||||||
class HttpAuthMiddlewareTest(unittest.TestCase):
|
class HttpAuthMiddlewareTest(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -21,13 +23,10 @@ class HttpAuthMiddlewareTest(unittest.TestCase):
|
|||||||
def test_auth(self):
|
def test_auth(self):
|
||||||
req = Request('http://scrapytest.org/')
|
req = Request('http://scrapytest.org/')
|
||||||
assert self.mw.process_request(req, self.spider) is None
|
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):
|
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
|
assert self.mw.process_request(req, self.spider) is None
|
||||||
self.assertEquals(req.headers['Authorization'], 'Digest 123')
|
self.assertEquals(req.headers['Authorization'], b'Digest 123')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user