libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [2/3] libcloud git commit: fix and also support for StringIO as enable_debug file handle argument
Date Wed, 18 Jan 2017 04:42:01 GMT
fix and also support for StringIO as enable_debug file handle argument


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

Branch: refs/heads/trunk
Commit: 57c5929bcab251560bacd1fd7c067a27bf6ed9ac
Parents: ed6d012
Author: Anthony Shaw <anthonyshaw@apache.org>
Authored: Wed Jan 18 15:20:56 2017 +1100
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Wed Jan 18 15:20:56 2017 +1100

----------------------------------------------------------------------
 libcloud/test/test_logging_connection.py | 10 ++++++++--
 libcloud/utils/loggingconnection.py      | 15 +++++++--------
 2 files changed, 15 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/57c5929b/libcloud/test/test_logging_connection.py
----------------------------------------------------------------------
diff --git a/libcloud/test/test_logging_connection.py b/libcloud/test/test_logging_connection.py
index 3824838..e7088a4 100644
--- a/libcloud/test/test_logging_connection.py
+++ b/libcloud/test/test_logging_connection.py
@@ -20,10 +20,14 @@ import requests_mock
 import libcloud
 from libcloud.test import unittest
 from libcloud.common.base import Connection
+from libcloud.httplib_ssl import LibcloudConnection
 from libcloud.utils.loggingconnection import LoggingConnection
 
 
 class TestLoggingConnection(unittest.TestCase):
+    def tearDown(self):
+        Connection.conn_class = LibcloudConnection
+
     def test_debug_method_uses_log_class(self):
         with StringIO() as fh:
             libcloud.enable_debug(fh)
@@ -39,9 +43,11 @@ class TestLoggingConnection(unittest.TestCase):
             self.assertEqual(conn.connection.host, 'http://test.com')
             with requests_mock.mock() as m:
                 m.get('http://test.com/test', text='data')
-                response = conn.request('/test')
-        self.assertEqual(response.body, 'data')
+                conn.request('/test')
+            log = fh.getvalue()
         self.assertTrue(isinstance(conn.connection, LoggingConnection))
+        self.assertIn('-i -X GET', log)
+        self.assertIn('data', log)
 
 if __name__ == '__main__':
     sys.exit(unittest.main())

http://git-wip-us.apache.org/repos/asf/libcloud/blob/57c5929b/libcloud/utils/loggingconnection.py
----------------------------------------------------------------------
diff --git a/libcloud/utils/loggingconnection.py b/libcloud/utils/loggingconnection.py
index adea0ba..1e3ff41 100644
--- a/libcloud/utils/loggingconnection.py
+++ b/libcloud/utils/loggingconnection.py
@@ -27,7 +27,7 @@ import os
 
 from libcloud.common.base import (LibcloudConnection,
                                   HttpLibResponseProxy)
-from libcloud.utils.py3 import u
+from libcloud.utils.py3 import _real_unicode as u
 
 from libcloud.utils.misc import lowercase_keys
 from libcloud.utils.compression import decompress_data
@@ -42,7 +42,6 @@ class LoggingConnection(LibcloudConnection):
     """
 
     protocol = 'https'
-    port = None
 
     log = None
     http_proxy_used = False
@@ -133,24 +132,24 @@ class LoggingConnection(LibcloudConnection):
             cmd.extend(["--data-binary", pquote(body)])
 
         cmd.extend(["--compress"])
-        cmd.extend([pquote("%s://%s:%d%s" % (self.protocol, self.host,
-                                             self.port, url))])
+        cmd.extend([pquote("%s%s" % (self.host, url))])
         return " ".join(cmd)
 
     def getresponse(self):
         original_response = LibcloudConnection.getresponse(self)
         if self.log is not None:
             rv = self._log_response(HttpLibResponseProxy(original_response))
-            self.log.write(rv + "\n")
+            self.log.write(u(rv + "\n"))
             self.log.flush()
         return original_response
 
-    def request(self, method, url, body=None, headers=None):
+    def request(self, method, url, body=None, headers=None, **kwargs):
         headers.update({'X-LC-Request-ID': str(id(self))})
         if self.log is not None:
             pre = "# -------- begin %d request ----------\n" % id(self)
-            self.log.write(pre +
-                           self._log_curl(method, url, body, headers) + "\n")
+            self.log.write(u(pre +
+                             self._log_curl(method, url, body, headers) +
+                             "\n"))
             self.log.flush()
         return LibcloudConnection.request(self, method, url, body,
                                           headers)


Mime
View raw message