libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [19/33] libcloud git commit: Fix brightbox testing
Date Tue, 05 Apr 2016 11:17:10 GMT
Fix brightbox testing


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/d95474e0
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/d95474e0
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/d95474e0

Branch: refs/heads/requests
Commit: d95474e097accb1d7482c8c8b60ee06f7d1441f0
Parents: dc1290f
Author: anthony-shaw <anthony.p.shaw@gmail.com>
Authored: Wed Mar 30 14:55:02 2016 +1100
Committer: anthony-shaw <anthony.p.shaw@gmail.com>
Committed: Wed Mar 30 14:55:02 2016 +1100

----------------------------------------------------------------------
 libcloud/test/__init__.py               |  2 +-
 libcloud/test/compute/test_brightbox.py | 49 ++++++++++++++++------------
 2 files changed, 29 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/d95474e0/libcloud/test/__init__.py
----------------------------------------------------------------------
diff --git a/libcloud/test/__init__.py b/libcloud/test/__init__.py
index cfd076c..af4a3b3 100644
--- a/libcloud/test/__init__.py
+++ b/libcloud/test/__init__.py
@@ -91,7 +91,7 @@ class MockResponse(object):
         self.reason = reason or self.reason
 
     def read(self, *args, **kwargs):
-        return self.body.read(*args, **kwargs)
+        return self.body
 
     def next(self):
         if sys.version_info >= (2, 5) and sys.version_info <= (2, 6):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/d95474e0/libcloud/test/compute/test_brightbox.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_brightbox.py b/libcloud/test/compute/test_brightbox.py
index 2ac57b0..d375f65 100644
--- a/libcloud/test/compute/test_brightbox.py
+++ b/libcloud/test/compute/test_brightbox.py
@@ -41,6 +41,7 @@ class BrightboxTest(unittest.TestCase, TestCaseMixin):
     def setUp(self):
         BrightboxNodeDriver.connectionCls.conn_class = BrightboxMockHttp
         BrightboxMockHttp.type = None
+        BrightboxNodeDriver.connectionCls.token = 'test'
         self.driver = BrightboxNodeDriver(*BRIGHTBOX_PARAMS)
 
     def test_authentication(self):
@@ -245,30 +246,36 @@ class BrightboxMockHttp(MockHttp):
 
     def _token(self, method, url, body, headers):
         if method == 'POST':
-            return self.response(httplib.OK, self.fixtures.load('token.json'))
+            return self.test_response(httplib.OK, self.fixtures.load('token.json'))
 
     def _token_INVALID_CLIENT(self, method, url, body, headers):
         if method == 'POST':
-            return self.response(httplib.BAD_REQUEST, '{"error":"invalid_client"}')
+            return self.test_response(httplib.BAD_REQUEST, '{"error":"invalid_client"}')
 
     def _token_UNAUTHORIZED_CLIENT(self, method, url, body, headers):
         if method == 'POST':
-            return self.response(httplib.UNAUTHORIZED, '{"error":"unauthorized_client"}')
+            return self.test_response(httplib.UNAUTHORIZED, '{"error":"unauthorized_client"}')
+
+    def _1_0_servers_INVALID_CLIENT(self, method, url, body, headers):
+        return self.test_response(httplib.BAD_REQUEST, '{"error":"invalid_client"}')
+
+    def _1_0_servers_UNAUTHORIZED_CLIENT(self, method, url, body, headers):
+        return self.test_response(httplib.UNAUTHORIZED, '{"error":"unauthorized_client"}')
 
     def _1_0_images(self, method, url, body, headers):
         if method == 'GET':
-            return self.response(httplib.OK, self.fixtures.load('list_images.json'))
+            return self.test_response(httplib.OK, self.fixtures.load('list_images.json'))
 
     def _1_0_servers(self, method, url, body, headers):
         if method == 'GET':
-            return self.response(httplib.OK, self.fixtures.load('list_servers.json'))
+            return self.test_response(httplib.OK, self.fixtures.load('list_servers.json'))
         elif method == 'POST':
             body = json.loads(body)
             encoded = base64.b64encode(b(USER_DATA)).decode('ascii')
 
             if 'user_data' in body and body['user_data'] != encoded:
                 data = '{"error_name":"dodgy user data", "errors": ["User data not encoded
