Skip to content
Myr

test_requests.py

This file

Path

test_requests.py

500 lines · 13.7 KiB · Python

Last changed by

test session persistent paramsKenneth Reitzbefore adoption7dc75ce

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

use gunicorn to serve testsKenneth Reitzbefore adoption1299708

line 6why, one step back
6import time

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 7why, one step back
7import cookielib

Test suite cleanupKenneth Reitzbefore adoption7a0f363

line 8why, one step back
8import os

use gunicorn to serve testsKenneth Reitzbefore adoption1299708

line 9why, one step back
9import unittest

temp "tests"Kenneth Reitzbefore adoption49f915f

line 10why, one step back
10

use gunicorn to serve testsKenneth Reitzbefore adoption1299708

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

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 13–16why, one step back
13try:
14 import omnijson as json15except ImportError:16 import json

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 17why, one step back
17

temp "tests"Kenneth Reitzbefore adoption49f915f

lines 18–19why, one step back
18import requests
19

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

temp "tests"Kenneth Reitzbefore adoption49f915f

line 21why, one step back
21

Test suite cleanupKenneth Reitzbefore adoption7a0f363

line 22why, one step back
22PORT = os.environ.get('HTTPBIN_PORT', '7045')

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 23why, one step back
23

Test suite cleanupKenneth Reitzbefore adoption7a0f363

line 24why, one step back
24HTTPBIN_URL = 'http://0.0.0.0:%s/' % (PORT)

use gunicorn to serve testsKenneth Reitzbefore adoption1299708

line 25why, one step back
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 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 35why, one step back
35

Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5

line 36why, one step back
36_httpbin = False

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 37why, one step back
37

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 40why, one step back
40

Make tests go to 11!Kenneth Reitzbefore adoption76b8afe

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 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

temp "tests"Kenneth Reitzbefore adoption49f915f

line 45why, one step back
45

Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5

line 46why, one step back
46 global _httpbin

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 47why, one step back
47

Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5

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

Test suite cleanupKenneth Reitzbefore adoption7a0f363

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

Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5

line 51why, one step back
51

use gunicorn to serve testsKenneth Reitzbefore adoption1299708

line 52why, one step back
52 _httpbin = True

Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5

lines 53–56why, one step back
53 time.sleep(1)
545556

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 60why, one step back
60

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 61why, one step back
61

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

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_HTTP_200_OK_GET(self):

Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5

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

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

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 73why, one step back
73

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

lines 74–77why, one step back
74 def test_HTTP_302_GET(self):
75 r = requests.get(httpbin('redirect', '1'), allow_redirects=False)76 self.assertEqual(r.status_code, 302)77

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 78why, one step back
78

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 81why, one step back
81

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 87why, one step back
87

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 93why, one step back
93

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 94why, one step back
94

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 97why, one step back
97

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 102why, one step back
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 'develop'Kenneth Reitzbefore adoptioncc16073

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 105why, one step back
105

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 114why, one step back
114

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 118why, one step back
118

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 119–129why, one step back
119
120 def test_HTTP_200_OK_PUT(self):121 r = requests.put(httpbin('put'))122 self.assertEqual(r.status_code, 200)123124125 def test_HTTP_200_OK_PATCH(self):126 r = requests.patch(httpbin('patch'))127 self.assertEqual(r.status_code, 200)128129

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 131why, one step back
131

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 133why, one step back
133

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa

line 136why, one step back
136

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 137–139why, one step back
137 r = requests.get(url, auth=auth)
138 # print r.__dict__139 self.assertEqual(r.status_code, 200)

Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa

line 140why, one step back
140

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 141why, one step back
141

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 142–145why, one step back
142 r = requests.get(url)
143 self.assertEqual(r.status_code, 200)144145

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 147why, one step back
147

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 149why, one step back
149

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4

line 152why, one step back
152

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 155why, one step back
155

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 158why, one step back
158

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 159–162why, one step back
159 post3 = requests.post(url, data='[{"some": "json"}]')
160 self.assertEqual(post3.status_code, 200)161162

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 164why, one step back
164

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 166why, one step back
166

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 167–170why, one step back
167 url = service('post')
168 post = requests.post(url,169 files={'some': open('test_requests.py')},170 data={'some': 'data'})

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 171why, one step back
171

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 172–174why, one step back
172 self.assertEqual(post.status_code, 200)
173174

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

lines 175–176why, one step back
175 def test_POSTBIN_GET_POST_FILES_WITH_HEADERS(self):
176

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

line 178why, one step back
178

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 180why, one step back
180

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 184why, one step back
184

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 186why, one step back
186

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 187why, one step back
187

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 189why, one step back
189

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 191why, one step back
191

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 194why, one step back
194

Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 196–198why, one step back
196 self.assertEqual(bool(r), True)
197198

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 200why, one step back
200

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 202why, one step back
202

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 203–206why, one step back
203 r = requests.get(service('status', '404'))
204 self.assertEqual(r.ok, False)205206

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 210why, one step back
210

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

