Skip to content
Myr

test_requests.py

This file

Path

test_requests.py

495 lines · 13.4 KiB · Python

Last changed by

Merge branch 'develop' into feature/asyncKenneth Reitzbefore adoption2115046

History of this 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

sample test fixtures (none)Kenneth Reitzbefore adoption75b499d

line 6why, one step back
6import unittest

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 7why, one step back
7import cookielib

temp "tests"Kenneth Reitzbefore adoption49f915f

line 8why, one step back
8

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 9–12why, one step back
9try:
10 import omnijson as json11except ImportError:12 import json

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 13why, one step back
13

temp "tests"Kenneth Reitzbefore adoption49f915f

lines 14–15why, one step back
14import requests
15

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 16why, one step back
16from requests.sessions import Session

temp "tests"Kenneth Reitzbefore adoption49f915f

line 17why, one step back
17

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 18why, one step back
18

Merge branch 'develop' into feature/asyncKenneth Reitzbefore adoption2115046

line 19why, one step back
19HTTPBIN_URL = 'http://httpbin.ep.io/'

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 20–37why, one step back
20HTTPSBIN_URL = 'https://httpbin.ep.io/'
2122# HTTPBIN_URL = 'http://staging.httpbin.org/'23# HTTPSBIN_URL = 'https://httpbin-staging.ep.io/'242526def httpbin(*suffix):27 """Returns url for HTTPBIN resource."""2829 return HTTPBIN_URL + '/'.join(suffix)303132def httpsbin(*suffix):33 """Returns url for HTTPSBIN resource."""3435 return HTTPSBIN_URL + '/'.join(suffix)3637

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 38why, one step back
38SERVICES = (httpbin, httpsbin)

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 39why, one step back
39

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 40–41why, one step back
40
41

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 44why, one step back
44

Merge branch 'develop' into feature/asyncKenneth Reitzbefore adoption2115046

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 47why, one step back
47

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

lines 48–49why, one step back
48 def setUp(self):
49 pass

temp "tests"Kenneth Reitzbefore adoption49f915f

line 50why, one step back
50

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 51why, one step back
51

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

lines 52–54why, one step back
52 def tearDown(self):
53 """Teardown."""54 pass

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 55why, one step back
55

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 56why, one step back
56

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 59why, one step back
59

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 60why, one step back
60

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 64why, one step back
64

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 65why, one step back
65

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

line 66why, one step back
66 def test_HTTPS_200_OK_GET(self):

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 67why, one step back
67 r = requests.get(httpsbin('/'))

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 69why, one step back
69

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 70why, one step back
70

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 73why, one step back
73

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

lines 77–78why, one step back
77 self.assertEqual(r.status_code, 200)
78

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 79why, one step back
79

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 85why, one step back
85

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 86why, one step back
86

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 89why, one step back
89

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

lines 90–93why, one step back
90 heads = {
91 'User-agent':92 'Mozilla/5.0 (github.com/kennethreitz/requests)'93 }

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 94why, one step back
94

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 97why, one step back
97

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

lines 98–102why, one step back
98 heads = {
99 'user-agent':100 'Mozilla/5.0 (github.com/kennethreitz/requests)'101 }102

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 106why, one step back
106

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 110why, one step back
110

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 111why, one step back
111

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

line 112why, one step back
112 def test_HTTPS_200_OK_HEAD(self):

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 113why, one step back
113 r = requests.head(httpsbin('/'))

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 115why, one step back
115

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 116–136why, one step back
116
117 def test_HTTP_200_OK_PUT(self):118 r = requests.put(httpbin('put'))119 self.assertEqual(r.status_code, 200)120121122 def test_HTTPS_200_OK_PUT(self):123 r = requests.put(httpsbin('put'))124 self.assertEqual(r.status_code, 200)125126127 def test_HTTP_200_OK_PATCH(self):128 r = requests.patch(httpbin('patch'))129 self.assertEqual(r.status_code, 200)130131132 def test_HTTPS_200_OK_PATCH(self):133 r = requests.patch(httpsbin('patch'))134 self.assertEqual(r.status_code, 200)135136

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 137why, one step back
137 def test_AUTH_HTTP_200_OK_GET(self):

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 138why, one step back
138

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 140why, one step back
140

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa

line 143why, one step back
143

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 144–146why, one step back
144 r = requests.get(url, auth=auth)
145 # print r.__dict__146 self.assertEqual(r.status_code, 200)

Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa

line 147why, one step back
147

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 148why, one step back
148

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 149–152why, one step back
149 r = requests.get(url)
150 self.assertEqual(r.status_code, 200)151152

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 154why, one step back
154

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 156why, one step back
156

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 159why, one step back
159

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 162why, one step back
162

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 165why, one step back
165

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 166–169why, one step back
166 post3 = requests.post(url, data='[{"some": "json"}]')
167 self.assertEqual(post3.status_code, 200)168169

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 171why, one step back
171

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 173why, one step back
173

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 174–177why, one step back
174 url = service('post')
175 post = requests.post(url,176 files={'some': open('test_requests.py')},177 data={'some': 'data'})

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 178why, one step back
178

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 179–181why, one step back
179 self.assertEqual(post.status_code, 200)
180181

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

