Skip to content
Myr

test_requests.py

This file

Path

test_requests.py

501 lines · 13.7 KiB · Python

Last changed by

Merge pull request #202 from kennethreitz/feature/content-streamKenneth Reitzbefore adoptionbfa0103

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

Make tests go to 11!Kenneth Reitzbefore adoption76b8afe

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

Make tests go to 11!Kenneth Reitzbefore adoption76b8afe

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 pull request #202 from kennethreitz/feature/content-streamKenneth Reitzbefore adoptionbfa0103

lines 65–67why, one step back
65 def test_HTTP_302_ALLOW_REDIRECT_GET(self):
66 r = requests.get(httpbin('redirect', '1'))67 self.assertEqual(r.status_code, 200)

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 68why, one step back
68

Merge pull request #202 from kennethreitz/feature/content-streamKenneth Reitzbefore adoptionbfa0103

lines 69–72why, one step back
69 def test_HTTP_302_GET(self):
70 r = requests.get(httpbin('redirect', '1'), allow_redirects=False)71 self.assertEqual(r.status_code, 302)72

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 76why, one step back
76

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 77why, one step back
77

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 80why, one step back
80

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

lines 84–85why, one step back
84 self.assertEqual(r.status_code, 200)
85

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 86why, one step back
86

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 92why, one step back
92

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 93why, one step back
93

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 96why, one step back
96

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 101why, one step back
101

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 104why, one step back
104

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

lines 105–109why, one step back
105 heads = {
106 'user-agent':107 'Mozilla/5.0 (github.com/kennethreitz/requests)'108 }109

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 113why, one step back
113

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 117why, one step back
117

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 118why, one step back
118

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 122why, one step back
122

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 123–143why, one step back
123
124 def test_HTTP_200_OK_PUT(self):125 r = requests.put(httpbin('put'))126 self.assertEqual(r.status_code, 200)127128129 def test_HTTPS_200_OK_PUT(self):130 r = requests.put(httpsbin('put'))131 self.assertEqual(r.status_code, 200)132133134 def test_HTTP_200_OK_PATCH(self):135 r = requests.patch(httpbin('patch'))136 self.assertEqual(r.status_code, 200)137138139 def test_HTTPS_200_OK_PATCH(self):140 r = requests.patch(httpsbin('patch'))141 self.assertEqual(r.status_code, 200)142143

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 145why, one step back
145

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 147why, one step back
147

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa

line 150why, one step back
150

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 151–153why, one step back
151 r = requests.get(url, auth=auth)
152 # print r.__dict__153 self.assertEqual(r.status_code, 200)

Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa

line 154why, one step back
154

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 155why, one step back
155

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 161why, one step back
161

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 163why, one step back
163

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 166why, one step back
166

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 169why, one step back
169

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 172why, one step back
172

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 173–176why, one step back
173 post3 = requests.post(url, data='[{"some": "json"}]')
174 self.assertEqual(post3.status_code, 200)175176

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 178why, one step back
178

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 180why, one step back
180

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 181–184why, one step back
181 url = service('post')
182 post = requests.post(url,183 files={'some': open('test_requests.py')},184 data={'some': 'data'})

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 185why, one step back
185

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 186–188why, one step back
186 self.assertEqual(post.status_code, 200)
187188

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

lines 189–190why, one step back
189 def test_POSTBIN_GET_POST_FILES_WITH_HEADERS(self):
190

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 192why, one step back
192

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 194why, one step back
194

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 198why, one step back
198

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 200why, one step back
200

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 201why, one step back
201

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 203why, one step back
203

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 205why, one step back
205

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 208why, one step back
208

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 209–212why, one step back
209 r = requests.get(service('/'))
210 self.assertEqual(bool(r), True)211212

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 214why, one step back
214

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 216why, one step back
216

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 217–220why, one step back
217 r = requests.get(service('status', '404'))
218 self.assertEqual(r.ok, False)219220

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 224why, one step back
224

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

