當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。