当前位置: 首页>>代码示例>>Python>>正文


Python awsrequest.AWSResponse方法代码示例

本文整理汇总了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) 
开发者ID:QData,项目名称:deepWordBug,代码行数:21,代码来源:stub.py

示例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 
开发者ID:pynamodb,项目名称:PynamoDB,代码行数:23,代码来源:test_base_connection.py

示例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' 
开发者ID:pynamodb,项目名称:PynamoDB,代码行数:19,代码来源:test_base_connection.py

示例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() 
开发者ID:gkrizek,项目名称:bash-lambda-layer,代码行数:27,代码来源:testutils.py

示例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)] 
开发者ID:pynamodb,项目名称:PynamoDB,代码行数:32,代码来源:test_base_connection.py

示例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) 
开发者ID:pynamodb,项目名称:PynamoDB,代码行数:38,代码来源:test_base_connection.py


注:本文中的botocore.awsrequest.AWSResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。