Skip to content
Myr

test_requests.py

This file

Path

test_requests.py

587 lines · 16.0 KiB · Python

Last changed by

didn't mean to save thatKenneth Reitzbefore adoptiona76f492

History of this file

Take it

The walk stopped after 200 commits: lines older than 2cc8015 point at it.

Readme update.Kenneth Reitzbefore adoption2cc8015

lines 1–3why, one step back
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-3

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

lines 4–5why, one step back
4from __future__ import with_statement
5

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 6–8why, one step back
6import time
7import os8import unittest

Readme update.Kenneth Reitzbefore adoption2cc8015

line 9why, one step back
9

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 10–11why, one step back
10import requests
11import envoy

stuff and things and stuffKenneth Reitzbefore adoptionb8c55da

line 12why, one step back
12from requests import HTTPError

Merge branch 'auth_callables' of https://github.com/idangazit/requests into developKenneth Reitzbefore adoptiona7a619b

line 13why, one step back
13from requests.auth import HTTPBasicAuth, HTTPDigestAuth

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 14why, one step back
14

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 15–18why, one step back
15try:
16 import omnijson as json17except ImportError:18 import json

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 19why, one step back
19

Readme update.Kenneth Reitzbefore adoption2cc8015

line 20why, one step back
20

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 21–22why, one step back
21# TODO: Detect an open port.
22PORT = os.environ.get('HTTPBIN_PORT', '7077')

Readme update.Kenneth Reitzbefore adoption2cc8015

line 23why, one step back
23

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 24–25why, one step back
24HTTPBIN_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 back
26
2728def httpbin(*suffix):29 """Returns url for HTTPBIN resource."""3031 return HTTPBIN_URL + '/'.join(suffix)3233

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 34why, one step back
34SERVICES = (httpbin, )

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 35why, one step back
35

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 36why, one step back
36_httpbin = False

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 37why, one step back
37

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 38–39why, one step back
38class RequestsTestSuite(unittest.TestCase):
39 """Requests test cases."""

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 40why, one step back
40

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 41–42why, one step back
41 # It goes to eleven.
42 _multiprocess_can_split_ = True

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 43why, one step back
43

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 44why, one step back
44 def setUp(self):

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 45why, one step back
45

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 46why, one step back
46 global _httpbin

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 47why, one step back
47

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 48why, one step back
48 if not _httpbin:

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 49why, one step back
49

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 50why, one step back
50 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 back
51

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 52–53why, one step back
52 self.httpbin = c
53 _httpbin = True

didn't mean to save thatKenneth Reitzbefore adoptiona76f492

line 54why, one step back
54 time.sleep(1)

Readme update.Kenneth Reitzbefore adoption2cc8015

line 55why, one step back
55

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 56why, one step back
56

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 57why, one step back
57

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

lines 58–59why, one step back
58 def tearDown(self):
59 """Teardown."""

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 60why, one step back
60 # self.httpbin.kill()

keep_alive is now disable-able!Kenneth Reitzbefore adoption0c4b973

line 61why, one step back
61 pass

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 62why, one step back
62

keep_alive is now disable-able!Kenneth Reitzbefore adoption0c4b973

line 63why, one step back
63

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 64why, one step back
64 def test_entry_points(self):

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 65why, one step back
65

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 66–76why, one step back
66 requests.session
67 requests.session().get68 requests.session().head69 requests.get70 requests.head71 requests.put72 requests.patch73 requests.post747576

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

lines 77–78why, one step back
77 def test_invalid_url(self):
78 self.assertRaises(ValueError, requests.get, 'hiwpefhipowhefopw')

Readme update.Kenneth Reitzbefore adoption2cc8015

line 79why, one step back
79

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

line 80why, one step back
80 def test_HTTP_200_OK_GET(self):

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 81why, one step back
81 r = requests.get(httpbin('/get'))

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

line 82why, one step back
82 self.assertEqual(r.status_code, 200)

Added test for Request.sent.Kenneth Reitzbefore adoption6bb4c4e

lines 83–87why, one step back
83
84 def test_response_sent(self):85 r = requests.get(httpbin('/get'))8687 self.assertTrue(r.request.sent)

Readme update.Kenneth Reitzbefore adoption2cc8015

line 88why, one step back
88

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 89–90why, one step back
89 def test_HTTP_302_ALLOW_REDIRECT_GET(self):
90 r = requests.get(httpbin('redirect', '1'))

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

line 91why, one step back
91 self.assertEqual(r.status_code, 200)

