Repository: libcloud Updated Branches: refs/heads/trunk 0f831f561 -> 419c69441
create a test to prove LIBCLOUD-887 is a bug Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/ed6d012a Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/ed6d012a Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/ed6d012a Branch: refs/heads/trunk Commit: ed6d012aab1c8bad83f66bf4ed4621b1d5fe0d27 Parents: 0f831f5 Author: Anthony Shaw <[email protected]> Authored: Wed Jan 18 14:24:53 2017 +1100 Committer: Anthony Shaw <[email protected]> Committed: Wed Jan 18 14:24:53 2017 +1100 ---------------------------------------------------------------------- libcloud/test/test_logging_connection.py | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/ed6d012a/libcloud/test/test_logging_connection.py ---------------------------------------------------------------------- diff --git a/libcloud/test/test_logging_connection.py b/libcloud/test/test_logging_connection.py new file mode 100644 index 0000000..3824838 --- /dev/null +++ b/libcloud/test/test_logging_connection.py @@ -0,0 +1,47 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +from io import StringIO +import requests_mock + +import libcloud +from libcloud.test import unittest +from libcloud.common.base import Connection +from libcloud.utils.loggingconnection import LoggingConnection + + +class TestLoggingConnection(unittest.TestCase): + def test_debug_method_uses_log_class(self): + with StringIO() as fh: + libcloud.enable_debug(fh) + conn = Connection(timeout=10) + conn.connect() + self.assertTrue(isinstance(conn.connection, LoggingConnection)) + + def test_debug_log_class_handles_request(self): + with StringIO() as fh: + libcloud.enable_debug(fh) + conn = Connection(url='http://test.com/') + conn.connect() + 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') + self.assertTrue(isinstance(conn.connection, LoggingConnection)) + +if __name__ == '__main__': + sys.exit(unittest.main())
