<s> import unittest <EOL> from scrapy . http import Request <EOL> from scrapy . downloadermiddlewares . httpauth import HttpAuthMiddleware <EOL> from scrapy . spiders import Spider <EOL> class TestSpider ( Spider ) : <EOL> http_user = '<STR_LIT:foo>' <EOL> http_pass = '<STR_LIT:bar>' <EOL> class HttpAuthMiddlewareTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . mw = HttpAuthMiddleware ( ) <EOL> self . spider = TestSpider ( '<STR_LIT:foo>' ) <EOL> self . mw . spider_opened ( self . spider ) <EOL> def tearDown ( self ) : <EOL> del self . mw <EOL> def test_auth ( self ) : <EOL> req = Request ( '<STR_LIT>' ) <EOL> assert self . mw . process_request ( req , self . spider ) is None <EOL> self . assertEquals ( req . headers [ '<STR_LIT>' ] , b'<STR_LIT>' ) <EOL> def test_auth_already_set ( self ) : <EOL> req = Request ( '<STR_LIT>' , <EOL> headers = dict ( Authorization = '<STR_LIT>' ) ) <EOL> assert self . mw . process_request ( req , self . spider ) is None <EOL> self . assertEquals ( req . headers [ '<STR_LIT>' ] , b'<STR_LIT>' ) </s>
