Skip to content
Myr

test_requests.py

This file

Path

test_requests.py

727 lines · 19.9 KiB · Python

Last changed by

Facilitate for multiple hooksJohannes Gorsetbefore adoption7647e52

History of this file

Take it

sample test fixtures (none)Kenneth Reitzbefore adoption75b499d

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'Kenneth Reitzbefore adoption9ed9304

line 6why, one step back
6import StringIO

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

lines 7–9why, one step back
7import time
8import os9import unittest

temp "tests"Kenneth Reitzbefore adoption49f915f

line 10why, one step back
10

Merge branch 'develop'Kenneth Reitzbefore adoption5b5b3de

line 11why, one step back
11import requests

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

line 12why, one step back
12import envoy

Merge branch 'develop'Kenneth Reitzbefore adoption6e9cb09

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

Merge branch 'develop'Kenneth Reitzbefore adoptiond1dfa02

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

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

line 15why, one step back
15

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 16–19why, one step back
16try:
17 import omnijson as json18except ImportError:19 import json

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 20why, one step back
20

temp "tests"Kenneth Reitzbefore adoption49f915f

line 21why, one step back
21

Merge branch 'develop'Kenneth Reitzbefore adoption5b5b3de

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

temp "tests"Kenneth Reitzbefore adoption49f915f

line 24why, one step back
24

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

lines 25–26why, one step back
25HTTPBIN_URL = 'http://0.0.0.0:%s/' % (PORT)
26# HTTPBIN_URL = 'http://127.0.0.1:8000/'

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 27–34why, one step back
27
2829def httpbin(*suffix):30 """Returns url for HTTPBIN resource."""3132 return HTTPBIN_URL + '/'.join(suffix)3334

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 36why, one step back
36

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

line 37why, one step back
37_httpbin = False

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 38why, one step back
38

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 39why, one step back
39class RequestsTestSuite(unittest.TestCase):

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

line 40why, one step back
40 """Requests test cases."""

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 41why, one step back
41

Merge branch 'release/0.6.3'Kenneth Reitzbefore adoption1551158

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 44why, one step back
44

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

temp "tests"Kenneth Reitzbefore adoption49f915f

line 46why, one step back
46

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

line 47why, one step back
47 global _httpbin

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 48why, one step back
48

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

lines 49–50why, one step back
49 if not _httpbin:
50

Merge branch 'develop'Kenneth Reitzbefore adoption5b5b3de

line 51why, one step back
51 c = envoy.connect('gunicorn httpbin:app --bind=0.0.0.0:%s' % (PORT))

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

line 52why, one step back
52

Merge branch 'develop'Kenneth Reitzbefore adoption5b5b3de

line 53why, one step back
53 self.httpbin = c

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

lines 54–58why, one step back
54 _httpbin = True
55 time.sleep(1)565758

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

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

Merge branch 'develop'Kenneth Reitzbefore adoption6e9cb09

line 62why, one step back
62 pass

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 63why, one step back
63

Merge branch 'develop'Kenneth Reitzbefore adoption6e9cb09

line 64why, one step back
64

Merge branch 'develop'Kenneth Reitzbefore adoption5b5b3de

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 66why, one step back
66

Merge branch 'develop'Kenneth Reitzbefore adoption5b5b3de

lines 67–77why, one step back
67 requests.session
68 requests.session().get69 requests.session().head70 requests.get71 requests.head72 requests.put73 requests.patch74 requests.post757677

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 80why, one step back
80

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 84why, one step back
84

Merge branch 'develop'Kenneth Reitzbefore adoption8c1fd5d

lines 85–89why, one step back
85 def test_response_sent(self):
86 r = requests.get(httpbin('/get'))8788 self.assertTrue(r.request.sent)89

Merge branch 'release/0.6.4'Kenneth Reitzbefore adoption4f6fc98

line 90why, one step back
90 def test_HTTP_302_ALLOW_REDIRECT_GET(self):

Merge branch 'develop'Kenneth Reitzbefore adoption5b5b3de

