test_requests.py
This file
Path
test_requests.py
211 lines · 6.0 KiB · Python
Last changed by
whitespaceKenneth Reitzbefore adoptioncd0d0a2
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 -*-3python2.5 withKenneth Reitzbefore adoption06e662b
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
lines 8–11why, one step back89import requests1011a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 12why, one step back12class RequestsTestSuite(unittest.TestCase):Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 13why, one step back13 """Requests test cases."""Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 14why, one step back14Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 15–16why, one step back15 def setUp(self):16 passtemp "tests"Kenneth Reitzbefore adoption49f915f
line 17why, one step back17whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 18why, one step back18 Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 19–21why, one step back19 def tearDown(self):20 """Teardown."""21 passMerge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 22why, one step back22whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 23why, one step back23 Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 24–25why, one step back24 def test_invalid_url(self):25 self.assertRaises(ValueError, requests.get, 'hiwpefhipowhefopw')a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 26why, one step back26whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 27why, one step back27 Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 28–30why, one step back28 def test_HTTP_200_OK_GET(self):29 r = requests.get('http://google.com')30 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 31why, one step back31whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 32why, one step back32 Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 33–35why, one step back33 def test_HTTPS_200_OK_GET(self):34 r = requests.get('https://google.com')35 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 36why, one step back36whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 37why, one step back37 Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 38–39why, one step back38 def test_HTTP_200_OK_GET_WITH_PARAMS(self):39 heads = {'User-agent': 'Mozilla/5.0'}test for gzip decompressKenneth Reitzbefore adoption1359094
line 40why, one step back40Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 41–43why, one step back41 r = requests.get('http://www.google.com/search', params={'q': 'test'}, headers=heads)42 self.assertEqual(r.status_code, 200)43whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 44why, one step back44 Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 45–49why, one step back45 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self):46 heads = {'User-agent': 'Mozilla/5.0'}4748 r = requests.get('http://google.com/search?test=true', params={'q': 'test'}, headers=heads)49 self.assertEqual(r.status_code, 200)Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 50why, one step back50whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 51why, one step back51 Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 52–53why, one step back52 def test_user_agent_transfers(self):53 """Issue XX"""useragentKenneth Reitzbefore adoption8a4d5c4
lines 54–57why, one step back54 heads = {55 'User-agent':56 'Mozilla/5.0 (github.com/kennethreitz/requests)'57 }Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 58–60why, one step back5859 r = requests.get('http://whatsmyua.com', headers=heads);60 self.assertTrue(heads['User-agent'] in r.content)useragentKenneth Reitzbefore adoption8a4d5c4
lines 61–68why, one step back6162 heads = {63 'user-agent':64 'Mozilla/5.0 (github.com/kennethreitz/requests)'65 }6667 r = requests.get('http://whatsmyua.com', headers=heads);68 self.assertTrue(heads['user-agent'] in r.content)test for gzip decompressKenneth Reitzbefore adoption1359094
line 69why, one step back69whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 70why, one step back70 Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 71–73why, one step back71 def test_HTTP_200_OK_HEAD(self):72 r = requests.head('http://google.com')73 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 74why, one step back74whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 75why, one step back75 Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 76–78why, one step back76 def test_HTTPS_200_OK_HEAD(self):77 r = requests.head('https://google.com')78 self.assertEqual(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 79why, one step back79whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 80why, one step back80 Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 81why, one step back81 def test_AUTH_HTTPS_200_OK_GET(self):Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 82why, one step back82 auth = ('requeststest', 'requeststest')Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 83–84why, one step back83 url = 'https://convore.com/api/account/verify.json'84 r = requests.get(url, auth=auth)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 85why, one step back85Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 86why, one step back86 self.assertEqual(r.status_code, 200)Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 87why, one step back87Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa
lines 88–91why, one step back88 r = requests.get(url)89 self.assertEqual(r.status_code, 200)9091 # reset auto authenticationMerge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 92why, one step back92 requests.auth_manager.empty()Merge branch 'release/0.2.4'Kenneth Reitzbefore adoptiond2cdefa
line 93why, one step back93whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 94why, one step back94 Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 95–96why, one step back95 def test_POSTBIN_GET_POST_FILES(self):96 bin = requests.post('http://www.postbin.org/')Improved redirection behavior for 301/303Kenneth Reitzbefore adoptione153b94
line 97why, one step back97 self.assertEqual(bin.status_code, 302)test for gzip decompressKenneth Reitzbefore adoption1359094
line 98why, one step back98Improved redirection behavior for 301/303Kenneth Reitzbefore adoptione153b94
lines 99–100why, one step back99 post_url = bin.headers['location']100 post = requests.post(post_url, data={'some': 'data'})Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 101why, one step back101 self.assertEqual(post.status_code, 201)Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 102why, one step back102Improved redirection behavior for 301/303Kenneth Reitzbefore adoptione153b94
line 103why, one step back103 post2 = requests.post(post_url, files={'some': open('test_requests.py')})Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 104why, one step back104 self.assertEqual(post2.status_code, 201)Merge branch 'release/0.2.1'Kenneth Reitzbefore adoptione09efc4
line 105why, one step back105Improved redirection behavior for 301/303Kenneth Reitzbefore adoptione153b94
line 106why, one step back106 post3 = requests.post(post_url, data='[{"some": "json"}]')Merge pull request #29 from meganemura/requestsKenneth Reitzbefore adoption9b0bb87
lines 107–108why, one step back107 self.assertEqual(post.status_code, 201)108Improved redirection behavior for 301/303Kenneth Reitzbefore adoptione153b94
line 109why, one step back109Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 110–111why, one step back110 def test_POSTBIN_GET_POST_FILES_WITH_PARAMS(self):111 bin = requests.post('http://www.postbin.org/')Improved redirection behavior for 301/303Kenneth Reitzbefore adoptione153b94
line 112why, one step back112 self.assertEqual(bin.status_code, 302)test for gzip decompressKenneth Reitzbefore adoption1359094
line 113why, one step back113Improved redirection behavior for 301/303Kenneth Reitzbefore adoptione153b94
line 114why, one step back114 post_url = bin.headers['location']Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 115why, one step back115Improved redirection behavior for 301/303Kenneth Reitzbefore adoptione153b94
line 116why, one step back116 post2 = requests.post(post_url, files={'some': open('test_requests.py')}, data={'some': 'data'})Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
lines 117–118why, one step back117 self.assertEqual(post2.status_code, 201)118Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 119–121why, one step back119120 def test_POSTBIN_GET_POST_FILES_WITH_HEADERS(self):121 bin = requests.post('http://www.postbin.org/')Improved redirection behavior for 301/303Kenneth Reitzbefore adoptione153b94
line 122why, one step back122 self.assertEqual(bin.status_code, 302)Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 123why, one step back123Improved redirection behavior for 301/303Kenneth Reitzbefore adoptione153b94
line 124why, one step back124 post_url = bin.headers['location']Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 125why, one step back125Improved redirection behavior for 301/303Kenneth Reitzbefore adoptione153b94
lines 126–128why, one step back126 post2 = requests.post(post_url, files={'some': open('test_requests.py')},127 headers = {'User-Agent': 'requests-tests'})128Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
line 129why, one step back129 self.assertEqual(post2.status_code, 201)test for gzip decompressKenneth Reitzbefore adoption1359094
line 130why, one step back130Improved redirection behavior for 301/303Kenneth Reitzbefore adoptione153b94
line 131why, one step back131Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 132–134why, one step back132 def test_nonzero_evaluation(self):133 r = requests.get('http://google.com/some-404-url')134 self.assertEqual(bool(r), False)test for gzip decompressKenneth Reitzbefore adoption1359094
line 135why, one step back135Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 136–137why, one step back136 r = requests.get('http://google.com/')137 self.assertEqual(bool(r), True)test for gzip decompressKenneth Reitzbefore adoption1359094
line 138why, one step back138whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 139why, one step back139 Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 140–142why, one step back140 def test_request_ok_set(self):141 r = requests.get('http://google.com/some-404-url')142 self.assertEqual(r.ok, False)test for gzip decompressKenneth Reitzbefore adoption1359094
line 143why, one step back143whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 144why, one step back144 Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 145–147why, one step back145 def test_status_raising(self):146 r = requests.get('http://google.com/some-404-url')147 self.assertRaises(requests.HTTPError, r.raise_for_status)test for gzip decompressKenneth Reitzbefore adoption1359094
line 148why, one step back148Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
lines 149–151why, one step back149 r = requests.get('http://google.com/')150 self.assertFalse(r.error)151 r.raise_for_status()test for gzip decompressKenneth Reitzbefore adoption1359094
line 152why, one step back152whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 153why, one step back153 Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 154–157why, one step back154 def test_cookie_jar(self):155 """156 .. todo:: This really doesn't test to make sure the cookie is working157 """package refactorKenneth Reitzbefore adoption14ef462
line 158why, one step back158Merge branch 'develop'Kenneth Reitzbefore adoptioncc16073
lines 159–163why, one step back159 jar = cookielib.CookieJar()160 self.assertFalse(jar)161162 requests.get('http://google.com', cookies=jar)163 self.assertTrue(jar)Merge branch 'release/0.3.0'Kenneth Reitzbefore adoption044252e
line 164why, one step back164whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 165why, one step back165 test for gzip decompressKenneth Reitzbefore adoption1359094
line 166why, one step back166 def test_decompress_gzip(self):a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 167why, one step back167test for gzip decompressKenneth Reitzbefore adoption1359094
lines 168–169why, one step back168 r = requests.get('http://api.stackoverflow.com/1.1/users/495995/top-answer-tags')169 r.content.decode('ascii')add autoauth tuple http basic testKenneth Reitzbefore adoptionf494cd9
line 170why, one step back170whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 171why, one step back171 add autoauth tuple http basic testKenneth Reitzbefore adoptionf494cd9
lines 172–178why, one step back172 def test_autoauth(self):173174 conv_auth = ('requeststest', 'requeststest')175 requests.auth_manager.add_auth('convore.com', conv_auth)176177 r = requests.get('https://convore.com/api/account/verify.json')178 self.assertEquals(r.status_code, 200)a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 179why, one step back179whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 180why, one step back180 test for unicode url issuesKenneth Reitzbefore adoption8a4a05a
line 181why, one step back181 def test_unicode_get(self):whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 182why, one step back182 test for unicode url issuesKenneth Reitzbefore adoption8a4a05a
line 183why, one step back183 requests.get('http://google.com', params={'foo': u'føø'})Merge https://github.com/jgorset/requests into developKenneth Reitzbefore adoption86fb0cb
lines 184–185why, one step back184 requests.get('http://google.com', params={u'føø': u'føø'})185 requests.get('http://google.com', params={'føø': 'føø'})test for unicode url issuesKenneth Reitzbefore adoption8a4a05a
lines 186–188why, one step back186 requests.get('http://google.com', params={'foo': u'foo'})187 requests.get('http://google.com/ø', params={'foo': u'foo'})188whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 189why, one step back189 HTTP Basic recursion. Fixes #31Kenneth Reitzbefore adoption1421ffa
lines 190–194why, one step back190 def test_httpauth_recursion(self):191 conv_auth = ('requeststest', 'bad_password')192193 r = requests.get('https://convore.com/api/account/verify.json', auth=conv_auth)194 self.assertEquals(r.status_code, 401)Improved redirection behavior for 301/303Kenneth Reitzbefore adoptione153b94
line 195why, one step back195whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 196why, one step back196 Add tests for settingsJohannes Gorsetbefore adoption21e2d0c
line 197why, one step back197 def test_settings(self):Adjust testsJohannesbefore adoptionda26f1f
lines 198–199why, one step back198 with requests.settings(timeout=0.0001):199 self.assertRaises(requests.Timeout, requests.get, 'http://google.com')Improved redirection behavior for 301/303Kenneth Reitzbefore adoptione153b94
line 200why, one step back200Add tests for settingsJohannes Gorsetbefore adoption21e2d0c
lines 201–202why, one step back201 with requests.settings(timeout=10):202 requests.get('http://google.com')whitespaceKenneth Reitzbefore adoptioncd0d0a2
line 203why, one step back203Improved redirection behavior for 301/303Kenneth Reitzbefore adoptione153b94
line 204why, one step back204Add test for non-urlencoded post dataJohannes Gorsetbefore adoption637d033
lines 205–206why, one step back205 def test_nonurlencoded_post_data(self):206 requests.post('http://google.com', data='foo')Improved redirection behavior for 301/303Kenneth Reitzbefore adoptione153b94
line 207why, one step back207HTTP Basic recursion. Fixes #31Kenneth Reitzbefore adoption1421ffa
line 208why, one step back208test for unicode url issuesKenneth Reitzbefore adoption8a4a05a
line 209why, one step back209a few test fixtures for nowKenneth Reitzbefore adoption4a3f559
line 210why, one step back210if __name__ == '__main__':Merge branch 'release/0.9.4'Kenneth Reitzbefore adoption952970f
line 211why, one step back211 unittest.main()