本文整理汇总了Python中ovh.client.Client.call方法的典型用法代码示例。如果您正苦于以下问题:Python Client.call方法的具体用法?Python Client.call怎么用?Python Client.call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ovh.client.Client
的用法示例。
在下文中一共展示了Client.call方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_call_no_sign
# 需要导入模块: from ovh.client import Client [as 别名]
# 或者: from ovh.client.Client import call [as 别名]
def test_call_no_sign(self, m_req):
m_res = m_req.return_value
m_json = m_res.json.return_value
api = Client(ENDPOINT, APPLICATION_KEY, APPLICATION_SECRET)
# nominal
m_res.status_code = 200
self.assertEqual(m_json, api.call(FAKE_METHOD, FAKE_PATH, None, False))
m_req.assert_called_once_with(
FAKE_METHOD, BASE_URL+'/unit/test',
headers={'X-Ovh-Application': APPLICATION_KEY}, data=''
)
m_req.reset_mock()
# data, nominal
m_res.status_code = 200
data = {'key': 'value'}
j_data = json.dumps(data)
self.assertEqual(m_json, api.call(FAKE_METHOD, FAKE_PATH, data, False))
m_req.assert_called_once_with(
FAKE_METHOD, BASE_URL+'/unit/test',
headers={
'X-Ovh-Application': APPLICATION_KEY,
'Content-type': 'application/json',
}, data=j_data
)
m_req.reset_mock()
# request fails, somehow
m_req.side_effect = requests.RequestException
self.assertRaises(HTTPError, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_req.side_effect = None
# response decoding fails
m_res.json.side_effect = ValueError
self.assertRaises(InvalidResponse, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.json.side_effect = None
# HTTP errors
m_res.status_code = 404
self.assertRaises(ResourceNotFoundError, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.status_code = 400
self.assertRaises(BadParametersError, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.status_code = 409
self.assertRaises(ResourceConflictError, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.status_code = 0
self.assertRaises(NetworkError, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.status_code = 99
self.assertRaises(APIError, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.status_code = 306
self.assertRaises(APIError, api.call, FAKE_METHOD, FAKE_PATH, None, False)
示例2: test_call_query_id
# 需要导入模块: from ovh.client import Client [as 别名]
# 或者: from ovh.client.Client import call [as 别名]
def test_call_query_id(self, m_req):
m_res = m_req.return_value
m_json = m_res.json.return_value
m_res.headers = {"X-OVH-QUERYID": "FR.test1"}
api = Client(ENDPOINT, APPLICATION_KEY, APPLICATION_SECRET)
m_res.status_code = 99
self.assertRaises(APIError, api.call, FAKE_METHOD, FAKE_PATH, None, False)
try:
api.call(FAKE_METHOD, FAKE_PATH, None, False)
self.assertEqual(0, 1) # should fail as method have to raise APIError
except APIError as e:
self.assertEqual(e.query_id, "FR.test1")
示例3: test_call_signature
# 需要导入模块: from ovh.client import Client [as 别名]
# 或者: from ovh.client.Client import call [as 别名]
def test_call_signature(self, m_time_delta, m_req):
m_res = m_req.return_value
m_json = m_res.json.return_value
m_time_delta.return_value = 42
api = Client(ENDPOINT, APPLICATION_KEY, APPLICATION_SECRET, CONSUMER_KEY)
# nominal
m_res.status_code = 200
self.assertEqual(m_json, api.call(FAKE_METHOD, FAKE_PATH, None, True))
m_time_delta.assert_called_once_with()
m_req.assert_called_once_with(
FAKE_METHOD, BASE_URL+'/unit/test',
headers={
'X-Ovh-Consumer': CONSUMER_KEY,
'X-Ovh-Application': APPLICATION_KEY,
'X-Ovh-Signature': '$1$16ae5ba8c63841b1951575be905867991d5f49dc',
'X-Ovh-Timestamp': '1404395931',
}, data=''
)
m_time_delta.reset_mock()
m_req.reset_mock()
# data, nominal
data = data={'some': 'random', 'data': 42}
m_res.status_code = 200
self.assertEqual(m_json, api.call(FAKE_METHOD, FAKE_PATH, data, True))
m_time_delta.assert_called_once_with()
m_req.assert_called_once_with(
FAKE_METHOD, BASE_URL+'/unit/test',
headers={
'X-Ovh-Consumer': CONSUMER_KEY,
'X-Ovh-Application': APPLICATION_KEY,
'Content-type': 'application/json',
'X-Ovh-Timestamp': '1404395931',
'X-Ovh-Signature': '$1$70e04549d8b9e3d7f499274090710206f8c87a78',
}, data=json.dumps(data)
)
m_time_delta.reset_mock()
m_req.reset_mock()
# errors
api = Client(ENDPOINT, APPLICATION_KEY, None, CONSUMER_KEY)
self.assertRaises(InvalidKey, api.call, FAKE_METHOD, FAKE_PATH, None, True)
api = Client(ENDPOINT, APPLICATION_KEY, APPLICATION_SECRET, None)
self.assertRaises(InvalidKey, api.call, FAKE_METHOD, FAKE_PATH, None, True)
示例4: test_call_signature
# 需要导入模块: from ovh.client import Client [as 别名]
# 或者: from ovh.client.Client import call [as 别名]
def test_call_signature(self, m_time_delta, m_req):
m_res = m_req.return_value
m_json = m_res.json.return_value
m_time_delta.return_value = 42
api = Client(ENDPOINT, APPLICATION_KEY, APPLICATION_SECRET, CONSUMER_KEY)
# nominal
m_res.status_code = 200
self.assertEqual(m_json, api.call(FAKE_METHOD, FAKE_PATH, None, True))
m_time_delta.assert_called_once_with()
m_req.assert_called_once_with(
FAKE_METHOD, BASE_URL+'/unit/test',
headers={
'X-Ovh-Consumer': CONSUMER_KEY,
'X-Ovh-Application': APPLICATION_KEY,
'X-Ovh-Signature': '$1$16ae5ba8c63841b1951575be905867991d5f49dc',
'X-Ovh-Timestamp': '1404395931',
}, data=''
)
m_time_delta.reset_mock()
m_req.reset_mock()
# data, nominal
data = OrderedDict([('some', 'random'), ('data', 42)])
m_res.status_code = 200
self.assertEqual(m_json, api.call(FAKE_METHOD, FAKE_PATH, data, True))
m_time_delta.assert_called_once_with()
m_req.assert_called_once_with(
FAKE_METHOD, BASE_URL+'/unit/test',
headers={
'X-Ovh-Consumer': CONSUMER_KEY,
'X-Ovh-Application': APPLICATION_KEY,
'Content-type': 'application/json',
'X-Ovh-Timestamp': '1404395931',
'X-Ovh-Signature': '$1$9acb1ac0120006d16261a635aed788e83ab172d2',
}, data=json.dumps(data)
)
m_time_delta.reset_mock()
m_req.reset_mock()
# Overwrite configuration to avoid interfering with any local config
from ovh.client import config
try:
from ConfigParser import RawConfigParser
except ImportError:
# Python 3
from configparser import RawConfigParser
self._orig_config = config.config
config.config = RawConfigParser()
# errors
try:
api = Client(ENDPOINT, APPLICATION_KEY, None, CONSUMER_KEY)
self.assertRaises(InvalidKey, api.call, FAKE_METHOD, FAKE_PATH, None, True)
api = Client(ENDPOINT, APPLICATION_KEY, APPLICATION_SECRET, None)
self.assertRaises(InvalidKey, api.call, FAKE_METHOD, FAKE_PATH, None, True)
finally:
# Restore configuration
config.config = self._orig_config
示例5: test_call_no_sign
# 需要导入模块: from ovh.client import Client [as 别名]
# 或者: from ovh.client.Client import call [as 别名]
def test_call_no_sign(self, m_req):
m_res = m_req.return_value
m_json = m_res.json.return_value
api = Client(ENDPOINT, APPLICATION_KEY, APPLICATION_SECRET)
# nominal
m_res.status_code = 200
self.assertEqual(m_json, api.call(FAKE_METHOD, FAKE_PATH, None, False))
m_req.assert_called_once_with(
FAKE_METHOD, BASE_URL+'/unit/test',
headers={'X-Ovh-Application': APPLICATION_KEY}, data='',
timeout=TIMEOUT
)
m_req.reset_mock()
# data, nominal
m_res.status_code = 200
data = {'key': 'value'}
j_data = json.dumps(data)
self.assertEqual(m_json, api.call(FAKE_METHOD, FAKE_PATH, data, False))
m_req.assert_called_once_with(
FAKE_METHOD, BASE_URL+'/unit/test',
headers={
'X-Ovh-Application': APPLICATION_KEY,
'Content-type': 'application/json',
}, data=j_data, timeout=TIMEOUT
)
m_req.reset_mock()
# request fails, somehow
m_req.side_effect = requests.RequestException
self.assertRaises(HTTPError, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_req.side_effect = None
# response decoding fails
m_res.json.side_effect = ValueError
self.assertRaises(InvalidResponse, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.json.side_effect = None
# HTTP errors
m_res.status_code = 404
self.assertRaises(ResourceNotFoundError, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.status_code = 403
m_res.json.return_value = {'errorCode': "NOT_GRANTED_CALL"}
self.assertRaises(NotGrantedCall, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.status_code = 403
m_res.json.return_value = {'errorCode': "NOT_CREDENTIAL"}
self.assertRaises(NotCredential, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.status_code = 403
m_res.json.return_value = {'errorCode': "INVALID_KEY"}
self.assertRaises(InvalidKey, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.status_code = 403
m_res.json.return_value = {'errorCode': "INVALID_CREDENTIAL"}
self.assertRaises(InvalidCredential, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.status_code = 403
m_res.json.return_value = {'errorCode': "FORBIDDEN"}
self.assertRaises(Forbidden, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.status_code = 400
self.assertRaises(BadParametersError, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.status_code = 409
self.assertRaises(ResourceConflictError, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.status_code = 460
self.assertRaises(ResourceExpiredError, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.status_code = 0
self.assertRaises(NetworkError, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.status_code = 99
self.assertRaises(APIError, api.call, FAKE_METHOD, FAKE_PATH, None, False)
m_res.status_code = 306
self.assertRaises(APIError, api.call, FAKE_METHOD, FAKE_PATH, None, False)