lines 182–183why, one step back
182 def test_POSTBIN_GET_POST_FILES_WITH_HEADERS(self):
183

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 185why, one step back
185

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 187why, one step back
187

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 191why, one step back
191

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 193why, one step back
193

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 194why, one step back
194

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 196why, one step back
196

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 198why, one step back
198

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 201why, one step back
201

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 202–205why, one step back
202 r = requests.get(service('/'))
203 self.assertEqual(bool(r), True)204205

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 207why, one step back
207

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 209why, one step back
209

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 210–213why, one step back
210 r = requests.get(service('status', '404'))
211 self.assertEqual(r.ok, False)212213

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 217why, one step back
217

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

lines 219–220why, one step back
219 self.assertFalse(r.error)
220 r.raise_for_status()

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 221why, one step back
221

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 222why, one step back
222

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 223why, one step back
223 def test_cookie_jar(self):

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 224why, one step back
224

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

lines 225–227why, one step back
225 jar = cookielib.CookieJar()
226 self.assertFalse(jar)227

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 228–229why, one step back
228 url = httpbin('cookies', 'set', 'requests_cookie', 'awesome')
229 r = requests.get(url, cookies=jar)

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 230why, one step back
230 self.assertTrue(jar)

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 231why, one step back
231

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 232–242why, one step back
232 cookie_found = False
233 for cookie in jar:234 if cookie.name == 'requests_cookie':235 self.assertEquals(cookie.value, 'awesome')236 cookie_found = True237 self.assertTrue(cookie_found)238239 r = requests.get(httpbin('cookies'), cookies=jar)240 self.assertTrue('awesome' in r.content)241242

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 244why, one step back
244

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

lines 246–247why, one step back
246 r.content.decode('ascii')
247

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 248why, one step back
248

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 250why, one step back
250

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 252why, one step back
252

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 254why, one step back
254

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 255–259why, one step back
255 requests.get(url, params={'foo': u'føø'})
256 requests.get(url, params={u'føø': u'føø'})257 requests.get(url, params={'føø': 'føø'})258 requests.get(url, params={'foo': u'foo'})259 requests.get(service('ø'), params={'foo': u'foo'})

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 260why, one step back
260

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 261why, one step back
261

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 263why, one step back
263

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 265why, one step back
265

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 269why, one step back
269

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 270why, one step back
270

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

lines 271–272why, one step back
271 def test_settings(self):
272

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 273–275why, one step back
273 def test():
274 r = requests.get(httpbin(''))275 r.raise_for_status()

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 276why, one step back
276

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 277–285why, one step back
277 with requests.settings(timeout=0.0000001):
278 self.assertRaises(requests.Timeout, test)279280 with requests.settings(timeout=100):281 requests.get(httpbin(''))282283284 def test_urlencoded_post_data(self):285

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 287why, one step back
287

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 288–299why, one step back
288 r = requests.post(service('post'), data=dict(test='fooaowpeuf'))
289290 self.assertEquals(r.status_code, 200)291 self.assertEquals(r.headers['content-type'], 'application/json')292 self.assertEquals(r.url, service('post'))293294 rbody = json.loads(r.content)295296 self.assertEquals(rbody.get('form'), dict(test='fooaowpeuf'))297 self.assertEquals(rbody.get('data'), '')298299

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 301why, one step back
301

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 303why, one step back
303

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 304–316why, one step back
304 r = requests.post(service('post'), data='fooaowpeuf')
305306 self.assertEquals(r.status_code, 200)307 self.assertEquals(r.headers['content-type'], 'application/json')308 self.assertEquals(r.url, service('post'))309310 rbody = json.loads(r.content)311 # Body wasn't valid url encoded data, so the server returns None as312 # "form" and the raw body as "data".313 self.assertEquals(rbody.get('form'), None)314 self.assertEquals(rbody.get('data'), 'fooaowpeuf')315316

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 317–318why, one step back
317 def test_urlencoded_post_querystring(self):
318

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 320why, one step back
320

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 321–331why, one step back
321 r = requests.post(service('post'), params=dict(test='fooaowpeuf'))
322323 self.assertEquals(r.status_code, 200)324 self.assertEquals(r.headers['content-type'], 'application/json')325 self.assertEquals(r.url, service('post?test=fooaowpeuf'))326327 rbody = json.loads(r.content)328 self.assertEquals(rbody.get('form'), {}) # No form supplied329 self.assertEquals(rbody.get('data'), '')330331

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 332–333why, one step back
332 def test_nonurlencoded_post_querystring(self):
333

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 335why, one step back
335

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 336–346why, one step back
336 r = requests.post(service('post'), params='fooaowpeuf')
337338 self.assertEquals(r.status_code, 200)339 self.assertEquals(r.headers['content-type'], 'application/json')340 self.assertEquals(r.url, service('post?fooaowpeuf'))341342 rbody = json.loads(r.content)343 self.assertEquals(rbody.get('form'), {}) # No form supplied344 self.assertEquals(rbody.get('data'), '')345346

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 347–348why, one step back
347 def test_urlencoded_post_query_and_data(self):
348

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 350why, one step back
350

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 351–364why, one step back
351 r = requests.post(
352 service('post'),353 params=dict(test='fooaowpeuf'),354 data=dict(test2="foobar"))355356 self.assertEquals(r.status_code, 200)357 self.assertEquals(r.headers['content-type'], 'application/json')358 self.assertEquals(r.url, service('post?test=fooaowpeuf'))359360 rbody = json.loads(r.content)361 self.assertEquals(rbody.get('form'), dict(test2='foobar'))362 self.assertEquals(rbody.get('data'), '')363364

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 365why, one step back
365 def test_nonurlencoded_post_query_and_data(self):

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 366why, one step back
366

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 367–381why, one step back
367 for service in SERVICES:
368369 r = requests.post(service('post'),370 params='fooaowpeuf', data="foobar")371372 self.assertEquals(r.status_code, 200)373 self.assertEquals(r.headers['content-type'], 'application/json')374 self.assertEquals(r.url, service('post?fooaowpeuf'))375376 rbody = json.loads(r.content)377378 self.assertEquals(rbody.get('form'), None)379 self.assertEquals(rbody.get('data'), 'foobar')380381

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

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

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

