Пример #1
0
 def test_response_metadata_on_rest_json_response(self):
     parser = parsers.RestJSONParser()
     response = b'{"Str": "mystring"}'
     headers = {'x-amzn-requestid': 'request-id'}
     output_shape = model.StructureShape(
         'OutputShape', {
             'type': 'structure',
             'members': {
                 'Str': {
                     'shape': 'StringType',
                 }
             }
         }, model.ShapeResolver({'StringType': {
             'type': 'string'
         }}))
     parsed = parser.parse(
         {
             'body': response,
             'headers': headers,
             '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': 'mystring',
             'ResponseMetadata': {
                 'RequestId': 'request-id',
                 'HTTPStatusCode': 200,
                 'HTTPHeaders': headers
             }
         })
Пример #2
0
 def test_recursive_shape(self):
     shapes = {
         'InputStructure': {
             'type': 'structure',
             'members': {
                 'A': {
                     'shape': 'RecursiveShape'
                 }
             }
         },
         'RecursiveShape': {
             'type': 'structure',
             'members': {
                 'B': {
                     'shape': 'StringType'
                 },
                 'C': {
                     'shape': 'RecursiveShape'
                 },
             }
         },
         'StringType': {
             'type': 'string'
         }
     }
     shape = model.StructureShape(
         shape_name='InputStructure',
         shape_model=shapes['InputStructure'],
         shape_resolver=model.ShapeResolver(shape_map=shapes))
     self.assertIn('recursive', detect_shape_structure(shape))
Пример #3
0
 def test_metadata_always_exists_on_rest_json_response(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.RestJSONParser()
     response = b'{"Str": "mystring"}'
     headers = {}
     output_shape = model.StructureShape(
         'OutputShape', {
             'type': 'structure',
             'members': {
                 'Str': {
                     'shape': 'StringType',
                 }
             }
         }, model.ShapeResolver({'StringType': {
             'type': 'string'
         }}))
     parsed = parser.parse(
         {
             'body': response,
             'headers': headers,
             'status_code': 200
         }, output_shape)
     expected = {
         'Str': 'mystring',
         'ResponseMetadata': {
             'HTTPStatusCode': 200,
             'HTTPHeaders': headers
         }
     }
     self.assertEqual(parsed, expected)
Пример #4
0
 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)
Пример #5
0
 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': {}
             }
         })
Пример #6
0
 def test_can_document_recursive_struct(self):
     # It's a little more work to set up a recursive
     # shape because DenormalizedStructureBuilder cannot handle
     # recursion.
     struct_shape = {
         'type': 'structure',
         'members': OrderedDict([
             ('Recurse', {'shape': 'SubShape'}),
             ('Scalar', {'shape': 'String'}),
         ]),
     }
     shapes = {
         'Top': struct_shape,
         'String': {'type': 'string'},
         'SubShape': {
             'type': 'structure',
             'members': OrderedDict([
                 ('SubRecurse', {'shape': 'Top'}),
                 ('Scalar', {'shape': 'String'}),
             ]),
         }
     }
     m = model.StructureShape(
         shape_name='Top',
         shape_model=struct_shape,
         shape_resolver=model.ShapeResolver(shapes))
     argument = mock.Mock()
     argument.argument_model = m
     argument.name = 'foo'
     argument.cli_name = '--foo'
     generated_example = self.get_generated_example_for(argument)
     self.assertIn(
         'Recurse={SubRecurse={( ... recursive ... ),Scalar=string},'
         'Scalar=string},Scalar=string',
         generated_example)
Пример #7
0
 def test_response_no_initial_event_stream(self):
     parser = parsers.JSONParser()
     output_shape = model.StructureShape(
         'OutputShape', {
             'type': 'structure',
             'members': {
                 'Payload': {
                     'shape': 'Payload'
                 }
             }
         },
         model.ShapeResolver({
             'Payload': {
                 'type': 'structure',
                 'members': [],
                 'eventstream': True
             }
         }))
     with self.assertRaises(parsers.ResponseParserError):
         response_dict = {
             'status_code': 200,
             'headers': {},
             'body': RawResponse(b''),
             'context': {
                 'operation_name': 'TestOperation'
             }
         }
         parser.parse(response_dict, output_shape)
Пример #8
0
 def create_arbitary_output_shape(self):
     output_shape = model.StructureShape(
         'OutputShape', {
             'type': 'structure',
             'members': {
                 'Str': {
                     'shape': 'StringType',
                 }
             }
         }, model.ShapeResolver({'StringType': {
             'type': 'string'
         }}))
     return output_shape
Пример #9
0
 def setUp(self):
     self.error_shape = model.StructureShape(
         'ErrorShape', {
             'type': 'structure',
             'exception': True,
             'members': {
                 'ModeledField': {
                     'shape': 'StringType',
                 }
             }
         }, model.ShapeResolver({'StringType': {
             'type': 'string'
         }}))
Пример #10
0
 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': {}
             }
         })
Пример #11
0
 def setUp(self):
     self.parser = parsers.EventStreamXMLParser()
     self.output_shape = model.StructureShape(
         'EventStream', {
             'eventstream': True,
             'type': 'structure',
             'members': {
                 'EventA': {
                     'shape': 'EventAStructure'
                 },
                 'EventB': {
                     'shape': 'EventBStructure'
                 },
                 'EventC': {
                     'shape': 'EventCStructure'
                 },
                 'EventD': {
                     'shape': 'EventDStructure'
                 },
             }
         },
         model.ShapeResolver({
             'EventAStructure': {
                 'event': True,
                 'type': 'structure',
                 'members': {
                     'Stats': {
                         'shape': 'StatsStructure',
                         'eventpayload': True
                     },
                     'Header': {
                         'shape': 'IntShape',
                         'eventheader': True
                     }
                 }
             },
             'EventBStructure': {
                 'event': True,
                 'type': 'structure',
                 'members': {
                     'Body': {
                         'shape': 'BlobShape',
                         'eventpayload': True
                     }
                 }
             },
             'EventCStructure': {
                 'event': True,
                 'type': 'structure',
                 'members': {
                     'Body': {
                         'shape': 'StringShape',
                         'eventpayload': True
                     }
                 }
             },
             'EventDStructure': {
                 'event': True,
                 'type': 'structure',
                 'members': {
                     'StringField': {
                         'shape': 'StringShape'
                     },
                     'IntField': {
                         'shape': 'IntShape'
                     },
                     'Header': {
                         'shape': 'IntShape',
                         'eventheader': True
                     }
                 }
             },
             'StatsStructure': {
                 'type': 'structure',
                 'members': {
                     'StringField': {
                         'shape': 'StringShape'
                     },
                     'IntField': {
                         'shape': 'IntShape'
                     }
                 }
             },
             'BlobShape': {
                 'type': 'blob'
             },
             'StringShape': {
                 'type': 'string'
             },
             'IntShape': {
                 'type': 'integer'
             }
         }))