lines 212–213why, one step back
212 self.assertFalse(r.error)
213 r.raise_for_status()

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

line 214why, one step back
214

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 215why, one step back
215

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 217why, one step back
217

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

lines 218–220why, one step back
218 jar = cookielib.CookieJar()
219 self.assertFalse(jar)220

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073

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

Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e

line 224why, one step back
224

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 225–235why, one step back
225 cookie_found = False
226 for cookie in jar:227 if cookie.name == 'requests_cookie':228 self.assertEquals(cookie.value, 'awesome')229 cookie_found = True230 self.assertTrue(cookie_found)231232 r = requests.get(httpbin('cookies'), cookies=jar)233 self.assertTrue('awesome' in r.content)234235

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

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

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

line 237why, one step back
237

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667

lines 239–240why, one step back
239 r.content.decode('ascii')
240

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 241why, one step back
241

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 243why, one step back
243

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 245why, one step back
245

Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 247why, one step back
247

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 248–252why, one step back
248 requests.get(url, params={'foo': u'føø'})
249 requests.get(url, params={u'føø': u'føø'})250 requests.get(url, params={'føø': 'føø'})251 requests.get(url, params={'foo': u'foo'})252 requests.get(service('ø'), params={'foo': u'foo'})

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 253why, one step back
253

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 254why, one step back
254

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 256why, one step back
256

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17

line 258why, one step back
258

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 262why, one step back
262

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 263–265why, one step back
263
264 def test_urlencoded_post_data(self):265

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 267why, one step back
267

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 268–279why, one step back
268 r = requests.post(service('post'), data=dict(test='fooaowpeuf'))
269270 self.assertEquals(r.status_code, 200)271 self.assertEquals(r.headers['content-type'], 'application/json')272 self.assertEquals(r.url, service('post'))273274 rbody = json.loads(r.content)275276 self.assertEquals(rbody.get('form'), dict(test='fooaowpeuf'))277 self.assertEquals(rbody.get('data'), '')278279

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 281why, one step back
281

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 283why, one step back
283

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 284–296why, one step back
284 r = requests.post(service('post'), data='fooaowpeuf')
285286 self.assertEquals(r.status_code, 200)287 self.assertEquals(r.headers['content-type'], 'application/json')288 self.assertEquals(r.url, service('post'))289290 rbody = json.loads(r.content)291 # Body wasn't valid url encoded data, so the server returns None as292 # "form" and the raw body as "data".293 self.assertEquals(rbody.get('form'), None)294 self.assertEquals(rbody.get('data'), 'fooaowpeuf')295296

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 297–298why, one step back
297 def test_urlencoded_post_querystring(self):
298

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

line 300why, one step back
300

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 301–311why, one step back
301 r = requests.post(service('post'), params=dict(test='fooaowpeuf'))
302303 self.assertEquals(r.status_code, 200)304 self.assertEquals(r.headers['content-type'], 'application/json')305 self.assertEquals(r.url, service('post?test=fooaowpeuf'))306307 rbody = json.loads(r.content)308 self.assertEquals(rbody.get('form'), {}) # No form supplied309 self.assertEquals(rbody.get('data'), '')310311

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

