Ejemplo n.º 1
0
 def test_can_parse_sdb_error_response_query_protocol(self):
     body = (
         '<OperationNameResponse>'
         '    <Errors>'
         '        <Error>'
         '            <Code>1</Code>'
         '            <Message>msg</Message>'
         '        </Error>'
         '    </Errors>'
         '    <RequestId>abc-123</RequestId>'
         '</OperationNameResponse>'
     ).encode('utf-8')
     parser = parsers.QueryParser()
     parsed = parser.parse({
         'body': body, 'headers': {}, 'status_code': 500}, None)
     self.assertIn('Error', parsed)
     self.assertEqual(parsed['Error'], {
         'Code': '1',
         'Message': 'msg'
     })
     self.assertEqual(parsed['ResponseMetadata'], {
         'RequestId': 'abc-123',
         'HTTPStatusCode': 500,
         'HTTPHeaders': {}
     })
Ejemplo n.º 2
0
 def test_invalid_xml_shown_in_error_message(self):
     # Missing the closing XML tags.
     invalid_xml = (
         b'<DeleteTagsResponse xmlns="http://autoscaling.amazonaws.com/">'
         b'  <ResponseMetadata>'
     )
     parser = parsers.QueryParser()
     output_shape = None
     # The XML body should be in the error message.
     with self.assertRaisesRegexp(parsers.ResponseParserError,
                                  '<DeleteTagsResponse'):
         parser.parse(
             {'body': invalid_xml, 'headers': {}, 'status_code': 200},
             output_shape)
 def test_response_metadata_parsed_for_query_service(self):
     parser = parsers.QueryParser()
     response = (
         '<OperationNameResponse>'
         '  <OperationNameResult><Str>myname</Str></OperationNameResult>'
         '  <ResponseMetadata>'
         '    <RequestId>request-id</RequestId>'
         '  </ResponseMetadata>'
         '</OperationNameResponse>').encode('utf-8')
     output_shape = model.StructureShape(
         'OutputShape', {
             'type': 'structure',
             'resultWrapper': 'OperationNameResult',
             'members': {
                 'Str': {
                     'shape': 'StringType',
                 },
                 'Num': {
                     'shape': 'IntegerType',
                 }
             }
         },
         model.ShapeResolver({
             'StringType': {
                 'type': 'string',
             },
             'IntegerType': {
                 'type': 'integer',
             }
         }))
     parsed = parser.parse(
         {
             'body': response,
             'headers': {},
             'status_code': 200
         }, output_shape)
     self.assertEqual(
         parsed, {
             'Str': 'myname',
             'ResponseMetadata': {
                 'RequestId': 'request-id',
                 'HTTPStatusCode': 200,
                 'HTTPHeaders': {}
             }
         })
Ejemplo n.º 4
0
 def test_empty_query_response(self):
     body = (
         b'<DeleteTagsResponse xmlns="http://autoscaling.amazonaws.com/">'
         b'  <ResponseMetadata>'
         b'    <RequestId>request-id</RequestId>'
         b'  </ResponseMetadata>'
         b'</DeleteTagsResponse>'
     )
     parser = parsers.QueryParser()
     output_shape = None
     parsed = parser.parse(
         {'body': body, 'headers': {}, 'status_code': 200},
         output_shape)
     self.assertEqual(
         parsed,
         {'ResponseMetadata': {'RequestId': 'request-id',
                               'HTTPStatusCode': 200,
                               'HTTPHeaders': {}}})
 def test_metadata_always_exists_for_query(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.QueryParser()
     response = (
         '<OperationNameResponse>'
         '  <OperationNameResult><Str>myname</Str></OperationNameResult>'
         '</OperationNameResponse>').encode('utf-8')
     output_shape = model.StructureShape(
         'OutputShape', {
             'type': 'structure',
             'resultWrapper': 'OperationNameResult',
             'members': {
                 'Str': {
                     'shape': 'StringType',
                 },
                 'Num': {
                     'shape': 'IntegerType',
                 }
             }
         },
         model.ShapeResolver({
             'StringType': {
                 'type': 'string',
             },
             'IntegerType': {
                 'type': 'integer',
             }
         }))
     parsed = parser.parse(
         {
             'body': response,
             'headers': {},
             'status_code': 200
         }, output_shape)
     expected = {
         'Str': 'myname',
         'ResponseMetadata': {
             'HTTPStatusCode': 200,
             'HTTPHeaders': {}
         }
     }
     self.assertEqual(parsed, expected)
Ejemplo n.º 6
0
 def test_parse_error_response_for_query_protocol(self):
     body = (
         '<ErrorResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">'
         '  <Error>'
         '    <Type>Sender</Type>'
         '    <Code>InvalidInput</Code>'
         '    <Message>ARN asdf is not valid.</Message>'
         '  </Error>'
         '  <RequestId>request-id</RequestId>'
         '</ErrorResponse>'
     ).encode('utf-8')
     parser = parsers.QueryParser()
     parsed = parser.parse({
         'body': body, 'headers': {}, 'status_code': 400}, None)
     self.assertIn('Error', parsed)
     self.assertEqual(parsed['Error'], {
         'Code': 'InvalidInput',
         'Message': 'ARN asdf is not valid.',
         'Type': 'Sender',
     })