test_requests.py
This file
Path
test_requests.py
500 lines · 13.7 KiB · Python
Last changed by
test session persistent paramsKenneth Reitzbefore adoption7dc75ce
History of this fileTake it
sample test fixtures (none)Kenneth Reitzbefore adoption75b499d
lines 1–3why, one step back1#!/usr/bin/env python2# -*- coding: utf-8 -*-3Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 4–5why, one step back4from __future__ import with_statement5use gunicorn to serve testsKenneth Reitzbefore adoption1299708
line 6why, one step back6import timeMerge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 7why, one step back7import cookielibTest suite cleanupKenneth Reitzbefore adoption7a0f363
line 8why, one step back8import osuse gunicorn to serve testsKenneth Reitzbefore adoption1299708
line 9why, one step back9import unittesttemp "tests"Kenneth Reitzbefore adoption49f915f
line 10why, one step back10use gunicorn to serve testsKenneth Reitzbefore adoption1299708
lines 11–12why, one step back11import envoy12Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 13–16why, one step back13try:14 import omnijson as json15except ImportError:16 import jsonMerge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 17why, one step back17temp "tests"Kenneth Reitzbefore adoption49f915f
lines 18–19why, one step back18import requests19Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 20why, one step back20from requests.sessions import Sessiontemp "tests"Kenneth Reitzbefore adoption49f915f
line 21why, one step back21Test suite cleanupKenneth Reitzbefore adoption7a0f363
line 22why, one step back22PORT = os.environ.get('HTTPBIN_PORT', '7045')Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 23why, one step back23Test suite cleanupKenneth Reitzbefore adoption7a0f363
line 24why, one step back24HTTPBIN_URL = 'http://0.0.0.0:%s/' % (PORT)use gunicorn to serve testsKenneth Reitzbefore adoption1299708
line 25why, one step back25# HTTPBIN_URL = 'http://127.0.0.1:8000/'Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 26–33why, one step back262728def httpbin(*suffix):29 """Returns url for HTTPBIN resource."""3031 return HTTPBIN_URL + '/'.join(suffix)3233Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5
line 34why, one step back34SERVICES = (httpbin, )Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 35why, one step back35Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5
line 36why, one step back36_httpbin = FalseMerge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 37why, one step back37a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 38why, one step back38class RequestsTestSuite(unittest.TestCase):Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 39why, one step back39 """Requests test cases."""Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 40why, one step back40Make tests go to 11!Kenneth Reitzbefore adoption76b8afe
lines 41–42why, one step back41 # It goes to eleven.42 _multiprocess_can_split_ = TrueMerge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 43why, one step back43Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 44why, one step back44 def setUp(self):temp "tests"Kenneth Reitzbefore adoption49f915f
line 45why, one step back45Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5
line 46why, one step back46 global _httpbinMerge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 47why, one step back47Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5
lines 48–49why, one step back48 if not _httpbin:49Test suite cleanupKenneth Reitzbefore adoption7a0f363
line 50why, one step back50 self.httpbin = envoy.connect('gunicorn httpbin:app --bind=0.0.0.0:%s' % (PORT))Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5
line 51why, one step back51use gunicorn to serve testsKenneth Reitzbefore adoption1299708
line 52why, one step back52 _httpbin = TrueMerge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5
lines 53–56why, one step back53 time.sleep(1)545556Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 57–58why, one step back57 def tearDown(self):58 """Teardown."""Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5
line 59why, one step back59 # self.httpbin.kill()Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 60why, one step back60Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 61why, one step back61Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 62–63why, one step back62 def test_invalid_url(self):63 self.assertRaises(ValueError, requests.get, 'hiwpefhipowhefopw')a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 64why, one step back64Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 65why, one step back65Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 66why, one step back66 def test_HTTP_200_OK_GET(self):Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5
line 67why, one step back67 r = requests.get(httpbin('/get'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 68why, one step back68 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 69why, one step back69Merge pull request #202 from kennethreitz/feature/content-streamKenneth Reitzbefore adoptionbfa0103
lines 70–72why, one step back70 def test_HTTP_302_ALLOW_REDIRECT_GET(self):71 r = requests.get(httpbin('redirect', '1'))72 self.assertEqual(r.status_code, 200)Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 73why, one step back73Merge pull request #202 from kennethreitz/feature/content-streamKenneth Reitzbefore adoptionbfa0103
lines 74–77why, one step back74 def test_HTTP_302_GET(self):75 r = requests.get(httpbin('redirect', '1'), allow_redirects=False)76 self.assertEqual(r.status_code, 302)77a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 78why, one step back78Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 79–80why, one step back79 def test_HTTP_200_OK_GET_WITH_PARAMS(self):80 heads = {'User-agent': 'Mozilla/5.0'}Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 81why, one step back81Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 82–84why, one step back82 r = requests.get(httpbin('user-agent'), headers=heads)8384 assert heads['User-agent'] in r.contentMerge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 85–86why, one step back85 self.assertEqual(r.status_code, 200)86Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 87why, one step back87Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 88–90why, one step back88 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self):89 heads = {'User-agent': 'Mozilla/5.0'}90Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 91why, one step back91 r = requests.get(httpbin('get') + '?test=true', params={'q': 'test'}, headers=heads)Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 92why, one step back92 self.assertEqual(r.status_code, 200)Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 93why, one step back93Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 94why, one step back94Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 95–96why, one step back95 def test_user_agent_transfers(self):96 """Issue XX"""Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 97why, one step back97Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 98–101why, one step back98 heads = {99 'User-agent':100 'Mozilla/5.0 (github.com/kennethreitz/requests)'101 }Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 102why, one step back102Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 103why, one step back103 r = requests.get(httpbin('user-agent'), headers=heads);Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 104why, one step back104 self.assertTrue(heads['User-agent'] in r.content)Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 105why, one step back105Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 106–110why, one step back106 heads = {107 'user-agent':108 'Mozilla/5.0 (github.com/kennethreitz/requests)'109 }110Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 111why, one step back111 r = requests.get(httpbin('user-agent'), headers=heads);Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 112–113why, one step back112 self.assertTrue(heads['user-agent'] in r.content)113Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 114why, one step back114Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 115why, one step back115 def test_HTTP_200_OK_HEAD(self):Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5
line 116why, one step back116 r = requests.head(httpbin('/get'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 117why, one step back117 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 118why, one step back118Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 119–129why, one step back119120 def test_HTTP_200_OK_PUT(self):121 r = requests.put(httpbin('put'))122 self.assertEqual(r.status_code, 200)123124125 def test_HTTP_200_OK_PATCH(self):126 r = requests.patch(httpbin('patch'))127 self.assertEqual(r.status_code, 200)128129Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 130why, one step back130 def test_AUTH_HTTP_200_OK_GET(self):a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 131why, one step back131Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 132why, one step back132 for service in SERVICES:Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 133why, one step back133Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 134–135why, one step back134 auth = ('user', 'pass')135 url = service('basic-auth', 'user', 'pass')Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa
line 136why, one step back136Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 137–139why, one step back137 r = requests.get(url, auth=auth)138 # print r.__dict__139 self.assertEqual(r.status_code, 200)Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa
line 140why, one step back140Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 141why, one step back141Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 142–145why, one step back142 r = requests.get(url)143 self.assertEqual(r.status_code, 200)144145Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 146why, one step back146 def test_POSTBIN_GET_POST_FILES(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 147why, one step back147Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 148why, one step back148 for service in SERVICES:Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 149why, one step back149Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 150–151why, one step back150 url = service('post')151 post = requests.post(url).raise_for_status()Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 152why, one step back152Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 153–154why, one step back153 post = requests.post(url, data={'some': 'data'})154 self.assertEqual(post.status_code, 200)Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 155why, one step back155Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 156–157why, one step back156 post2 = requests.post(url, files={'some': open('test_requests.py')})157 self.assertEqual(post2.status_code, 200)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 158why, one step back158Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 159–162why, one step back159 post3 = requests.post(url, data='[{"some": "json"}]')160 self.assertEqual(post3.status_code, 200)161162Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 163why, one step back163 def test_POSTBIN_GET_POST_FILES_WITH_PARAMS(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 164why, one step back164Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 165why, one step back165 for service in SERVICES:Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 166why, one step back166Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 167–170why, one step back167 url = service('post')168 post = requests.post(url,169 files={'some': open('test_requests.py')},170 data={'some': 'data'})Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 171why, one step back171Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 172–174why, one step back172 self.assertEqual(post.status_code, 200)173174Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 175–176why, one step back175 def test_POSTBIN_GET_POST_FILES_WITH_HEADERS(self):176Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 177why, one step back177 for service in SERVICES:Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 178why, one step back178Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 179why, one step back179 url = service('post')Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 180why, one step back180Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 181–183why, one step back181 post2 = requests.post(url,182 files={'some': open('test_requests.py')},183 headers = {'User-Agent': 'requests-tests'})Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 184why, one step back184Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 185why, one step back185 self.assertEqual(post2.status_code, 200)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 186why, one step back186Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 187why, one step back187Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 188why, one step back188 def test_nonzero_evaluation(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 189why, one step back189Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 190why, one step back190 for service in SERVICES:Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 191why, one step back191Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 192–193why, one step back192 r = requests.get(service('status', '500'))193 self.assertEqual(bool(r), False)Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 194why, one step back194Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5
line 195why, one step back195 r = requests.get(service('/get'))Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 196–198why, one step back196 self.assertEqual(bool(r), True)197198Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 199why, one step back199 def test_request_ok_set(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 200why, one step back200Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 201why, one step back201 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 202why, one step back202Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 203–206why, one step back203 r = requests.get(service('status', '404'))204 self.assertEqual(r.ok, False)205206Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 207why, one step back207 def test_status_raising(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 208why, one step back208 r = requests.get(httpbin('status', '404'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 209why, one step back209 self.assertRaises(requests.HTTPError, r.raise_for_status)Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 210why, one step back210Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 211why, one step back211 r = requests.get(httpbin('status', '200'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 212–213why, one step back212 self.assertFalse(r.error)213 r.raise_for_status()Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 214why, one step back214Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 215why, one step back215Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 216why, one step back216 def test_cookie_jar(self):Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 217why, one step back217Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 218–220why, one step back218 jar = cookielib.CookieJar()219 self.assertFalse(jar)220Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 221–222why, one step back221 url = httpbin('cookies', 'set', 'requests_cookie', 'awesome')222 r = requests.get(url, cookies=jar)Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 223why, one step back223 self.assertTrue(jar)Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 224why, one step back224Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 225–235why, one step back225 cookie_found = False226 for cookie in jar:227 if cookie.name == 'requests_cookie':228 self.assertEquals(cookie.value, 'awesome')229 cookie_found = True230 self.assertTrue(cookie_found)231232 r = requests.get(httpbin('cookies'), cookies=jar)233 self.assertTrue('awesome' in r.content)234235Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 236why, one step back236 def test_decompress_gzip(self):a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 237why, one step back237Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 238why, one step back238 r = requests.get(httpbin('gzip'))Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
lines 239–240why, one step back239 r.content.decode('ascii')240Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 241why, one step back241Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 242why, one step back242 def test_unicode_get(self):Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 243why, one step back243Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 244why, one step back244 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 245why, one step back245Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5
line 246why, one step back246 url = service('/get')Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 247why, one step back247Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 248–252why, one step back248 requests.get(url, params={'foo': u'føø'})249 requests.get(url, params={u'føø': u'føø'})250 requests.get(url, params={'føø': 'føø'})251 requests.get(url, params={'foo': u'foo'})252 requests.get(service('ø'), params={'foo': u'foo'})Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 253why, one step back253Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 254why, one step back254Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 255why, one step back255 def test_httpauth_recursion(self):Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 256why, one step back256Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 257why, one step back257 http_auth = ('user', 'BADpass')Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 258why, one step back258Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 259–261why, one step back259 for service in SERVICES:260 r = requests.get(service('basic-auth', 'user', 'pass'), auth=http_auth)261 self.assertEquals(r.status_code, 401)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 262why, one step back262Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 263–265why, one step back263264 def test_urlencoded_post_data(self):265Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 266why, one step back266 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 267why, one step back267Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 268–279why, one step back268 r = requests.post(service('post'), data=dict(test='fooaowpeuf'))269270 self.assertEquals(r.status_code, 200)271 self.assertEquals(r.headers['content-type'], 'application/json')272 self.assertEquals(r.url, service('post'))273274 rbody = json.loads(r.content)275276 self.assertEquals(rbody.get('form'), dict(test='fooaowpeuf'))277 self.assertEquals(rbody.get('data'), '')278279Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 280why, one step back280 def test_nonurlencoded_post_data(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 281why, one step back281Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 282why, one step back282 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 283why, one step back283Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 284–296why, one step back284 r = requests.post(service('post'), data='fooaowpeuf')285286 self.assertEquals(r.status_code, 200)287 self.assertEquals(r.headers['content-type'], 'application/json')288 self.assertEquals(r.url, service('post'))289290 rbody = json.loads(r.content)291 # Body wasn't valid url encoded data, so the server returns None as292 # "form" and the raw body as "data".293 self.assertEquals(rbody.get('form'), None)294 self.assertEquals(rbody.get('data'), 'fooaowpeuf')295296Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 297–298why, one step back297 def test_urlencoded_post_querystring(self):298Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 299why, one step back299 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 300why, one step back300Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 301–311why, one step back301 r = requests.post(service('post'), params=dict(test='fooaowpeuf'))302303 self.assertEquals(r.status_code, 200)304 self.assertEquals(r.headers['content-type'], 'application/json')305 self.assertEquals(r.url, service('post?test=fooaowpeuf'))306307 rbody = json.loads(r.content)308 self.assertEquals(rbody.get('form'), {}) # No form supplied309 self.assertEquals(rbody.get('data'), '')310311Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 312–313why, one step back312 def test_nonurlencoded_post_querystring(self):313Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 314why, one step back314 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 315why, one step back315Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 316–326why, one step back316 r = requests.post(service('post'), params='fooaowpeuf')317318 self.assertEquals(r.status_code, 200)319 self.assertEquals(r.headers['content-type'], 'application/json')320 self.assertEquals(r.url, service('post?fooaowpeuf'))321322 rbody = json.loads(r.content)323 self.assertEquals(rbody.get('form'), {}) # No form supplied324 self.assertEquals(rbody.get('data'), '')325326Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 327–328why, one step back327 def test_urlencoded_post_query_and_data(self):328Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 329why, one step back329 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 330why, one step back330Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 331–344why, one step back331 r = requests.post(332 service('post'),333 params=dict(test='fooaowpeuf'),334 data=dict(test2="foobar"))335336 self.assertEquals(r.status_code, 200)337 self.assertEquals(r.headers['content-type'], 'application/json')338 self.assertEquals(r.url, service('post?test=fooaowpeuf'))339340 rbody = json.loads(r.content)341 self.assertEquals(rbody.get('form'), dict(test2='foobar'))342 self.assertEquals(rbody.get('data'), '')343344Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 345why, one step back345 def test_nonurlencoded_post_query_and_data(self):Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 346why, one step back346Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 347–361why, one step back347 for service in SERVICES:348349 r = requests.post(service('post'),350 params='fooaowpeuf', data="foobar")351352 self.assertEquals(r.status_code, 200)353 self.assertEquals(r.headers['content-type'], 'application/json')354 self.assertEquals(r.url, service('post?fooaowpeuf'))355356 rbody = json.loads(r.content)357358 self.assertEquals(rbody.get('form'), None)359 self.assertEquals(rbody.get('data'), 'foobar')360361remove idna tests, for nowKenneth Reitzbefore adoptiond85c535
lines 362–364why, one step back362 # def test_idna(self):363 # r = requests.get(u'http://➡.ws/httpbin')364 # assert 'httpbin' in r.urlMerge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 365why, one step back365Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 366why, one step back366Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 367–368why, one step back367 def test_urlencoded_get_query_multivalued_param(self):368Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 369–375why, one step back369 for service in SERVICES:370371 r = requests.get(service('get'), params=dict(test=['foo','baz']))372 self.assertEquals(r.status_code, 200)373 self.assertEquals(r.url, service('get?test=foo&test=baz'))374375Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 376–377why, one step back376 def test_urlencoded_post_querystring_multivalued(self):377Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 378–389why, one step back378 for service in SERVICES:379380 r = requests.post(service('post'), params=dict(test=['foo','baz']))381 self.assertEquals(r.status_code, 200)382 self.assertEquals(r.headers['content-type'], 'application/json')383 self.assertEquals(r.url, service('post?test=foo&test=baz'))384385 rbody = json.loads(r.content)386 self.assertEquals(rbody.get('form'), {}) # No form supplied387 self.assertEquals(rbody.get('data'), '')388389Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 390–391why, one step back390 def test_urlencoded_post_query_multivalued_and_data(self):391Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 392why, one step back392 for service in SERVICES:Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
line 393why, one step back393Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 394–406why, one step back394 r = requests.post(395 service('post'),396 params=dict(test=['foo','baz']),397 data=dict(test2="foobar",test3=['foo','baz']))398399 self.assertEquals(r.status_code, 200)400 self.assertEquals(r.headers['content-type'], 'application/json')401 self.assertEquals(r.url, service('post?test=foo&test=baz'))402 rbody = json.loads(r.content)403 self.assertEquals(rbody.get('form'), dict(test2='foobar',test3='foo'))404 self.assertEquals(rbody.get('data'), '')405406Merge branch 'redirect-no-follow' of https://github.com/millerdev/requestsKenneth Reitzbefore adoption98c719f
lines 407–424why, one step back407 def test_GET_no_redirect(self):408409 for service in SERVICES:410411 r = requests.get(service('redirect', '3'), allow_redirects=False)412 self.assertEquals(r.status_code, 302)413 self.assertEquals(len(r.history), 0)414415416 def test_HEAD_no_redirect(self):417418 for service in SERVICES:419420 r = requests.head(service('redirect', '3'), allow_redirects=False)421 self.assertEquals(r.status_code, 302)422 self.assertEquals(len(r.history), 0)423424Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 425–426why, one step back425 def test_redirect_history(self):426Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 427–445why, one step back427 for service in SERVICES:428429 r = requests.get(service('redirect', '3'))430 self.assertEquals(r.status_code, 200)431 self.assertEquals(len(r.history), 3)432433434 def test_relative_redirect_history(self):435436 for service in SERVICES:437438 r = requests.get(service('relative-redirect', '3'))439 self.assertEquals(r.status_code, 200)440 self.assertEquals(len(r.history), 3)441442443 def test_session_HTTP_200_OK_GET(self):444445 s = Session()Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5
line 446why, one step back446 r = s.get(httpbin('/get'))Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 447–455why, one step back447 self.assertEqual(r.status_code, 200)448449450 def test_session_persistent_headers(self):451452 heads = {'User-agent': 'Mozilla/5.0'}453454 s = Session()455 s.headers = headstesting session method attribute mergingKenneth Reitzbefore adoptionec94f50
line 456why, one step back456Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 457–460why, one step back457 # Make 2 requests from Session object, should send header both times458 r1 = s.get(httpbin('user-agent'))459 assert heads['User-agent'] in r1.content460testing session method attribute mergingKenneth Reitzbefore adoptionec94f50
line 461why, one step back461 r2 = s.get(httpbin('user-agent'))Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 462why, one step back462 assert heads['User-agent'] in r2.contenttesting session method attribute mergingKenneth Reitzbefore adoptionec94f50
lines 463–467why, one step back463464 new_heads = {'User-agent': 'blah'}465 r3 = s.get(httpbin('user-agent'), headers=new_heads)466 assert new_heads['User-agent'] in r3.content467Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 468–469why, one step back468 self.assertEqual(r2.status_code, 200)469Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 470why, one step back470test session persistent paramsKenneth Reitzbefore adoption7dc75ce
lines 471–498why, one step back471 def test_session_persistent_params(self):472473 params = {'a': 'a_test'}474475 s = Session()476 s.params = params477478 # Make 2 requests from Session object, should send header both times479 r1 = s.get(httpbin('get'))480 assert params['a'] in r1.content481482483 params2 = {'b': 'b_test'}484485 r2 = s.get(httpbin('get'), params=params2)486 assert params['a'] in r2.content487 assert params2['b'] in r2.content488489490 params3 = {'b': 'b_test', 'a': None, 'c': 'c_test'}491492 r3 = s.get(httpbin('get'), params=params3)493494 assert not params['a'] in r3.content495 assert params3['b'] in r3.content496 assert params3['c'] in r3.content497498a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 499why, one step back499if __name__ == '__main__':Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 500why, one step back500 unittest.main()