def test_get_response_nonstreaming_ok(self): headers = { 'content-type': 'application/xml', 'date': 'Sun, 09 Mar 2014 02:55:43 GMT', 'server': 'AmazonS3', 'transfer-encoding': 'chunked', 'x-amz-id-2': 'AAAAAAAAAAAAAAAAAAA', 'x-amz-request-id': 'XXXXXXXXXXXXXXXX' } raw = FakeRawResponse(XMLBODY1) http_response = AWSResponse(None, 403, headers, raw) session = ibm_botocore.session.get_session() service_model = session.get_service_model('s3') operation_model = service_model.operation_model('ListObjects') self.assert_response_with_subset_metadata( response.get_response(operation_model, http_response)[1], { 'ResponseMetadata': { 'RequestId': 'XXXXXXXXXXXXXXXX', 'HostId': 'AAAAAAAAAAAAAAAAAAA', 'HTTPStatusCode': 403 }, 'Error': { 'Message': 'Access Denied', 'Code': 'AccessDenied' } })
def add_response(self, url='https://example.com', status=200, headers=None, body=b''): if headers is None: headers = {} raw = RawResponse(body) response = AWSResponse(url, status, headers, raw) self.responses.append(response)
def test_get_response_nonstreaming_ng(self): headers = { 'content-type': 'application/xml', 'date': 'Sat, 08 Mar 2014 12:05:44 GMT', 'server': 'AmazonS3', 'transfer-encoding': 'chunked', 'x-amz-id-2': 'AAAAAAAAAAAAAAAAAAA', 'x-amz-request-id': 'XXXXXXXXXXXXXXXX' } raw = FakeRawResponse(XMLBODY2) http_response = AWSResponse(None, 200, headers, raw) session = ibm_botocore.session.get_session() service_model = session.get_service_model('s3') operation_model = service_model.operation_model('ListObjects') self.assert_response_with_subset_metadata( response.get_response(operation_model, http_response)[1], { u'Contents': [{ u'ETag': '"00000000000000000000000000000000"', u'Key': 'test.png', u'LastModified': datetime.datetime(2014, 3, 1, 17, 6, 40, tzinfo=tzutc()), u'Owner': { u'DisplayName': 'dummy', u'ID': 'AAAAAAAAAAAAAAAAAAA' }, u'Size': 6702, u'StorageClass': 'STANDARD' }], u'IsTruncated': False, u'Marker': "", u'MaxKeys': 1000, u'Name': 'mybucket', u'Prefix': "", 'ResponseMetadata': { 'RequestId': 'XXXXXXXXXXXXXXXX', 'HostId': 'AAAAAAAAAAAAAAAAAAA', 'HTTPStatusCode': 200, } })
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)
def test_get_response_streaming_ok(self): headers = { 'content-type': 'image/png', 'server': 'AmazonS3', 'AcceptRanges': 'bytes', 'transfer-encoding': 'chunked', 'ETag': '"00000000000000000000000000000000"', } raw = FakeRawResponse(b'\x89PNG\r\n\x1a\n\x00\x00') http_response = AWSResponse(None, 200, headers, raw) session = ibm_botocore.session.get_session() service_model = session.get_service_model('s3') operation_model = service_model.operation_model('GetObject') res = response.get_response(operation_model, http_response) self.assertTrue(isinstance(res[1]['Body'], response.StreamingBody)) self.assertEqual(res[1]['ETag'], '"00000000000000000000000000000000"')
def setUp(self): self.response = AWSResponse('http://url.com', 200, HeadersDict(), None) self.response.raw = Mock()
def add_client_error(self, method, service_error_code='', service_message='', http_status_code=400, service_error_meta=None, expected_params=None, response_meta=None): """ Adds a ``ClientError`` to the response queue. :param method: The name of the service method to return the error on. :type method: str :param service_error_code: The service error code to return, e.g. ``NoSuchBucket`` :type service_error_code: str :param service_message: The service message to return, e.g. 'The specified bucket does not exist.' :type service_message: str :param http_status_code: The HTTP status code to return, e.g. 404, etc :type http_status_code: int :param service_error_meta: Additional keys to be added to the service Error :type service_error_meta: dict :param expected_params: A dictionary of the expected parameters to be called for the provided service response. The parameters match the names of keyword arguments passed to that client call. If any of the parameters differ a ``StubResponseError`` is thrown. You can use stub.ANY to indicate a particular parameter to ignore in validation. :param response_meta: Additional keys to be added to the response's ResponseMetadata :type response_meta: dict """ http_response = AWSResponse(None, http_status_code, {}, None) # We don't look to the model to build this because the caller would # need to know the details of what the HTTP body would need to # look like. parsed_response = { 'ResponseMetadata': { 'HTTPStatusCode': http_status_code }, 'Error': { 'Message': service_message, 'Code': service_error_code } } if service_error_meta is not None: parsed_response['Error'].update(service_error_meta) if response_meta is not None: parsed_response['ResponseMetadata'].update(response_meta) operation_name = self.client.meta.method_to_api_mapping.get(method) # Note that we do not allow for expected_params while # adding errors into the queue yet. response = { 'operation_name': operation_name, 'response': (http_response, parsed_response), 'expected_params': expected_params, } self._queue.append(response)