lines 312–313why, one step back
312 def test_nonurlencoded_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='fooaowpeuf')
317318 self.assertEquals(r.status_code, 200)319 self.assertEquals(r.headers['content-type'], 'application/json')320 self.assertEquals(r.url, service('post?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_urlencoded_post_query_and_data(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–344why, one step back
331 r = requests.post(
332 service('post'),333 params=dict(test='fooaowpeuf'),334 data=dict(test2="foobar"))335336 self.assertEquals(r.status_code, 200)337 self.assertEquals(r.headers['content-type'], 'application/json')338 self.assertEquals(r.url, service('post?test=fooaowpeuf'))339340 rbody = json.loads(r.content)341 self.assertEquals(rbody.get('form'), dict(test2='foobar'))342 self.assertEquals(rbody.get('data'), '')343344

Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7

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

Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea

line 346why, one step back
346

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 347–361why, one step back
347 for service in SERVICES:
348349 r = requests.post(service('post'),350 params='fooaowpeuf', data="foobar")351352 self.assertEquals(r.status_code, 200)353 self.assertEquals(r.headers['content-type'], 'application/json')354 self.assertEquals(r.url, service('post?fooaowpeuf'))355356 rbody = json.loads(r.content)357358 self.assertEquals(rbody.get('form'), None)359 self.assertEquals(rbody.get('data'), 'foobar')360361

remove idna tests, for nowKenneth Reitzbefore adoptiond85c535

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

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

line 365why, one step back
365

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

line 366why, one step back
366

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 367–368why, one step back
367 def test_urlencoded_get_query_multivalued_param(self):
368

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 369–375why, one step back
369 for service in SERVICES:
370371 r = requests.get(service('get'), params=dict(test=['foo','baz']))372 self.assertEquals(r.status_code, 200)373 self.assertEquals(r.url, service('get?test=foo&test=baz'))374375

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 376–377why, one step back
376 def test_urlencoded_post_querystring_multivalued(self):
377

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 378–389why, one step back
378 for service in SERVICES:
379380 r = requests.post(service('post'), params=dict(test=['foo','baz']))381 self.assertEquals(r.status_code, 200)382 self.assertEquals(r.headers['content-type'], 'application/json')383 self.assertEquals(r.url, service('post?test=foo&test=baz'))384385 rbody = json.loads(r.content)386 self.assertEquals(rbody.get('form'), {}) # No form supplied387 self.assertEquals(rbody.get('data'), '')388389

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

lines 390–391why, one step back
390 def test_urlencoded_post_query_multivalued_and_data(self):
391

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

line 393why, one step back
393

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 394–406why, one step back
394 r = requests.post(
395 service('post'),396 params=dict(test=['foo','baz']),397 data=dict(test2="foobar",test3=['foo','baz']))398399 self.assertEquals(r.status_code, 200)400 self.assertEquals(r.headers['content-type'], 'application/json')401 self.assertEquals(r.url, service('post?test=foo&test=baz'))402 rbody = json.loads(r.content)403 self.assertEquals(rbody.get('form'), dict(test2='foobar',test3='foo'))404 self.assertEquals(rbody.get('data'), '')405406

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

lines 407–424why, one step back
407 def test_GET_no_redirect(self):
408409 for service in SERVICES:410411 r = requests.get(service('redirect', '3'), allow_redirects=False)412 self.assertEquals(r.status_code, 302)413 self.assertEquals(len(r.history), 0)414415416 def test_HEAD_no_redirect(self):417418 for service in SERVICES:419420 r = requests.head(service('redirect', '3'), allow_redirects=False)421 self.assertEquals(r.status_code, 302)422 self.assertEquals(len(r.history), 0)423424

Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 427–445why, one step back
427 for service in SERVICES:
428429 r = requests.get(service('redirect', '3'))430 self.assertEquals(r.status_code, 200)431 self.assertEquals(len(r.history), 3)432433434 def test_relative_redirect_history(self):435436 for service in SERVICES:437438 r = requests.get(service('relative-redirect', '3'))439 self.assertEquals(r.status_code, 200)440 self.assertEquals(len(r.history), 3)441442443 def test_session_HTTP_200_OK_GET(self):444445 s = Session()

Merge branch 'feature/httpbin' into developKenneth Reitzbefore adoptionff6dbc5

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 447–455why, one step back
447 self.assertEqual(r.status_code, 200)
448449450 def test_session_persistent_headers(self):451452 heads = {'User-agent': 'Mozilla/5.0'}453454 s = Session()455 s.headers = heads

testing session method attribute mergingKenneth Reitzbefore adoptionec94f50

line 456why, one step back
456

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 457–460why, one step back
457 # Make 2 requests from Session object, should send header both times
458 r1 = s.get(httpbin('user-agent'))459 assert heads['User-agent'] in r1.content460

testing session method attribute mergingKenneth Reitzbefore adoptionec94f50

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

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

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

testing session method attribute mergingKenneth Reitzbefore adoptionec94f50

lines 463–467why, one step back
463
464 new_heads = {'User-agent': 'blah'}465 r3 = s.get(httpbin('user-agent'), headers=new_heads)466 assert new_heads['User-agent'] in r3.content467

Merge branch 'develop'Kenneth Reitzbefore adoption81d5997

lines 468–469why, one step back
468 self.assertEqual(r2.status_code, 200)
469

Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452

line 470why, one step back
470

test session persistent paramsKenneth Reitzbefore adoption7dc75ce

lines 471–498why, one step back
471 def test_session_persistent_params(self):
472473 params = {'a': 'a_test'}474475 s = Session()476 s.params = params477478 # Make 2 requests from Session object, should send header both times479 r1 = s.get(httpbin('get'))480 assert params['a'] in r1.content481482483 params2 = {'b': 'b_test'}484485 r2 = s.get(httpbin('get'), params=params2)486 assert params['a'] in r2.content487 assert params2['b'] in r2.content488489490 params3 = {'b': 'b_test', 'a': None, 'c': 'c_test'}491492 r3 = s.get(httpbin('get'), params=params3)493494 assert not params['a'] in r3.content495 assert params3['b'] in r3.content496 assert params3['c'] in r3.content497498

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

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

Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f

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