lines 226–227why, one step back
226 self.assertFalse(r.error)
227 r.raise_for_status()

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 228why, one step back
228

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 229why, one step back
229

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 231why, one step back
231

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

lines 232–234why, one step back
232 jar = cookielib.CookieJar()
233 self.assertFalse(jar)234

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 238why, one step back
238

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 239–249why, one step back
239 cookie_found = False
240 for cookie in jar:241 if cookie.name == 'requests_cookie':242 self.assertEquals(cookie.value, 'awesome')243 cookie_found = True244 self.assertTrue(cookie_found)245246 r = requests.get(httpbin('cookies'), cookies=jar)247 self.assertTrue('awesome' in r.content)248249

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 251why, one step back
251

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

lines 253–254why, one step back
253 r.content.decode('ascii')
254

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 255why, one step back
255

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 257why, one step back
257

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 259why, one step back
259

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 261why, one step back
261

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 262–266why, one step back
262 requests.get(url, params={'foo': u'føø'})
263 requests.get(url, params={u'føø': u'føø'})264 requests.get(url, params={'føø': 'føø'})265 requests.get(url, params={'foo': u'foo'})266 requests.get(service('ø'), params={'foo': u'foo'})

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 267why, one step back
267

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 268why, one step back
268

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 270why, one step back
270

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 272why, one step back
272

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 276why, one step back
276

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 277why, one step back
277

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

lines 278–279why, one step back
278 def test_settings(self):
279

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 280–282why, one step back
280 def test():
281 r = requests.get(httpbin(''))282 r.raise_for_status()

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 283why, one step back
283

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 284–292why, one step back
284 with requests.settings(timeout=0.0000001):
285 self.assertRaises(requests.Timeout, test)286287 with requests.settings(timeout=100):288 requests.get(httpbin(''))289290291 def test_urlencoded_post_data(self):292

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 294why, one step back
294

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 295–306why, one step back
295 r = requests.post(service('post'), data=dict(test='fooaowpeuf'))
296297 self.assertEquals(r.status_code, 200)298 self.assertEquals(r.headers['content-type'], 'application/json')299 self.assertEquals(r.url, service('post'))300301 rbody = json.loads(r.content)302303 self.assertEquals(rbody.get('form'), dict(test='fooaowpeuf'))304 self.assertEquals(rbody.get('data'), '')305306

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 308why, one step back
308

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 310why, one step back
310

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 311–323why, one step back
311 r = requests.post(service('post'), data='fooaowpeuf')
312313 self.assertEquals(r.status_code, 200)314 self.assertEquals(r.headers['content-type'], 'application/json')315 self.assertEquals(r.url, service('post'))316317 rbody = json.loads(r.content)318 # Body wasn't valid url encoded data, so the server returns None as319 # "form" and the raw body as "data".320 self.assertEquals(rbody.get('form'), None)321 self.assertEquals(rbody.get('data'), 'fooaowpeuf')322323

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 324–325why, one step back
324 def test_urlencoded_post_querystring(self):
325

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 327why, one step back
327

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 328–338why, one step back
328 r = requests.post(service('post'), params=dict(test='fooaowpeuf'))
329330 self.assertEquals(r.status_code, 200)331 self.assertEquals(r.headers['content-type'], 'application/json')332 self.assertEquals(r.url, service('post?test=fooaowpeuf'))333334 rbody = json.loads(r.content)335 self.assertEquals(rbody.get('form'), {}) # No form supplied336 self.assertEquals(rbody.get('data'), '')337338

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 339–340why, one step back
339 def test_nonurlencoded_post_querystring(self):
340

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 342why, one step back
342

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 343–353why, one step back
343 r = requests.post(service('post'), params='fooaowpeuf')
344345 self.assertEquals(r.status_code, 200)346 self.assertEquals(r.headers['content-type'], 'application/json')347 self.assertEquals(r.url, service('post?fooaowpeuf'))348349 rbody = json.loads(r.content)350 self.assertEquals(rbody.get('form'), {}) # No form supplied351 self.assertEquals(rbody.get('data'), '')352353

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 354–355why, one step back
354 def test_urlencoded_post_query_and_data(self):
355

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 357why, one step back
357

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 358–371why, one step back
358 r = requests.post(
359 service('post'),360 params=dict(test='fooaowpeuf'),361 data=dict(test2="foobar"))362363 self.assertEquals(r.status_code, 200)364 self.assertEquals(r.headers['content-type'], 'application/json')365 self.assertEquals(r.url, service('post?test=fooaowpeuf'))366367 rbody = json.loads(r.content)368 self.assertEquals(rbody.get('form'), dict(test2='foobar'))369 self.assertEquals(rbody.get('data'), '')370371

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 373why, one step back
373

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 374–388why, one step back
374 for service in SERVICES:
375376 r = requests.post(service('post'),377 params='fooaowpeuf', data="foobar")378379 self.assertEquals(r.status_code, 200)380 self.assertEquals(r.headers['content-type'], 'application/json')381 self.assertEquals(r.url, service('post?fooaowpeuf'))382383 rbody = json.loads(r.content)384385 self.assertEquals(rbody.get('form'), None)386 self.assertEquals(rbody.get('data'), 'foobar')387388

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

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

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

