Beispiel #1
0
 def test_keep_cookie_from_default_request_headers_middleware(self):
     DEFAULT_REQUEST_HEADERS = dict(Cookie='default=value; asdf=qwerty')
     mw_default_headers = DefaultHeadersMiddleware(
         DEFAULT_REQUEST_HEADERS.items())
     # overwrite with values from 'cookies' request argument
     req1 = Request('http://example.org', cookies={'default': 'something'})
     assert mw_default_headers.process_request(req1, self.spider) is None
     assert self.mw.process_request(req1, self.spider) is None
     self.assertCookieValEqual(req1.headers['Cookie'],
                               b'default=something; asdf=qwerty')
     # keep both
     req2 = Request('http://example.com', cookies={'a': 'b'})
     assert mw_default_headers.process_request(req2, self.spider) is None
     assert self.mw.process_request(req2, self.spider) is None
     self.assertCookieValEqual(req2.headers['Cookie'],
                               b'default=value; a=b; asdf=qwerty')
 def test_keep_cookie_from_default_request_headers_middleware(self):
     DEFAULT_REQUEST_HEADERS = dict(Cookie="default=value; asdf=qwerty")
     mw_default_headers = DefaultHeadersMiddleware(
         DEFAULT_REQUEST_HEADERS.items())
     # overwrite with values from 'cookies' request argument
     req1 = Request("http://example.org", cookies={"default": "something"})
     assert mw_default_headers.process_request(req1, self.spider) is None
     assert self.mw.process_request(req1, self.spider) is None
     self.assertCookieValEqual(req1.headers["Cookie"],
                               b"default=something; asdf=qwerty")
     # keep both
     req2 = Request("http://example.com", cookies={"a": "b"})
     assert mw_default_headers.process_request(req2, self.spider) is None
     assert self.mw.process_request(req2, self.spider) is None
     self.assertCookieValEqual(req2.headers["Cookie"],
                               b"default=value; a=b; asdf=qwerty")