mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-22 18:03:51 +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):
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user