def test_session_fragment_query_string(self): qs = testlib.randdict(5) query_string = urlfetch.urlencode(qs) cookiepair = (testlib.randstr(), testlib.randstr()) headerpair = (testlib.randstr(), testlib.randstr()) s = urlfetch.Session(headers=dict((headerpair, )), cookies=dict((cookiepair, ))) r = s.get(testlib.url()) o = json.loads(r.text) self.assertEqual(r.status, 200) self.assertTrue(isinstance(r.json, dict)) self.assertTrue(isinstance(r.text, urlfetch.unicode)) self.assertEqual(o['method'], 'GET') self.assertEqual(r.reqheaders[headerpair[0]], headerpair[1]) self.assertEqual(r.reqheaders['Cookie'], '='.join(cookiepair)) r = s.get(testlib.url('?' + query_string + '#urlfetch')) o = json.loads(r.text) self.assertEqual(r.status, 200) self.assertTrue(isinstance(r.json, dict)) self.assertTrue(isinstance(r.text, urlfetch.unicode)) self.assertEqual(o['method'], 'GET') self.assertEqual(r.reqheaders[headerpair[0]], headerpair[1]) self.assertEqual(r.reqheaders['Cookie'], '='.join(cookiepair)) self.assertEqual(o['query_string'], query_string) self.assertEqual(o['get'], qs)
def test_session_query_string(self): qs = testlib.randdict(5) query_string = urlfetch.urlencode(qs) cookiepair = (testlib.randstr(), testlib.randstr()) headerpair = (testlib.randstr(), testlib.randstr()) s = urlfetch.Session(headers=dict((headerpair,)), cookies=dict((cookiepair,))) r = s.get(testlib.test_server_host) o = json.loads(r.text) self.assertEqual(r.status, 200) self.assertTrue(isinstance(r.json, dict)) self.assertTrue(isinstance(r.text, urlfetch.unicode)) self.assertEqual(o['method'], 'GET') self.assertEqual(r.reqheaders[headerpair[0]], headerpair[1]) self.assertEqual(r.reqheaders['Cookie'], '='.join(cookiepair)) r = s.get(testlib.url('?' + query_string)) o = json.loads(r.text) self.assertEqual(r.status, 200) self.assertTrue(isinstance(r.json, dict)) self.assertTrue(isinstance(r.text, urlfetch.unicode)) self.assertEqual(o['method'], 'GET') self.assertEqual(r.reqheaders[headerpair[0]], headerpair[1]) self.assertEqual(r.reqheaders['Cookie'], '='.join(cookiepair)) self.assertEqual(o['query_string'], query_string) self.assertEqual(o['get'], qs)
def test_session_get(self): cookiepair = (testlib.randstr(), testlib.randstr()) headerpair = (testlib.randstr(), testlib.randstr()) s = urlfetch.Session(headers=dict((headerpair,)), cookies=dict((cookiepair,))) r = s.get(testlib.test_server_host) o = json.loads(r.text) self.assertEqual(r.status, 200) self.assertEqual(o['method'], 'GET') self.assertEqual(r.reqheaders[headerpair[0].title()], headerpair[1]) self.assertEqual(r.reqheaders['Cookie'], '='.join(cookiepair))
def test_session_fragment(self): cookiepair = (testlib.randstr(), testlib.randstr()) headerpair = (testlib.randstr(), testlib.randstr()) s = urlfetch.Session(headers=dict((headerpair,)), cookies=dict((cookiepair,))) r = s.get(testlib.url('#urlfetch')) o = json.loads(r.text) self.assertEqual(r.status, 200) self.assertTrue(isinstance(r.json, dict)) self.assertTrue(isinstance(r.text, urlfetch.unicode)) self.assertEqual(o['method'], 'GET') self.assertEqual(r.reqheaders[headerpair[0]], headerpair[1]) self.assertEqual(r.reqheaders['Cookie'], '='.join(cookiepair))
def test_session_basic_auth(self): cookiepair = (testlib.randstr(), testlib.randstr()) headerpair = (testlib.randstr(), testlib.randstr()) s = urlfetch.Session(headers=dict((headerpair,)), cookies=dict((cookiepair,)), auth=('urlfetch', 'fetchurl')) r = s.get(testlib.test_server_host + 'basic_auth') o = json.loads(r.text) self.assertEqual(r.status, 200) self.assertTrue(isinstance(r.json, dict)) self.assertTrue(isinstance(r.text, urlfetch.unicode)) self.assertEqual(o['method'], 'GET') self.assertEqual(r.reqheaders[headerpair[0]], headerpair[1]) self.assertEqual(r.reqheaders['Cookie'], '='.join(cookiepair))
def test_get_params(self): p1 = (randstr(), randstr()) p2 = (randstr(), randstr()) params = dict((p1, p2)) r = urlfetch.get(testlib.test_server_host, params=params) o = json.loads(r.text) self.assertEqual(r.status, 200) self.assertTrue(isinstance(r.json, dict)) self.assertTrue(isinstance(r.text, urlfetch.unicode)) self.assertEqual(o['method'], 'GET') self.assertTrue(('%s=%s' % p1) in r.url) self.assertTrue(('%s=%s' % p2) in r.url)
def test_session_get(self): cookiepair = (testlib.randstr(), testlib.randstr()) headerpair = (testlib.randstr(), testlib.randstr()) s = urlfetch.Session(headers=dict((headerpair, )), cookies=dict((cookiepair, ))) r = s.get(testlib.url()) o = json.loads(r.text) self.assertEqual(r.status, 200) self.assertTrue(isinstance(r.json, dict)) self.assertTrue(isinstance(r.text, urlfetch.unicode)) self.assertEqual(o['method'], 'GET') self.assertEqual(r.reqheaders[headerpair[0]], headerpair[1]) self.assertEqual(r.reqheaders['Cookie'], '='.join(cookiepair))
def test_get_params(self): p1 = (randstr(), randstr()) p2 = (randstr(), randstr()) params = dict((p1, p2)) r = urlfetch.get(testlib.test_server_host, params=params) o = json.loads(r.text) self.assertEqual(r.status, 200) self.assertTrue(isinstance(r.json, dict)) self.assertTrue(isinstance(r.text, urlfetch.unicode)) self.assertEqual(r.links, []) self.assertEqual(o['method'], 'GET') self.assertTrue(('%s=%s' % p1) in r.url) self.assertTrue(('%s=%s' % p2) in r.url)
def test_session_fragment_basic_auth_query_string(self): qs = testlib.randdict(5) query_string = urlfetch.urlencode(qs) cookiepair = (testlib.randstr(), testlib.randstr()) headerpair = (testlib.randstr(), testlib.randstr()) s = urlfetch.Session(headers=dict((headerpair,)), cookies=dict((cookiepair,)), auth=('urlfetch', 'fetchurl')) r = s.get(testlib.test_server_host + 'basic_auth?' + query_string + '#urlfetch') o = json.loads(r.text) self.assertEqual(r.status, 200) self.assertEqual(o['method'], 'GET') self.assertEqual(r.reqheaders[headerpair[0].title()], headerpair[1]) self.assertEqual(r.reqheaders['Cookie'], '='.join(cookiepair)) self.assertEqual(o['query_string'], query_string) self.assertEqual(o['get'], qs)
def test_cookie(self): cookie = (randstr(), randstr()) r = urlfetch.get(testlib.url('setcookie/%s/%s' % cookie)) self.assertEqual(r.links, []) self.assertEqual(r.cookies[cookie[0]], cookie[1]) self.assertTrue(('%s=%s' % cookie) in r.cookiestring)
def test_cookie(self): cookie = (randstr(), randstr()) r = urlfetch.get(testlib.url('setcookie/%s/%s' % cookie)) self.assertEqual(r.links, []) self.assertEqual(r.cookies[cookie[0]], cookie[1]) self.assertTrue(('%s=%s' % cookie) in r.cookiestring)
def test_cookie(self): cookie = (randstr(), randstr()) r = urlfetch.get(testlib.test_server_host + 'setcookie/%s/%s' % cookie) self.assertEqual(r.cookies[cookie[0]], cookie[1]) self.assertTrue(('%s=%s' % cookie) in r.cookiestring)