Skip to content
Myr

test_requests.py

This file

Path

test_requests.py

515 lines · 14.0 KiB · Python

Last changed by

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption5b54b3e

History of this 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' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 6why, one step back
6import time

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 7why, one step back
7import cookielib

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 8–9why, one step back
8import os
9import unittest

temp "tests"Kenneth Reitzbefore adoption49f915f

line 10why, one step back
10

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption5b54b3e

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

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 14why, one step back
14

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 19why, one step back
19

temp "tests"Kenneth Reitzbefore adoption49f915f

line 20why, one step back
20

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

temp "tests"Kenneth Reitzbefore adoption49f915f

line 23why, one step back
23

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 26–33why, one step back
26
2728def httpbin(*suffix):29 """Returns url for HTTPBIN resource."""3031 return HTTPBIN_URL + '/'.join(suffix)3233

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 35why, one step back
35

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 36why, one step back
36_httpbin = False

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 37why, one step back
37

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 40why, one step back
40

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 43why, one step back
43

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 45why, one step back
45

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 46why, one step back
46 global _httpbin

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 47why, one step back
47

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 49why, one step back
49

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 51why, one step back
51

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 52–54why, one step back
52 self.httpbin = c
53 _httpbin = True54 time.sleep(1)

temp "tests"Kenneth Reitzbefore adoption49f915f

line 55why, one step back
55

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 56why, one step back
56

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 57why, one step back
57

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 61why, one step back
61

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 62–63why, one step back
62 def test_entry_points(self):
63 import requests

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 64why, one step back
64

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 65–75why, one step back
65 requests.session
66 requests.session().get67 requests.session().head68 requests.get69 requests.head70 requests.put71 requests.patch72 requests.post737475

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 78why, one step back
78

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 82why, one step back
82

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 86why, one step back
86

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 90why, one step back
90

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 91why, one step back
91

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 94why, one step back
94

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

lines 98–99why, one step back
98 self.assertEqual(r.status_code, 200)
99

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 100why, one step back
100

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 106why, one step back
106

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 107why, one step back
107

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 110why, one step back
110

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

lines 111–114why, one step back
111 heads = {
112 'User-agent':113 'Mozilla/5.0 (github.com/kennethreitz/requests)'114 }

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 115why, one step back
115

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 118why, one step back
118

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 127why, one step back
127

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 131why, one step back
131

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 132–142why, one step back
132
133 def test_HTTP_200_OK_PUT(self):134 r = requests.put(httpbin('put'))135 self.assertEqual(r.status_code, 200)136137138 def test_HTTP_200_OK_PATCH(self):139 r = requests.patch(httpbin('patch'))140 self.assertEqual(r.status_code, 200)141142

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 143why, one step back
143 def test_BASICAUTH_HTTP_200_OK_GET(self):

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 144why, one step back
144

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 146why, one step back
146

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa

line 149why, one step back
149

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa

line 152why, one step back
152

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 154–158why, one step back
154 self.assertEqual(r.status_code, 401)
155156157 s = requests.session(auth=auth)158 r = s.get(url)

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 159–161why, one step back
159 self.assertEqual(r.status_code, 200)
160161

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 162–179why, one step back
162 def test_DIGESTAUTH_HTTP_200_OK_GET(self):
163164 for service in SERVICES:165166 auth = ('digest', 'user', 'pass')167 url = service('digest-auth', 'auth', 'user', 'pass')168169 r = requests.get(url, auth=auth)170 self.assertEqual(r.status_code, 200)171172 r = requests.get(url)173 self.assertEqual(r.status_code, 401)174175176 s = requests.session(auth=auth)177 r = s.get(url)178 self.assertEqual(r.status_code, 200)179

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 181why, one step back
181

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 183why, one step back
183

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 186why, one step back
186

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 189why, one step back
189

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 192why, one step back
192

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 193–196why, one step back
193 post3 = requests.post(url, data='[{"some": "json"}]')
194 self.assertEqual(post3.status_code, 200)195196

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

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 for service in SERVICES:

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 200why, one step back
200

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 201–204why, one step back
201 url = service('post')
202 post = requests.post(url,203 files={'some': open('test_requests.py')},204 data={'some': 'data'})

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 205why, one step back
205

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 206–208why, one step back
206 self.assertEqual(post.status_code, 200)
207208

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

