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
This commit is contained in:
		| @@ -13,7 +13,6 @@ | |||||||
| #    License for the specific language governing permissions and limitations | #    License for the specific language governing permissions and limitations | ||||||
| #    under the License. | #    under the License. | ||||||
|  |  | ||||||
| import contextlib |  | ||||||
| import mock | import mock | ||||||
|  |  | ||||||
| from ceilometerclient.common import http | from ceilometerclient.common import http | ||||||
| @@ -47,17 +46,13 @@ class HttpClientTest(utils.BaseTestCase): | |||||||
|         client = http.HTTPClient(self.url) |         client = http.HTTPClient(self.url) | ||||||
|         self.assertIsNotNone(client.get_connection()) |         self.assertIsNotNone(client.get_connection()) | ||||||
|  |  | ||||||
|     def test_url_generation_with_proxy(self): |     @mock.patch.object(http.HTTPClient, 'get_connection') | ||||||
|         client = http.HTTPClient(self.url) |     def test_url_generation_with_proxy(self, get_conn): | ||||||
|  |         client = http.HTTPClient(self.url, token=lambda: 'token') | ||||||
|         client.proxy_url = "http://localhost:3128/" |         client.proxy_url = "http://localhost:3128/" | ||||||
|         conn = mock.MagicMock() |         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") |         conn.request.side_effect = Exception("stop") | ||||||
|         get_conn.return_value = conn |         get_conn.return_value = conn | ||||||
|             auth_token.return_value = "token" |  | ||||||
|         try: |         try: | ||||||
|             client._http_request('/v1/resources', 'GET') |             client._http_request('/v1/resources', 'GET') | ||||||
|         except Exception: |         except Exception: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Cyril Roelandt
					Cyril Roelandt