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,21 +46,17 @@ 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(
|
conn.request.side_effect = Exception("stop")
|
||||||
mock.patch.object(client, 'get_connection'),
|
get_conn.return_value = conn
|
||||||
mock.patch.object(client, 'auth_token')
|
try:
|
||||||
) as (get_conn, auth_token):
|
client._http_request('/v1/resources', 'GET')
|
||||||
conn.request.side_effect = Exception("stop")
|
except Exception:
|
||||||
get_conn.return_value = conn
|
pass
|
||||||
auth_token.return_value = "token"
|
|
||||||
try:
|
|
||||||
client._http_request('/v1/resources', 'GET')
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
conn.request.assert_called_once_with('GET', (self.url.rstrip('/') +
|
conn.request.assert_called_once_with('GET', (self.url.rstrip('/') +
|
||||||
'/v1/resources'),
|
'/v1/resources'),
|
||||||
headers=mock.ANY)
|
headers=mock.ANY)
|
||||||
|
|||||||
Reference in New Issue
Block a user