lines 91–92why, one step back
91 r = requests.get(httpbin('redirect', '1'))
92 self.assertEqual(r.status_code, 200)

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 93why, one step back
93

Merge branch 'release/0.6.4'Kenneth Reitzbefore adoption4f6fc98

line 94why, one step back
94 def test_HTTP_302_GET(self):

Merge branch 'develop'Kenneth Reitzbefore adoption5b5b3de

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

Merge branch 'release/0.6.4'Kenneth Reitzbefore adoption4f6fc98

line 97why, one step back
97

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 98why, one step back
98

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 101why, one step back
101

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 107why, one step back
107

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 113why, one step back
113

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 114why, one step back
114

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 117why, one step back
117

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 122why, one step back
122

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 125why, one step back
125

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 134why, one step back
134

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 138why, one step back
138

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 139–149why, one step back
139
140 def test_HTTP_200_OK_PUT(self):141 r = requests.put(httpbin('put'))142 self.assertEqual(r.status_code, 200)143144145 def test_HTTP_200_OK_PATCH(self):146 r = requests.patch(httpbin('patch'))147 self.assertEqual(r.status_code, 200)148149

Merge branch 'develop'Kenneth Reitzbefore adoptiond1dfa02

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 151why, one step back
151

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 153why, one step back
153

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa

line 156why, one step back
156

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa

line 159why, one step back
159

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'develop'Kenneth Reitzbefore adoption6b9cb05

lines 161–165why, one step back
161 self.assertEqual(r.status_code, 401)
162163164 s = requests.session(auth=auth)165 r = s.get(url)

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'develop'Kenneth Reitzbefore adoption6b9cb05

line 168why, one step back
168

Merge branch 'develop'Kenneth Reitzbefore adoptiond1dfa02

lines 169–191why, one step back
169 def test_BASICAUTH_HTTP_200_OK_GET(self):
170171 for service in SERVICES:172173 auth = HTTPBasicAuth('user', 'pass')174 url = service('basic-auth', 'user', 'pass')175176 r = requests.get(url, auth=auth)177 self.assertEqual(r.status_code, 200)178179 auth = ('user', 'pass')180 r = requests.get(url, auth=auth)181 self.assertEqual(r.status_code, 200)182183 r = requests.get(url)184 self.assertEqual(r.status_code, 401)185186187 s = requests.session(auth=auth)188 r = s.get(url)189 self.assertEqual(r.status_code, 200)190191

Merge branch 'develop'Kenneth Reitzbefore adoption6b9cb05

lines 192–195why, one step back
192 def test_DIGESTAUTH_HTTP_200_OK_GET(self):
193194 for service in SERVICES:195

Merge branch 'develop'Kenneth Reitzbefore adoptiond1dfa02

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

Merge branch 'develop'Kenneth Reitzbefore adoption6b9cb05

lines 197–208why, one step back
197 url = service('digest-auth', 'auth', 'user', 'pass')
198199 r = requests.get(url, auth=auth)200 self.assertEqual(r.status_code, 200)201202 r = requests.get(url)203 self.assertEqual(r.status_code, 401)204205206 s = requests.session(auth=auth)207 r = s.get(url)208 self.assertEqual(r.status_code, 200)

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 209why, one step back
209

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 211why, one step back
211

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 213why, one step back
213

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 216why, one step back
216

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 219why, one step back
219

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 222why, one step back
222

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 228why, one step back
228

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 230why, one step back
230

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 235why, one step back
235

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 236–238why, one step back
236 self.assertEqual(post.status_code, 200)
237238

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 242why, one step back
242

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 244why, one step back
244

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 248why, one step back
248

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 250why, one step back
250

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 251why, one step back
251

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 253why, one step back
253

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 255why, one step back
255

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 258why, one step back
258

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 260–262why, one step back
260 self.assertEqual(bool(r), True)
261262

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 264why, one step back
264

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 266why, one step back
266

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'develop'Kenneth Reitzbefore adoption6e9cb09

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 270–272why, one step back
270 self.assertEqual(r.ok, False)
271272

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'develop'Kenneth Reitzbefore adoptiond0b96f8

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 276why, one step back
276

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 280why, one step back
280

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 281why, one step back
281

