From 9322d13f610fc26f63cc51c8c4b0a907d7392153 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 16 Aug 2011 23:58:55 -0400 Subject: [PATCH] cleanups --- test_requests.py | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/test_requests.py b/test_requests.py index d6f948e..dd92347 100755 --- a/test_requests.py +++ b/test_requests.py @@ -13,7 +13,7 @@ except ImportError: import requests -from requests.session import Session +from requests.sessions import Session HTTPBIN_URL = 'http://httpbin.org/' @@ -132,22 +132,21 @@ class RequestsTestSuite(unittest.TestCase): self.assertEqual(r.status_code, 200) - def test_AUTH_HTTPS_200_OK_GET(self): + def test_AUTH_HTTP_200_OK_GET(self): for service in SERVICES: auth = ('user', 'pass') url = service('basic-auth', 'user', 'pass') - r = requests.get(url, auth=auth) + r = requests.get(url, auth=auth) + # print r.__dict__ self.assertEqual(r.status_code, 200) + r = requests.get(url) self.assertEqual(r.status_code, 200) - # reset auto authentication - requests.auth_manager.empty() - def test_POSTBIN_GET_POST_FILES(self): @@ -245,21 +244,6 @@ class RequestsTestSuite(unittest.TestCase): r.content.decode('ascii') - def test_autoauth(self): - - http_auth = ('user', 'pass') - requests.auth_manager.add_auth('httpbin.org', http_auth) - - r = requests.get(httpbin('basic-auth', 'user', 'pass')) - self.assertEquals(r.status_code, 200) - - - requests.auth_manager.add_auth('httpbin.ep.io', http_auth) - - r = requests.get(httpsbin('basic-auth', 'user', 'pass')) - self.assertEquals(r.status_code, 200) - - def test_unicode_get(self): for service in SERVICES: @@ -457,27 +441,35 @@ class RequestsTestSuite(unittest.TestCase): def test_session_HTTP_200_OK_GET(self): + s = Session() r = s.get(httpbin('/')) self.assertEqual(r.status_code, 200) + def test_session_HTTPS_200_OK_GET(self): + s = Session() r = s.get(httpsbin('/')) self.assertEqual(r.status_code, 200) + def test_session_persistent_headers(self): + heads = {'User-agent': 'Mozilla/5.0'} + s = Session() s.headers = heads # Make 2 requests from Session object, should send header both times - r1 = s.get(httpbin('user-agent') + r1 = s.get(httpbin('user-agent')) + assert heads['User-agent'] in r1.content - r2 = s.get(httpbin('user-agent') + r2 = s.get(httpbin('user-agent')) + assert heads['User-agent'] in r2.content - self.assertEqual(r.status_code, 200) - - + self.assertEqual(r2.status_code, 200) + + if __name__ == '__main__': unittest.main() -- 2.7.4