line 385why, one step back
385

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 386why, one step back
386

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 387–388why, one step back
387 def test_urlencoded_get_query_multivalued_param(self):
388

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 389–395why, one step back
389 for service in SERVICES:
390391 r = requests.get(service('get'), params=dict(test=['foo','baz']))392 self.assertEquals(r.status_code, 200)393 self.assertEquals(r.url, service('get?test=foo&test=baz'))394395

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 396–397why, one step back
396 def test_urlencoded_post_querystring_multivalued(self):
397

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 398–409why, one step back
398 for service in SERVICES:
399400 r = requests.post(service('post'), params=dict(test=['foo','baz']))401 self.assertEquals(r.status_code, 200)402 self.assertEquals(r.headers['content-type'], 'application/json')403 self.assertEquals(r.url, service('post?test=foo&test=baz'))404405 rbody = json.loads(r.content)406 self.assertEquals(rbody.get('form'), {}) # No form supplied407 self.assertEquals(rbody.get('data'), '')408409

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 410–411why, one step back
410 def test_urlencoded_post_query_multivalued_and_data(self):
411

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

line 413why, one step back
413

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 414–426why, one step back
414 r = requests.post(
415 service('post'),416 params=dict(test=['foo','baz']),417 data=dict(test2="foobar",test3=['foo','baz']))418419 self.assertEquals(r.status_code, 200)420 self.assertEquals(r.headers['content-type'], 'application/json')421 self.assertEquals(r.url, service('post?test=foo&test=baz'))422 rbody = json.loads(r.content)423 self.assertEquals(rbody.get('form'), dict(test2='foobar',test3='foo'))424 self.assertEquals(rbody.get('data'), '')425426

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

lines 427–444why, one step back
427 def test_GET_no_redirect(self):
428429 for service in SERVICES:430431 r = requests.get(service('redirect', '3'), allow_redirects=False)432 self.assertEquals(r.status_code, 302)433 self.assertEquals(len(r.history), 0)434435436 def test_HEAD_no_redirect(self):437438 for service in SERVICES:439440 r = requests.head(service('redirect', '3'), allow_redirects=False)441 self.assertEquals(r.status_code, 302)442 self.assertEquals(len(r.history), 0)443444

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 445–446why, one step back
445 def test_redirect_history(self):
446

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 447–492why, one step back
447 for service in SERVICES:
448449 r = requests.get(service('redirect', '3'))450 self.assertEquals(r.status_code, 200)451 self.assertEquals(len(r.history), 3)452453454 def test_relative_redirect_history(self):455456 for service in SERVICES:457458 r = requests.get(service('relative-redirect', '3'))459 self.assertEquals(r.status_code, 200)460 self.assertEquals(len(r.history), 3)461462463 def test_session_HTTP_200_OK_GET(self):464465 s = Session()466 r = s.get(httpbin('/'))467 self.assertEqual(r.status_code, 200)468469470 def test_session_HTTPS_200_OK_GET(self):471472 s = Session()473 r = s.get(httpsbin('/'))474 self.assertEqual(r.status_code, 200)475476477 def test_session_persistent_headers(self):478479 heads = {'User-agent': 'Mozilla/5.0'}480481 s = Session()482 s.headers = heads483 # Make 2 requests from Session object, should send header both times484 r1 = s.get(httpbin('user-agent'))485486 assert heads['User-agent'] in r1.content487 r2 = s.get(httpbin('user-agent'))488489 assert heads['User-agent'] in r2.content490 self.assertEqual(r2.status_code, 200)491492

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

line 493why, one step back
493

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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