test_requests.py
This file
Path
test_requests.py
501 lines · 13.7 KiB · Python
Last changed by
Merge pull request #202 from kennethreitz/feature/content-streamKenneth Reitzbefore adoptionbfa0103
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 back18Make tests go to 11!Kenneth Reitzbefore adoption76b8afe
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 back44Make tests go to 11!Kenneth Reitzbefore adoption76b8afe
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 pull request #202 from kennethreitz/feature/content-streamKenneth Reitzbefore adoptionbfa0103
lines 65–67why, one step back65 def test_HTTP_302_ALLOW_REDIRECT_GET(self):66 r = requests.get(httpbin('redirect', '1'))67 self.assertEqual(r.status_code, 200)Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 68why, one step back68Merge pull request #202 from kennethreitz/feature/content-streamKenneth Reitzbefore adoptionbfa0103
lines 69–72why, one step back69 def test_HTTP_302_GET(self):70 r = requests.get(httpbin('redirect', '1'), allow_redirects=False)71 self.assertEqual(r.status_code, 302)72Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 73why, one step back73 def test_HTTPS_200_OK_GET(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 74why, one step back74 r = requests.get(httpsbin('/'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 75why, one step back75 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 76why, one step back76Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 77why, one step back77Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 78–79why, one step back78 def test_HTTP_200_OK_GET_WITH_PARAMS(self):79 heads = {'User-agent': 'Mozilla/5.0'}Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 80why, one step back80Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 81–83why, one step back81 r = requests.get(httpbin('user-agent'), headers=heads)8283 assert heads['User-agent'] in r.contentMerge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 84–85why, one step back84 self.assertEqual(r.status_code, 200)85Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 86why, one step back86Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 87–89why, one step back87 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self):88 heads = {'User-agent': 'Mozilla/5.0'}89Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 90why, one step back90 r = requests.get(httpbin('get') + '?test=true', params={'q': 'test'}, headers=heads)Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 91why, one step back91 self.assertEqual(r.status_code, 200)Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 92why, one step back92Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 93why, one step back93Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 94–95why, one step back94 def test_user_agent_transfers(self):95 """Issue XX"""Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 96why, one step back96Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 97–100why, one step back97 heads = {98 'User-agent':99 'Mozilla/5.0 (github.com/kennethreitz/requests)'100 }Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 101why, one step back101Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 102why, one step back102 r = requests.get(httpbin('user-agent'), headers=heads);Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 103why, one step back103 self.assertTrue(heads['User-agent'] in r.content)Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 104why, one step back104Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 105–109why, one step back105 heads = {106 'user-agent':107 'Mozilla/5.0 (github.com/kennethreitz/requests)'108 }109Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 110why, one step back110 r = requests.get(httpbin('user-agent'), headers=heads);Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 111–112why, one step back111 self.assertTrue(heads['user-agent'] in r.content)112Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 113why, one step back113Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 114why, one step back114 def test_HTTP_200_OK_HEAD(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 115why, one step back115 r = requests.head(httpbin('/'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 116why, one step back116 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 117why, one step back117Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 118why, one step back118Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 119why, one step back119 def test_HTTPS_200_OK_HEAD(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 120why, one step back120 r = requests.head(httpsbin('/'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 121why, one step back121 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 122why, one step back122Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 123–143why, one step back123124 def test_HTTP_200_OK_PUT(self):125 r = requests.put(httpbin('put'))126 self.assertEqual(r.status_code, 200)127128129 def test_HTTPS_200_OK_PUT(self):130 r = requests.put(httpsbin('put'))131 self.assertEqual(r.status_code, 200)132133134 def test_HTTP_200_OK_PATCH(self):135 r = requests.patch(httpbin('patch'))136 self.assertEqual(r.status_code, 200)137138139 def test_HTTPS_200_OK_PATCH(self):140 r = requests.patch(httpsbin('patch'))141 self.assertEqual(r.status_code, 200)142143Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 144why, one step back144 def test_AUTH_HTTP_200_OK_GET(self):a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 145why, one step back145Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 146why, one step back146 for service in SERVICES:Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 147why, one step back147Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 148–149why, one step back148 auth = ('user', 'pass')149 url = service('basic-auth', 'user', 'pass')Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa
line 150why, one step back150Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 151–153why, one step back151 r = requests.get(url, auth=auth)152 # print r.__dict__153 self.assertEqual(r.status_code, 200)Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa
line 154why, one step back154Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 155why, one step back155Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 156–159why, one step back156 r = requests.get(url)157 self.assertEqual(r.status_code, 200)158159Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 160why, one step back160 def test_POSTBIN_GET_POST_FILES(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 161why, one step back161Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 162why, one step back162 for service in SERVICES:Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 163why, one step back163Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 164–165why, one step back164 url = service('post')165 post = requests.post(url).raise_for_status()Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 166why, one step back166Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 167–168why, one step back167 post = requests.post(url, data={'some': 'data'})168 self.assertEqual(post.status_code, 200)Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 169why, one step back169Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 170–171why, one step back170 post2 = requests.post(url, files={'some': open('test_requests.py')})171 self.assertEqual(post2.status_code, 200)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 172why, one step back172Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 173–176why, one step back173 post3 = requests.post(url, data='[{"some": "json"}]')174 self.assertEqual(post3.status_code, 200)175176Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 177why, one step back177 def test_POSTBIN_GET_POST_FILES_WITH_PARAMS(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 178why, one step back178Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 179why, one step back179 for service in SERVICES:Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 180why, one step back180Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 181–184why, one step back181 url = service('post')182 post = requests.post(url,183 files={'some': open('test_requests.py')},184 data={'some': 'data'})Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 185why, one step back185Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 186–188why, one step back186 self.assertEqual(post.status_code, 200)187188Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 189–190why, one step back189 def test_POSTBIN_GET_POST_FILES_WITH_HEADERS(self):190Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 191why, one step back191 for service in SERVICES:Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 192why, one step back192Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 193why, one step back193 url = service('post')Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 194why, one step back194Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 195–197why, one step back195 post2 = requests.post(url,196 files={'some': open('test_requests.py')},197 headers = {'User-Agent': 'requests-tests'})Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 198why, one step back198Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 199why, one step back199 self.assertEqual(post2.status_code, 200)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 200why, one step back200Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 201why, one step back201Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 202why, one step back202 def test_nonzero_evaluation(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 203why, one step back203Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 204why, one step back204 for service in SERVICES:Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 205why, one step back205Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 206–207why, one step back206 r = requests.get(service('status', '500'))207 self.assertEqual(bool(r), False)Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 208why, one step back208Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 209–212why, one step back209 r = requests.get(service('/'))210 self.assertEqual(bool(r), True)211212Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 213why, one step back213 def test_request_ok_set(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 214why, one step back214Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 215why, one step back215 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 216why, one step back216Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 217–220why, one step back217 r = requests.get(service('status', '404'))218 self.assertEqual(r.ok, False)219220Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 221why, one step back221 def test_status_raising(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 222why, one step back222 r = requests.get(httpbin('status', '404'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 223why, one step back223 self.assertRaises(requests.HTTPError, r.raise_for_status)Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 224why, one step back224Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 225why, one step back225 r = requests.get(httpbin('status', '200'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 226–227why, one step back226 self.assertFalse(r.error)227 r.raise_for_status()Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 228why, one step back228Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 229why, one step back229Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 230why, one step back230 def test_cookie_jar(self):Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 231why, one step back231Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 232–234why, one step back232 jar = cookielib.CookieJar()233 self.assertFalse(jar)234Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 235–236why, one step back235 url = httpbin('cookies', 'set', 'requests_cookie', 'awesome')236 r = requests.get(url, cookies=jar)Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 237why, one step back237 self.assertTrue(jar)Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 238why, one step back238Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 239–249why, one step back239 cookie_found = False240 for cookie in jar:241 if cookie.name == 'requests_cookie':242 self.assertEquals(cookie.value, 'awesome')243 cookie_found = True244 self.assertTrue(cookie_found)245246 r = requests.get(httpbin('cookies'), cookies=jar)247 self.assertTrue('awesome' in r.content)248249Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 250why, one step back250 def test_decompress_gzip(self):a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 251why, one step back251Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 252why, one step back252 r = requests.get(httpbin('gzip'))Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
lines 253–254why, one step back253 r.content.decode('ascii')254Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 255why, one step back255Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 256why, one step back256 def test_unicode_get(self):Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 257why, one step back257Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 258why, one step back258 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 259why, one step back259Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 260why, one step back260 url = service('/')Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 261why, one step back261Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 262–266why, one step back262 requests.get(url, params={'foo': u'føø'})263 requests.get(url, params={u'føø': u'føø'})264 requests.get(url, params={'føø': 'føø'})265 requests.get(url, params={'foo': u'foo'})266 requests.get(service('ø'), params={'foo': u'foo'})Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 267why, one step back267Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 268why, one step back268Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 269why, one step back269 def test_httpauth_recursion(self):Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 270why, one step back270Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 271why, one step back271 http_auth = ('user', 'BADpass')Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 272why, one step back272Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 273–275why, one step back273 for service in SERVICES:274 r = requests.get(service('basic-auth', 'user', 'pass'), auth=http_auth)275 self.assertEquals(r.status_code, 401)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 276why, one step back276Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 277why, one step back277Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 278–279why, one step back278 def test_settings(self):279Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 280–282why, one step back280 def test():281 r = requests.get(httpbin(''))282 r.raise_for_status()Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 283why, one step back283Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 284–292why, one step back284 with requests.settings(timeout=0.0000001):285 self.assertRaises(requests.Timeout, test)286287 with requests.settings(timeout=100):288 requests.get(httpbin(''))289290291 def test_urlencoded_post_data(self):292Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 293why, one step back293 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 294why, one step back294Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 295–306why, one step back295 r = requests.post(service('post'), data=dict(test='fooaowpeuf'))296297 self.assertEquals(r.status_code, 200)298 self.assertEquals(r.headers['content-type'], 'application/json')299 self.assertEquals(r.url, service('post'))300301 rbody = json.loads(r.content)302303 self.assertEquals(rbody.get('form'), dict(test='fooaowpeuf'))304 self.assertEquals(rbody.get('data'), '')305306Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 307why, one step back307 def test_nonurlencoded_post_data(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 308why, one step back308Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 309why, one step back309 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 310why, one step back310Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 311–323why, one step back311 r = requests.post(service('post'), data='fooaowpeuf')312313 self.assertEquals(r.status_code, 200)314 self.assertEquals(r.headers['content-type'], 'application/json')315 self.assertEquals(r.url, service('post'))316317 rbody = json.loads(r.content)318 # Body wasn't valid url encoded data, so the server returns None as319 # "form" and the raw body as "data".320 self.assertEquals(rbody.get('form'), None)321 self.assertEquals(rbody.get('data'), 'fooaowpeuf')322323Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 324–325why, one step back324 def test_urlencoded_post_querystring(self):325Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 326why, one step back326 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 327why, one step back327Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 328–338why, one step back328 r = requests.post(service('post'), params=dict(test='fooaowpeuf'))329330 self.assertEquals(r.status_code, 200)331 self.assertEquals(r.headers['content-type'], 'application/json')332 self.assertEquals(r.url, service('post?test=fooaowpeuf'))333334 rbody = json.loads(r.content)335 self.assertEquals(rbody.get('form'), {}) # No form supplied336 self.assertEquals(rbody.get('data'), '')337338Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 339–340why, one step back339 def test_nonurlencoded_post_querystring(self):340Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 341why, one step back341 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 342why, one step back342Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 343–353why, one step back343 r = requests.post(service('post'), params='fooaowpeuf')344345 self.assertEquals(r.status_code, 200)346 self.assertEquals(r.headers['content-type'], 'application/json')347 self.assertEquals(r.url, service('post?fooaowpeuf'))348349 rbody = json.loads(r.content)350 self.assertEquals(rbody.get('form'), {}) # No form supplied351 self.assertEquals(rbody.get('data'), '')352353Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 354–355why, one step back354 def test_urlencoded_post_query_and_data(self):355Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 356why, one step back356 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 357why, one step back357Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 358–371why, one step back358 r = requests.post(359 service('post'),360 params=dict(test='fooaowpeuf'),361 data=dict(test2="foobar"))362363 self.assertEquals(r.status_code, 200)364 self.assertEquals(r.headers['content-type'], 'application/json')365 self.assertEquals(r.url, service('post?test=fooaowpeuf'))366367 rbody = json.loads(r.content)368 self.assertEquals(rbody.get('form'), dict(test2='foobar'))369 self.assertEquals(rbody.get('data'), '')370371Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 372why, one step back372 def test_nonurlencoded_post_query_and_data(self):Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 373why, one step back373Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 374–388why, one step back374 for service in SERVICES:375376 r = requests.post(service('post'),377 params='fooaowpeuf', data="foobar")378379 self.assertEquals(r.status_code, 200)380 self.assertEquals(r.headers['content-type'], 'application/json')381 self.assertEquals(r.url, service('post?fooaowpeuf'))382383 rbody = json.loads(r.content)384385 self.assertEquals(rbody.get('form'), None)386 self.assertEquals(rbody.get('data'), 'foobar')387388Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 389–391why, one step back389 def test_idna(self):390 r = requests.get(u'http://➡.ws/httpbin')391 assert 'httpbin' in r.urlMerge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 392why, one step back392Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 393why, one step back393Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 394–395why, one step back394 def test_urlencoded_get_query_multivalued_param(self):395Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 396–402why, one step back396 for service in SERVICES:397398 r = requests.get(service('get'), params=dict(test=['foo','baz']))399 self.assertEquals(r.status_code, 200)400 self.assertEquals(r.url, service('get?test=foo&test=baz'))401402Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 403–404why, one step back403 def test_urlencoded_post_querystring_multivalued(self):404Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 405–416why, one step back405 for service in SERVICES:406407 r = requests.post(service('post'), params=dict(test=['foo','baz']))408 self.assertEquals(r.status_code, 200)409 self.assertEquals(r.headers['content-type'], 'application/json')410 self.assertEquals(r.url, service('post?test=foo&test=baz'))411412 rbody = json.loads(r.content)413 self.assertEquals(rbody.get('form'), {}) # No form supplied414 self.assertEquals(rbody.get('data'), '')415416Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 417–418why, one step back417 def test_urlencoded_post_query_multivalued_and_data(self):418Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 419why, one step back419 for service in SERVICES:Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
line 420why, one step back420Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 421–433why, one step back421 r = requests.post(422 service('post'),423 params=dict(test=['foo','baz']),424 data=dict(test2="foobar",test3=['foo','baz']))425426 self.assertEquals(r.status_code, 200)427 self.assertEquals(r.headers['content-type'], 'application/json')428 self.assertEquals(r.url, service('post?test=foo&test=baz'))429 rbody = json.loads(r.content)430 self.assertEquals(rbody.get('form'), dict(test2='foobar',test3='foo'))431 self.assertEquals(rbody.get('data'), '')432433Merge branch 'redirect-no-follow' of https://github.com/millerdev/requestsKenneth Reitzbefore adoption98c719f
lines 434–451why, one step back434 def test_GET_no_redirect(self):435436 for service in SERVICES:437438 r = requests.get(service('redirect', '3'), allow_redirects=False)439 self.assertEquals(r.status_code, 302)440 self.assertEquals(len(r.history), 0)441442443 def test_HEAD_no_redirect(self):444445 for service in SERVICES:446447 r = requests.head(service('redirect', '3'), allow_redirects=False)448 self.assertEquals(r.status_code, 302)449 self.assertEquals(len(r.history), 0)450451Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 452–453why, one step back452 def test_redirect_history(self):453Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 454–498why, one step back454 for service in SERVICES:455456 r = requests.get(service('redirect', '3'))457 self.assertEquals(r.status_code, 200)458 self.assertEquals(len(r.history), 3)459460461 def test_relative_redirect_history(self):462463 for service in SERVICES:464465 r = requests.get(service('relative-redirect', '3'))466 self.assertEquals(r.status_code, 200)467 self.assertEquals(len(r.history), 3)468469470 def test_session_HTTP_200_OK_GET(self):471472 s = Session()473 r = s.get(httpbin('/'))474 self.assertEqual(r.status_code, 200)475476477 def test_session_HTTPS_200_OK_GET(self):478479 s = Session()480 r = s.get(httpsbin('/'))481 self.assertEqual(r.status_code, 200)482483484 def test_session_persistent_headers(self):485486 heads = {'User-agent': 'Mozilla/5.0'}487488 s = Session()489 s.headers = heads490 # Make 2 requests from Session object, should send header both times491 r1 = s.get(httpbin('user-agent'))492493 assert heads['User-agent'] in r1.content494 r2 = s.get(httpbin('user-agent'))495496 assert heads['User-agent'] in r2.content497 self.assertEqual(r2.status_code, 200)498Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 499why, one step back499a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 500why, one step back500if __name__ == '__main__':Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 501why, one step back501 unittest.main()