Readme update.Kenneth Reitzbefore adoption2cc8015

line 92why, one step back
92

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 93–95why, one step back
93 def test_HTTP_302_GET(self):
94 r = requests.get(httpbin('redirect', '1'), allow_redirects=False)95 self.assertEqual(r.status_code, 302)

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 96why, one step back
96

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 97why, one step back
97

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

lines 98–99why, one step back
98 def test_HTTP_200_OK_GET_WITH_PARAMS(self):
99 heads = {'User-agent': 'Mozilla/5.0'}

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 100why, one step back
100

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 101–103why, one step back
101 r = requests.get(httpbin('user-agent'), headers=heads)
102103 assert heads['User-agent'] in r.content

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

lines 104–105why, one step back
104 self.assertEqual(r.status_code, 200)
105

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 106why, one step back
106

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

lines 107–109why, one step back
107 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self):
108 heads = {'User-agent': 'Mozilla/5.0'}109

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 110why, one step back
110 r = requests.get(httpbin('get') + '?test=true', params={'q': 'test'}, headers=heads)

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 111why, one step back
111 self.assertEqual(r.status_code, 200)

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 112why, one step back
112

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 113why, one step back
113

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

lines 114–115why, one step back
114 def test_user_agent_transfers(self):
115 """Issue XX"""

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 116why, one step back
116

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

lines 117–120why, one step back
117 heads = {
118 'User-agent':119 'Mozilla/5.0 (github.com/kennethreitz/requests)'120 }

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 121why, one step back
121

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 122why, one step back
122 r = requests.get(httpbin('user-agent'), headers=heads);

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 123why, one step back
123 self.assertTrue(heads['User-agent'] in r.content)

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 124why, one step back
124

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

lines 125–129why, one step back
125 heads = {
126 'user-agent':127 'Mozilla/5.0 (github.com/kennethreitz/requests)'128 }129

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 130why, one step back
130 r = requests.get(httpbin('user-agent'), headers=heads);

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

lines 131–132why, one step back
131 self.assertTrue(heads['user-agent'] in r.content)
132

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 133why, one step back
133

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

line 134why, one step back
134 def test_HTTP_200_OK_HEAD(self):

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 135why, one step back
135 r = requests.head(httpbin('/get'))

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

line 136why, one step back
136 self.assertEqual(r.status_code, 200)

Readme update.Kenneth Reitzbefore adoption2cc8015

line 137why, one step back
137

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 138–148why, one step back
138
139 def test_HTTP_200_OK_PUT(self):140 r = requests.put(httpbin('put'))141 self.assertEqual(r.status_code, 200)142143144 def test_HTTP_200_OK_PATCH(self):145 r = requests.patch(httpbin('patch'))146 self.assertEqual(r.status_code, 200)147148

Merge branch 'auth_callables' of https://github.com/idangazit/requests into developKenneth Reitzbefore adoptiona7a619b

line 149why, one step back
149 def test_BASICAUTH_TUPLE_HTTP_200_OK_GET(self):

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 150why, one step back
150

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 151why, one step back
151 for service in SERVICES:

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 152why, one step back
152

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 153–154why, one step back
153 auth = ('user', 'pass')
154 url = service('basic-auth', 'user', 'pass')

Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa

line 155why, one step back
155

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 156–157why, one step back
156 r = requests.get(url, auth=auth)
157 self.assertEqual(r.status_code, 200)

Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa

line 158why, one step back
158

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 159why, one step back
159 r = requests.get(url)

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 160–164why, one step back
160 self.assertEqual(r.status_code, 401)
161162163 s = requests.session(auth=auth)164 r = s.get(url)

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 165–167why, one step back
165 self.assertEqual(r.status_code, 200)
166167

Merge branch 'auth_callables' of https://github.com/idangazit/requests into developKenneth Reitzbefore adoptiona7a619b

lines 168–177why, one step back
168 def test_BASICAUTH_HTTP_200_OK_GET(self):
169170 for service in SERVICES:171172 auth = HTTPBasicAuth('user', 'pass')173 url = service('basic-auth', 'user', 'pass')174175 r = requests.get(url, auth=auth)176 self.assertEqual(r.status_code, 200)177

test tuple'd authKenneth Reitzbefore adoptionee36baf

lines 178–181why, one step back
178 auth = ('user', 'pass')
179 r = requests.get(url, auth=auth)180 self.assertEqual(r.status_code, 200)181

Merge branch 'auth_callables' of https://github.com/idangazit/requests into developKenneth Reitzbefore adoptiona7a619b

