test_requests.py
This file
Path
test_requests.py
493 lines · 13.3 KiB · Python
Last changed by
Merge branch 'redirect-no-follow' of https://github.com/millerdev/requestsKenneth Reitzbefore adoption98c719f
History of this fileTake it
sample test fixtures (none)Kenneth Reitzbefore adoption75b499d
lines 1–3why, one step back1#!/usr/bin/env python2# -*- coding: utf-8 -*-3Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 4–5why, one step back4from __future__ import with_statement5sample test fixtures (none)Kenneth Reitzbefore adoption75b499d
line 6why, one step back6import unittestMerge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 7why, one step back7import cookielibtemp "tests"Kenneth Reitzbefore adoption49f915f
line 8why, one step back8Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 9–12why, one step back9try:10 import omnijson as json11except ImportError:12 import jsonMerge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 13why, one step back13temp "tests"Kenneth Reitzbefore adoption49f915f
lines 14–15why, one step back14import requests15Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 16why, one step back16from requests.sessions import Sessiontemp "tests"Kenneth Reitzbefore adoption49f915f
line 17why, one step back17Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 18–37why, one step back1819HTTPBIN_URL = 'http://httpbin.org/'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)3637Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 38why, one step back38SERVICES = (httpbin, httpsbin)Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 39why, one step back39Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 40–41why, one step back4041a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 42why, one step back42class RequestsTestSuite(unittest.TestCase):Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 43why, one step back43 """Requests test cases."""Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 44why, one step back44Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 45why, one step back45Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 46–47why, one step back46 def setUp(self):47 passtemp "tests"Kenneth Reitzbefore adoption49f915f
line 48why, one step back48Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 49why, one step back49Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 50–52why, one step back50 def tearDown(self):51 """Teardown."""52 passMerge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 53why, one step back53Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 54why, one step back54Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 55–56why, one step back55 def test_invalid_url(self):56 self.assertRaises(ValueError, requests.get, 'hiwpefhipowhefopw')a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 57why, one step back57Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 58why, one step back58Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 59why, one step back59 def test_HTTP_200_OK_GET(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 60why, one step back60 r = requests.get(httpbin('/'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 61why, one step back61 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 62why, one step back62Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 63why, one step back63Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 64why, one step back64 def test_HTTPS_200_OK_GET(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 65why, one step back65 r = requests.get(httpsbin('/'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 66why, one step back66 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 67why, one step back67Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 68why, one step back68Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 69–70why, one step back69 def test_HTTP_200_OK_GET_WITH_PARAMS(self):70 heads = {'User-agent': 'Mozilla/5.0'}Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 71why, one step back71Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 72–74why, one step back72 r = requests.get(httpbin('user-agent'), headers=heads)7374 assert heads['User-agent'] in r.contentMerge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 75–76why, one step back75 self.assertEqual(r.status_code, 200)76Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 77why, one step back77Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 78–80why, one step back78 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self):79 heads = {'User-agent': 'Mozilla/5.0'}80Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 81why, one step back81 r = requests.get(httpbin('get') + '?test=true', params={'q': 'test'}, headers=heads)Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 82why, one step back82 self.assertEqual(r.status_code, 200)Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 83why, one step back83Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 84why, one step back84Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 85–86why, one step back85 def test_user_agent_transfers(self):86 """Issue XX"""Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 87why, one step back87Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 88–91why, one step back88 heads = {89 'User-agent':90 'Mozilla/5.0 (github.com/kennethreitz/requests)'91 }Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 92why, one step back92Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 93why, one step back93 r = requests.get(httpbin('user-agent'), headers=heads);Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 94why, one step back94 self.assertTrue(heads['User-agent'] in r.content)Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 95why, one step back95Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 96–100why, one step back96 heads = {97 'user-agent':98 'Mozilla/5.0 (github.com/kennethreitz/requests)'99 }100Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 101why, one step back101 r = requests.get(httpbin('user-agent'), headers=heads);Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 102–103why, one step back102 self.assertTrue(heads['user-agent'] in r.content)103Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 104why, one step back104Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 105why, one step back105 def test_HTTP_200_OK_HEAD(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 106why, one step back106 r = requests.head(httpbin('/'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 107why, one step back107 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 108why, one step back108Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 109why, one step back109Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 110why, one step back110 def test_HTTPS_200_OK_HEAD(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 111why, one step back111 r = requests.head(httpsbin('/'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 112why, one step back112 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 113why, one step back113Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 114–134why, one step back114115 def test_HTTP_200_OK_PUT(self):116 r = requests.put(httpbin('put'))117 self.assertEqual(r.status_code, 200)118119120 def test_HTTPS_200_OK_PUT(self):121 r = requests.put(httpsbin('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)128129130 def test_HTTPS_200_OK_PATCH(self):131 r = requests.patch(httpsbin('patch'))132 self.assertEqual(r.status_code, 200)133134Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 135why, one step back135 def test_AUTH_HTTP_200_OK_GET(self):a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 136why, one step back136Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 137why, one step back137 for service in SERVICES:Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 138why, one step back138Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 139–140why, one step back139 auth = ('user', 'pass')140 url = service('basic-auth', 'user', 'pass')Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa
line 141why, one step back141Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 142–144why, one step back142 r = requests.get(url, auth=auth)143 # print r.__dict__144 self.assertEqual(r.status_code, 200)Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa
line 145why, one step back145Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 146why, one step back146Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 147–150why, one step back147 r = requests.get(url)148 self.assertEqual(r.status_code, 200)149150Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 151why, one step back151 def test_POSTBIN_GET_POST_FILES(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 152why, one step back152Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 153why, one step back153 for service in SERVICES:Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 154why, one step back154Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 155–156why, one step back155 url = service('post')156 post = requests.post(url).raise_for_status()Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 157why, one step back157Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 158–159why, one step back158 post = requests.post(url, data={'some': 'data'})159 self.assertEqual(post.status_code, 200)Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 160why, one step back160Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 161–162why, one step back161 post2 = requests.post(url, files={'some': open('test_requests.py')})162 self.assertEqual(post2.status_code, 200)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 163why, one step back163Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 164–167why, one step back164 post3 = requests.post(url, data='[{"some": "json"}]')165 self.assertEqual(post3.status_code, 200)166167Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 168why, one step back168 def test_POSTBIN_GET_POST_FILES_WITH_PARAMS(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 169why, one step back169Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 170why, one step back170 for service in SERVICES:Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 171why, one step back171Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 172–175why, one step back172 url = service('post')173 post = requests.post(url,174 files={'some': open('test_requests.py')},175 data={'some': 'data'})Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 176why, one step back176Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 177–179why, one step back177 self.assertEqual(post.status_code, 200)178179Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 180–181why, one step back180 def test_POSTBIN_GET_POST_FILES_WITH_HEADERS(self):181Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 182why, one step back182 for service in SERVICES:Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 183why, one step back183Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 184why, one step back184 url = service('post')Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 185why, one step back185Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 186–188why, one step back186 post2 = requests.post(url,187 files={'some': open('test_requests.py')},188 headers = {'User-Agent': 'requests-tests'})Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 189why, one step back189Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 190why, one step back190 self.assertEqual(post2.status_code, 200)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 191why, one step back191Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 192why, one step back192Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 193why, one step back193 def test_nonzero_evaluation(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 194why, one step back194Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 195why, one step back195 for service in SERVICES:Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 196why, one step back196Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 197–198why, one step back197 r = requests.get(service('status', '500'))198 self.assertEqual(bool(r), False)Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 199why, one step back199Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 200–203why, one step back200 r = requests.get(service('/'))201 self.assertEqual(bool(r), True)202203Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 204why, one step back204 def test_request_ok_set(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 205why, one step back205Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 206why, one step back206 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 207why, one step back207Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 208–211why, one step back208 r = requests.get(service('status', '404'))209 self.assertEqual(r.ok, False)210211Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 212why, one step back212 def test_status_raising(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 213why, one step back213 r = requests.get(httpbin('status', '404'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 214why, one step back214 self.assertRaises(requests.HTTPError, r.raise_for_status)Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 215why, one step back215Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 216why, one step back216 r = requests.get(httpbin('status', '200'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 217–218why, one step back217 self.assertFalse(r.error)218 r.raise_for_status()Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 219why, one step back219Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 220why, one step back220Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 221why, one step back221 def test_cookie_jar(self):Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 222why, one step back222Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 223–225why, one step back223 jar = cookielib.CookieJar()224 self.assertFalse(jar)225Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 226–227why, one step back226 url = httpbin('cookies', 'set', 'requests_cookie', 'awesome')227 r = requests.get(url, cookies=jar)Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 228why, one step back228 self.assertTrue(jar)Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 229why, one step back229Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 230–240why, one step back230 cookie_found = False231 for cookie in jar:232 if cookie.name == 'requests_cookie':233 self.assertEquals(cookie.value, 'awesome')234 cookie_found = True235 self.assertTrue(cookie_found)236237 r = requests.get(httpbin('cookies'), cookies=jar)238 self.assertTrue('awesome' in r.content)239240Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 241why, one step back241 def test_decompress_gzip(self):a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 242why, one step back242Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 243why, one step back243 r = requests.get(httpbin('gzip'))Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
lines 244–245why, one step back244 r.content.decode('ascii')245Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 246why, one step back246Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 247why, one step back247 def test_unicode_get(self):Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 248why, one step back248Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 249why, one step back249 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 250why, one step back250Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 251why, one step back251 url = service('/')Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 252why, one step back252Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 253–257why, one step back253 requests.get(url, params={'foo': u'føø'})254 requests.get(url, params={u'føø': u'føø'})255 requests.get(url, params={'føø': 'føø'})256 requests.get(url, params={'foo': u'foo'})257 requests.get(service('ø'), params={'foo': u'foo'})Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 258why, one step back258Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 259why, one step back259Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 260why, one step back260 def test_httpauth_recursion(self):Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 261why, one step back261Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 262why, one step back262 http_auth = ('user', 'BADpass')Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 263why, one step back263Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 264–266why, one step back264 for service in SERVICES:265 r = requests.get(service('basic-auth', 'user', 'pass'), auth=http_auth)266 self.assertEquals(r.status_code, 401)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 267why, one step back267Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 268why, one step back268Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 269–270why, one step back269 def test_settings(self):270Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 271–273why, one step back271 def test():272 r = requests.get(httpbin(''))273 r.raise_for_status()Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 274why, one step back274Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 275–283why, one step back275 with requests.settings(timeout=0.0000001):276 self.assertRaises(requests.Timeout, test)277278 with requests.settings(timeout=100):279 requests.get(httpbin(''))280281282 def test_urlencoded_post_data(self):283Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 284why, one step back284 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 285why, one step back285Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 286–297why, one step back286 r = requests.post(service('post'), data=dict(test='fooaowpeuf'))287288 self.assertEquals(r.status_code, 200)289 self.assertEquals(r.headers['content-type'], 'application/json')290 self.assertEquals(r.url, service('post'))291292 rbody = json.loads(r.content)293294 self.assertEquals(rbody.get('form'), dict(test='fooaowpeuf'))295 self.assertEquals(rbody.get('data'), '')296297Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 298why, one step back298 def test_nonurlencoded_post_data(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 299why, one step back299Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 300why, one step back300 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 301why, one step back301Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 302–314why, one step back302 r = requests.post(service('post'), data='fooaowpeuf')303304 self.assertEquals(r.status_code, 200)305 self.assertEquals(r.headers['content-type'], 'application/json')306 self.assertEquals(r.url, service('post'))307308 rbody = json.loads(r.content)309 # Body wasn't valid url encoded data, so the server returns None as310 # "form" and the raw body as "data".311 self.assertEquals(rbody.get('form'), None)312 self.assertEquals(rbody.get('data'), 'fooaowpeuf')313314Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 315–316why, one step back315 def test_urlencoded_post_querystring(self):316Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 317why, one step back317 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 318why, one step back318Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 319–329why, one step back319 r = requests.post(service('post'), params=dict(test='fooaowpeuf'))320321 self.assertEquals(r.status_code, 200)322 self.assertEquals(r.headers['content-type'], 'application/json')323 self.assertEquals(r.url, service('post?test=fooaowpeuf'))324325 rbody = json.loads(r.content)326 self.assertEquals(rbody.get('form'), {}) # No form supplied327 self.assertEquals(rbody.get('data'), '')328329Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 330–331why, one step back330 def test_nonurlencoded_post_querystring(self):331Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 332why, one step back332 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 333why, one step back333Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 334–344why, one step back334 r = requests.post(service('post'), params='fooaowpeuf')335336 self.assertEquals(r.status_code, 200)337 self.assertEquals(r.headers['content-type'], 'application/json')338 self.assertEquals(r.url, service('post?fooaowpeuf'))339340 rbody = json.loads(r.content)341 self.assertEquals(rbody.get('form'), {}) # No form supplied342 self.assertEquals(rbody.get('data'), '')343344Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 345–346why, one step back345 def test_urlencoded_post_query_and_data(self):346Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 347why, one step back347 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 348why, one step back348Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 349–362why, one step back349 r = requests.post(350 service('post'),351 params=dict(test='fooaowpeuf'),352 data=dict(test2="foobar"))353354 self.assertEquals(r.status_code, 200)355 self.assertEquals(r.headers['content-type'], 'application/json')356 self.assertEquals(r.url, service('post?test=fooaowpeuf'))357358 rbody = json.loads(r.content)359 self.assertEquals(rbody.get('form'), dict(test2='foobar'))360 self.assertEquals(rbody.get('data'), '')361362Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 363why, one step back363 def test_nonurlencoded_post_query_and_data(self):Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 364why, one step back364Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 365–379why, one step back365 for service in SERVICES:366367 r = requests.post(service('post'),368 params='fooaowpeuf', data="foobar")369370 self.assertEquals(r.status_code, 200)371 self.assertEquals(r.headers['content-type'], 'application/json')372 self.assertEquals(r.url, service('post?fooaowpeuf'))373374 rbody = json.loads(r.content)375376 self.assertEquals(rbody.get('form'), None)377 self.assertEquals(rbody.get('data'), 'foobar')378379Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 380–382why, one step back380 def test_idna(self):381 r = requests.get(u'http://➡.ws/httpbin')382 assert 'httpbin' in r.urlMerge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 383why, one step back383Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 384why, one step back384Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 385–386why, one step back385 def test_urlencoded_get_query_multivalued_param(self):386Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 387–393why, one step back387 for service in SERVICES:388389 r = requests.get(service('get'), params=dict(test=['foo','baz']))390 self.assertEquals(r.status_code, 200)391 self.assertEquals(r.url, service('get?test=foo&test=baz'))392393Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 394–395why, one step back394 def test_urlencoded_post_querystring_multivalued(self):395Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 396–407why, one step back396 for service in SERVICES:397398 r = requests.post(service('post'), params=dict(test=['foo','baz']))399 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'))402403 rbody = json.loads(r.content)404 self.assertEquals(rbody.get('form'), {}) # No form supplied405 self.assertEquals(rbody.get('data'), '')406407Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 408–409why, one step back408 def test_urlencoded_post_query_multivalued_and_data(self):409Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 410why, one step back410 for service in SERVICES:Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
line 411why, one step back411Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 412–424why, one step back412 r = requests.post(413 service('post'),414 params=dict(test=['foo','baz']),415 data=dict(test2="foobar",test3=['foo','baz']))416417 self.assertEquals(r.status_code, 200)418 self.assertEquals(r.headers['content-type'], 'application/json')419 self.assertEquals(r.url, service('post?test=foo&test=baz'))420 rbody = json.loads(r.content)421 self.assertEquals(rbody.get('form'), dict(test2='foobar',test3='foo'))422 self.assertEquals(rbody.get('data'), '')423424Merge branch 'redirect-no-follow' of https://github.com/millerdev/requestsKenneth Reitzbefore adoption98c719f
lines 425–442why, one step back425 def test_GET_no_redirect(self):426427 for service in SERVICES:428429 r = requests.get(service('redirect', '3'), allow_redirects=False)430 self.assertEquals(r.status_code, 302)431 self.assertEquals(len(r.history), 0)432433434 def test_HEAD_no_redirect(self):435436 for service in SERVICES:437438 r = requests.head(service('redirect', '3'), allow_redirects=False)439 self.assertEquals(r.status_code, 302)440 self.assertEquals(len(r.history), 0)441442Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 443–444why, one step back443 def test_redirect_history(self):444Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 445–490why, one step back445 for service in SERVICES:446447 r = requests.get(service('redirect', '3'))448 self.assertEquals(r.status_code, 200)449 self.assertEquals(len(r.history), 3)450451452 def test_relative_redirect_history(self):453454 for service in SERVICES:455456 r = requests.get(service('relative-redirect', '3'))457 self.assertEquals(r.status_code, 200)458 self.assertEquals(len(r.history), 3)459460461 def test_session_HTTP_200_OK_GET(self):462463 s = Session()464 r = s.get(httpbin('/'))465 self.assertEqual(r.status_code, 200)466467468 def test_session_HTTPS_200_OK_GET(self):469470 s = Session()471 r = s.get(httpsbin('/'))472 self.assertEqual(r.status_code, 200)473474475 def test_session_persistent_headers(self):476477 heads = {'User-agent': 'Mozilla/5.0'}478479 s = Session()480 s.headers = heads481 # Make 2 requests from Session object, should send header both times482 r1 = s.get(httpbin('user-agent'))483484 assert heads['User-agent'] in r1.content485 r2 = s.get(httpbin('user-agent'))486487 assert heads['User-agent'] in r2.content488 self.assertEqual(r2.status_code, 200)489490Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 491why, one step back491a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 492why, one step back492if __name__ == '__main__':Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 493why, one step back493 unittest.main()