libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [23/33] libcloud git commit: Fix digital ocean tests
Date Tue, 05 Apr 2016 11:17:14 GMT
Fix digital ocean tests


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

Branch: refs/heads/requests
Commit: b164cfc793f99ed6c0e52f2e681abd9dfe744a50
Parents: aac34de
Author: anthony-shaw <anthony.p.shaw@gmail.com>
Authored: Wed Mar 30 15:46:40 2016 +1100
Committer: anthony-shaw <anthony.p.shaw@gmail.com>
Committed: Wed Mar 30 15:46:40 2016 +1100

----------------------------------------------------------------------
 libcloud/common/base.py                | 12 ++---
 libcloud/test/__init__.py              |  2 +-
 libcloud/test/dns/test_digitalocean.py | 70 ++++++++++++++---------------
 3 files changed, 42 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/b164cfc7/libcloud/common/base.py
----------------------------------------------------------------------
diff --git a/libcloud/common/base.py b/libcloud/common/base.py
index 40d9c39..67d66b1 100644
--- a/libcloud/common/base.py
+++ b/libcloud/common/base.py
@@ -36,11 +36,10 @@ import requests
 
 import libcloud
 
-from libcloud.utils.py3 import PY3, PY25
+from libcloud.utils.py3 import PY25
 from libcloud.utils.py3 import httplib
 from libcloud.utils.py3 import urlparse
 from libcloud.utils.py3 import urlencode
-from libcloud.utils.py3 import b
 
 from libcloud.utils.misc import lowercase_keys, retry
 from libcloud.utils.compression import decompress_data
@@ -153,7 +152,7 @@ class Response(object):
         self.error = response.reason
         self.status = response.status_code
 
-        self.body = response.text
+        self.body = response.text if response.text is not None else ''
 
         if not self.success():
             raise exception_from_message(code=self.status,
@@ -170,7 +169,7 @@ class Response(object):
         :return: Parsed body.
         :rtype: ``str``
         """
-        return self.body
+        return self.body if self.body is not None else ''
 
     def parse_error(self):
         """
@@ -227,7 +226,8 @@ class JsonResponse(Response):
     """
 
     def parse_body(self):
-        if len(self.body) == 0 and not self.parse_zero_length_body:
+        if self.body is not None and \
+        len(self.body) == 0 and not self.parse_zero_length_body:
             return self.body
 
         try:
@@ -249,7 +249,7 @@ class XmlResponse(Response):
 
     def parse_body(self):
         if len(self.body) == 0 and not self.parse_zero_length_body:
-            return self.body
+            return self.body if self.body is not None else ''
 
         try:
             body = ET.XML(self.body)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b164cfc7/libcloud/test/__init__.py
----------------------------------------------------------------------
diff --git a/libcloud/test/__init__.py b/libcloud/test/__init__.py
index af4a3b3..17e1f2f 100644
--- a/libcloud/test/__init__.py
+++ b/libcloud/test/__init__.py
@@ -79,7 +79,7 @@ class MockResponse(object):
     A mock HTTPResponse
     """
     headers = {}
-    body = None
+    body = ''
     status = 0
     reason = ''
     version = 11

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b164cfc7/libcloud/test/dns/test_digitalocean.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_digitalocean.py b/libcloud/test/dns/test_digitalocean.py
index 8046fda..33d0cb9 100644
--- a/libcloud/test/dns/test_digitalocean.py
+++ b/libcloud/test/dns/test_digitalocean.py
@@ -96,7 +96,7 @@ class DigitalOceanDNSTests(LibcloudTestCase):
 class DigitalOceanDNSMockHttp(MockHttpTestCase):
     fixtures = DNSFileFixtures('digitalocean')
 
-    response = {
+    response_map = {
         None: httplib.OK,
         'CREATE': httplib.CREATED,
         'DELETE': httplib.NO_CONTENT,
@@ -108,103 +108,103 @@ class DigitalOceanDNSMockHttp(MockHttpTestCase):
 
     def _v2_domains(self, method, url, body, headers):
         body = self.fixtures.load('_v2_domains.json')
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
     def _v2_domains_CREATE(self, method, url, body, headers):
         body = self.fixtures.load('_v2_domains_CREATE.json')
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
     def _v2_domains_EMPTY(self, method, url, body, headers):
         body = self.fixtures.load('_v2_domains_EMPTY.json')
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
     def _v2_domains_UNAUTHORIZED(self, method, url, body, headers):
         body = self.fixtures.load('_v2_domains_UNAUTHORIZED.json')
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
     def _v2_domains_testdomain(self, method, url, body, headers):
         body = self.fixtures.load('_v2_domains_testdomain.json')
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
     def _v2_domains_testdomain_DELETE(self, method, url, body, headers):
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
     def _v2_domains_testdomain_NOT_FOUND(self, method, url, body, headers):
         body = self.fixtures.load('_v2_domains_testdomain_NOT_FOUND.json')
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
     def _v2_domains_testdomain_records(self, method, url, body, headers):
         body = self.fixtures.load('_v2_domains_testdomain_records.json')
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
     def _v2_domains_testdomain_records_CREATE(self, method, url,
                                               body, headers):
         body = self.fixtures.load('_v2_domains_testdomain_records_CREATE.json')
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
     def _v2_domains_testdomain_records_1234560(
             self, method, url, body, headers):
         body = self.fixtures.load(
             '_v2_domains_testdomain_records_1234560.json')
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
     def _v2_domains_testdomain_records_1234561(
             self, method, url, body, headers):
         body = self.fixtures.load(
             '_v2_domains_testdomain_records_1234561.json')
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
     def _v2_domains_testdomain_records_1234562(
             self, method, url, body, headers):
         body = self.fixtures.load(
             '_v2_domains_testdomain_records_1234562.json')
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
     def _v2_domains_testdomain_records_1234563(
             self, method, url, body, headers):
         body = self.fixtures.load(
             '_v2_domains_testdomain_records_1234563.json')
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
     def _v2_domains_testdomain_records_1234564(
             self, method, url, body, headers):
         body = self.fixtures.load(
             '_v2_domains_testdomain_records_1234564.json')
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
     def _v2_domains_testdomain_records_1234564_DELETE(
             self, method, url, body, headers):
         self.type = 'DELETE'
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
     def _v2_domains_testdomain_records_1234564_NOT_FOUND(
             self, method, url, body, headers):
         body = self.fixtures.load(
             '_v2_domains_testdomain_records_1234564_NOT_FOUND.json')
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
     def _v2_domains_testdomain_records_1234564_UPDATE(
             self, method, url, body, headers):
         body = self.fixtures.load(
             '_v2_domains_testdomain_records_1234564_UPDATE.json')
-        return (self.response[self.type], body, {},
-                httplib.responses[self.response[self.type]])
+        return (self.response_map[self.type], body, {},
+                httplib.responses[self.response_map[self.type]])
 
 if __name__ == '__main__':
     sys.exit(unittest.main())


Mime
View raw message