def get_validation_error_message(self, given_shapes, input_params):
     s = ShapeResolver(given_shapes)
     input_shape = s.get_shape_by_name('Input')
     validator = ParamValidator()
     errors_found = validator.validate(input_params, input_shape)
     error_message = errors_found.generate_report()
     return errors_found
Beispiel #2
0
 def get_validation_error_message(self, given_shapes, input_params):
     s = ShapeResolver(given_shapes)
     input_shape = s.get_shape_by_name('Input')
     validator = ParamValidator()
     errors_found = validator.validate(input_params, input_shape)
     error_message = errors_found.generate_report()
     return errors_found
Beispiel #3
0
 def test_handles_recursive_shapes(self):
     # We're not using assert_skeleton_from_model_is
     # because we can't use a DenormalizedStructureBuilder,
     # we need a normalized model to represent recursive
     # shapes.
     shape_map = ShapeResolver(
         {
             "InputShape": {
                 "type": "structure",
                 "members": {"A": {"shape": "RecursiveStruct"}, "B": {"shape": "StringType"}},
             },
             "RecursiveStruct": {
                 "type": "structure",
                 "members": {"C": {"shape": "RecursiveStruct"}, "D": {"shape": "StringType"}},
             },
             "StringType": {"type": "string"},
         }
     )
     shape = shape_map.get_shape_by_name("InputShape")
     actual = self.arg_generator.generate_skeleton(shape)
     expected = {
         "A": {
             "C": {
                 # For recurisve shapes, we'll just show
                 # an empty dict.
             },
             "D": "",
         },
         "B": "",
     }
     self.assertEqual(actual, expected)
Beispiel #4
0
    def test_handle_recursive_output(self):
        shape_map = {
            'RecursiveStruct': {
                'type': 'structure',
                'members': {
                    'A': {
                        'shape': 'NonRecursive'
                    },
                    'B': {
                        'shape': 'RecursiveStruct'
                    },
                }
            },
            'NonRecursive': {
                'type': 'string'
            }
        }
        shape = StructureShape('RecursiveStruct', shape_map['RecursiveStruct'],
                               ShapeResolver(shape_map))

        operation_model = mock.Mock()
        operation_model.output_shape = shape
        self.help_command.obj = operation_model
        self.operation_handler.doc_output(self.help_command, 'event-name')
        self.assert_rendered_docs_contain('( ... recursive ... )')
Beispiel #5
0
    def test_handle_recursive_input(self):
        shape_map = {
            'RecursiveStruct': {
                'type': 'structure',
                'members': {
                    'A': {
                        'shape': 'NonRecursive'
                    },
                    'B': {
                        'shape': 'RecursiveStruct'
                    },
                }
            },
            'NonRecursive': {
                'type': 'string'
            }
        }
        shape = StructureShape('RecursiveStruct', shape_map['RecursiveStruct'],
                               ShapeResolver(shape_map))

        self.arg_table['arg-name'] = mock.Mock(argument_model=shape)
        self.operation_handler.doc_option_example('arg-name',
                                                  self.help_command,
                                                  'process-cli-arg.foo.bar')
        self.assert_rendered_docs_contain('{ ... recursive ... }')
Beispiel #6
0
 def test_documents_nested_map(self):
     shape_map = {
         'UpperMap': {
             'type': 'map',
             'key': {
                 'shape': 'NestedStruct'
             },
             'value': {
                 'shape': 'NestedStruct'
             },
         },
         'NestedStruct': {
             'type': 'structure',
             'members': {
                 'Nested_A': {
                     'shape': 'Line'
                 },
                 'Nested_B': {
                     'shape': 'Line'
                 },
             }
         },
         'Line': {
             'type': 'string'
         }
     }
     shape = MapShape('UpperMap', shape_map['UpperMap'],
                      ShapeResolver(shape_map))
     rendered = self.get_help_docs_for_argument(shape)
     self.assertEqual(rendered.count('key -> (structure)'), 1)
     self.assertEqual(rendered.count('value -> (structure)'), 1)
     self.assertEqual(rendered.count('Nested_A -> (string)'), 2)
     self.assertEqual(rendered.count('Nested_B -> (string)'), 2)
