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:
Cyril Roelandt
2014-02-14 16:31:55 +01:00
parent 97957eae21
commit 117767df47

View File

@@ -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)