properly"]}'
-                return self.response(httplib.BAD_REQUEST, data)
+                return self.test_response(httplib.BAD_REQUEST, data)
             if body.get('zone', '') == 'zon-remk1':
                 node = json.loads(
                     self.fixtures.load('create_server_gb1_b.json'))
@@ -281,30 +288,30 @@ class BrightboxMockHttp(MockHttp):
                                          for x in body['server_groups']]
             if 'user_data' in body:
                 node['user_data'] = body['user_data']
-            return self.response(httplib.ACCEPTED, json.dumps(node))
+            return self.test_response(httplib.ACCEPTED, json.dumps(node))
 
     def _1_0_servers_srv_xvpn7(self, method, url, body, headers):
         if method == 'DELETE':
-            return self.response(httplib.ACCEPTED, '')
+            return self.test_response(httplib.ACCEPTED, '')
 
     def _1_0_server_types(self, method, url, body, headers):
         if method == 'GET':
-            return self.response(httplib.OK, self.fixtures.load('list_server_types.json'))
+            return self.test_response(httplib.OK, self.fixtures.load('list_server_types.json'))
 
     def _1_0_zones(self, method, url, body, headers):
         if method == 'GET':
             if headers['Host'] == 'api.gbt.brightbox.com':
-                return self.response(httplib.OK, "{}")
+                return self.test_response(httplib.OK, "{}")
             else:
-                return self.response(httplib.OK, self.fixtures.load('list_zones.json'))
+                return self.test_response(httplib.OK, self.fixtures.load('list_zones.json'))
 
     def _2_0_zones(self, method, url, body, headers):
         data = '{"error_name":"unrecognised_endpoint", "errors": ["The request was for an
unrecognised API endpoint"]}'
-        return self.response(httplib.BAD_REQUEST, data)
+        return self.test_response(httplib.BAD_REQUEST, data)
 
     def _1_0_cloud_ips(self, method, url, body, headers):
         if method == 'GET':
-            return self.response(httplib.OK, self.fixtures.load('list_cloud_ips.json'))
+            return self.test_response(httplib.OK, self.fixtures.load('list_cloud_ips.json'))
         elif method == 'POST':
             if body:
                 body = json.loads(body)
@@ -313,32 +320,32 @@ class BrightboxMockHttp(MockHttp):
 
             if 'reverse_dns' in body:
                 node['reverse_dns'] = body['reverse_dns']
-            return self.response(httplib.ACCEPTED, json.dumps(node))
+            return self.test_response(httplib.ACCEPTED, json.dumps(node))
 
     def _1_0_cloud_ips_cip_jsjc5(self, method, url, body, headers):
         if method == 'DELETE':
-            return self.response(httplib.OK, '')
+            return self.test_response(httplib.OK, '')
         elif method == 'PUT':
             body = json.loads(body)
             if body.get('reverse_dns', None) == 'fred.co.uk':
-                return self.response(httplib.OK, '')
+                return self.test_response(httplib.OK, '')
             else:
-                return self.response(httplib.BAD_REQUEST, '{"error_name":"bad dns", "errors":
["Bad dns"]}')
+                return self.test_response(httplib.BAD_REQUEST, '{"error_name":"bad dns",
"errors": ["Bad dns"]}')
 
     def _1_0_cloud_ips_cip_jsjc5_map(self, method, url, body, headers):
         if method == 'POST':
             body = json.loads(body)
             if 'destination' in body:
-                return self.response(httplib.ACCEPTED, '')
+                return self.test_response(httplib.ACCEPTED, '')
             else:
                 data = '{"error_name":"bad destination", "errors": ["Bad destination"]}'
-                return self.response(httplib.BAD_REQUEST, data)
+                return self.test_response(httplib.BAD_REQUEST, data)
 
     def _1_0_cloud_ips_cip_jsjc5_unmap(self, method, url, body, headers):
         if method == 'POST':
-            return self.response(httplib.ACCEPTED, '')
+            return self.test_response(httplib.ACCEPTED, '')
 
-    def response(self, status, body):
+    def test_response(self, status, body):
         return (status, body, {'content-type': 'application/json'}, httplib.responses[status])
 
 


Mime
View raw message