test_requests.py
This file
Path
test_requests.py
515 lines · 14.0 KiB · Python
Last changed by
Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption5b54b3e
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_statement5Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 6why, one step back6import timeMerge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 7why, one step back7import cookielibMerge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 8–9why, one step back8import os9import unittesttemp "tests"Kenneth Reitzbefore adoption49f915f
line 10why, one step back10Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 11–12why, one step back11import requests12import envoyMerge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption5b54b3e
line 13why, one step back13from urllib2 import HTTPErrorMerge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 14why, one step back14Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 15–18why, one step back15try:16 import omnijson as json17except ImportError:18 import jsonMerge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 19why, one step back19temp "tests"Kenneth Reitzbefore adoption49f915f
line 20why, one step back20Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 21–22why, one step back21# TODO: Detect an open port.22PORT = os.environ.get('HTTPBIN_PORT', '7077')temp "tests"Kenneth Reitzbefore adoption49f915f
line 23why, one step back23Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 24–25why, one step back24HTTPBIN_URL = 'http://0.0.0.0:%s/' % (PORT)25# 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 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 34why, one step back34SERVICES = (httpbin, )Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 35why, one step back35Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 36why, one step back36_httpbin = FalseMerge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 37why, one step back37Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 38–39why, one step back38class RequestsTestSuite(unittest.TestCase):39 """Requests test cases."""Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 40why, one step back40Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
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 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 44why, one step back44 def setUp(self):Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 45why, one step back45Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 46why, one step back46 global _httpbinMerge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 47why, one step back47Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 48why, one step back48 if not _httpbin:Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 49why, one step back49Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 50why, one step back50 c = envoy.connect('gunicorn httpbin:app --bind=0.0.0.0:%s' % (PORT))Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 51why, one step back51Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 52–54why, one step back52 self.httpbin = c53 _httpbin = True54 time.sleep(1)temp "tests"Kenneth Reitzbefore adoption49f915f
line 55why, one step back55Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 56why, one step back56Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 57why, one step back57Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 58–59why, one step back58 def tearDown(self):59 """Teardown."""Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 60why, one step back60 # self.httpbin.kill()Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 61why, one step back61Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 62–63why, one step back62 def test_entry_points(self):63 import requestsMerge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 64why, one step back64Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 65–75why, one step back65 requests.session66 requests.session().get67 requests.session().head68 requests.get69 requests.head70 requests.put71 requests.patch72 requests.post737475Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 76–77why, one step back76 def test_invalid_url(self):77 self.assertRaises(ValueError, requests.get, 'hiwpefhipowhefopw')a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 78why, one step back78Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 79why, one step back79 def test_HTTP_200_OK_GET(self):Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 80why, one step back80 r = requests.get(httpbin('/get'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 81why, one step back81 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 82why, one step back82Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 83–84why, one step back83 def test_HTTP_302_ALLOW_REDIRECT_GET(self):84 r = requests.get(httpbin('redirect', '1'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 85why, one step back85 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 86why, one step back86Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 87–89why, one step back87 def test_HTTP_302_GET(self):88 r = requests.get(httpbin('redirect', '1'), allow_redirects=False)89 self.assertEqual(r.status_code, 302)Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 90why, one step back90Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 91why, one step back91Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 92–93why, one step back92 def test_HTTP_200_OK_GET_WITH_PARAMS(self):93 heads = {'User-agent': 'Mozilla/5.0'}Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 94why, one step back94Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 95–97why, one step back95 r = requests.get(httpbin('user-agent'), headers=heads)9697 assert heads['User-agent'] in r.contentMerge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 98–99why, one step back98 self.assertEqual(r.status_code, 200)99Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 100why, one step back100Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 101–103why, one step back101 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self):102 heads = {'User-agent': 'Mozilla/5.0'}103Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 104why, one step back104 r = requests.get(httpbin('get') + '?test=true', params={'q': 'test'}, headers=heads)Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 105why, one step back105 self.assertEqual(r.status_code, 200)Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 106why, one step back106Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 107why, one step back107Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 108–109why, one step back108 def test_user_agent_transfers(self):109 """Issue XX"""Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 110why, one step back110Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 111–114why, one step back111 heads = {112 'User-agent':113 'Mozilla/5.0 (github.com/kennethreitz/requests)'114 }Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 115why, one step back115Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 116why, one step back116 r = requests.get(httpbin('user-agent'), headers=heads);Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 117why, one step back117 self.assertTrue(heads['User-agent'] in r.content)Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 118why, one step back118Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 119–123why, one step back119 heads = {120 'user-agent':121 'Mozilla/5.0 (github.com/kennethreitz/requests)'122 }123Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 124why, one step back124 r = requests.get(httpbin('user-agent'), headers=heads);Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 125–126why, one step back125 self.assertTrue(heads['user-agent'] in r.content)126Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 127why, one step back127Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 128why, one step back128 def test_HTTP_200_OK_HEAD(self):Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 129why, one step back129 r = requests.head(httpbin('/get'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 130why, one step back130 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 131why, one step back131Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 132–142why, one step back132133 def test_HTTP_200_OK_PUT(self):134 r = requests.put(httpbin('put'))135 self.assertEqual(r.status_code, 200)136137138 def test_HTTP_200_OK_PATCH(self):139 r = requests.patch(httpbin('patch'))140 self.assertEqual(r.status_code, 200)141142Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 143why, one step back143 def test_BASICAUTH_HTTP_200_OK_GET(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 144why, one step back144Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 145why, one step back145 for service in SERVICES:Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 146why, one step back146Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 147–148why, one step back147 auth = ('user', 'pass')148 url = service('basic-auth', 'user', 'pass')Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa
line 149why, one step back149Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 150–151why, one step back150 r = requests.get(url, auth=auth)151 self.assertEqual(r.status_code, 200)Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa
line 152why, one step back152Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 153why, one step back153 r = requests.get(url)Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 154–158why, one step back154 self.assertEqual(r.status_code, 401)155156157 s = requests.session(auth=auth)158 r = s.get(url)Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 159–161why, one step back159 self.assertEqual(r.status_code, 200)160161Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 162–179why, one step back162 def test_DIGESTAUTH_HTTP_200_OK_GET(self):163164 for service in SERVICES:165166 auth = ('digest', 'user', 'pass')167 url = service('digest-auth', 'auth', 'user', 'pass')168169 r = requests.get(url, auth=auth)170 self.assertEqual(r.status_code, 200)171172 r = requests.get(url)173 self.assertEqual(r.status_code, 401)174175176 s = requests.session(auth=auth)177 r = s.get(url)178 self.assertEqual(r.status_code, 200)179Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 180why, one step back180 def test_POSTBIN_GET_POST_FILES(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 181why, one step back181Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 182why, one step back182 for service in SERVICES:Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 183why, one step back183Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 184–185why, one step back184 url = service('post')185 post = requests.post(url).raise_for_status()Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 186why, one step back186Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 187–188why, one step back187 post = requests.post(url, data={'some': 'data'})188 self.assertEqual(post.status_code, 200)Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 189why, one step back189Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 190–191why, one step back190 post2 = requests.post(url, files={'some': open('test_requests.py')})191 self.assertEqual(post2.status_code, 200)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 192why, one step back192Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 193–196why, one step back193 post3 = requests.post(url, data='[{"some": "json"}]')194 self.assertEqual(post3.status_code, 200)195196Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 197why, one step back197 def test_POSTBIN_GET_POST_FILES_WITH_PARAMS(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 198why, one step back198Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 199why, one step back199 for service in SERVICES:Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 200why, one step back200Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 201–204why, one step back201 url = service('post')202 post = requests.post(url,203 files={'some': open('test_requests.py')},204 data={'some': 'data'})Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 205why, one step back205Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 206–208why, one step back206 self.assertEqual(post.status_code, 200)207208Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 209–210why, one step back209 def test_POSTBIN_GET_POST_FILES_WITH_HEADERS(self):210Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 211why, one step back211 for service in SERVICES:Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 212why, one step back212Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 213why, one step back213 url = service('post')Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 214why, one step back214Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 215–217why, one step back215 post2 = requests.post(url,216 files={'some': open('test_requests.py')},217 headers = {'User-Agent': 'requests-tests'})Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 218why, one step back218Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 219why, one step back219 self.assertEqual(post2.status_code, 200)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 220why, one step back220Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 221why, one step back221Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 222why, one step back222 def test_nonzero_evaluation(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 223why, one step back223Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 224why, one step back224 for service in SERVICES:Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 225why, one step back225Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 226–227why, one step back226 r = requests.get(service('status', '500'))227 self.assertEqual(bool(r), False)Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 228why, one step back228Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 229why, one step back229 r = requests.get(service('/get'))Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 230–232why, one step back230 self.assertEqual(bool(r), True)231232Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 233why, one step back233 def test_request_ok_set(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 234why, one step back234Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 235why, one step back235 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 236why, one step back236Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 237why, one step back237 r = requests.get(service('status', '404'))PASS ALL TEH TESTSKenneth Reitzbefore adoption428fc9c
line 238why, one step back238 print r.status_codeMerge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 239–241why, one step back239 self.assertEqual(r.ok, False)240241Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 242why, one step back242 def test_status_raising(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 243why, one step back243 r = requests.get(httpbin('status', '404'))Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption5b54b3e
line 244why, one step back244 self.assertRaises(HTTPError, r.raise_for_status)Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 245why, one step back245Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 246why, one step back246 r = requests.get(httpbin('status', '200'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 247–248why, one step back247 self.assertFalse(r.error)248 r.raise_for_status()Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 249–250why, one step back249250Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 251why, one step back251 def test_decompress_gzip(self):a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 252why, one step back252Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 253why, one step back253 r = requests.get(httpbin('gzip'))Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
lines 254–255why, one step back254 r.content.decode('ascii')255Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 256why, one step back256Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 257why, one step back257 def test_unicode_get(self):Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 258why, one step back258Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 259why, one step back259 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 260why, one step back260Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 261why, one step back261 url = service('/get')Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 262why, one step back262Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 263–267why, one step back263 requests.get(url, params={'foo': u'føø'})264 requests.get(url, params={u'føø': u'føø'})265 requests.get(url, params={'føø': 'føø'})266 requests.get(url, params={'foo': u'foo'})267 requests.get(service('ø'), params={'foo': u'foo'})Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 268why, one step back268Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 269why, one step back269Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 270why, one step back270 def test_httpauth_recursion(self):Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 271why, one step back271Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 272why, one step back272 http_auth = ('user', 'BADpass')Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 273why, one step back273Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 274–276why, one step back274 for service in SERVICES:275 r = requests.get(service('basic-auth', 'user', 'pass'), auth=http_auth)276 self.assertEquals(r.status_code, 401)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 277why, one step back277Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 278–280why, one step back278279 def test_urlencoded_post_data(self):280Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 281why, one step back281 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 282why, one step back282Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 283–294why, one step back283 r = requests.post(service('post'), data=dict(test='fooaowpeuf'))284285 self.assertEquals(r.status_code, 200)286 self.assertEquals(r.headers['content-type'], 'application/json')287 self.assertEquals(r.url, service('post'))288289 rbody = json.loads(r.content)290291 self.assertEquals(rbody.get('form'), dict(test='fooaowpeuf'))292 self.assertEquals(rbody.get('data'), '')293294Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 295why, one step back295 def test_nonurlencoded_post_data(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 296why, one step back296Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 297why, one step back297 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 298why, one step back298Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 299–311why, one step back299 r = requests.post(service('post'), data='fooaowpeuf')300301 self.assertEquals(r.status_code, 200)302 self.assertEquals(r.headers['content-type'], 'application/json')303 self.assertEquals(r.url, service('post'))304305 rbody = json.loads(r.content)306 # Body wasn't valid url encoded data, so the server returns None as307 # "form" and the raw body as "data".308 self.assertEquals(rbody.get('form'), None)309 self.assertEquals(rbody.get('data'), 'fooaowpeuf')310311Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 312–313why, one step back312 def test_urlencoded_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=dict(test='fooaowpeuf'))317318 self.assertEquals(r.status_code, 200)319 self.assertEquals(r.headers['content-type'], 'application/json')320 self.assertEquals(r.url, service('post?test=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_nonurlencoded_post_querystring(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–341why, one step back331 r = requests.post(service('post'), params='fooaowpeuf')332333 self.assertEquals(r.status_code, 200)334 self.assertEquals(r.headers['content-type'], 'application/json')335 self.assertEquals(r.url, service('post?fooaowpeuf'))336337 rbody = json.loads(r.content)338 self.assertEquals(rbody.get('form'), {}) # No form supplied339 self.assertEquals(rbody.get('data'), '')340341Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 342–343why, one step back342 def test_urlencoded_post_query_and_data(self):343Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 344why, one step back344 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 345why, one step back345Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 346–359why, one step back346 r = requests.post(347 service('post'),348 params=dict(test='fooaowpeuf'),349 data=dict(test2="foobar"))350351 self.assertEquals(r.status_code, 200)352 self.assertEquals(r.headers['content-type'], 'application/json')353 self.assertEquals(r.url, service('post?test=fooaowpeuf'))354355 rbody = json.loads(r.content)356 self.assertEquals(rbody.get('form'), dict(test2='foobar'))357 self.assertEquals(rbody.get('data'), '')358359Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 360why, one step back360 def test_nonurlencoded_post_query_and_data(self):Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 361why, one step back361Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 362–376why, one step back362 for service in SERVICES:363364 r = requests.post(service('post'),365 params='fooaowpeuf', data="foobar")366367 self.assertEquals(r.status_code, 200)368 self.assertEquals(r.headers['content-type'], 'application/json')369 self.assertEquals(r.url, service('post?fooaowpeuf'))370371 rbody = json.loads(r.content)372373 self.assertEquals(rbody.get('form'), None)374 self.assertEquals(rbody.get('data'), 'foobar')375376Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 377–379why, one step back377 # def test_idna(self):378 # r = requests.get(u'http://➡.ws/httpbin')379 # assert 'httpbin' in r.urlMerge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 380why, one step back380Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 381why, one step back381Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 382–383why, one step back382 def test_urlencoded_get_query_multivalued_param(self):383Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 384–390why, one step back384 for service in SERVICES:385386 r = requests.get(service('get'), params=dict(test=['foo','baz']))387 self.assertEquals(r.status_code, 200)388 self.assertEquals(r.url, service('get?test=foo&test=baz'))389390Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 391–392why, one step back391 def test_urlencoded_post_querystring_multivalued(self):392Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 393–404why, one step back393 for service in SERVICES:394395 r = requests.post(service('post'), params=dict(test=['foo','baz']))396 self.assertEquals(r.status_code, 200)397 self.assertEquals(r.headers['content-type'], 'application/json')398 self.assertEquals(r.url, service('post?test=foo&test=baz'))399400 rbody = json.loads(r.content)401 self.assertEquals(rbody.get('form'), {}) # No form supplied402 self.assertEquals(rbody.get('data'), '')403404Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 405–406why, one step back405 def test_urlencoded_post_query_multivalued_and_data(self):406Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 407why, one step back407 for service in SERVICES:Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
line 408why, one step back408Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 409–421why, one step back409 r = requests.post(410 service('post'),411 params=dict(test=['foo','baz']),412 data=dict(test2="foobar",test3=['foo','baz']))413414 self.assertEquals(r.status_code, 200)415 self.assertEquals(r.headers['content-type'], 'application/json')416 self.assertEquals(r.url, service('post?test=foo&test=baz'))417 rbody = json.loads(r.content)418 self.assertEquals(rbody.get('form'), dict(test2='foobar',test3='foo'))419 self.assertEquals(rbody.get('data'), '')420421Merge branch 'redirect-no-follow' of https://github.com/millerdev/requestsKenneth Reitzbefore adoption98c719f
lines 422–439why, one step back422 def test_GET_no_redirect(self):423424 for service in SERVICES:425426 r = requests.get(service('redirect', '3'), allow_redirects=False)427 self.assertEquals(r.status_code, 302)428 self.assertEquals(len(r.history), 0)429430431 def test_HEAD_no_redirect(self):432433 for service in SERVICES:434435 r = requests.head(service('redirect', '3'), allow_redirects=False)436 self.assertEquals(r.status_code, 302)437 self.assertEquals(len(r.history), 0)438439Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 440–441why, one step back440 def test_redirect_history(self):441Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 442–459why, one step back442 for service in SERVICES:443444 r = requests.get(service('redirect', '3'))445 self.assertEquals(r.status_code, 200)446 self.assertEquals(len(r.history), 3)447448449 def test_relative_redirect_history(self):450451 for service in SERVICES:452453 r = requests.get(service('relative-redirect', '3'))454 self.assertEquals(r.status_code, 200)455 self.assertEquals(len(r.history), 3)456457458 def test_session_HTTP_200_OK_GET(self):459Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 460–461why, one step back460 s = requests.session()461 r = s.get(httpbin('/get'))Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 462–468why, one step back462 self.assertEqual(r.status_code, 200)463464465 def test_session_persistent_headers(self):466467 heads = {'User-agent': 'Mozilla/5.0'}468Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 469why, one step back469 s = requests.session()Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 470why, one step back470 s.headers = headsMerge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 471why, one step back471Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 472–475why, one step back472 # Make 2 requests from Session object, should send header both times473 r1 = s.get(httpbin('user-agent'))474 assert heads['User-agent'] in r1.content475Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 476why, one step back476 r2 = s.get(httpbin('user-agent'))Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 477why, one step back477 assert heads['User-agent'] in r2.contentMerge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 478–482why, one step back478479 new_heads = {'User-agent': 'blah'}480 r3 = s.get(httpbin('user-agent'), headers=new_heads)481 assert new_heads['User-agent'] in r3.content482Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 483–484why, one step back483 self.assertEqual(r2.status_code, 200)484Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 485–511why, one step back485486 def test_session_persistent_params(self):487488 params = {'a': 'a_test'}489490 s = requests.session()491 s.params = params492493 # Make 2 requests from Session object, should send header both times494 r1 = s.get(httpbin('get'))495 assert params['a'] in r1.content496497498 params2 = {'b': 'b_test'}499500 r2 = s.get(httpbin('get'), params=params2)501 assert params['a'] in r2.content502 assert params2['b'] in r2.content503504505 params3 = {'b': 'b_test', 'a': None, 'c': 'c_test'}506507 r3 = s.get(httpbin('get'), params=params3)508509 assert not params['a'] in r3.content510 assert params3['b'] in r3.content511 assert params3['c'] in r3.contentMerge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 512why, one step back512Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 513why, one step back513a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 514why, one step back514if __name__ == '__main__':Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 515why, one step back515 unittest.main()