示例#1
0
 def __init__(self, name, documentation, parse_type, serialized_name):
     self.argument_model = model.Shape('PageArgument', {'type': 'string'})
     self._name = name
     self._serialized_name = serialized_name
     self._documentation = documentation
     self._parse_type = parse_type
     self._required = False
 def __init__(self, operation, name):
     self.argument_model = model.Shape('LaunchKeyArgument',
                                       {'type': 'string'})
     self._operation = operation
     self._name = name
     self._key_path = None
     self._required = False
示例#3
0
    def test_normal_blob_parsing(self):
        output_shape = model.Shape(shape_name='BlobType',
                                   shape_model={'type': 'blob'})
        parser = self.factory.create_parser('json')

        hello_world_b64 = b'"aGVsbG8gd29ybGQ="'
        expected_parsed = b'hello world'
        parsed = parser.parse(
            self.create_request_dict(with_body=hello_world_b64), output_shape)
        self.assertEqual(parsed, expected_parsed)
示例#4
0
    def test_can_alias_an_argument(self):
        arg = arguments.CustomArgument('foo',
                                       dest='foo',
                                       argument_model=model.Shape(
                                           'FooArg', {'type': 'string'}))
        self.argument_table['foo'] = arg
        handler = argrename.hidden_alias('foo', 'alias-name')

        handler(self.argument_table)

        self.assertIn('alias-name', self.argument_table)
        self.assertIn('foo', self.argument_table)
        self.assertEqual(self.argument_table['alias-name'].name, 'alias-name')
示例#5
0
    def test_can_decorate_scalar_parsing(self):
        output_shape = model.Shape(shape_name='BlobType',
                                   shape_model={'type': 'blob'})
        # Here we're overriding the blob parser so that
        # we can change it to a noop parser.
        self.factory.set_parser_defaults(blob_parser=lambda x: x)
        parser = self.factory.create_parser('json')

        hello_world_b64 = b'"aGVsbG8gd29ybGQ="'
        expected_parsed = "aGVsbG8gd29ybGQ="
        parsed = parser.parse(
            self.create_request_dict(with_body=hello_world_b64), output_shape)
        self.assertEqual(parsed, expected_parsed)
示例#6
0
    def test_can_decorate_timestamp_parser(self):
        output_shape = model.Shape(shape_name='datetime',
                                   shape_model={'type': 'timestamp'})
        # Here we're overriding the timestamp parser so that
        # we can change it to just convert a string to an integer
        # instead of converting to a datetime.
        self.factory.set_parser_defaults(timestamp_parser=lambda x: int(x))
        parser = self.factory.create_parser('json')

        timestamp_as_int = b'1407538750'
        expected_parsed = int(timestamp_as_int)
        parsed = parser.parse(
            self.create_request_dict(with_body=timestamp_as_int), output_shape)
        self.assertEqual(parsed, expected_parsed)
示例#7
0
 def test_can_parse_float_timestamps(self):
     # The type "timestamp" can come back as both an integer or as a float.
     # We need to make sure we handle the case where the timestamp comes
     # back as a float.  It might make sense to move this to protocol tests.
     output_shape = model.Shape(shape_name='datetime',
                                shape_model={'type': 'timestamp'})
     parser = parsers.JSONParser()
     timestamp_as_float = b'1407538750.49'
     expected_parsed = datetime.datetime(
         2014, 8, 8, 22, 59, 10, 490000, tzinfo=tzutc())
     parsed = parser.parse(
         {'body': timestamp_as_float,
          'headers': [],
          'status_code': 200}, output_shape)
     self.assertEqual(parsed, expected_parsed)
示例#8
0
 def __init__(self, operation, name):
     self.argument_model = model.Shape('CountArgument', {'type': 'string'})
     self._operation = operation
     self._name = name
     self._required = False