From 117767df47a19c2db9f79b56ad4a0a8a31007410 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Fri, 14 Feb 2014 16:31:55 +0100 Subject: [PATCH] test_url_generation_with_proxy: do not use contextlib.nested() This method does not exist in Python 3, use the "@mock.patch.object" decorator instead. Change-Id: Ic45fea1553320c61be284a9397b54fd32f7d30ef --- ceilometerclient/tests/test_http.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/ceilometerclient/tests/test_http.py b/ceilometerclient/tests/test_http.py index 0c3c0912..239bb861 100644 --- a/ceilometerclient/tests/test_http.py +++ b/ceilometerclient/tests/test_http.py @@ -13,7 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import contextlib import mock from ceilometerclient.common import http @@ -47,21 +46,17 @@ class HttpClientTest(utils.BaseTestCase): client = http.HTTPClient(self.url) self.assertIsNotNone(client.get_connection()) - def test_url_generation_with_proxy(self): - client = http.HTTPClient(self.url) + @mock.patch.object(http.HTTPClient, 'get_connection') + def test_url_generation_with_proxy(self, get_conn): + client = http.HTTPClient(self.url, token=lambda: 'token') client.proxy_url = "http://localhost:3128/" conn = mock.MagicMock() - with contextlib.nested( - mock.patch.object(client, 'get_connection'), - mock.patch.object(client, 'auth_token') - ) as (get_conn, auth_token): - conn.request.side_effect = Exception("stop") - get_conn.return_value = conn - auth_token.return_value = "token" - try: - client._http_request('/v1/resources', 'GET') - except Exception: - pass + conn.request.side_effect = Exception("stop") + get_conn.return_value = conn + try: + client._http_request('/v1/resources', 'GET') + except Exception: + pass conn.request.assert_called_once_with('GET', (self.url.rstrip('/') + '/v1/resources'), headers=mock.ANY)