test_requests.py
This file
Path
test_requests.py
495 lines · 13.4 KiB · Python
Last changed by
Merge branch 'develop' into feature/asyncKenneth Reitzbefore adoption2115046
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_statement5sample test fixtures (none)Kenneth Reitzbefore adoption75b499d
line 6why, one step back6import unittestMerge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 7why, one step back7import cookielibtemp "tests"Kenneth Reitzbefore adoption49f915f
line 8why, one step back8Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 9–12why, one step back9try:10 import omnijson as json11except ImportError:12 import jsonMerge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 13why, one step back13temp "tests"Kenneth Reitzbefore adoption49f915f
lines 14–15why, one step back14import requests15Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 16why, one step back16from requests.sessions import Sessiontemp "tests"Kenneth Reitzbefore adoption49f915f
line 17why, one step back17Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 18why, one step back18Merge branch 'develop' into feature/asyncKenneth Reitzbefore adoption2115046
line 19why, one step back19HTTPBIN_URL = 'http://httpbin.ep.io/'Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 20–37why, one step back20HTTPSBIN_URL = 'https://httpbin.ep.io/'2122# HTTPBIN_URL = 'http://staging.httpbin.org/'23# HTTPSBIN_URL = 'https://httpbin-staging.ep.io/'242526def httpbin(*suffix):27 """Returns url for HTTPBIN resource."""2829 return HTTPBIN_URL + '/'.join(suffix)303132def httpsbin(*suffix):33 """Returns url for HTTPSBIN resource."""3435 return HTTPSBIN_URL + '/'.join(suffix)3637Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 38why, one step back38SERVICES = (httpbin, httpsbin)Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 39why, one step back39Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 40–41why, one step back4041a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 42why, one step back42class RequestsTestSuite(unittest.TestCase):Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 43why, one step back43 """Requests test cases."""Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 44why, one step back44Merge branch 'develop' into feature/asyncKenneth Reitzbefore adoption2115046
lines 45–46why, one step back45 # It goes to eleven.46 _multiprocess_can_split_ = TrueMerge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 47why, one step back47Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 48–49why, one step back48 def setUp(self):49 passtemp "tests"Kenneth Reitzbefore adoption49f915f
line 50why, one step back50Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 51why, one step back51Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 52–54why, one step back52 def tearDown(self):53 """Teardown."""54 passMerge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 55why, one step back55Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 56why, one step back56Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 57–58why, one step back57 def test_invalid_url(self):58 self.assertRaises(ValueError, requests.get, 'hiwpefhipowhefopw')a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 59why, one step back59Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 60why, one step back60Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 61why, one step back61 def test_HTTP_200_OK_GET(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 62why, one step back62 r = requests.get(httpbin('/'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 63why, one step back63 self.assertEqual(r.status_code, 200)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_HTTPS_200_OK_GET(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 67why, one step back67 r = requests.get(httpsbin('/'))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 branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 70why, one step back70Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 71–72why, one step back71 def test_HTTP_200_OK_GET_WITH_PARAMS(self):72 heads = {'User-agent': 'Mozilla/5.0'}Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 73why, one step back73Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 74–76why, one step back74 r = requests.get(httpbin('user-agent'), headers=heads)7576 assert heads['User-agent'] in r.contentMerge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 77–78why, one step back77 self.assertEqual(r.status_code, 200)78Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 79why, one step back79Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 80–82why, one step back80 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self):81 heads = {'User-agent': 'Mozilla/5.0'}82Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 83why, one step back83 r = requests.get(httpbin('get') + '?test=true', params={'q': 'test'}, headers=heads)Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 84why, one step back84 self.assertEqual(r.status_code, 200)Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 85why, one step back85Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 86why, one step back86Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 87–88why, one step back87 def test_user_agent_transfers(self):88 """Issue XX"""Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 89why, one step back89Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 90–93why, one step back90 heads = {91 'User-agent':92 'Mozilla/5.0 (github.com/kennethreitz/requests)'93 }Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 94why, one step back94Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 95why, one step back95 r = requests.get(httpbin('user-agent'), headers=heads);Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 96why, one step back96 self.assertTrue(heads['User-agent'] in r.content)Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 97why, one step back97Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 98–102why, one step back98 heads = {99 'user-agent':100 'Mozilla/5.0 (github.com/kennethreitz/requests)'101 }102Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 103why, one step back103 r = requests.get(httpbin('user-agent'), headers=heads);Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 104–105why, one step back104 self.assertTrue(heads['user-agent'] in r.content)105Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 106why, one step back106Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 107why, one step back107 def test_HTTP_200_OK_HEAD(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 108why, one step back108 r = requests.head(httpbin('/'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 109why, one step back109 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 110why, one step back110Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 111why, one step back111Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 112why, one step back112 def test_HTTPS_200_OK_HEAD(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 113why, one step back113 r = requests.head(httpsbin('/'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 114why, one step back114 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 115why, one step back115Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 116–136why, one step back116117 def test_HTTP_200_OK_PUT(self):118 r = requests.put(httpbin('put'))119 self.assertEqual(r.status_code, 200)120121122 def test_HTTPS_200_OK_PUT(self):123 r = requests.put(httpsbin('put'))124 self.assertEqual(r.status_code, 200)125126127 def test_HTTP_200_OK_PATCH(self):128 r = requests.patch(httpbin('patch'))129 self.assertEqual(r.status_code, 200)130131132 def test_HTTPS_200_OK_PATCH(self):133 r = requests.patch(httpsbin('patch'))134 self.assertEqual(r.status_code, 200)135136Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 137why, one step back137 def test_AUTH_HTTP_200_OK_GET(self):a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 138why, one step back138Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 139why, one step back139 for service in SERVICES:Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 140why, one step back140Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 141–142why, one step back141 auth = ('user', 'pass')142 url = service('basic-auth', 'user', 'pass')Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa
line 143why, one step back143Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 144–146why, one step back144 r = requests.get(url, auth=auth)145 # print r.__dict__146 self.assertEqual(r.status_code, 200)Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa
line 147why, one step back147Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 148why, one step back148Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 149–152why, one step back149 r = requests.get(url)150 self.assertEqual(r.status_code, 200)151152Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 153why, one step back153 def test_POSTBIN_GET_POST_FILES(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 154why, one step back154Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 155why, one step back155 for service in SERVICES:Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 156why, one step back156Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 157–158why, one step back157 url = service('post')158 post = requests.post(url).raise_for_status()Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 159why, one step back159Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 160–161why, one step back160 post = requests.post(url, data={'some': 'data'})161 self.assertEqual(post.status_code, 200)Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 162why, one step back162Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 163–164why, one step back163 post2 = requests.post(url, files={'some': open('test_requests.py')})164 self.assertEqual(post2.status_code, 200)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 165why, one step back165Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 166–169why, one step back166 post3 = requests.post(url, data='[{"some": "json"}]')167 self.assertEqual(post3.status_code, 200)168169Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 170why, one step back170 def test_POSTBIN_GET_POST_FILES_WITH_PARAMS(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 171why, one step back171Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 172why, one step back172 for service in SERVICES:Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 173why, one step back173Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 174–177why, one step back174 url = service('post')175 post = requests.post(url,176 files={'some': open('test_requests.py')},177 data={'some': 'data'})Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 178why, one step back178Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 179–181why, one step back179 self.assertEqual(post.status_code, 200)180181Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 182–183why, one step back182 def test_POSTBIN_GET_POST_FILES_WITH_HEADERS(self):183Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 184why, one step back184 for service in SERVICES:Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 185why, one step back185Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 186why, one step back186 url = service('post')Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 187why, one step back187Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 188–190why, one step back188 post2 = requests.post(url,189 files={'some': open('test_requests.py')},190 headers = {'User-Agent': 'requests-tests'})Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 191why, one step back191Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 192why, one step back192 self.assertEqual(post2.status_code, 200)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 193why, one step back193Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 194why, one step back194Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 195why, one step back195 def test_nonzero_evaluation(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 196why, one step back196Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 197why, one step back197 for service in SERVICES:Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 198why, one step back198Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 199–200why, one step back199 r = requests.get(service('status', '500'))200 self.assertEqual(bool(r), False)Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 201why, one step back201Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 202–205why, one step back202 r = requests.get(service('/'))203 self.assertEqual(bool(r), True)204205Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 206why, one step back206 def test_request_ok_set(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 207why, one step back207Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 208why, one step back208 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 209why, one step back209Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 210–213why, one step back210 r = requests.get(service('status', '404'))211 self.assertEqual(r.ok, False)212213Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 214why, one step back214 def test_status_raising(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 215why, one step back215 r = requests.get(httpbin('status', '404'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 216why, one step back216 self.assertRaises(requests.HTTPError, r.raise_for_status)Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 217why, one step back217Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 218why, one step back218 r = requests.get(httpbin('status', '200'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 219–220why, one step back219 self.assertFalse(r.error)220 r.raise_for_status()Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 221why, one step back221Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 222why, one step back222Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 223why, one step back223 def test_cookie_jar(self):Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 224why, one step back224Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 225–227why, one step back225 jar = cookielib.CookieJar()226 self.assertFalse(jar)227Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 228–229why, one step back228 url = httpbin('cookies', 'set', 'requests_cookie', 'awesome')229 r = requests.get(url, cookies=jar)Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 230why, one step back230 self.assertTrue(jar)Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 231why, one step back231Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 232–242why, one step back232 cookie_found = False233 for cookie in jar:234 if cookie.name == 'requests_cookie':235 self.assertEquals(cookie.value, 'awesome')236 cookie_found = True237 self.assertTrue(cookie_found)238239 r = requests.get(httpbin('cookies'), cookies=jar)240 self.assertTrue('awesome' in r.content)241242Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 243why, one step back243 def test_decompress_gzip(self):a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 244why, one step back244Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 245why, one step back245 r = requests.get(httpbin('gzip'))Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
lines 246–247why, one step back246 r.content.decode('ascii')247Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 248why, one step back248Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 249why, one step back249 def test_unicode_get(self):Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 250why, one step back250Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 251why, one step back251 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 252why, one step back252Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 253why, one step back253 url = service('/')Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 254why, one step back254Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 255–259why, one step back255 requests.get(url, params={'foo': u'føø'})256 requests.get(url, params={u'føø': u'føø'})257 requests.get(url, params={'føø': 'føø'})258 requests.get(url, params={'foo': u'foo'})259 requests.get(service('ø'), params={'foo': u'foo'})Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 260why, one step back260Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 261why, one step back261Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 262why, one step back262 def test_httpauth_recursion(self):Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 263why, one step back263Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 264why, one step back264 http_auth = ('user', 'BADpass')Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 265why, one step back265Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 266–268why, one step back266 for service in SERVICES:267 r = requests.get(service('basic-auth', 'user', 'pass'), auth=http_auth)268 self.assertEquals(r.status_code, 401)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 269why, one step back269Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 270why, one step back270Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 271–272why, one step back271 def test_settings(self):272Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 273–275why, one step back273 def test():274 r = requests.get(httpbin(''))275 r.raise_for_status()Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 276why, one step back276Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 277–285why, one step back277 with requests.settings(timeout=0.0000001):278 self.assertRaises(requests.Timeout, test)279280 with requests.settings(timeout=100):281 requests.get(httpbin(''))282283284 def test_urlencoded_post_data(self):285Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 286why, one step back286 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 287why, one step back287Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 288–299why, one step back288 r = requests.post(service('post'), data=dict(test='fooaowpeuf'))289290 self.assertEquals(r.status_code, 200)291 self.assertEquals(r.headers['content-type'], 'application/json')292 self.assertEquals(r.url, service('post'))293294 rbody = json.loads(r.content)295296 self.assertEquals(rbody.get('form'), dict(test='fooaowpeuf'))297 self.assertEquals(rbody.get('data'), '')298299Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 300why, one step back300 def test_nonurlencoded_post_data(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 301why, one step back301Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 302why, one step back302 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 303why, one step back303Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 304–316why, one step back304 r = requests.post(service('post'), data='fooaowpeuf')305306 self.assertEquals(r.status_code, 200)307 self.assertEquals(r.headers['content-type'], 'application/json')308 self.assertEquals(r.url, service('post'))309310 rbody = json.loads(r.content)311 # Body wasn't valid url encoded data, so the server returns None as312 # "form" and the raw body as "data".313 self.assertEquals(rbody.get('form'), None)314 self.assertEquals(rbody.get('data'), 'fooaowpeuf')315316Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 317–318why, one step back317 def test_urlencoded_post_querystring(self):318Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 319why, one step back319 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 320why, one step back320Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 321–331why, one step back321 r = requests.post(service('post'), params=dict(test='fooaowpeuf'))322323 self.assertEquals(r.status_code, 200)324 self.assertEquals(r.headers['content-type'], 'application/json')325 self.assertEquals(r.url, service('post?test=fooaowpeuf'))326327 rbody = json.loads(r.content)328 self.assertEquals(rbody.get('form'), {}) # No form supplied329 self.assertEquals(rbody.get('data'), '')330331Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 332–333why, one step back332 def test_nonurlencoded_post_querystring(self):333Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 334why, one step back334 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 335why, one step back335Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 336–346why, one step back336 r = requests.post(service('post'), params='fooaowpeuf')337338 self.assertEquals(r.status_code, 200)339 self.assertEquals(r.headers['content-type'], 'application/json')340 self.assertEquals(r.url, service('post?fooaowpeuf'))341342 rbody = json.loads(r.content)343 self.assertEquals(rbody.get('form'), {}) # No form supplied344 self.assertEquals(rbody.get('data'), '')345346Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 347–348why, one step back347 def test_urlencoded_post_query_and_data(self):348Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 349why, one step back349 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 350why, one step back350Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 351–364why, one step back351 r = requests.post(352 service('post'),353 params=dict(test='fooaowpeuf'),354 data=dict(test2="foobar"))355356 self.assertEquals(r.status_code, 200)357 self.assertEquals(r.headers['content-type'], 'application/json')358 self.assertEquals(r.url, service('post?test=fooaowpeuf'))359360 rbody = json.loads(r.content)361 self.assertEquals(rbody.get('form'), dict(test2='foobar'))362 self.assertEquals(rbody.get('data'), '')363364Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 365why, one step back365 def test_nonurlencoded_post_query_and_data(self):Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 366why, one step back366Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 367–381why, one step back367 for service in SERVICES:368369 r = requests.post(service('post'),370 params='fooaowpeuf', data="foobar")371372 self.assertEquals(r.status_code, 200)373 self.assertEquals(r.headers['content-type'], 'application/json')374 self.assertEquals(r.url, service('post?fooaowpeuf'))375376 rbody = json.loads(r.content)377378 self.assertEquals(rbody.get('form'), None)379 self.assertEquals(rbody.get('data'), 'foobar')380381Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 382–384why, one step back382 def test_idna(self):383 r = requests.get(u'http://➡.ws/httpbin')384 assert 'httpbin' in r.urlMerge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 385why, one step back385Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 386why, one step back386Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 387–388why, one step back387 def test_urlencoded_get_query_multivalued_param(self):388Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 389–395why, one step back389 for service in SERVICES:390391 r = requests.get(service('get'), params=dict(test=['foo','baz']))392 self.assertEquals(r.status_code, 200)393 self.assertEquals(r.url, service('get?test=foo&test=baz'))394395Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 396–397why, one step back396 def test_urlencoded_post_querystring_multivalued(self):397Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 398–409why, one step back398 for service in SERVICES:399400 r = requests.post(service('post'), params=dict(test=['foo','baz']))401 self.assertEquals(r.status_code, 200)402 self.assertEquals(r.headers['content-type'], 'application/json')403 self.assertEquals(r.url, service('post?test=foo&test=baz'))404405 rbody = json.loads(r.content)406 self.assertEquals(rbody.get('form'), {}) # No form supplied407 self.assertEquals(rbody.get('data'), '')408409Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 410–411why, one step back410 def test_urlencoded_post_query_multivalued_and_data(self):411Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 412why, one step back412 for service in SERVICES:Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
line 413why, one step back413Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 414–426why, one step back414 r = requests.post(415 service('post'),416 params=dict(test=['foo','baz']),417 data=dict(test2="foobar",test3=['foo','baz']))418419 self.assertEquals(r.status_code, 200)420 self.assertEquals(r.headers['content-type'], 'application/json')421 self.assertEquals(r.url, service('post?test=foo&test=baz'))422 rbody = json.loads(r.content)423 self.assertEquals(rbody.get('form'), dict(test2='foobar',test3='foo'))424 self.assertEquals(rbody.get('data'), '')425426Merge branch 'redirect-no-follow' of https://github.com/millerdev/requestsKenneth Reitzbefore adoption98c719f
lines 427–444why, one step back427 def test_GET_no_redirect(self):428429 for service in SERVICES:430431 r = requests.get(service('redirect', '3'), allow_redirects=False)432 self.assertEquals(r.status_code, 302)433 self.assertEquals(len(r.history), 0)434435436 def test_HEAD_no_redirect(self):437438 for service in SERVICES:439440 r = requests.head(service('redirect', '3'), allow_redirects=False)441 self.assertEquals(r.status_code, 302)442 self.assertEquals(len(r.history), 0)443444Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 445–446why, one step back445 def test_redirect_history(self):446Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 447–492why, one step back447 for service in SERVICES:448449 r = requests.get(service('redirect', '3'))450 self.assertEquals(r.status_code, 200)451 self.assertEquals(len(r.history), 3)452453454 def test_relative_redirect_history(self):455456 for service in SERVICES:457458 r = requests.get(service('relative-redirect', '3'))459 self.assertEquals(r.status_code, 200)460 self.assertEquals(len(r.history), 3)461462463 def test_session_HTTP_200_OK_GET(self):464465 s = Session()466 r = s.get(httpbin('/'))467 self.assertEqual(r.status_code, 200)468469470 def test_session_HTTPS_200_OK_GET(self):471472 s = Session()473 r = s.get(httpsbin('/'))474 self.assertEqual(r.status_code, 200)475476477 def test_session_persistent_headers(self):478479 heads = {'User-agent': 'Mozilla/5.0'}480481 s = Session()482 s.headers = heads483 # Make 2 requests from Session object, should send header both times484 r1 = s.get(httpbin('user-agent'))485486 assert heads['User-agent'] in r1.content487 r2 = s.get(httpbin('user-agent'))488489 assert heads['User-agent'] in r2.content490 self.assertEqual(r2.status_code, 200)491492Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 493why, one step back493a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 494why, one step back494if __name__ == '__main__':Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 495why, one step back495 unittest.main()