lines 182–190why, one step back
182 r = requests.get(url)
183 self.assertEqual(r.status_code, 401)184185186 s = requests.session(auth=auth)187 r = s.get(url)188 self.assertEqual(r.status_code, 200)189190

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 191–194why, one step back
191 def test_DIGESTAUTH_HTTP_200_OK_GET(self):
192193 for service in SERVICES:194

Merge branch 'auth_callables' of https://github.com/idangazit/requests into developKenneth Reitzbefore adoptiona7a619b

line 195why, one step back
195 auth = HTTPDigestAuth('user', 'pass')

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 196–208why, one step back
196 url = service('digest-auth', 'auth', 'user', 'pass')
197198 r = requests.get(url, auth=auth)199 self.assertEqual(r.status_code, 200)200201 r = requests.get(url)202 self.assertEqual(r.status_code, 401)203204205 s = requests.session(auth=auth)206 r = s.get(url)207 self.assertEqual(r.status_code, 200)208

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

line 209why, one step back
209 def test_POSTBIN_GET_POST_FILES(self):

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 210why, one step back
210

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 211why, one step back
211 for service in SERVICES:

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 212why, one step back
212

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 213–214why, one step back
213 url = service('post')
214 post = requests.post(url).raise_for_status()

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 215why, one step back
215

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 216–217why, one step back
216 post = requests.post(url, data={'some': 'data'})
217 self.assertEqual(post.status_code, 200)

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 218why, one step back
218

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 219–220why, one step back
219 post2 = requests.post(url, files={'some': open('test_requests.py')})
220 self.assertEqual(post2.status_code, 200)

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 221why, one step back
221

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 222–225why, one step back
222 post3 = requests.post(url, data='[{"some": "json"}]')
223 self.assertEqual(post3.status_code, 200)224225

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 226why, one step back
226 def test_POSTBIN_GET_POST_FILES_WITH_PARAMS(self):

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 227why, one step back
227

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 228why, one step back
228 for service in SERVICES:

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 229why, one step back
229

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 230–233why, one step back
230 url = service('post')
231 post = requests.post(url,232 files={'some': open('test_requests.py')},233 data={'some': 'data'})

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 234why, one step back
234

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 235–237why, one step back
235 self.assertEqual(post.status_code, 200)
236237

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

lines 238–239why, one step back
238 def test_POSTBIN_GET_POST_FILES_WITH_HEADERS(self):
239

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 240why, one step back
240 for service in SERVICES:

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 241why, one step back
241

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 242why, one step back
242 url = service('post')

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 243why, one step back
243

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 244–246why, one step back
244 post2 = requests.post(url,
245 files={'some': open('test_requests.py')},246 headers = {'User-Agent': 'requests-tests'})

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 247why, one step back
247

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 248why, one step back
248 self.assertEqual(post2.status_code, 200)

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 249why, one step back
249

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 250why, one step back
250

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

line 251why, one step back
251 def test_nonzero_evaluation(self):

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 252why, one step back
252

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 253why, one step back
253 for service in SERVICES:

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 254why, one step back
254

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 255–256why, one step back
255 r = requests.get(service('status', '500'))
256 self.assertEqual(bool(r), False)

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 257why, one step back
257

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 258why, one step back
258 r = requests.get(service('/get'))

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 259–261why, one step back
259 self.assertEqual(bool(r), True)
260261

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

line 262why, one step back
262 def test_request_ok_set(self):

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 263why, one step back
263

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 264why, one step back
264 for service in SERVICES:

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 265why, one step back
265

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 266why, one step back
266 r = requests.get(service('status', '404'))

stuff and things and stuffKenneth Reitzbefore adoptionb8c55da

lines 267–268why, one step back
267 # print r.status_code
268 # r.raise_for_status()

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 269–271why, one step back
269 self.assertEqual(r.ok, False)
270271

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

line 272why, one step back
272 def test_status_raising(self):

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 273why, one step back
273 r = requests.get(httpbin('status', '404'))

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption5b54b3e

line 274why, one step back
274 self.assertRaises(HTTPError, r.raise_for_status)

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 275why, one step back
275

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 276why, one step back
276 r = requests.get(httpbin('status', '200'))

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

lines 277–278why, one step back
277 self.assertFalse(r.error)
278 r.raise_for_status()

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 279–280why, one step back
279
280

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 281why, one step back
281 def test_decompress_gzip(self):

Readme update.Kenneth Reitzbefore adoption2cc8015

