test for gzip decompress
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent 7a62b10 · Browse files · 1 file·+13 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+13 added−10 removed
- other:+13 added−10 removed
Provenance
- Commit
1359094- Tree
ffcc705- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
7a62b10
1 file changed+13 added−10 removed
modified:test_requests.py+13 added-10 removed
28 unmodified lines29 self.assertEqual(r.status_code, 200)30 31 def test_HTTP_200_OK_GET_WITH_PARAMS(self):32 heads = {'User-agent': 'Mozilla/5.0'}33- 33+34 r = requests.get('http://www.google.com/search', params={'q': 'test'}, headers=heads)35 self.assertEqual(r.status_code, 200)36 37 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self):8 unmodified lines46 'Mozilla/5.0 (github.com/kennethreitz/requests)'}47 48 r = requests.get('http://whatsmyua.com', headers=heads);49 self.assertTrue(heads['User-agent'] in r.content)50- 50+51 def test_HTTP_200_OK_HEAD(self):52 r = requests.head('http://google.com')53 self.assertEqual(r.status_code, 200)54 17 unmodified lines72 def test_POSTBIN_GET_POST_FILES(self):73 bin = requests.post('http://www.postbin.org/')74 print bin.url75 self.assertEqual(bin.status_code, 200)76- 76+77 post = requests.post(bin.url, data={'some': 'data'})78 self.assertEqual(post.status_code, 201)79 80 post2 = requests.post(bin.url, files={'some': open('test_requests.py')})81 self.assertEqual(post2.status_code, 201)82 83 def test_POSTBIN_GET_POST_FILES_WITH_PARAMS(self):84 bin = requests.post('http://www.postbin.org/')85- 85+86 self.assertEqual(bin.status_code, 200)87 88 post2 = requests.post(bin.url, files={'some': open('test_requests.py')}, data={'some': 'data'})89 self.assertEqual(post2.status_code, 201)6 unmodified lines96 post2 = requests.post(bin.url, files={'some': open('test_requests.py')},97 headers={'User-Agent': 'requests-tests'})98 99 self.assertEqual(post2.status_code, 201)100- 100+101 def test_nonzero_evaluation(self):102 r = requests.get('http://google.com/some-404-url')103 self.assertEqual(bool(r), False)104- 104+105 r = requests.get('http://google.com/')106 self.assertEqual(bool(r), True)107- 107+108 def test_request_ok_set(self):109 r = requests.get('http://google.com/some-404-url')110 self.assertEqual(r.ok, False)111- 111+112 def test_status_raising(self):113 r = requests.get('http://google.com/some-404-url')114 self.assertRaises(requests.HTTPError, r.raise_for_status)115- 115+116 r = requests.get('http://google.com/')117 self.assertFalse(r.error)118 r.raise_for_status()119- 119+120 def test_cookie_jar(self):121 """122 .. todo:: This really doesn't test to make sure the cookie is working123 """2 unmodified lines126 127 requests.get('http://google.com', cookies=jar)128 self.assertTrue(jar)129 130+ def test_decompress_gzip(self):131 132+ r = requests.get('http://api.stackoverflow.com/1.1/users/495995/top-answer-tags')133+ r.content.decode('ascii')134 135 if __name__ == '__main__':136 unittest.main()