def test_refresh(self): # XXX processor constructor optional args h = HTTPRefreshProcessor() o = h.parent = MockOpener() req = Request("http://example.com/") headers = MockHeaders({"refresh": '0; url="http://example.com/foo/"'}) r = MockResponse(200, "OK", headers, "") newr = h.http_response(req, r) self.assert_(o.proto == "http") self.assert_(o.args == (req, r, "refresh", "OK", headers))
def test_refresh(self): # XXX test processor constructor optional args h = HTTPRefreshProcessor(max_time=None, honor_time=False) for val in ['0; url="http://example.com/foo/"', "2"]: o = h.parent = MockOpener() req = Request("http://example.com/") headers = MockHeaders({"refresh": val}) r = MockResponse(200, "OK", headers, "") newr = h.http_response(req, r) self.assertEqual(o.proto, "http") self.assertEqual(o.args, (req, r, "refresh", "OK", headers))
def test_clientcookie(self): # XXX set up test page on SF or python.org # this test page depends on cookies, and an http-equiv refresh #cj = CreateBSDDBCookieJar("/home/john/db.db") cj = CookieJar() handlers = [ HTTPCookieProcessor(cj), HTTPRefreshProcessor(max_time=None, honor_time=False), HTTPEquivProcessor(), HTTPRedirectHandler(), # needed for Refresh handling in 2.4.0 # HTTPHandler(True), # HTTPRedirectDebugProcessor(), # HTTPResponseDebugProcessor(), ] o = apply(build_opener, handlers) try: install_opener(o) r = urlopen("http://boards.ign.com/help/cookie_test.asp") data = r.read() self.assert_( string.find(data, "Your browser supports cookies!") >= 0) self.assert_(len(cj) == 1) # test response.seek() (added by HTTPEquivProcessor) r.seek(0) samedata = r.read() r.close() self.assert_(samedata == data) finally: o.close() # uninstall opener (don't try this at home) ClientCookie._urllib2_support._opener = None
def test_clientcookie(self): # XXX set up test page on SF or python.org # this test page depends on cookies, and an http-equiv refresh #cj = CreateBSDDBCookieJar("/home/john/db.db") cj = CookieJar() handlers = [ HTTPCookieProcessor(cj), HTTPRefreshProcessor(max_time=None, honor_time=False), HTTPEquivProcessor(), HTTPRedirectHandler(), # needed for Refresh handling in 2.4.0 # HTTPHandler(True), # HTTPRedirectDebugProcessor(), # HTTPResponseDebugProcessor(), ] o = apply(build_opener, handlers) try: install_opener(o) try: r = urlopen("http://wwwsearch.sf.net/cgi-bin/cookietest.cgi") except urllib2.URLError, e: #print e.read() raise data = r.read() #print data self.assert_( string.find(data, "Your browser supports cookies!") >= 0) self.assert_(len(cj) == 1) # test response.seek() (added by HTTPEquivProcessor) r.seek(0) samedata = r.read() r.close() self.assert_(samedata == data)