File: test_downloadermiddleware_httpauth.py

package info (click to toggle)
python-scrapy 0.8-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,904 kB
  • ctags: 2,981
  • sloc: python: 15,349; xml: 199; makefile: 68; sql: 64; sh: 34
file content (28 lines) | stat: -rw-r--r-- 740 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import unittest

from scrapy.http import Request
from scrapy.contrib.downloadermiddleware.httpauth import HttpAuthMiddleware
from scrapy.spider import BaseSpider

class TestSpider(BaseSpider):
    http_user = 'foo'
    http_pass = 'bar'

class HttpAuthMiddlewareTest(unittest.TestCase):

    def setUp(self):
        self.mw = HttpAuthMiddleware()

    def tearDown(self):
        del self.mw

    def test_auth(self):
        self.mw.default_useragent = 'default_useragent'
        spider = TestSpider()
        req = Request('http://scrapytest.org/')
        assert self.mw.process_request(req, spider) is None
        self.assertEquals(req.headers['Authorization'], 'Basic Zm9vOmJhcg==')


if __name__ == '__main__':
    unittest.main()