Merge pull request #333 from bryanhelmig/developKenneth Reitzbefore adoption281e059

lines 282–291why, one step back
282 def test_default_status_raising(self):
283 config = {'danger_mode': True}284 args = [httpbin('status', '404')]285 kwargs = dict(config=config)286 self.assertRaises(HTTPError, requests.get, *args, **kwargs)287288 r = requests.get(httpbin('status', '200'))289 self.assertEqual(r.status_code, 200)290291

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 293why, one step back
293

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

lines 295–296why, one step back
295 r.content.decode('ascii')
296

Merge pull request #368 from jgorset/unicode-response-urlKenneth Reitzbefore adoption99f6581

lines 297–306why, one step back
297 def test_response_has_unicode_url(self):
298299 for service in SERVICES:300301 url = service('get')302303 response = requests.get(url)304305 self.assertIsInstance(response.url, unicode)306

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 307why, one step back
307

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 309why, one step back
309

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 311why, one step back
311

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 313why, one step back
313

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 314–318why, one step back
314 requests.get(url, params={'foo': u'føø'})
315 requests.get(url, params={u'føø': u'føø'})316 requests.get(url, params={'føø': 'føø'})317 requests.get(url, params={'foo': u'foo'})318 requests.get(service('ø'), params={'foo': u'foo'})

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 319why, one step back
319

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 320why, one step back
320

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 322why, one step back
322

Merge branch 'develop'Kenneth Reitzbefore adoptiond1dfa02

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 324why, one step back
324

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 328why, one step back
328

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 329–331why, one step back
329
330 def test_urlencoded_post_data(self):331

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 333why, one step back
333

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 334–345why, one step back
334 r = requests.post(service('post'), data=dict(test='fooaowpeuf'))
335336 self.assertEquals(r.status_code, 200)337 self.assertEquals(r.headers['content-type'], 'application/json')338 self.assertEquals(r.url, service('post'))339340 rbody = json.loads(r.content)341342 self.assertEquals(rbody.get('form'), dict(test='fooaowpeuf'))343 self.assertEquals(rbody.get('data'), '')344345

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 347why, one step back
347

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 349why, one step back
349

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 350–358why, one step back
350 r = requests.post(service('post'), data='fooaowpeuf')
351352 self.assertEquals(r.status_code, 200)353 self.assertEquals(r.headers['content-type'], 'application/json')354 self.assertEquals(r.url, service('post'))355356 rbody = json.loads(r.content)357 # Body wasn't valid url encoded data, so the server returns None as358 # "form" and the raw body as "data".

Merge branch 'develop'Kenneth Reitzbefore adoption6e9cb09

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 360–362why, one step back
360 self.assertEquals(rbody.get('data'), 'fooaowpeuf')
361362

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 363–364why, one step back
363 def test_urlencoded_post_querystring(self):
364

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 366why, one step back
366

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 367–377why, one step back
367 r = requests.post(service('post'), params=dict(test='fooaowpeuf'))
368369 self.assertEquals(r.status_code, 200)370 self.assertEquals(r.headers['content-type'], 'application/json')371 self.assertEquals(r.url, service('post?test=fooaowpeuf'))372373 rbody = json.loads(r.content)374 self.assertEquals(rbody.get('form'), {}) # No form supplied375 self.assertEquals(rbody.get('data'), '')376377

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 378–379why, one step back
378 def test_urlencoded_post_query_and_data(self):
379

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 381why, one step back
381

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 382–395why, one step back
382 r = requests.post(
383 service('post'),384 params=dict(test='fooaowpeuf'),385 data=dict(test2="foobar"))386387 self.assertEquals(r.status_code, 200)388 self.assertEquals(r.headers['content-type'], 'application/json')389 self.assertEquals(r.url, service('post?test=fooaowpeuf'))390391 rbody = json.loads(r.content)392 self.assertEquals(rbody.get('form'), dict(test2='foobar'))393 self.assertEquals(rbody.get('data'), '')394395

