Scrapy, a fast high-level web crawling & scraping framework for Python.
cookies: check mw outputs. refs #73
Daniel Grana45f55c0df0bc
diff --git a/scrapy/trunk/scrapy/contrib/downloadermiddleware/cookies.py b/scrapy/trunk/scrapy/contrib/downloadermiddleware/cookies.pyindex abec8191a..b5bb3782f 100644--- a/scrapy/trunk/scrapy/contrib/downloadermiddleware/cookies.py+++ b/scrapy/trunk/scrapy/contrib/downloadermiddleware/cookies.py@@ -35,7 +35,7 @@ class CookiesMiddleware(object):def process_response(self, request, response, spider):if request.meta.get('dont_merge_cookies', False):- return+ return response# extract cookies from Set-Cookie and drop invalid/expired cookiesjar = self.jars[spider.domain_name]diff --git a/scrapy/trunk/scrapy/tests/test_downloadermiddleware_cookies.py b/scrapy/trunk/scrapy/tests/test_downloadermiddleware_cookies.pyindex f942a9dd6..4451fbd9d 100644--- a/scrapy/trunk/scrapy/tests/test_downloadermiddleware_cookies.py+++ b/scrapy/trunk/scrapy/tests/test_downloadermiddleware_cookies.py@@ -23,65 +23,64 @@ class CookiesMiddlewareTest(TestCase):def test_basic(self):headers = {'Set-Cookie': 'C1=value1; path=/'}req = Request('http://scrapytest.org/')- self.mw.process_request(req, self.spider)-+ assert self.mw.process_request(req, self.spider) is Noneassert 'Cookie' not in req.headersres = Response('http://scrapytest.org/', headers=headers)- self.mw.process_response(req, res, self.spider)+ assert self.mw.process_response(req, res, self.spider) is res#assert res.cookiesreq2 = Request('http://scrapytest.org/sub1/')- self.mw.process_request(req2, self.spider)+ assert self.mw.process_request(req2, self.spider) is Noneself.assertEquals(req2.headers.get('Cookie'), "C1=value1")def test_http_exception(self):- headers = {'Set-Cookie': 'C1=value1; path=/'}- res = Response('http://scrapytest.org/', headers=headers)- exc = HttpException(302, 'Redirect', res)-req = Request('http://scrapytest.org/')- self.mw.process_request(req, self.spider)+ assert self.mw.process_request(req, self.spider) is Noneassert 'Cookie' not in req.headers- self.mw.process_exception(req, exc, self.spider)+ headers = {'Set-Cookie': 'C1=value1; path=/'}+ res = Response('http://scrapytest.org/', headers=headers)+ exc = HttpException(302, 'Redirect', res)+ assert self.mw.process_exception(req, exc, self.spider) is None#assert exc.response.cookiesreq2 = Request('http://scrapytest.org/sub1/')- self.mw.process_request(req2, self.spider)+ assert self.mw.process_request(req2, self.spider) is Noneself.assertEquals(req2.headers.get('Cookie'), "C1=value1")-def test_dont_merge_cookies(self):# merge some cookies into jarheaders = {'Set-Cookie': 'C1=value1; path=/'}req = Request('http://scrapytest.org/')res = Response('http://scrapytest.org/', headers=headers)- self.mw.process_response(req, res, self.spider)+ assert self.mw.process_response(req, res, self.spider) is res# test Cookie header is not seted to requestreq = Request('http://scrapytest.org/dontmerge', meta={'dont_merge_cookies': 1})- self.mw.process_request(req, self.spider)+ assert self.mw.process_request(req, self.spider) is Noneassert 'Cookie' not in req.headers# check that returned cookies are not merged back to jarres = Response('http://scrapytest.org/dontmerge', headers={'Set-Cookie': 'dont=mergeme; path=/'})- self.mw.process_response(req, res, self.spider)+ assert self.mw.process_response(req, res, self.spider) is res+req = Request('http://scrapytest.org/mergeme')- self.mw.process_request(req, self.spider)+ assert self.mw.process_request(req, self.spider) is Noneself.assertEquals(req.headers.get('Cookie'), 'C1=value1')def test_merge_request_cookies(self):req = Request('http://scrapytest.org/', cookies={'galleta': 'salada'})- self.mw.process_request(req, self.spider)+ assert self.mw.process_request(req, self.spider) is Noneself.assertEquals(req.headers.get('Cookie'), 'galleta=salada')headers = {'Set-Cookie': 'C1=value1; path=/'}res = Response('http://scrapytest.org/', headers=headers)- self.mw.process_response(req, res, self.spider)+ assert self.mw.process_response(req, res, self.spider) is res+req2 = Request('http://scrapytest.org/sub1/')- self.mw.process_request(req2, self.spider)+ assert self.mw.process_request(req2, self.spider) is Noneself.assertEquals(req2.headers.get('Cookie'), "C1=value1; galleta=salada")