HTTP Integration
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 d98de70 · Browse files · 1 file·+23 added−46 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+23 added−46 removed
- other:+23 added−46 removed
Provenance
- Commit
35bfa9e- Tree
6b0b95e- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
d98de70
1 file changed+23 added−46 removed
modified:test_requests.py+23 added-46 removed
14 unmodified lines15 16 from requests.sessions import Session17 18 19-HTTPBIN_URL = 'http://httpbin.ep.io/'20-HTTPSBIN_URL = 'https://httpbin.ep.io/'19+HTTPBIN_URL = 'http://127.0.0.1:44444/'20 22-# HTTPBIN_URL = 'http://staging.httpbin.org/'23-# HTTPSBIN_URL = 'https://httpbin-staging.ep.io/'21 25-22 def httpbin(*suffix):23 """Returns url for HTTPBIN resource."""24 25 return HTTPBIN_URL + '/'.join(suffix)26 27 32-def httpsbin(*suffix):33- """Returns url for HTTPSBIN resource."""28+SERVICES = (httpbin, )29 35- return HTTPSBIN_URL + '/'.join(suffix)30+_httpbin = False31 37-38-SERVICES = (httpbin, httpsbin)39-40-41-32 class RequestsTestSuite(unittest.TestCase):33 """Requests test cases."""34 35 # It goes to eleven.36 _multiprocess_can_split_ = True37 38 def setUp(self):49- pass39 40+ global _httpbin41 42+ if not _httpbin:43+ import envoy44+ self.httpbin = envoy.connect('httpbin 44444')45+ # print self.httpbin46+47+ _httpbin = True48+ # print '!'/49+50+ import time51+ time.sleep(1)52+53+54+55 def tearDown(self):56 """Teardown."""54- pass57+ # self.httpbin.kill()58 59 60 def test_invalid_url(self):61 self.assertRaises(ValueError, requests.get, 'hiwpefhipowhefopw')62 63 64 def test_HTTP_200_OK_GET(self):62- r = requests.get(httpbin('/'))65+ r = requests.get(httpbin('/get'))66 self.assertEqual(r.status_code, 200)67 68 def test_HTTP_302_ALLOW_REDIRECT_GET(self):69 r = requests.get(httpbin('redirect', '1'))2 unmodified lines72 def test_HTTP_302_GET(self):73 r = requests.get(httpbin('redirect', '1'), allow_redirects=False)74 self.assertEqual(r.status_code, 302)75 73- def test_HTTPS_200_OK_GET(self):74- r = requests.get(httpsbin('/'))75- self.assertEqual(r.status_code, 200)76 77-77 def test_HTTP_200_OK_GET_WITH_PARAMS(self):78 heads = {'User-agent': 'Mozilla/5.0'}79 80 r = requests.get(httpbin('user-agent'), headers=heads)29 unmodified lines110 self.assertTrue(heads['user-agent'] in r.content)111 112 113 def test_HTTP_200_OK_HEAD(self):115- r = requests.head(httpbin('/'))114+ r = requests.head(httpbin('/get'))115 self.assertEqual(r.status_code, 200)116 117 119- def test_HTTPS_200_OK_HEAD(self):120- r = requests.head(httpsbin('/'))121- self.assertEqual(r.status_code, 200)122-123-118 def test_HTTP_200_OK_PUT(self):119 r = requests.put(httpbin('put'))120 self.assertEqual(r.status_code, 200)121 122 129- def test_HTTPS_200_OK_PUT(self):130- r = requests.put(httpsbin('put'))131- self.assertEqual(r.status_code, 200)132-133-123 def test_HTTP_200_OK_PATCH(self):124 r = requests.patch(httpbin('patch'))125 self.assertEqual(r.status_code, 200)126 127 139- def test_HTTPS_200_OK_PATCH(self):140- r = requests.patch(httpsbin('patch'))141- self.assertEqual(r.status_code, 200)142-143-128 def test_AUTH_HTTP_200_OK_GET(self):129 130 for service in SERVICES:131 57 unmodified lines189 190 r = requests.get(service('status', '500'))191 self.assertEqual(bool(r), False)192 209- r = requests.get(service('/'))193+ r = requests.get(service('/get'))194 self.assertEqual(bool(r), True)195 196 197 def test_request_ok_set(self):42 unmodified lines240 def test_unicode_get(self):241 242 for service in SERVICES:243 260- url = service('/')244+ url = service('/get')245 246 requests.get(url, params={'foo': u'føø'})247 requests.get(url, params={u'føø': u'føø'})248 requests.get(url, params={'føø': 'føø'})204 unmodified lines453 454 def test_session_HTTP_200_OK_GET(self):455 456 s = Session()473- r = s.get(httpbin('/'))457+ r = s.get(httpbin('/get'))458 self.assertEqual(r.status_code, 200)459 460 477- def test_session_HTTPS_200_OK_GET(self):478-479- s = Session()480- r = s.get(httpsbin('/'))481- self.assertEqual(r.status_code, 200)482-483-461 def test_session_persistent_headers(self):462 463 heads = {'User-agent': 'Mozilla/5.0'}464 14 unmodified lines