lines 209–210why, one step back
209 def test_POSTBIN_GET_POST_FILES_WITH_HEADERS(self):
210

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 212why, one step back
212

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 214why, one step back
214

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 218why, one step back
218

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 220why, one step back
220

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 221why, one step back
221

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 223why, one step back
223

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 225why, one step back
225

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 228why, one step back
228

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 230–232why, one step back
230 self.assertEqual(bool(r), True)
231232

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 234why, one step back
234

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 236why, one step back
236

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

PASS ALL TEH TESTSKenneth Reitzbefore adoption428fc9c

line 238why, one step back
238 print r.status_code

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 239–241why, one step back
239 self.assertEqual(r.ok, False)
240241

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption5b54b3e

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 245why, one step back
245

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

lines 247–248why, one step back
247 self.assertFalse(r.error)
248 r.raise_for_status()

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 249–250why, one step back
249
250

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 252why, one step back
252

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 256why, one step back
256

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 258why, one step back
258

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 260why, one step back
260

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 262why, one step back
262

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 268why, one step back
268

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 269why, one step back
269

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 271why, one step back
271

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 273why, one step back
273

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 277why, one step back
277

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 282why, one step back
282

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 283–294why, one step back
283 r = requests.post(service('post'), data=dict(test='fooaowpeuf'))
284285 self.assertEquals(r.status_code, 200)286 self.assertEquals(r.headers['content-type'], 'application/json')287 self.assertEquals(r.url, service('post'))288289 rbody = json.loads(r.content)290291 self.assertEquals(rbody.get('form'), dict(test='fooaowpeuf'))292 self.assertEquals(rbody.get('data'), '')293294

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 296why, one step back
296

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 298why, one step back
298

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 299–311why, one step back
299 r = requests.post(service('post'), data='fooaowpeuf')
300301 self.assertEquals(r.status_code, 200)302 self.assertEquals(r.headers['content-type'], 'application/json')303 self.assertEquals(r.url, service('post'))304305 rbody = json.loads(r.content)306 # Body wasn't valid url encoded data, so the server returns None as307 # "form" and the raw body as "data".308 self.assertEquals(rbody.get('form'), None)309 self.assertEquals(rbody.get('data'), 'fooaowpeuf')310311

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 312–313why, one step back
312 def test_urlencoded_post_querystring(self):
313

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 315why, one step back
315

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 316–326why, one step back
316 r = requests.post(service('post'), params=dict(test='fooaowpeuf'))
317318 self.assertEquals(r.status_code, 200)319 self.assertEquals(r.headers['content-type'], 'application/json')320 self.assertEquals(r.url, service('post?test=fooaowpeuf'))321322 rbody = json.loads(r.content)323 self.assertEquals(rbody.get('form'), {}) # No form supplied324 self.assertEquals(rbody.get('data'), '')325326

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 327–328why, one step back
327 def test_nonurlencoded_post_querystring(self):
328

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 330why, one step back
330

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 331–341why, one step back
331 r = requests.post(service('post'), params='fooaowpeuf')
332333 self.assertEquals(r.status_code, 200)334 self.assertEquals(r.headers['content-type'], 'application/json')335 self.assertEquals(r.url, service('post?fooaowpeuf'))336337 rbody = json.loads(r.content)338 self.assertEquals(rbody.get('form'), {}) # No form supplied339 self.assertEquals(rbody.get('data'), '')340341

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 345why, one step back
345

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 346–359why, one step back
346 r = requests.post(
347 service('post'),348 params=dict(test='fooaowpeuf'),349 data=dict(test2="foobar"))350351 self.assertEquals(r.status_code, 200)352 self.assertEquals(r.headers['content-type'], 'application/json')353 self.assertEquals(r.url, service('post?test=fooaowpeuf'))354355 rbody = json.loads(r.content)356 self.assertEquals(rbody.get('form'), dict(test2='foobar'))357 self.assertEquals(rbody.get('data'), '')358359

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 361why, one step back
361

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 362–376why, one step back
362 for service in SERVICES:
363364 r = requests.post(service('post'),365 params='fooaowpeuf', data="foobar")366367 self.assertEquals(r.status_code, 200)368 self.assertEquals(r.headers['content-type'], 'application/json')369 self.assertEquals(r.url, service('post?fooaowpeuf'))370371 rbody = json.loads(r.content)372373 self.assertEquals(rbody.get('form'), None)374 self.assertEquals(rbody.get('data'), 'foobar')375376

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

