本文整理汇总了Python中botocore.awsrequest.AWSResponse方法的典型用法代码示例。如果您正苦于以下问题:Python awsrequest.AWSResponse方法的具体用法?Python awsrequest.AWSResponse怎么用?Python awsrequest.AWSResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类botocore.awsrequest
的用法示例。
在下文中一共展示了awsrequest.AWSResponse方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_response
# 需要导入模块: from botocore import awsrequest [as 别名]
# 或者: from botocore.awsrequest import AWSResponse [as 别名]
def _add_response(self, method, service_response, expected_params):
if not hasattr(self.client, method):
raise ValueError(
"Client %s does not have method: %s"
% (self.client.meta.service_model.service_name, method))
# Create a successful http response
http_response = AWSResponse(None, 200, {}, None)
operation_name = self.client.meta.method_to_api_mapping.get(method)
self._validate_response(operation_name, service_response)
# Add the service_response to the queue for returning responses
response = {
'operation_name': operation_name,
'response': (http_response, service_response),
'expected_params': expected_params
}
self._queue.append(response)
示例2: test_make_api_call_throws_verbose_error_after_backoff
# 需要导入模块: from botocore import awsrequest [as 别名]
# 或者: from botocore.awsrequest import AWSResponse [as 别名]
def test_make_api_call_throws_verbose_error_after_backoff(self, client_mock):
response = AWSResponse(
url='http://lyft.com',
status_code=500,
raw='', # todo: use stream, like `botocore.tests.RawResponse`?
headers={'x-amzn-RequestId': 'abcdef'},
)
response._content = json.dumps({'message': 'There is a problem', '__type': 'InternalServerError'}).encode('utf-8')
client_mock._endpoint.http_session.send.return_value = response
c = Connection()
with self.assertRaises(ClientError):
try:
c._make_api_call('CreateTable', {'TableName': 'MyTable'})
except Exception as e:
self.assertEqual(
str(e),
'An error occurred (InternalServerError) on request (abcdef) on table (MyTable) when calling the CreateTable operation: There is a problem'
)
raise
示例3: test_make_api_call___extra_headers
# 需要导入模块: from botocore import awsrequest [as 别名]
# 或者: from botocore.awsrequest import AWSResponse [as 别名]
def test_make_api_call___extra_headers(self, client_mock):
good_response = mock.Mock(spec=AWSResponse, status_code=200, headers={}, text='{}', content=b'{}')
send_mock = client_mock._endpoint.http_session.send
send_mock.return_value = good_response
client_mock._convert_to_request_dict.return_value = {'method': 'POST', 'url': '', 'headers': {}, 'body': '', 'context': {}}
mock_req = mock.Mock(spec=AWSPreparedRequest, headers={})
create_request_mock = client_mock._endpoint.prepare_request
create_request_mock.return_value = mock_req
c = Connection(extra_headers={'foo': 'bar'})
c._make_api_call('DescribeTable', {'TableName': 'MyTable'})
assert send_mock.call_count == 1
assert send_mock.call_args[0][0].headers.get('foo') == 'bar'
示例4: setUp
# 需要导入模块: from botocore import awsrequest [as 别名]
# 或者: from botocore.awsrequest import AWSResponse [as 别名]
def setUp(self):
self.last_params = {}
self.last_kwargs = None
# awscli/__init__.py injects AWS_DATA_PATH at import time
# so that we can find cli.json. This might be fixed in the
# future, but for now we just grab that value out of the real
# os.environ so the patched os.environ has this data and
# the CLI works.
self.environ = {
'AWS_DATA_PATH': os.environ['AWS_DATA_PATH'],
'AWS_DEFAULT_REGION': 'us-east-1',
'AWS_ACCESS_KEY_ID': 'access_key',
'AWS_SECRET_ACCESS_KEY': 'secret_key',
'AWS_CONFIG_FILE': '',
'AWS_SHARED_CREDENTIALS_FILE': '',
}
self.environ_patch = mock.patch('os.environ', self.environ)
self.environ_patch.start()
self.http_response = AWSResponse(None, 200, {}, None)
self.parsed_response = {}
self.make_request_patch = mock.patch('botocore.endpoint.Endpoint.make_request')
self.make_request_is_patched = False
self.operations_called = []
self.parsed_responses = None
self.driver = create_clidriver()
示例5: test_make_api_call_throws_verbose_error_after_backoff_later_succeeds
# 需要导入模块: from botocore import awsrequest [as 别名]
# 或者: from botocore.awsrequest import AWSResponse [as 别名]
def test_make_api_call_throws_verbose_error_after_backoff_later_succeeds(self, client_mock, rand_int_mock):
# mock response
bad_response = mock.Mock(spec=AWSResponse)
bad_response.status_code = 500
bad_response.headers = {'x-amzn-RequestId': 'abcdef'}
bad_response.text = json.dumps({'message': 'There is a problem', '__type': 'InternalServerError'})
bad_response.content = bad_response.text.encode()
good_response_content = {'TableDescription': {'TableName': 'table', 'TableStatus': 'Creating'}}
good_response = mock.Mock(spec=AWSResponse)
good_response.status_code = 200
good_response.headers = {}
good_response.text = json.dumps(good_response_content)
good_response.content = good_response.text.encode()
send_mock = client_mock._endpoint.http_session.send
send_mock.side_effect = [
bad_response,
bad_response,
good_response,
]
rand_int_mock.return_value = 1
c = Connection()
self.assertEqual(good_response_content, c._make_api_call('CreateTable', {'TableName': 'MyTable'}))
self.assertEqual(len(send_mock.mock_calls), 3)
assert rand_int_mock.call_args_list == [mock.call(0, 25), mock.call(0, 50)]
示例6: test_make_api_call_retries_properly
# 需要导入模块: from botocore import awsrequest [as 别名]
# 或者: from botocore.awsrequest import AWSResponse [as 别名]
def test_make_api_call_retries_properly(self, client_mock):
deserializable_response = AWSResponse(
url='',
status_code=200,
headers={},
raw='',
)
deserializable_response._content = json.dumps({'hello': 'world'}).encode('utf-8')
bad_response = AWSResponse(
url='',
status_code=503,
headers={},
raw='',
)
bad_response._content = 'not_json'.encode('utf-8')
prepared_request = AWSRequest('GET', 'http://lyft.com').prepare()
send_mock = client_mock._endpoint.http_session.send
send_mock.side_effect = [
bad_response,
botocore.exceptions.ReadTimeoutError(endpoint_url='http://lyft.com'),
bad_response,
deserializable_response,
]
c = Connection()
c._max_retry_attempts_exception = 3
c._create_prepared_request = mock.Mock()
c._create_prepared_request.return_value = prepared_request
c._make_api_call('DescribeTable', {'TableName': 'MyTable'})
self.assertEqual(len(send_mock.mock_calls), 4)
for call in send_mock.mock_calls:
self.assertEqual(call[1][0], prepared_request)