test_requests.py
This file
Path
test_requests.py
587 lines · 16.0 KiB · Python
Last changed by
Added test for Request.sent.Kenneth Reitzbefore adoption6bb4c4e
History of this fileTake it
The walk stopped after 200 commits: lines older than 2c168d2 point at it.
no dependencies!Kenneth Reitzbefore adoption2c168d2
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_statement5Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 6–8why, one step back6import time7import os8import unittestno dependencies!Kenneth Reitzbefore adoption2c168d2
line 9why, one step back9Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 10–11why, one step back10import requests11import envoystuff and things and stuffKenneth Reitzbefore adoptionb8c55da
line 12why, one step back12from requests import HTTPErrorMerge branch 'auth_callables' of https://github.com/idangazit/requests into developKenneth Reitzbefore adoptiona7a619b
line 13why, one step back13from requests.auth import HTTPBasicAuth, HTTPDigestAuthMerge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 14why, one step back14Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 15–18why, one step back15try:16 import omnijson as json17except ImportError:18 import jsonMerge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 19why, one step back19no dependencies!Kenneth Reitzbefore adoption2c168d2
line 20why, one step back20Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 21–22why, one step back21# TODO: Detect an open port.22PORT = os.environ.get('HTTPBIN_PORT', '7077')no dependencies!Kenneth Reitzbefore adoption2c168d2
line 23why, one step back23Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 24–25why, one step back24HTTPBIN_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 back262728def httpbin(*suffix):29 """Returns url for HTTPBIN resource."""3031 return HTTPBIN_URL + '/'.join(suffix)3233Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 34why, one step back34SERVICES = (httpbin, )Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 35why, one step back35Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 36why, one step back36_httpbin = FalseMerge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 37why, one step back37Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 38–39why, one step back38class RequestsTestSuite(unittest.TestCase):39 """Requests test cases."""Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 40why, one step back40Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 41–42why, one step back41 # It goes to eleven.42 _multiprocess_can_split_ = TrueMerge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 43why, one step back43Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 44why, one step back44 def setUp(self):Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 45why, one step back45Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 46why, one step back46 global _httpbinMerge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 47why, one step back47Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 48why, one step back48 if not _httpbin:Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 49why, one step back49Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 50why, one step back50 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 back51Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 52–53why, one step back52 self.httpbin = c53 _httpbin = TrueAdded test for Request.sent.Kenneth Reitzbefore adoption6bb4c4e
line 54why, one step back54 time.sleep(.01)no dependencies!Kenneth Reitzbefore adoption2c168d2
line 55why, one step back55Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 56why, one step back56Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 57why, one step back57Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 58–59why, one step back58 def tearDown(self):59 """Teardown."""Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 60why, one step back60 # self.httpbin.kill()keep_alive is now disable-able!Kenneth Reitzbefore adoption0c4b973
line 61why, one step back61 passMerge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 62why, one step back62keep_alive is now disable-able!Kenneth Reitzbefore adoption0c4b973
line 63why, one step back63Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 64why, one step back64 def test_entry_points(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 65why, one step back65Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 66–76why, one step back66 requests.session67 requests.session().get68 requests.session().head69 requests.get70 requests.head71 requests.put72 requests.patch73 requests.post747576Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 77–78why, one step back77 def test_invalid_url(self):78 self.assertRaises(ValueError, requests.get, 'hiwpefhipowhefopw')a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 79why, one step back79Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 80why, one step back80 def test_HTTP_200_OK_GET(self):Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 81why, one step back81 r = requests.get(httpbin('/get'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 82why, one step back82 self.assertEqual(r.status_code, 200)Added test for Request.sent.Kenneth Reitzbefore adoption6bb4c4e
lines 83–87why, one step back8384 def test_response_sent(self):85 r = requests.get(httpbin('/get'))8687 self.assertTrue(r.request.sent)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 88why, one step back88Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 89–90why, one step back89 def test_HTTP_302_ALLOW_REDIRECT_GET(self):90 r = requests.get(httpbin('redirect', '1'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 91why, one step back91 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 92why, one step back92Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 93–95why, one step back93 def test_HTTP_302_GET(self):94 r = requests.get(httpbin('redirect', '1'), allow_redirects=False)95 self.assertEqual(r.status_code, 302)Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 96why, one step back96Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 97why, one step back97Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 98–99why, one step back98 def test_HTTP_200_OK_GET_WITH_PARAMS(self):99 heads = {'User-agent': 'Mozilla/5.0'}Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 100why, one step back100Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 101–103why, one step back101 r = requests.get(httpbin('user-agent'), headers=heads)102103 assert heads['User-agent'] in r.contentMerge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 104–105why, one step back104 self.assertEqual(r.status_code, 200)105Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 106why, one step back106Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 107–109why, one step back107 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self):108 heads = {'User-agent': 'Mozilla/5.0'}109Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 110why, one step back110 r = requests.get(httpbin('get') + '?test=true', params={'q': 'test'}, headers=heads)Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 111why, one step back111 self.assertEqual(r.status_code, 200)Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 112why, one step back112Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 113why, one step back113Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 114–115why, one step back114 def test_user_agent_transfers(self):115 """Issue XX"""Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 116why, one step back116Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 117–120why, one step back117 heads = {118 'User-agent':119 'Mozilla/5.0 (github.com/kennethreitz/requests)'120 }Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 121why, one step back121Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 122why, one step back122 r = requests.get(httpbin('user-agent'), headers=heads);Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 123why, one step back123 self.assertTrue(heads['User-agent'] in r.content)Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 124why, one step back124Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 125–129why, one step back125 heads = {126 'user-agent':127 'Mozilla/5.0 (github.com/kennethreitz/requests)'128 }129Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 130why, one step back130 r = requests.get(httpbin('user-agent'), headers=heads);Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
lines 131–132why, one step back131 self.assertTrue(heads['user-agent'] in r.content)132Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 133why, one step back133Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 134why, one step back134 def test_HTTP_200_OK_HEAD(self):Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 135why, one step back135 r = requests.head(httpbin('/get'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 136why, one step back136 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 137why, one step back137Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 138–148why, one step back138139 def test_HTTP_200_OK_PUT(self):140 r = requests.put(httpbin('put'))141 self.assertEqual(r.status_code, 200)142143144 def test_HTTP_200_OK_PATCH(self):145 r = requests.patch(httpbin('patch'))146 self.assertEqual(r.status_code, 200)147148Merge branch 'auth_callables' of https://github.com/idangazit/requests into developKenneth Reitzbefore adoptiona7a619b
line 149why, one step back149 def test_BASICAUTH_TUPLE_HTTP_200_OK_GET(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 150why, one step back150Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 151why, one step back151 for service in SERVICES:Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 152why, one step back152Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 153–154why, one step back153 auth = ('user', 'pass')154 url = service('basic-auth', 'user', 'pass')Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa
line 155why, one step back155Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 156–157why, one step back156 r = requests.get(url, auth=auth)157 self.assertEqual(r.status_code, 200)Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa
line 158why, one step back158Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 159why, one step back159 r = requests.get(url)Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 160–164why, one step back160 self.assertEqual(r.status_code, 401)161162163 s = requests.session(auth=auth)164 r = s.get(url)Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 165–167why, one step back165 self.assertEqual(r.status_code, 200)166167Merge branch 'auth_callables' of https://github.com/idangazit/requests into developKenneth Reitzbefore adoptiona7a619b
lines 168–177why, one step back168 def test_BASICAUTH_HTTP_200_OK_GET(self):169170 for service in SERVICES:171172 auth = HTTPBasicAuth('user', 'pass')173 url = service('basic-auth', 'user', 'pass')174175 r = requests.get(url, auth=auth)176 self.assertEqual(r.status_code, 200)177test tuple'd authKenneth Reitzbefore adoptionee36baf
lines 178–181why, one step back178 auth = ('user', 'pass')179 r = requests.get(url, auth=auth)180 self.assertEqual(r.status_code, 200)181Merge branch 'auth_callables' of https://github.com/idangazit/requests into developKenneth Reitzbefore adoptiona7a619b
lines 182–190why, one step back182 r = requests.get(url)183 self.assertEqual(r.status_code, 401)184185186 s = requests.session(auth=auth)187 r = s.get(url)188 self.assertEqual(r.status_code, 200)189190Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 191–194why, one step back191 def test_DIGESTAUTH_HTTP_200_OK_GET(self):192193 for service in SERVICES:194Merge branch 'auth_callables' of https://github.com/idangazit/requests into developKenneth Reitzbefore adoptiona7a619b
line 195why, one step back195 auth = HTTPDigestAuth('user', 'pass')Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 196–208why, one step back196 url = service('digest-auth', 'auth', 'user', 'pass')197198 r = requests.get(url, auth=auth)199 self.assertEqual(r.status_code, 200)200201 r = requests.get(url)202 self.assertEqual(r.status_code, 401)203204205 s = requests.session(auth=auth)206 r = s.get(url)207 self.assertEqual(r.status_code, 200)208Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 209why, one step back209 def test_POSTBIN_GET_POST_FILES(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 210why, one step back210Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 211why, one step back211 for service in SERVICES:Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 212why, one step back212Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 213–214why, one step back213 url = service('post')214 post = requests.post(url).raise_for_status()Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 215why, one step back215Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 216–217why, one step back216 post = requests.post(url, data={'some': 'data'})217 self.assertEqual(post.status_code, 200)Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 218why, one step back218Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 219–220why, one step back219 post2 = requests.post(url, files={'some': open('test_requests.py')})220 self.assertEqual(post2.status_code, 200)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 221why, one step back221Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 222–225why, one step back222 post3 = requests.post(url, data='[{"some": "json"}]')223 self.assertEqual(post3.status_code, 200)224225Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 226why, one step back226 def test_POSTBIN_GET_POST_FILES_WITH_PARAMS(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 227why, one step back227Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 228why, one step back228 for service in SERVICES:Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 229why, one step back229Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 230–233why, one step back230 url = service('post')231 post = requests.post(url,232 files={'some': open('test_requests.py')},233 data={'some': 'data'})Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 234why, one step back234Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 235–237why, one step back235 self.assertEqual(post.status_code, 200)236237Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 238–239why, one step back238 def test_POSTBIN_GET_POST_FILES_WITH_HEADERS(self):239Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 240why, one step back240 for service in SERVICES:Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 241why, one step back241Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 242why, one step back242 url = service('post')Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 243why, one step back243Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 244–246why, one step back244 post2 = requests.post(url,245 files={'some': open('test_requests.py')},246 headers = {'User-Agent': 'requests-tests'})Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 247why, one step back247Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 248why, one step back248 self.assertEqual(post2.status_code, 200)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 249why, one step back249Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 250why, one step back250Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 251why, one step back251 def test_nonzero_evaluation(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 252why, one step back252Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 253why, one step back253 for service in SERVICES:Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 254why, one step back254Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 255–256why, one step back255 r = requests.get(service('status', '500'))256 self.assertEqual(bool(r), False)Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 257why, one step back257Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 258why, one step back258 r = requests.get(service('/get'))Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 259–261why, one step back259 self.assertEqual(bool(r), True)260261Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 262why, one step back262 def test_request_ok_set(self):Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 263why, one step back263Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 264why, one step back264 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 265why, one step back265Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 266why, one step back266 r = requests.get(service('status', '404'))stuff and things and stuffKenneth Reitzbefore adoptionb8c55da
lines 267–268why, one step back267 # print r.status_code268 # r.raise_for_status()Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 269–271why, one step back269 self.assertEqual(r.ok, False)270271Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 272why, one step back272 def test_status_raising(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 273why, one step back273 r = requests.get(httpbin('status', '404'))Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption5b54b3e
line 274why, one step back274 self.assertRaises(HTTPError, r.raise_for_status)Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 275why, one step back275Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 276why, one step back276 r = requests.get(httpbin('status', '200'))Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 277–278why, one step back277 self.assertFalse(r.error)278 r.raise_for_status()Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 279–280why, one step back279280Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
line 281why, one step back281 def test_decompress_gzip(self):a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 282why, one step back282Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 283why, one step back283 r = requests.get(httpbin('gzip'))Merge branch 'release/0.3.2'Kenneth Reitzbefore adoption642c667
lines 284–285why, one step back284 r.content.decode('ascii')285Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 286why, one step back286Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 287why, one step back287 def test_unicode_get(self):Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 288why, one step back288Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 289why, one step back289 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 290why, one step back290Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 291why, one step back291 url = service('/get')Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 292why, one step back292Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 293–297why, one step back293 requests.get(url, params={'foo': u'føø'})294 requests.get(url, params={u'føø': u'føø'})295 requests.get(url, params={'føø': 'føø'})296 requests.get(url, params={'foo': u'foo'})297 requests.get(service('ø'), params={'foo': u'foo'})Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 298why, one step back298Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 299why, one step back299Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 300why, one step back300 def test_httpauth_recursion(self):Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 301why, one step back301Merge branch 'auth_callables' of https://github.com/idangazit/requests into developKenneth Reitzbefore adoptiona7a619b
line 302why, one step back302 http_auth = HTTPBasicAuth('user', 'BADpass')Merge branch 'release/0.3.4'Kenneth Reitzbefore adoption0c00a17
line 303why, one step back303Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 304–306why, one step back304 for service in SERVICES:305 r = requests.get(service('basic-auth', 'user', 'pass'), auth=http_auth)306 self.assertEquals(r.status_code, 401)Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 307why, one step back307Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 308–310why, one step back308309 def test_urlencoded_post_data(self):310Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 311why, one step back311 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 312why, one step back312Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 313–324why, one step back313 r = requests.post(service('post'), data=dict(test='fooaowpeuf'))314315 self.assertEquals(r.status_code, 200)316 self.assertEquals(r.headers['content-type'], 'application/json')317 self.assertEquals(r.url, service('post'))318319 rbody = json.loads(r.content)320321 self.assertEquals(rbody.get('form'), dict(test='fooaowpeuf'))322 self.assertEquals(rbody.get('data'), '')323324Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 325why, one step back325 def test_nonurlencoded_post_data(self):Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 326why, one step back326Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 327why, one step back327 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 328why, one step back328Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 329–337why, one step back329 r = requests.post(service('post'), data='fooaowpeuf')330331 self.assertEquals(r.status_code, 200)332 self.assertEquals(r.headers['content-type'], 'application/json')333 self.assertEquals(r.url, service('post'))334335 rbody = json.loads(r.content)336 # Body wasn't valid url encoded data, so the server returns None as337 # "form" and the raw body as "data".test fixKenneth Reitzbefore adoptionec926a4
line 338why, one step back338 self.assertEquals(rbody.get('form'), {})Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 339–341why, one step back339 self.assertEquals(rbody.get('data'), 'fooaowpeuf')340341Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 342–343why, one step back342 def test_urlencoded_post_querystring(self):343Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 344why, one step back344 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 345why, one step back345Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 346–356why, one step back346 r = requests.post(service('post'), params=dict(test='fooaowpeuf'))347348 self.assertEquals(r.status_code, 200)349 self.assertEquals(r.headers['content-type'], 'application/json')350 self.assertEquals(r.url, service('post?test=fooaowpeuf'))351352 rbody = json.loads(r.content)353 self.assertEquals(rbody.get('form'), {}) # No form supplied354 self.assertEquals(rbody.get('data'), '')355356Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
lines 357–358why, one step back357 def test_urlencoded_post_query_and_data(self):358Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 359why, one step back359 for service in SERVICES:Merge branch 'release/0.5.0'Kenneth Reitzbefore adoption2d98ca7
line 360why, one step back360Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 361–374why, one step back361 r = requests.post(362 service('post'),363 params=dict(test='fooaowpeuf'),364 data=dict(test2="foobar"))365366 self.assertEquals(r.status_code, 200)367 self.assertEquals(r.headers['content-type'], 'application/json')368 self.assertEquals(r.url, service('post?test=fooaowpeuf'))369370 rbody = json.loads(r.content)371 self.assertEquals(rbody.get('form'), dict(test2='foobar'))372 self.assertEquals(rbody.get('data'), '')373374add query data yourself, foo'Kenneth Reitzbefore adoption0f2dcff
line 375why, one step back375 def test_nonurlencoded_postdata(self):Merge branch 'release/0.4.1'Kenneth Reitzbefore adoptionadd6fea
line 376why, one step back376Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 377–378why, one step back377 for service in SERVICES:378add query data yourself, foo'Kenneth Reitzbefore adoption0f2dcff
line 379why, one step back379 r = requests.post(service('post'), data="foobar")Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 380–385why, one step back380381 self.assertEquals(r.status_code, 200)382 self.assertEquals(r.headers['content-type'], 'application/json')383384 rbody = json.loads(r.content)385fix form data testsKenneth Reitzbefore adoptiondf2c80e
line 386why, one step back386 self.assertEquals(rbody.get('form'), {})Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 387–389why, one step back387 self.assertEquals(rbody.get('data'), 'foobar')388389Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 390–392why, one step back390 # def test_idna(self):391 # r = requests.get(u'http://➡.ws/httpbin')392 # assert 'httpbin' in r.urlMerge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 393why, one step back393Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 394why, one step back394Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 395–396why, one step back395 def test_urlencoded_get_query_multivalued_param(self):396Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 397–403why, one step back397 for service in SERVICES:398399 r = requests.get(service('get'), params=dict(test=['foo','baz']))400 self.assertEquals(r.status_code, 200)401 self.assertEquals(r.url, service('get?test=foo&test=baz'))402403Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 404–405why, one step back404 def test_urlencoded_post_querystring_multivalued(self):405Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 406–417why, one step back406 for service in SERVICES:407408 r = requests.post(service('post'), params=dict(test=['foo','baz']))409 self.assertEquals(r.status_code, 200)410 self.assertEquals(r.headers['content-type'], 'application/json')411 self.assertEquals(r.url, service('post?test=foo&test=baz'))412413 rbody = json.loads(r.content)414 self.assertEquals(rbody.get('form'), {}) # No form supplied415 self.assertEquals(rbody.get('data'), '')416417Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 418–419why, one step back418 def test_urlencoded_post_query_multivalued_and_data(self):419Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 420why, one step back420 for service in SERVICES:Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
line 421why, one step back421Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 422–434why, one step back422 r = requests.post(423 service('post'),424 params=dict(test=['foo','baz']),425 data=dict(test2="foobar",test3=['foo','baz']))426427 self.assertEquals(r.status_code, 200)428 self.assertEquals(r.headers['content-type'], 'application/json')429 self.assertEquals(r.url, service('post?test=foo&test=baz'))430 rbody = json.loads(r.content)431 self.assertEquals(rbody.get('form'), dict(test2='foobar',test3='foo'))432 self.assertEquals(rbody.get('data'), '')433434Merge branch 'redirect-no-follow' of https://github.com/millerdev/requestsKenneth Reitzbefore adoption98c719f
lines 435–452why, one step back435 def test_GET_no_redirect(self):436437 for service in SERVICES:438439 r = requests.get(service('redirect', '3'), allow_redirects=False)440 self.assertEquals(r.status_code, 302)441 self.assertEquals(len(r.history), 0)442443444 def test_HEAD_no_redirect(self):445446 for service in SERVICES:447448 r = requests.head(service('redirect', '3'), allow_redirects=False)449 self.assertEquals(r.status_code, 302)450 self.assertEquals(len(r.history), 0)451452Merge branch 'release/0.5.1'Kenneth Reitzbefore adoption95ba6fc
lines 453–454why, one step back453 def test_redirect_history(self):454Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 455–472why, one step back455 for service in SERVICES:456457 r = requests.get(service('redirect', '3'))458 self.assertEquals(r.status_code, 200)459 self.assertEquals(len(r.history), 3)460461462 def test_relative_redirect_history(self):463464 for service in SERVICES:465466 r = requests.get(service('relative-redirect', '3'))467 self.assertEquals(r.status_code, 200)468 self.assertEquals(len(r.history), 3)469470471 def test_session_HTTP_200_OK_GET(self):472Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 473–474why, one step back473 s = requests.session()474 r = s.get(httpbin('/get'))Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 475–481why, one step back475 self.assertEqual(r.status_code, 200)476477478 def test_session_persistent_headers(self):479480 heads = {'User-agent': 'Mozilla/5.0'}481Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 482why, one step back482 s = requests.session()Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 483why, one step back483 s.headers = headsMerge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 484why, one step back484Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
lines 485–488why, one step back485 # Make 2 requests from Session object, should send header both times486 r1 = s.get(httpbin('user-agent'))487 assert heads['User-agent'] in r1.content488Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
line 489why, one step back489 r2 = s.get(httpbin('user-agent'))Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 490why, one step back490 assert heads['User-agent'] in r2.contentMerge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 491–495why, one step back491492 new_heads = {'User-agent': 'blah'}493 r3 = s.get(httpbin('user-agent'), headers=new_heads)494 assert new_heads['User-agent'] in r3.content495Merge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 496why, one step back496 self.assertEqual(r2.status_code, 200)test the cookies!Kenneth Reitzbefore adoptione649003
lines 497–520why, one step back497498 def test_session_persistent_cookies(self):499500 s = requests.session()501502 # Internally dispatched cookies are sent.503 _c = {'kenneth': 'reitz', 'bessie': 'monke'}504 r = s.get(httpbin('cookies'), cookies=_c)505 r = s.get(httpbin('cookies'))506507 # Those cookies persist transparently.508 c = json.loads(r.content).get('cookies')509 assert c == _c510511 # Double check.512 r = s.get(httpbin('cookies'), cookies={})513 c = json.loads(r.content).get('cookies')514 assert c == _c515516 # Remove a cookie by setting it's value to None.517 r = s.get(httpbin('cookies'), cookies={'bessie': None})518 c = json.loads(r.content).get('cookies')519 del _c['bessie']520 assert c == _cMerge branch 'develop'Kenneth Reitzbefore adoption81d5997
line 521why, one step back521ultra cookie compatibilityKenneth Reitzbefore adoption7a1a40e
line 522why, one step back522 # Test session-level cookies.Make sure that session-level cookies work.Kenneth Reitzbefore adoptionf9141f5
line 523why, one step back523 s = requests.session(cookies=_c)ultra cookie compatibilityKenneth Reitzbefore adoption7a1a40e
line 524why, one step back524 r = s.get(httpbin('cookies'))Make sure that session-level cookies work.Kenneth Reitzbefore adoptionf9141f5
lines 525–527why, one step back525 c = json.loads(r.content).get('cookies')526 assert c == _c527ultra cookie compatibilityKenneth Reitzbefore adoption7a1a40e
lines 528–530why, one step back528 # Have the server set a cookie.529 r = s.get(httpbin('cookies', 'set', 'k', 'v'), allow_redirects=True)530 c = json.loads(r.content).get('cookies')Make sure that session-level cookies work.Kenneth Reitzbefore adoptionf9141f5
line 531why, one step back531ultra cookie compatibilityKenneth Reitzbefore adoption7a1a40e
line 532why, one step back532 assert 'k' in cMake sure that session-level cookies work.Kenneth Reitzbefore adoptionf9141f5
line 533why, one step back533ultra cookie compatibilityKenneth Reitzbefore adoption7a1a40e
lines 534–541why, one step back534 # And server-set cookie persistience.535 r = s.get(httpbin('cookies'))536 c = json.loads(r.content).get('cookies')537538 assert 'k' in c539540541Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoption95336a0
lines 542–567why, one step back542 def test_session_persistent_params(self):543544 params = {'a': 'a_test'}545546 s = requests.session()547 s.params = params548549 # Make 2 requests from Session object, should send header both times550 r1 = s.get(httpbin('get'))551 assert params['a'] in r1.content552553554 params2 = {'b': 'b_test'}555556 r2 = s.get(httpbin('get'), params=params2)557 assert params['a'] in r2.content558 assert params2['b'] in r2.content559560561 params3 = {'b': 'b_test', 'a': None, 'c': 'c_test'}562563 r3 = s.get(httpbin('get'), params=params3)564565 assert not params['a'] in r3.content566 assert params3['b'] in r3.content567 assert params3['c'] in r3.contentadd query data yourself, foo'Kenneth Reitzbefore adoption0f2dcff
line 568why, one step back568Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoptionc48f0d9
lines 569–571why, one step back569 def test_invalid_content(self):570 # WARNING: if you're using a terrible DNS provider (comcast),571 # this will fail.add query data yourself, foo'Kenneth Reitzbefore adoption0f2dcff
lines 572–578why, one step back572 try:573 hah = 'http://somedomainthatclearlydoesntexistg.com'574 r = requests.get(hah, allow_redirects=False)575 except requests.ConnectionError:576 pass # \o/577 else:578 assert FalseMerge branch 'develop' into feature/rewriteKenneth Reitzbefore adoptionc48f0d9
line 579why, one step back579add query data yourself, foo'Kenneth Reitzbefore adoption0f2dcff
lines 580–582why, one step back580581 config = {'safe_mode': True}582 r = requests.get(hah, allow_redirects=False, config=config)Merge branch 'develop' into feature/rewriteKenneth Reitzbefore adoptionc48f0d9
lines 583–584why, one step back583 assert r.content == None584Merge branch 'release/0.3.3'Kenneth Reitzbefore adoption7215452
line 585why, one step back585a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 586why, one step back586if __name__ == '__main__':Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 587why, one step back587 unittest.main()