HTTP Integration
authorKenneth Reitz <me@kennethreitz.com>
Sat, 15 Oct 2011 15:55:57 +0000 (11:55 -0400)
committerKenneth Reitz <me@kennethreitz.com>
Sat, 15 Oct 2011 15:55:57 +0000 (11:55 -0400)
test_requests.py

index 83b827abd4981b66c3d8bc805c0fbb3328edc597..ff42a7a53eed1c4ad4ffe3679ea474732b12b180 100755 (executable)
@@ -16,11 +16,7 @@ import requests
 from requests.sessions import Session
 
 
-HTTPBIN_URL = 'http://httpbin.ep.io/'
-HTTPSBIN_URL = 'https://httpbin.ep.io/'
-
-# HTTPBIN_URL = 'http://staging.httpbin.org/'
-# HTTPSBIN_URL = 'https://httpbin-staging.ep.io/'
+HTTPBIN_URL = 'http://127.0.0.1:44444/'
 
 
 def httpbin(*suffix):
@@ -29,15 +25,9 @@ def httpbin(*suffix):
     return HTTPBIN_URL + '/'.join(suffix)
 
 
-def httpsbin(*suffix):
-    """Returns url for HTTPSBIN resource."""
-
-    return HTTPSBIN_URL + '/'.join(suffix)
-
-
-SERVICES = (httpbin, httpsbin)
-
+SERVICES = (httpbin, )
 
+_httpbin = False
 
 class RequestsTestSuite(unittest.TestCase):
     """Requests test cases."""
@@ -46,12 +36,25 @@ class RequestsTestSuite(unittest.TestCase):
     _multiprocess_can_split_ = True
 
     def setUp(self):
-        pass
+
+        global _httpbin
+
+        if not _httpbin:
+            import envoy
+            self.httpbin = envoy.connect('httpbin 44444')
+            # print self.httpbin
+
+            _httpbin = True
+            # print '!'/
+
+            import time
+            time.sleep(1)
+
 
 
     def tearDown(self):
         """Teardown."""
-        pass
+        # self.httpbin.kill()
 
 
     def test_invalid_url(self):
@@ -59,7 +62,7 @@ class RequestsTestSuite(unittest.TestCase):
 
 
     def test_HTTP_200_OK_GET(self):
-        r = requests.get(httpbin('/'))
+        r = requests.get(httpbin('/get'))
         self.assertEqual(r.status_code, 200)
 
     def test_HTTP_302_ALLOW_REDIRECT_GET(self):
@@ -70,10 +73,6 @@ class RequestsTestSuite(unittest.TestCase):
        r = requests.get(httpbin('redirect', '1'), allow_redirects=False)
        self.assertEqual(r.status_code, 302)
 
-    def test_HTTPS_200_OK_GET(self):
-        r = requests.get(httpsbin('/'))
-        self.assertEqual(r.status_code, 200)
-
 
     def test_HTTP_200_OK_GET_WITH_PARAMS(self):
         heads = {'User-agent': 'Mozilla/5.0'}
@@ -112,12 +111,7 @@ class RequestsTestSuite(unittest.TestCase):
 
 
     def test_HTTP_200_OK_HEAD(self):
-        r = requests.head(httpbin('/'))
-        self.assertEqual(r.status_code, 200)
-
-
-    def test_HTTPS_200_OK_HEAD(self):
-        r = requests.head(httpsbin('/'))
+        r = requests.head(httpbin('/get'))
         self.assertEqual(r.status_code, 200)
 
 
@@ -126,21 +120,11 @@ class RequestsTestSuite(unittest.TestCase):
         self.assertEqual(r.status_code, 200)
 
 
-    def test_HTTPS_200_OK_PUT(self):
-        r = requests.put(httpsbin('put'))
-        self.assertEqual(r.status_code, 200)
-
-
     def test_HTTP_200_OK_PATCH(self):
         r = requests.patch(httpbin('patch'))
         self.assertEqual(r.status_code, 200)
 
 
-    def test_HTTPS_200_OK_PATCH(self):
-        r = requests.patch(httpsbin('patch'))
-        self.assertEqual(r.status_code, 200)
-
-
     def test_AUTH_HTTP_200_OK_GET(self):
 
         for service in SERVICES:
@@ -206,7 +190,7 @@ class RequestsTestSuite(unittest.TestCase):
             r = requests.get(service('status', '500'))
             self.assertEqual(bool(r), False)
 
-            r = requests.get(service('/'))
+            r = requests.get(service('/get'))
             self.assertEqual(bool(r), True)
 
 
@@ -257,7 +241,7 @@ class RequestsTestSuite(unittest.TestCase):
 
         for service in SERVICES:
 
-            url = service('/')
+            url = service('/get')
 
             requests.get(url, params={'foo': u'føø'})
             requests.get(url, params={u'føø': u'føø'})
@@ -470,14 +454,7 @@ 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('/'))
+        r = s.get(httpbin('/get'))
         self.assertEqual(r.status_code, 200)