line 282why, one step back
282

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 283why, one step back
283 r = requests.get(httpbin('gzip'))

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

lines 284–285why, one step back
284 r.content.decode('ascii')
285

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 286why, one step back
286

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

line 287why, one step back
287 def test_unicode_get(self):

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 288why, one step back
288

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 289why, one step back
289 for service in SERVICES:

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 290why, one step back
290

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 291why, one step back
291 url = service('/get')

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 292why, one step back
292

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 293–297why, one step back
293 requests.get(url, params={'foo': u'føø'})
294 requests.get(url, params={u'føø': u'føø'})295 requests.get(url, params={'føø': 'føø'})296 requests.get(url, params={'foo': u'foo'})297 requests.get(service('ø'), params={'foo': u'foo'})

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 298why, one step back
298

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 299why, one step back
299

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 300why, one step back
300 def test_httpauth_recursion(self):

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 301why, one step back
301

Merge branch 'auth_callables' of https://github.com/idangazit/requests into developKenneth Reitzbefore adoptiona7a619b

line 302why, one step back
302 http_auth = HTTPBasicAuth('user', 'BADpass')

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 303why, one step back
303

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 304–306why, one step back
304 for service in SERVICES:
305 r = requests.get(service('basic-auth', 'user', 'pass'), auth=http_auth)306 self.assertEquals(r.status_code, 401)

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 307why, one step back
307

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 308–310why, one step back
308
309 def test_urlencoded_post_data(self):310

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 311why, one step back
311 for service in SERVICES:

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 312why, one step back
312

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 313–324why, one step back
313 r = requests.post(service('post'), data=dict(test='fooaowpeuf'))
314315 self.assertEquals(r.status_code, 200)316 self.assertEquals(r.headers['content-type'], 'application/json')317 self.assertEquals(r.url, service('post'))318319 rbody = json.loads(r.content)320321 self.assertEquals(rbody.get('form'), dict(test='fooaowpeuf'))322 self.assertEquals(rbody.get('data'), '')323324

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 325why, one step back
325 def test_nonurlencoded_post_data(self):

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 326why, one step back
326

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 327why, one step back
327 for service in SERVICES:

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 328why, one step back
328

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 329–337why, one step back
329 r = requests.post(service('post'), data='fooaowpeuf')
330331 self.assertEquals(r.status_code, 200)332 self.assertEquals(r.headers['content-type'], 'application/json')333 self.assertEquals(r.url, service('post'))334335 rbody = json.loads(r.content)336 # Body wasn't valid url encoded data, so the server returns None as337 # "form" and the raw body as "data".

test fixKenneth Reitzbefore adoptionec926a4

line 338why, one step back
338 self.assertEquals(rbody.get('form'), {})

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 339–341why, one step back
339 self.assertEquals(rbody.get('data'), 'fooaowpeuf')
340341

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 342–343why, one step back
342 def test_urlencoded_post_querystring(self):
343

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 344why, one step back
344 for service in SERVICES:

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 345why, one step back
345

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 346–356why, one step back
346 r = requests.post(service('post'), params=dict(test='fooaowpeuf'))
347348 self.assertEquals(r.status_code, 200)349 self.assertEquals(r.headers['content-type'], 'application/json')350 self.assertEquals(r.url, service('post?test=fooaowpeuf'))351352 rbody = json.loads(r.content)353 self.assertEquals(rbody.get('form'), {}) # No form supplied354 self.assertEquals(rbody.get('data'), '')355356

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 357–358why, one step back
357 def test_urlencoded_post_query_and_data(self):
358

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 359why, one step back
359 for service in SERVICES:

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 360why, one step back
360

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 361–374why, one step back
361 r = requests.post(
362 service('post'),363 params=dict(test='fooaowpeuf'),364 data=dict(test2="foobar"))365366 self.assertEquals(r.status_code, 200)367 self.assertEquals(r.headers['content-type'], 'application/json')368 self.assertEquals(r.url, service('post?test=fooaowpeuf'))369370 rbody = json.loads(r.content)371 self.assertEquals(rbody.get('form'), dict(test2='foobar'))372 self.assertEquals(rbody.get('data'), '')373374

add query data yourself, foo'Kenneth Reitzbefore adoption0f2dcff

line 375why, one step back
375 def test_nonurlencoded_postdata(self):

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 376why, one step back
376

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 377–378why, one step back
377 for service in SERVICES:
378

add query data yourself, foo'Kenneth Reitzbefore adoption0f2dcff

