def test_response_metadata_parsed_for_ec2(self): parser = parsers.EC2QueryParser() response = ('<OperationNameResponse>' ' <Str>myname</Str>' ' <requestId>request-id</requestId>' '</OperationNameResponse>').encode('utf-8') output_shape = model.StructureShape( 'OutputShape', { 'type': 'structure', 'members': { 'Str': { 'shape': 'StringType', } } }, model.ShapeResolver({'StringType': { 'type': 'string' }})) parsed = parser.parse( { 'headers': {}, 'body': response, 'status_code': 200 }, output_shape) # Note that the response metadata is normalized to match the query # protocol, even though this is not how it appears in the output. self.assertEqual( parsed, { 'Str': 'myname', 'ResponseMetadata': { 'RequestId': 'request-id', 'HTTPStatusCode': 200, 'HTTPHeaders': {} } })
def test_metadata_always_exists_for_ec2(self): # ResponseMetadata is used for more than just the request id. It # should always get populated, even if the request doesn't seem to # have an id. parser = parsers.EC2QueryParser() response = ('<OperationNameResponse>' ' <Str>myname</Str>' '</OperationNameResponse>').encode('utf-8') output_shape = model.StructureShape( 'OutputShape', { 'type': 'structure', 'members': { 'Str': { 'shape': 'StringType', } } }, model.ShapeResolver({'StringType': { 'type': 'string' }})) parsed = parser.parse( { 'headers': {}, 'body': response, 'status_code': 200 }, output_shape) expected = { 'Str': 'myname', 'ResponseMetadata': { 'HTTPStatusCode': 200, 'HTTPHeaders': {} } } self.assertEqual(parsed, expected)
def test_can_parser_ec2_errors(self): body = ( '<Response>' ' <Errors>' ' <Error>' ' <Code>InvalidInstanceID.NotFound</Code>' ' <Message>The instance ID i-12345 does not exist</Message>' ' </Error>' ' </Errors>' ' <RequestID>06f382b0-d521-4bb6-988c-ca49d5ae6070</RequestID>' '</Response>' ).encode('utf-8') parser = parsers.EC2QueryParser() parsed = parser.parse({ 'body': body, 'headers': {}, 'status_code': 400}, None) self.assertIn('Error', parsed) self.assertEqual(parsed['Error'], { 'Code': 'InvalidInstanceID.NotFound', 'Message': 'The instance ID i-12345 does not exist', })