line 380why, one step back
380

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 381why, one step back
381

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 382–383why, one step back
382 def test_urlencoded_get_query_multivalued_param(self):
383

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 384–390why, one step back
384 for service in SERVICES:
385386 r = requests.get(service('get'), params=dict(test=['foo','baz']))387 self.assertEquals(r.status_code, 200)388 self.assertEquals(r.url, service('get?test=foo&test=baz'))389390

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 391–392why, one step back
391 def test_urlencoded_post_querystring_multivalued(self):
392

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 393–404why, one step back
393 for service in SERVICES:
394395 r = requests.post(service('post'), params=dict(test=['foo','baz']))396 self.assertEquals(r.status_code, 200)397 self.assertEquals(r.headers['content-type'], 'application/json')398 self.assertEquals(r.url, service('post?test=foo&test=baz'))399400 rbody = json.loads(r.content)401 self.assertEquals(rbody.get('form'), {}) # No form supplied402 self.assertEquals(rbody.get('data'), '')403404

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 405–406why, one step back
405 def test_urlencoded_post_query_multivalued_and_data(self):
406

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

line 408why, one step back
408

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 409–421why, one step back
409 r = requests.post(
410 service('post'),411 params=dict(test=['foo','baz']),412 data=dict(test2="foobar",test3=['foo','baz']))413414 self.assertEquals(r.status_code, 200)415 self.assertEquals(r.headers['content-type'], 'application/json')416 self.assertEquals(r.url, service('post?test=foo&test=baz'))417 rbody = json.loads(r.content)418 self.assertEquals(rbody.get('form'), dict(test2='foobar',test3='foo'))419 self.assertEquals(rbody.get('data'), '')420421

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

lines 422–439why, one step back
422 def test_GET_no_redirect(self):
423424 for service in SERVICES:425426 r = requests.get(service('redirect', '3'), allow_redirects=False)427 self.assertEquals(r.status_code, 302)428 self.assertEquals(len(r.history), 0)429430431 def test_HEAD_no_redirect(self):432433 for service in SERVICES:434435 r = requests.head(service('redirect', '3'), allow_redirects=False)436 self.assertEquals(r.status_code, 302)437 self.assertEquals(len(r.history), 0)438439

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 440–441why, one step back
440 def test_redirect_history(self):
441

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 442–459why, one step back
442 for service in SERVICES:
443444 r = requests.get(service('redirect', '3'))445 self.assertEquals(r.status_code, 200)446 self.assertEquals(len(r.history), 3)447448449 def test_relative_redirect_history(self):450451 for service in SERVICES:452453 r = requests.get(service('relative-redirect', '3'))454 self.assertEquals(r.status_code, 200)455 self.assertEquals(len(r.history), 3)456457458 def test_session_HTTP_200_OK_GET(self):459

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 462–468why, one step back
462 self.assertEqual(r.status_code, 200)
463464465 def test_session_persistent_headers(self):466467 heads = {'User-agent': 'Mozilla/5.0'}468

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

line 471why, one step back
471

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 472–475why, one step back
472 # Make 2 requests from Session object, should send header both times
473 r1 = s.get(httpbin('user-agent'))474 assert heads['User-agent'] in r1.content475

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 478–482why, one step back
478
479 new_heads = {'User-agent': 'blah'}480 r3 = s.get(httpbin('user-agent'), headers=new_heads)481 assert new_heads['User-agent'] in r3.content482

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 483–484why, one step back
483 self.assertEqual(r2.status_code, 200)
484

Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0

lines 485–511why, one step back
485
486 def test_session_persistent_params(self):487488 params = {'a': 'a_test'}489490 s = requests.session()491 s.params = params492493 # Make 2 requests from Session object, should send header both times494 r1 = s.get(httpbin('get'))495 assert params['a'] in r1.content496497498 params2 = {'b': 'b_test'}499500 r2 = s.get(httpbin('get'), params=params2)501 assert params['a'] in r2.content502 assert params2['b'] in r2.content503504505 params3 = {'b': 'b_test', 'a': None, 'c': 'c_test'}506507 r3 = s.get(httpbin('get'), params=params3)508509 assert not params['a'] in r3.content510 assert params3['b'] in r3.content511 assert params3['c'] in r3.content

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 512why, one step back
512

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

line 513why, one step back
513

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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