line 379why, one step back
379 r = requests.post(service('post'), data="foobar")

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 380–385why, one step back
380
381 self.assertEquals(r.status_code, 200)382 self.assertEquals(r.headers['content-type'], 'application/json')383384 rbody = json.loads(r.content)385

fix form data testsKenneth Reitzbefore adoptiondf2c80e

line 386why, one step back
386 self.assertEquals(rbody.get('form'), {})

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 387–389why, one step back
387 self.assertEquals(rbody.get('data'), 'foobar')
388389

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 390–392why, one step back
390 # def test_idna(self):
391 # r = requests.get(u'http://➡.ws/httpbin')392 # assert 'httpbin' in r.url

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

line 393why, one step back
393

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 394why, one step back
394

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 395–396why, one step back
395 def test_urlencoded_get_query_multivalued_param(self):
396

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 397–403why, one step back
397 for service in SERVICES:
398399 r = requests.get(service('get'), params=dict(test=['foo','baz']))400 self.assertEquals(r.status_code, 200)401 self.assertEquals(r.url, service('get?test=foo&test=baz'))402403

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 404–405why, one step back
404 def test_urlencoded_post_querystring_multivalued(self):
405

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 406–417why, one step back
406 for service in SERVICES:
407408 r = requests.post(service('post'), params=dict(test=['foo','baz']))409 self.assertEquals(r.status_code, 200)410 self.assertEquals(r.headers['content-type'], 'application/json')411 self.assertEquals(r.url, service('post?test=foo&test=baz'))412413 rbody = json.loads(r.content)414 self.assertEquals(rbody.get('form'), {}) # No form supplied415 self.assertEquals(rbody.get('data'), '')416417

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 418–419why, one step back
418 def test_urlencoded_post_query_multivalued_and_data(self):
419

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 420why, one step back
420 for service in SERVICES:

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

line 421why, one step back
421

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 422–434why, one step back
422 r = requests.post(
423 service('post'),424 params=dict(test=['foo','baz']),425 data=dict(test2="foobar",test3=['foo','baz']))426427 self.assertEquals(r.status_code, 200)428 self.assertEquals(r.headers['content-type'], 'application/json')429 self.assertEquals(r.url, service('post?test=foo&test=baz'))430 rbody = json.loads(r.content)431 self.assertEquals(rbody.get('form'), dict(test2='foobar',test3='foo'))432 self.assertEquals(rbody.get('data'), '')433434

Merge branch 'redirect-no-follow' of https://github.com/millerdev/requestsKenneth Reitzbefore adoption98c719f

lines 435–452why, one step back
435 def test_GET_no_redirect(self):
436437 for service in SERVICES:438439 r = requests.get(service('redirect', '3'), allow_redirects=False)440 self.assertEquals(r.status_code, 302)441 self.assertEquals(len(r.history), 0)442443444 def test_HEAD_no_redirect(self):445446 for service in SERVICES:447448 r = requests.head(service('redirect', '3'), allow_redirects=False)449 self.assertEquals(r.status_code, 302)450 self.assertEquals(len(r.history), 0)451452

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 453–454why, one step back
453 def test_redirect_history(self):
454

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 455–472why, one step back
455 for service in SERVICES:
456457 r = requests.get(service('redirect', '3'))458 self.assertEquals(r.status_code, 200)459 self.assertEquals(len(r.history), 3)460461462 def test_relative_redirect_history(self):463464 for service in SERVICES:465466 r = requests.get(service('relative-redirect', '3'))467 self.assertEquals(r.status_code, 200)468 self.assertEquals(len(r.history), 3)469470471 def test_session_HTTP_200_OK_GET(self):472

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 473–474why, one step back
473 s = requests.session()
474 r = s.get(httpbin('/get'))

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 475–481why, one step back
475 self.assertEqual(r.status_code, 200)
476477478 def test_session_persistent_headers(self):479480 heads = {'User-agent': 'Mozilla/5.0'}481

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 482why, one step back
482 s = requests.session()

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 483why, one step back
483 s.headers = heads

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 484why, one step back
484

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 485–488why, one step back
485 # Make 2 requests from Session object, should send header both times
486 r1 = s.get(httpbin('user-agent'))487 assert heads['User-agent'] in r1.content488

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 489why, one step back
489 r2 = s.get(httpbin('user-agent'))

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 490why, one step back
490 assert heads['User-agent'] in r2.content

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 491–495why, one step back
491
492 new_heads = {'User-agent': 'blah'}493 r3 = s.get(httpbin('user-agent'), headers=new_heads)494 assert new_heads['User-agent'] in r3.content495

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 496why, one step back
496 self.assertEqual(r2.status_code, 200)