Beispiel #7
0
 def test_documents_nested_list(self):
     shape_map = {
         'UpperList': {
             'type': 'list',
             'member': {
                 'shape': 'NestedStruct'
             },
         },
         'NestedStruct': {
             'type': 'structure',
             'members': {
                 'Nested_A': {
                     'shape': 'Line'
                 },
                 'Nested_B': {
                     'shape': 'Line'
                 },
             }
         },
         'Line': {
             'type': 'string'
         }
     }
     shape = ListShape('UpperList', shape_map['UpperList'],
                       ShapeResolver(shape_map))
     rendered = self.get_help_docs_for_argument(shape)
     self.assertEqual(rendered.count('(structure)'), 1)
     self.assertEqual(rendered.count('Nested_A -> (string)'), 1)
     self.assertEqual(rendered.count('Nested_B -> (string)'), 1)
Beispiel #8
0
 def test_handles_recursive_shapes(self):
     # We're not using assert_skeleton_from_model_is
     # because we can't use a DenormalizedStructureBuilder,
     # we need a normalized model to represent recursive
     # shapes.
     shape_map = ShapeResolver({
         'InputShape': {
             'type': 'structure',
             'members': {
                 'A': {
                     'shape': 'RecursiveStruct'
                 },
                 'B': {
                     'shape': 'StringType'
                 },
             }
         },
         'RecursiveStruct': {
             'type': 'structure',
             'members': {
                 'C': {
                     'shape': 'RecursiveStruct'
                 },
                 'D': {
                     'shape': 'StringType'
                 },
             }
         },
         'StringType': {
             'type': 'string',
         }
     })
     shape = shape_map.get_shape_by_name('InputShape')
     actual = self.arg_generator.generate_skeleton(shape)
     expected = {
         'A': {
             'C': {
                 # For recurisve shapes, we'll just show
                 # an empty dict.
             },
             'D': ''
         },
         'B': ''
     }
     self.assertEqual(actual, expected)
Beispiel #9
0
    def test_handle_memberless_output_shape(self):
        shape_map = {'NoMembers': {'type': 'structure', 'members': {}}}
        shape = StructureShape('NoMembers', shape_map['NoMembers'],
                               ShapeResolver(shape_map))

        operation_model = mock.Mock()
        operation_model.output_shape = shape
        self.help_command.obj = operation_model
        self.operation_handler.doc_output(self.help_command, 'event-name')
        self.assert_rendered_docs_contain('None')
Beispiel #10
0
 def test_handles_recursive_shapes(self):
     # We're not using assert_skeleton_from_model_is
     # because we can't use a DenormalizedStructureBuilder,
     # we need a normalized model to represent recursive
     # shapes.
     shape_map = ShapeResolver({
         'InputShape': {
             'type': 'structure',
             'members': {
                 'A': {'shape': 'RecursiveStruct'},
                 'B': {'shape': 'StringType'},
             }
         },
         'RecursiveStruct': {
             'type': 'structure',
             'members': {
                 'C': {'shape': 'RecursiveStruct'},
                 'D': {'shape': 'StringType'},
             }
         },
         'StringType': {
             'type': 'string',
         }
     })
     shape = shape_map.get_shape_by_name('InputShape')
     actual = self.arg_generator.generate_skeleton(shape)
     expected = {
         'A': {
             'C': {
                 # For recurisve shapes, we'll just show
                 # an empty dict.
             },
             'D': ''
         },
         'B': ''
     }
     self.assertEqual(actual, expected)
Beispiel #11
0
    def test_handle_empty_nested_struct(self):
        shape_map = {
            'InputStruct': {
                'type': 'structure',
                'members': {
                    'A': {'shape': 'Empty'},
                }
            },
            'Empty': {'type': 'structure', 'members': {}}
        }
        shape = StructureShape('InputStruct', shape_map['InputStruct'],
                               ShapeResolver(shape_map))

        self.arg_table['arg-name'] = mock.Mock(argument_model=shape)
        self.operation_handler.doc_option_example(
            'arg-name', self.help_command, 'process-cli-arg.foo.bar')
        self.assert_proper_indentation()
Beispiel #12
0
 def test_documents_recursive_input(self):
     shape_map = {
         'RecursiveStruct': {
             'type': 'structure',
             'members': {
                 'A': {
                     'shape': 'NonRecursive'
                 },
                 'B': {
                     'shape': 'RecursiveStruct'
                 },
             }
         },
         'NonRecursive': {
             'type': 'string'
         }
     }
     shape = StructureShape('RecursiveStruct', shape_map['RecursiveStruct'],
                            ShapeResolver(shape_map))
     rendered = self.get_help_docs_for_argument(shape)
     self.assertIn('( ... recursive ... )', rendered)