Merge branch 'develop'Kenneth Reitzbefore adoption6e9cb09

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 397why, one step back
397

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 398–399why, one step back
398 for service in SERVICES:
399

Merge branch 'develop'Kenneth Reitzbefore adoption6e9cb09

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 401–406why, one step back
401
402 self.assertEquals(r.status_code, 200)403 self.assertEquals(r.headers['content-type'], 'application/json')404405 rbody = json.loads(r.content)406

Merge branch 'develop'Kenneth Reitzbefore adoption6e9cb09

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 408–410why, one step back
408 self.assertEquals(rbody.get('data'), 'foobar')
409410

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

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

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

line 414why, one step back
414

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 415why, one step back
415

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 416–417why, one step back
416 def test_urlencoded_get_query_multivalued_param(self):
417

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 418–424why, one step back
418 for service in SERVICES:
419420 r = requests.get(service('get'), params=dict(test=['foo','baz']))421 self.assertEquals(r.status_code, 200)422 self.assertEquals(r.url, service('get?test=foo&test=baz'))423424

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 425–426why, one step back
425 def test_urlencoded_post_querystring_multivalued(self):
426

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 427–438why, one step back
427 for service in SERVICES:
428429 r = requests.post(service('post'), params=dict(test=['foo','baz']))430 self.assertEquals(r.status_code, 200)431 self.assertEquals(r.headers['content-type'], 'application/json')432 self.assertEquals(r.url, service('post?test=foo&test=baz'))433434 rbody = json.loads(r.content)435 self.assertEquals(rbody.get('form'), {}) # No form supplied436 self.assertEquals(rbody.get('data'), '')437438

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 439–440why, one step back
439 def test_urlencoded_post_query_multivalued_and_data(self):
440

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

line 442why, one step back
442

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 443–451why, one step back
443 r = requests.post(
444 service('post'),445 params=dict(test=['foo','baz']),446 data=dict(test2="foobar",test3=['foo','baz']))447448 self.assertEquals(r.status_code, 200)449 self.assertEquals(r.headers['content-type'], 'application/json')450 self.assertEquals(r.url, service('post?test=foo&test=baz'))451 rbody = json.loads(r.content)

Merge branch 'develop'Kenneth Reitzbefore adoption19a2a6c

line 452why, one step back
452 self.assertEquals(rbody.get('form'), dict(test2='foobar',test3=['foo','baz']))

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 453–455why, one step back
453 self.assertEquals(rbody.get('data'), '')
454455

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

lines 456–473why, one step back
456 def test_GET_no_redirect(self):
457458 for service in SERVICES:459460 r = requests.get(service('redirect', '3'), allow_redirects=False)461 self.assertEquals(r.status_code, 302)462 self.assertEquals(len(r.history), 0)463464465 def test_HEAD_no_redirect(self):466467 for service in SERVICES:468469 r = requests.head(service('redirect', '3'), allow_redirects=False)470 self.assertEquals(r.status_code, 302)471 self.assertEquals(len(r.history), 0)472473

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 474–475why, one step back
474 def test_redirect_history(self):
475

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 476–493why, one step back
476 for service in SERVICES:
477478 r = requests.get(service('redirect', '3'))479 self.assertEquals(r.status_code, 200)480 self.assertEquals(len(r.history), 3)481482483 def test_relative_redirect_history(self):484485 for service in SERVICES:486487 r = requests.get(service('relative-redirect', '3'))488 self.assertEquals(r.status_code, 200)489 self.assertEquals(len(r.history), 3)490491492 def test_session_HTTP_200_OK_GET(self):493

Merge branch 'develop'Kenneth Reitzbefore adoption5b5b3de

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

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

line 495why, one step back
495 r = s.get(httpbin('/get'))

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 496–502why, one step back
496 self.assertEqual(r.status_code, 200)
497498499 def test_session_persistent_headers(self):500501 heads = {'User-agent': 'Mozilla/5.0'}502

Merge branch 'develop'Kenneth Reitzbefore adoption5b5b3de

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

