本文整理匯總了Python中quantumclient.client.HTTPClient.request方法的典型用法代碼示例。如果您正苦於以下問題:Python HTTPClient.request方法的具體用法?Python HTTPClient.request怎麽用?Python HTTPClient.request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類quantumclient.client.HTTPClient
的用法示例。
在下文中一共展示了HTTPClient.request方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: CLITestAuthKeystone
# 需要導入模塊: from quantumclient.client import HTTPClient [as 別名]
# 或者: from quantumclient.client.HTTPClient import request [as 別名]
class CLITestAuthKeystone(unittest.TestCase):
def setUp(self):
"""Prepare the test environment"""
self.mox = mox.Mox()
self.client = HTTPClient(username=USERNAME, tenant_name=TENANT_NAME,
password=PASSWORD, auth_url=AUTH_URL,
region_name=REGION)
def tearDown(self):
"""Clear the test environment"""
self.mox.VerifyAll()
self.mox.UnsetStubs()
def test_get_token(self):
self.mox.StubOutWithMock(self.client, "request")
res200 = self.mox.CreateMock(httplib2.Response)
res200.status = 200
self.client.request(AUTH_URL + '/tokens', 'POST',
body=IsA(str), headers=IsA(dict)).\
AndReturn((res200, json.dumps(KS_TOKEN_RESULT)))
self.client.request(StrContains(ENDPOINT_URL + '/resource'), 'GET',
headers=ContainsKeyValue('X-Auth-Token', TOKEN)).\
AndReturn((res200, ''))
self.mox.ReplayAll()
self.client.do_request('/resource', 'GET')
self.assertEqual(self.client.endpoint_url, ENDPOINT_URL)
self.assertEqual(self.client.auth_token, TOKEN)
self.assertEqual(self.client.token_retrieved, True)
def test_already_token_retrieved(self):
self.mox.StubOutWithMock(self.client, "request")
self.client.auth_token = TOKEN
self.client.endpoint_url = ENDPOINT_URL
self.client.token_retrieved = True
res200 = self.mox.CreateMock(httplib2.Response)
res200.status = 200
self.client.request(StrContains(ENDPOINT_URL + '/resource'), 'GET',
headers=ContainsKeyValue('X-Auth-Token', TOKEN)).\
AndReturn((res200, ''))
self.mox.ReplayAll()
self.client.do_request('/resource', 'GET')
def test_refresh_token(self):
self.mox.StubOutWithMock(self.client, "request")
self.client.auth_token = TOKEN
self.client.endpoint_url = ENDPOINT_URL
self.client.token_retrieved = True
res200 = self.mox.CreateMock(httplib2.Response)
res200.status = 200
res401 = self.mox.CreateMock(httplib2.Response)
res401.status = 401
# If a token is expired, quantum server retruns 401
self.client.request(StrContains(ENDPOINT_URL + '/resource'), 'GET',
headers=ContainsKeyValue('X-Auth-Token', TOKEN)).\
AndReturn((res401, ''))
self.client.request(AUTH_URL + '/tokens', 'POST',
body=IsA(str), headers=IsA(dict)).\
AndReturn((res200, json.dumps(KS_TOKEN_RESULT)))
self.client.request(StrContains(ENDPOINT_URL + '/resource'), 'GET',
headers=ContainsKeyValue('X-Auth-Token', TOKEN)).\
AndReturn((res200, ''))
self.mox.ReplayAll()
self.client.do_request('/resource', 'GET')
示例2: CLITestAuthKeystone
# 需要導入模塊: from quantumclient.client import HTTPClient [as 別名]
# 或者: from quantumclient.client.HTTPClient import request [as 別名]
class CLITestAuthKeystone(testtools.TestCase):
def setUp(self):
"""Prepare the test environment."""
super(CLITestAuthKeystone, self).setUp()
self.mox = mox.Mox()
self.client = HTTPClient(username=USERNAME, tenant_name=TENANT_NAME,
password=PASSWORD, auth_url=AUTH_URL,
region_name=REGION)
self.addCleanup(self.mox.VerifyAll)
self.addCleanup(self.mox.UnsetStubs)
def test_get_token(self):
self.mox.StubOutWithMock(self.client, "request")
res200 = self.mox.CreateMock(httplib2.Response)
res200.status = 200
self.client.request(AUTH_URL + '/tokens', 'POST',
body=IsA(str), headers=IsA(dict)).\
AndReturn((res200, json.dumps(KS_TOKEN_RESULT)))
self.client.request(StrContains(ENDPOINT_URL + '/resource'), 'GET',
headers=ContainsKeyValue('X-Auth-Token', TOKEN)).\
AndReturn((res200, ''))
self.mox.ReplayAll()
self.client.do_request('/resource', 'GET')
self.assertEqual(self.client.endpoint_url, ENDPOINT_URL)
self.assertEqual(self.client.auth_token, TOKEN)
def test_refresh_token(self):
self.mox.StubOutWithMock(self.client, "request")
self.client.auth_token = TOKEN
self.client.endpoint_url = ENDPOINT_URL
res200 = self.mox.CreateMock(httplib2.Response)
res200.status = 200
res401 = self.mox.CreateMock(httplib2.Response)
res401.status = 401
# If a token is expired, quantum server retruns 401
self.client.request(StrContains(ENDPOINT_URL + '/resource'), 'GET',
headers=ContainsKeyValue('X-Auth-Token', TOKEN)).\
AndReturn((res401, ''))
self.client.request(AUTH_URL + '/tokens', 'POST',
body=IsA(str), headers=IsA(dict)).\
AndReturn((res200, json.dumps(KS_TOKEN_RESULT)))
self.client.request(StrContains(ENDPOINT_URL + '/resource'), 'GET',
headers=ContainsKeyValue('X-Auth-Token', TOKEN)).\
AndReturn((res200, ''))
self.mox.ReplayAll()
self.client.do_request('/resource', 'GET')
def test_get_endpoint_url(self):
self.mox.StubOutWithMock(self.client, "request")
self.client.auth_token = TOKEN
res200 = self.mox.CreateMock(httplib2.Response)
res200.status = 200
self.client.request(StrContains(AUTH_URL +
'/tokens/%s/endpoints' % TOKEN), 'GET',
headers=IsA(dict)). \
AndReturn((res200, json.dumps(ENDPOINTS_RESULT)))
self.client.request(StrContains(ENDPOINT_URL + '/resource'), 'GET',
headers=ContainsKeyValue('X-Auth-Token', TOKEN)). \
AndReturn((res200, ''))
self.mox.ReplayAll()
self.client.do_request('/resource', 'GET')
def test_get_endpoint_url_other(self):
self.client = HTTPClient(username=USERNAME, tenant_name=TENANT_NAME,
password=PASSWORD, auth_url=AUTH_URL,
region_name=REGION, endpoint_type='otherURL')
self.mox.StubOutWithMock(self.client, "request")
self.client.auth_token = TOKEN
res200 = self.mox.CreateMock(httplib2.Response)
res200.status = 200
self.client.request(StrContains(AUTH_URL +
'/tokens/%s/endpoints' % TOKEN), 'GET',
headers=IsA(dict)). \
AndReturn((res200, json.dumps(ENDPOINTS_RESULT)))
self.mox.ReplayAll()
self.assertRaises(exceptions.EndpointTypeNotFound,
self.client.do_request,
'/resource',
'GET')
def test_get_endpoint_url_failed(self):
self.mox.StubOutWithMock(self.client, "request")
self.client.auth_token = TOKEN
res200 = self.mox.CreateMock(httplib2.Response)
res200.status = 200
#.........這裏部分代碼省略.........