Skip to content

Commit

Permalink
PY3 fix HttpAuthMiddleware tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kmike committed Aug 31, 2015
1 parent 179a440 commit 78a4cd0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions scrapy/downloadermiddlewares/httpauth.py
Expand Up @@ -27,5 +27,5 @@ def spider_opened(self, spider):

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
1 change: 0 additions & 1 deletion tests/py3-ignores.txt
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions tests/test_downloadermiddleware_httpauth.py
Expand Up @@ -4,10 +4,12 @@
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):
Expand All @@ -21,13 +23,10 @@ def tearDown(self):
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')

0 comments on commit 78a4cd0

Please sign in to comment.