def test_cookiejar(self): c1 = create_cookie('foo', 'bar') c2 = create_cookie('foo', 'bar') self.assertFalse(c1 == c2) c = create_cookie('foo', 'bar', domain='.dumpz.org') self.assertEquals(c.domain, '.dumpz.org') cj = CookieJar() cj.set_cookie(create_cookie('foo', 'bar', domain='foo.com')) cj.set_cookie(create_cookie('foo', 'bar', domain='bar.com')) self.assertEqual(len(cj), 2)
def test_cookiejar(self): cookie1 = create_cookie('foo', 'bar', self.server.address) cookie2 = create_cookie('foo', 'bar', self.server.address) self.assertFalse(cookie1 == cookie2) cookie0 = create_cookie('foo', 'bar', domain='.dumpz.org') self.assertEqual(cookie0.domain, '.dumpz.org') jar = CookieJar() jar.set_cookie(create_cookie('foo', 'bar', domain='foo.com')) jar.set_cookie(create_cookie('foo', 'bar', domain='bar.com')) self.assertEqual(len(jar), 2)
def test_pickle_serialization(self): cookie = create_cookie('foo', 'bar') mgr = CookieManager.from_cookie_list([cookie]) dump = pickle.dumps(mgr) mgr2 = pickle.loads(dump) self.assertEqual(list(mgr.cookiejar)[0].value, list(mgr2.cookiejar)[0].value)
def extract_cookiejar(self): """ Extract cookies that pycurl instance knows. Returns `CookieJar` object. """ # Example of line: # www.google.com\tFALSE\t/accounts/\tFALSE\t0\tGoogleAccountsLocale_session\ten # Fields: # * domain # * whether or not all machines under that domain can read the cookie's information. # * path # * Secure Flag: whether or not a secure connection (HTTPS) is required to read the cookie. # * exp. timestamp # * name # * value cookiejar = CookieJar() for line in self.curl.getinfo(pycurl.INFO_COOKIELIST): values = line.split('\t') # old #cookies[values[-2]] = values[-1] # new cookie = create_cookie( name=values[5], value=values[6], domain=values[0], path=values[2], secure=values[3] == "TRUE", expires=int(values[4]) if values[4] else None, ) cookiejar.set_cookie(cookie) return cookiejar
def test_from_cookie_list(self): cookie = create_cookie("foo", "bar", self.server.address) mgr = CookieManager.from_cookie_list([cookie]) test_cookie = [x for x in mgr.cookiejar if x.name == "foo"][0] self.assertEqual(cookie.name, test_cookie.name) mgr = CookieManager.from_cookie_list([]) self.assertEqual(0, len(list(mgr.cookiejar)))
def test_from_cookie_list(self): cookie = create_cookie('foo', 'bar') mgr = CookieManager.from_cookie_list([cookie]) test_cookie = [x for x in mgr.cookiejar if x.name == 'foo'][0] self.assertEqual(cookie.name, test_cookie.name) mgr = CookieManager.from_cookie_list([]) self.assertEqual(0, len(list(mgr.cookiejar)))
def test_get_item(self): cookie = create_cookie("foo", "bar", self.server.address) mgr = CookieManager.from_cookie_list([cookie]) self.assertEqual("bar", mgr["foo"]) self.assertRaises(KeyError, lambda: mgr["zzz"])
def test_get_item(self): cookie = create_cookie('foo', 'bar') mgr = CookieManager.from_cookie_list([cookie]) self.assertEqual('bar', mgr['foo']) self.assertRaises(KeyError, lambda: mgr['zzz'])
def test_cookie(self): create_cookie('foo', 'bar') self.assertRaises(TypeError, create_cookie, 'foo', 'bar', x='y')
def test_cookie(self): create_cookie('foo', 'bar', self.server.address) self.assertRaises(GrabMisuseError, create_cookie, 'foo', 'bar', self.server.address, x='y')
def test_get_item(self): cookie = create_cookie('foo', 'bar', self.server.address) mgr = CookieManager.from_cookie_list([cookie]) self.assertEqual('bar', mgr['foo']) self.assertRaises(KeyError, lambda: mgr['zzz'])