line 505why, one step back
505

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 506–509why, one step back
506 # Make 2 requests from Session object, should send header both times
507 r1 = s.get(httpbin('user-agent'))508 assert heads['User-agent'] in r1.content509

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'develop'Kenneth Reitzbefore adoption82e8fdb

lines 512–516why, one step back
512
513 new_heads = {'User-agent': 'blah'}514 r3 = s.get(httpbin('user-agent'), headers=new_heads)515 assert new_heads['User-agent'] in r3.content516

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 517–518why, one step back
517 self.assertEqual(r2.status_code, 200)
518

Facilitate for multiple hooksJohannes Gorsetbefore adoption7647e52

lines 519–577why, one step back
519 def test_single_hook(self):
520521 def add_foo_header(args):522 if not args.get('headers'):523 args['headers'] = {}524525 args['headers'].update({526 'X-Foo': 'foo'527 })528529 return args530531 for service in SERVICES:532 url = service('headers')533534 response = requests.get(535 url = url,536 hooks = {537 'args': add_foo_header538 }539 )540541 assert 'foo' in response.content542543 def test_multiple_hooks(self):544545 def add_foo_header(args):546 if not args.get('headers'):547 args['headers'] = {}548549 args['headers'].update({550 'X-Foo': 'foo'551 })552553 return args554555 def add_bar_header(args):556 if not args.get('headers'):557 args['headers'] = {}558559 args['headers'].update({560 'X-Bar': 'bar'561 })562563 return args564565 for service in SERVICES:566 url = service('headers')567568 response = requests.get(569 url = url,570 hooks = {571 'args': [add_foo_header, add_bar_header]572 }573 )574575 assert 'foo' in response.content576 assert 'bar' in response.content577

Merge branch 'develop'Kenneth Reitzbefore adoption6e9cb09

line 578why, one step back
578 def test_session_persistent_cookies(self):

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

line 579why, one step back
579

Merge branch 'develop'Kenneth Reitzbefore adoption6e9cb09

lines 580–621why, one step back
580 s = requests.session()
581582 # Internally dispatched cookies are sent.583 _c = {'kenneth': 'reitz', 'bessie': 'monke'}584 r = s.get(httpbin('cookies'), cookies=_c)585 r = s.get(httpbin('cookies'))586587 # Those cookies persist transparently.588 c = json.loads(r.content).get('cookies')589 assert c == _c590591 # Double check.592 r = s.get(httpbin('cookies'), cookies={})593 c = json.loads(r.content).get('cookies')594 assert c == _c595596 # Remove a cookie by setting it's value to None.597 r = s.get(httpbin('cookies'), cookies={'bessie': None})598 c = json.loads(r.content).get('cookies')599 del _c['bessie']600 assert c == _c601602 # Test session-level cookies.603 s = requests.session(cookies=_c)604 r = s.get(httpbin('cookies'))605 c = json.loads(r.content).get('cookies')606 assert c == _c607608 # Have the server set a cookie.609 r = s.get(httpbin('cookies', 'set', 'k', 'v'), allow_redirects=True)610 c = json.loads(r.content).get('cookies')611612 assert 'k' in c613614 # And server-set cookie persistience.615 r = s.get(httpbin('cookies'))616 c = json.loads(r.content).get('cookies')617618 assert 'k' in c619620621

Merge branch 'develop'Kenneth Reitzbefore adoption23efd56

lines 622–625why, one step back
622 def test_session_persistent_params(self):
623624 params = {'a': 'a_test'}625

Merge branch 'develop'Kenneth Reitzbefore adoption5b5b3de

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

Merge branch 'develop'Kenneth Reitzbefore adoption23efd56

lines 627–647why, one step back
627 s.params = params
628629 # Make 2 requests from Session object, should send header both times630 r1 = s.get(httpbin('get'))631 assert params['a'] in r1.content632633634 params2 = {'b': 'b_test'}635636 r2 = s.get(httpbin('get'), params=params2)637 assert params['a'] in r2.content638 assert params2['b'] in r2.content639640641 params3 = {'b': 'b_test', 'a': None, 'c': 'c_test'}642643 r3 = s.get(httpbin('get'), params=params3)644645 assert not params['a'] in r3.content646 assert params3['b'] in r3.content647 assert params3['c'] in r3.content