line 392why, one step back
392

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 393why, one step back
393

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 396–402why, one step back
396 for service in SERVICES:
397398 r = requests.get(service('get'), params=dict(test=['foo','baz']))399 self.assertEquals(r.status_code, 200)400 self.assertEquals(r.url, service('get?test=foo&test=baz'))401402

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 405–416why, one step back
405 for service in SERVICES:
406407 r = requests.post(service('post'), params=dict(test=['foo','baz']))408 self.assertEquals(r.status_code, 200)409 self.assertEquals(r.headers['content-type'], 'application/json')410 self.assertEquals(r.url, service('post?test=foo&test=baz'))411412 rbody = json.loads(r.content)413 self.assertEquals(rbody.get('form'), {}) # No form supplied414 self.assertEquals(rbody.get('data'), '')415416

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

line 420why, one step back
420

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

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

lines 434–451why, one step back
434 def test_GET_no_redirect(self):
435436 for service in SERVICES:437438 r = requests.get(service('redirect', '3'), allow_redirects=False)439 self.assertEquals(r.status_code, 302)440 self.assertEquals(len(r.history), 0)441442443 def test_HEAD_no_redirect(self):444445 for service in SERVICES:446447 r = requests.head(service('redirect', '3'), allow_redirects=False)448 self.assertEquals(r.status_code, 302)449 self.assertEquals(len(r.history), 0)450451

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 454–498why, one step back
454 for service in SERVICES:
455456 r = requests.get(service('redirect', '3'))457 self.assertEquals(r.status_code, 200)458 self.assertEquals(len(r.history), 3)459460461 def test_relative_redirect_history(self):462463 for service in SERVICES:464465 r = requests.get(service('relative-redirect', '3'))466 self.assertEquals(r.status_code, 200)467 self.assertEquals(len(r.history), 3)468469470 def test_session_HTTP_200_OK_GET(self):471472 s = Session()473 r = s.get(httpbin('/'))474 self.assertEqual(r.status_code, 200)475476477 def test_session_HTTPS_200_OK_GET(self):478479 s = Session()480 r = s.get(httpsbin('/'))481 self.assertEqual(r.status_code, 200)482483484 def test_session_persistent_headers(self):485486 heads = {'User-agent': 'Mozilla/5.0'}487488 s = Session()489 s.headers = heads490 # Make 2 requests from Session object, should send header both times491 r1 = s.get(httpbin('user-agent'))492493 assert heads['User-agent'] in r1.content494 r2 = s.get(httpbin('user-agent'))495496 assert heads['User-agent'] in r2.content497 self.assertEqual(r2.status_code, 200)498

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

line 499why, one step back
499

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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