test the cookies!Kenneth Reitzbefore adoptione649003

lines 497–520why, one step back
497
498 def test_session_persistent_cookies(self):499500 s = requests.session()501502 # Internally dispatched cookies are sent.503 _c = {'kenneth': 'reitz', 'bessie': 'monke'}504 r = s.get(httpbin('cookies'), cookies=_c)505 r = s.get(httpbin('cookies'))506507 # Those cookies persist transparently.508 c = json.loads(r.content).get('cookies')509 assert c == _c510511 # Double check.512 r = s.get(httpbin('cookies'), cookies={})513 c = json.loads(r.content).get('cookies')514 assert c == _c515516 # Remove a cookie by setting it's value to None.517 r = s.get(httpbin('cookies'), cookies={'bessie': None})518 c = json.loads(r.content).get('cookies')519 del _c['bessie']520 assert c == _c

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 521why, one step back
521

ultra cookie compatibilityKenneth Reitzbefore adoption7a1a40e

line 522why, one step back
522 # Test session-level cookies.

Make sure that session-level cookies work.Kenneth Reitzbefore adoptionf9141f5

line 523why, one step back
523 s = requests.session(cookies=_c)

ultra cookie compatibilityKenneth Reitzbefore adoption7a1a40e

line 524why, one step back
524 r = s.get(httpbin('cookies'))

Make sure that session-level cookies work.Kenneth Reitzbefore adoptionf9141f5

lines 525–527why, one step back
525 c = json.loads(r.content).get('cookies')
526 assert c == _c527

ultra cookie compatibilityKenneth Reitzbefore adoption7a1a40e

lines 528–530why, one step back
528 # Have the server set a cookie.
529 r = s.get(httpbin('cookies', 'set', 'k', 'v'), allow_redirects=True)530 c = json.loads(r.content).get('cookies')

Make sure that session-level cookies work.Kenneth Reitzbefore adoptionf9141f5

line 531why, one step back
531

ultra cookie compatibilityKenneth Reitzbefore adoption7a1a40e

line 532why, one step back
532 assert 'k' in c

Make sure that session-level cookies work.Kenneth Reitzbefore adoptionf9141f5

line 533why, one step back
533

ultra cookie compatibilityKenneth Reitzbefore adoption7a1a40e

lines 534–541why, one step back
534 # And server-set cookie persistience.
535 r = s.get(httpbin('cookies'))536 c = json.loads(r.content).get('cookies')537538 assert 'k' in c539540541

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 542–567why, one step back
542 def test_session_persistent_params(self):
543544 params = {'a': 'a_test'}545546 s = requests.session()547 s.params = params548549 # Make 2 requests from Session object, should send header both times550 r1 = s.get(httpbin('get'))551 assert params['a'] in r1.content552553554 params2 = {'b': 'b_test'}555556 r2 = s.get(httpbin('get'), params=params2)557 assert params['a'] in r2.content558 assert params2['b'] in r2.content559560561 params3 = {'b': 'b_test', 'a': None, 'c': 'c_test'}562563 r3 = s.get(httpbin('get'), params=params3)564565 assert not params['a'] in r3.content566 assert params3['b'] in r3.content567 assert params3['c'] in r3.content

add query data yourself, foo'Kenneth Reitzbefore adoption0f2dcff

line 568why, one step back
568

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoptionc48f0d9

lines 569–571why, one step back
569 def test_invalid_content(self):
570 # WARNING: if you're using a terrible DNS provider (comcast),571 # this will fail.

add query data yourself, foo'Kenneth Reitzbefore adoption0f2dcff

lines 572–578why, one step back
572 try:
573 hah = 'http://somedomainthatclearlydoesntexistg.com'574 r = requests.get(hah, allow_redirects=False)575 except requests.ConnectionError:576 pass # \o/577 else:578 assert False

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoptionc48f0d9

line 579why, one step back
579

add query data yourself, foo'Kenneth Reitzbefore adoption0f2dcff

lines 580–582why, one step back
580
581 config = {'safe_mode': True}582 r = requests.get(hah, allow_redirects=False, config=config)

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoptionc48f0d9

lines 583–584why, one step back
583 assert r.content == None
584

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

line 585why, one step back
585

Readme update.Kenneth Reitzbefore adoption2cc8015

line 586why, one step back
586if __name__ == '__main__':

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

line 587why, one step back
587 unittest.main()