Merge branch 'develop'Kenneth Reitzbefore adoptiond0b96f8

lines 648–649why, one step back
648
649 def test_invalid_content(self):

Merge branch 'develop'Kenneth Reitzbefore adoption6e9cb09

lines 650–658why, one step back
650 # WARNING: if you're using a terrible DNS provider (comcast),
651 # this will fail.652 try:653 hah = 'http://somedomainthatclearlydoesntexistg.com'654 r = requests.get(hah, allow_redirects=False)655 except requests.ConnectionError:656 pass # \o/657 else:658 assert False

Merge branch 'develop'Kenneth Reitzbefore adoptiond0b96f8

line 659why, one step back
659

Merge branch 'develop'Kenneth Reitzbefore adoption6e9cb09

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

Merge branch 'develop'Kenneth Reitzbefore adoptiond0b96f8

line 663why, one step back
663 assert r.content == None

Merge branch 'develop'Kenneth Reitzbefore adoption23efd56

line 664why, one step back
664

Merge branch 'develop'Kenneth Reitzbefore adoption8c1fd5d

lines 665–671why, one step back
665 def test_cached_response(self):
666667 r1 = requests.get(httpbin('get'), prefetch=False)668 assert r1.content669 assert r1.content670671 r2 = requests.get(httpbin('get'), prefetch=True)

Merge branch 'develop'Kenneth Reitzbefore adoption19a2a6c

line 672why, one step back
672 assert r2._content

Merge branch 'develop'Kenneth Reitzbefore adoption8c1fd5d

line 673why, one step back
673 assert r2.content

Merge branch 'develop'Kenneth Reitzbefore adoption19a2a6c

lines 674–680why, one step back
674
675 def test_iter_lines(self):676677 lines = (0, 2, 10, 100)678679 for i in lines:680 r = requests.get(httpbin('stream', str(i)), prefetch=False)

Merge branch 'streaming' of https://github.com/RonnyPfannschmidt/requests into developKenneth Reitzbefore adoptionf3ba022

lines 681–682why, one step back
681 lines = list(r.iter_lines())
682 len_lines = len(lines)

Merge branch 'develop'Kenneth Reitzbefore adoption19a2a6c

lines 683–684why, one step back
683
684 self.assertEqual(i, len_lines)

Merge branch 'develop'Kenneth Reitzbefore adoption9ed9304

lines 685–724why, one step back
685
686 # Test 'dangling' fragment in responses that do not terminate in687 # a newline.688 quote = (689 '''Why will he not upon our fair request\n'''690 '''Untent his person and share the air with us?'''691 )692693 # Make a request and monkey-patch its contents694 r = requests.get(httpbin('get'))695 r.raw = StringIO.StringIO(quote)696697 # Make sure iter_lines doesn't chop the trailing bit698 lines = '\n'.join(r.iter_lines())699 self.assertEqual(lines, quote)700701 def test_safe_mode(self):702703 safe = requests.session(config=dict(safe_mode=True))704705 # Safe mode creates empty responses for failed requests.706 # Iterating on these responses should produce empty sequences707 r = safe.get('http://_/')708 self.assertEquals(list(r.iter_lines()), [])709 self.assertIsInstance(r.error, requests.exceptions.ConnectionError)710711 r = safe.get('http://_/')712 self.assertEquals(list(r.iter_content()), [])713 self.assertIsInstance(r.error, requests.exceptions.ConnectionError)714715 # When not in safe mode, should raise Timeout exception716 with self.assertRaises(requests.exceptions.Timeout):717 r = requests.get(httpbin('stream', '1000'), timeout=0.0001)718719 # In safe mode, should return a blank response720 r = requests.get(httpbin('stream', '1000'), timeout=0.0001,721 config=dict(safe_mode=True))722 self.assertIsNone(r.content)723 self.assertIsInstance(r.error, requests.exceptions.Timeout)724

Merge branch 'develop'Kenneth Reitzbefore adoption23efd56

line 725why, one step back
725

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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