コード例 #1
0
    def generate_json_skeleton(self, call_parameters, parsed_args,
                               parsed_globals, **kwargs):
        if getattr(parsed_args, 'generate_cli_skeleton', None):
            for_output = parsed_args.generate_cli_skeleton == 'output'
            operation_model = self._operation_model

            if for_output:
                service_name = operation_model.service_model.service_name
                operation_name = operation_model.name
                # TODO: It would be better to abstract this logic into
                # classes for both the input and output option such that
                # a similar set of inputs are taken in and output
                # similar functionality.
                return StubbedCLIOperationCaller(self._session).invoke(
                    service_name, operation_name, call_parameters,
                    parsed_globals)
            else:
                argument_generator = ArgumentGenerator()
                operation_input_shape = operation_model.input_shape
                if operation_input_shape is None:
                    skeleton = {}
                else:
                    skeleton = argument_generator.generate_skeleton(
                        operation_input_shape)

                sys.stdout.write(
                    json.dumps(skeleton, indent=4, default=json_encoder)
                )
                sys.stdout.write('\n')
                return 0
コード例 #2
0
    def generate_json_skeleton(self, call_parameters, parsed_args,
                               parsed_globals, **kwargs):

        # Only perform the method if the ``--generate-cli-skeleton`` was
        # included in the command line.
        if getattr(parsed_args, 'generate_cli_skeleton', False):

            # Obtain the model of the operation
            operation_model = self._operation_model

            # Generate the skeleton based on the ``input_shape``.
            argument_generator = ArgumentGenerator()
            operation_input_shape = operation_model.input_shape
            # If the ``input_shape`` is ``None``, generate an empty
            # dictionary.
            if operation_input_shape is None:
                skeleton = {}
            else:
                skeleton = argument_generator.generate_skeleton(
                    operation_input_shape)

            # Write the generated skeleton to standard output.
            sys.stdout.write(json.dumps(skeleton, indent=4))
            sys.stdout.write('\n')
            # This is the return code
            return 0
コード例 #3
0
    def generate_json_skeleton(self, call_parameters, parsed_args,
                               parsed_globals, **kwargs):
        if getattr(parsed_args, 'generate_cli_skeleton', None):
            for_output = parsed_args.generate_cli_skeleton == 'output'
            operation_model = self._operation_model

            if for_output:
                service_name = operation_model.service_model.service_name
                operation_name = operation_model.name
                # TODO: It would be better to abstract this logic into
                # classes for both the input and output option such that
                # a similar set of inputs are taken in and output
                # similar functionality.
                return StubbedCLIOperationCaller(self._session).invoke(
                    service_name, operation_name, call_parameters,
                    parsed_globals)
            else:
                argument_generator = ArgumentGenerator()
                operation_input_shape = operation_model.input_shape
                if operation_input_shape is None:
                    skeleton = {}
                else:
                    skeleton = argument_generator.generate_skeleton(
                        operation_input_shape)

                sys.stdout.write(
                    json.dumps(skeleton, indent=4, default=json_encoder))
                sys.stdout.write('\n')
                return 0
コード例 #4
0
 def _generate_input_skeleton(self, **kwargs):
     outfile = sys.stdout
     input_shape = self._operation_model.input_shape
     skeleton = {}
     if input_shape is not None:
         argument_generator = ArgumentGenerator()
         skeleton = argument_generator.generate_skeleton(input_shape)
     json.dump(skeleton, outfile, indent=4, default=json_encoder)
     outfile.write('\n')
     return 0
コード例 #5
0
 def _make_client_call(self, client, operation_name, parameters,
                       parsed_globals):
     method_name = xform_name(operation_name)
     operation_model = client.meta.service_model.operation_model(
         operation_name)
     fake_response = {}
     if operation_model.output_shape:
         argument_generator = ArgumentGenerator(use_member_names=True)
         fake_response = argument_generator.generate_skeleton(
             operation_model.output_shape)
     with Stubber(client) as stubber:
         stubber.add_response(method_name, fake_response)
         return getattr(client, method_name)(**parameters)
コード例 #6
0
 def _make_client_call(self, client, operation_name, parameters,
                       parsed_globals):
     method_name = xform_name(operation_name)
     operation_model = client.meta.service_model.operation_model(
         operation_name)
     fake_response = {}
     if operation_model.output_shape:
         argument_generator = ArgumentGenerator(use_member_names=True)
         fake_response = argument_generator.generate_skeleton(
             operation_model.output_shape)
     with Stubber(client) as stubber:
         stubber.add_response(method_name, fake_response)
         return getattr(client, method_name)(**parameters)
コード例 #7
0
ファイル: test_utils.py プロジェクト: zined/botocore
def test_can_generate_all_inputs():
    session = botocore.session.get_session()
    generator = ArgumentGenerator()
    for service_name in session.get_available_services():
        service_model = session.get_service_model(service_name)
        for operation_name in service_model.operation_names:
            operation_model = service_model.operation_model(operation_name)
            input_shape = operation_model.input_shape
            if input_shape is not None and input_shape.members:
                yield (_test_can_generate_skeleton, generator,
                       input_shape, service_name, operation_name)
コード例 #8
0
    def generate_json_skeleton(self, call_parameters, parsed_args, parsed_globals, **kwargs):

        # Only perform the method if the ``--generate-cli-skeleton`` was
        # included in the command line.
        if getattr(parsed_args, "generate_cli_skeleton", False):

            # Obtain the model of the operation
            operation_model = self._operation_object.model

            # Generate the skeleton based on the ``input_shape``.
            argument_generator = ArgumentGenerator()
            operation_input_shape = operation_model.input_shape
            # If the ``input_shape`` is ``None``, generate an empty
            # dictionary.
            if operation_input_shape is None:
                skeleton = {}
            else:
                skeleton = argument_generator.generate_skeleton(operation_input_shape)

            # Write the generated skeleton to standard output.
            sys.stdout.write(json.dumps(skeleton, indent=4))
            sys.stdout.write("\n")
            # This is the return code
            return 0
コード例 #9
0
ファイル: test_utils.py プロジェクト: CloverHealth/botocore
 def setUp(self):
     self.arg_generator = ArgumentGenerator()
コード例 #10
0
ファイル: test_utils.py プロジェクト: CloverHealth/botocore
class TestArgumentGenerator(unittest.TestCase):
    def setUp(self):
        self.arg_generator = ArgumentGenerator()

    def assert_skeleton_from_model_is(self, model, generated_skeleton):
        shape = DenormalizedStructureBuilder().with_members(
            model).build_model()
        actual = self.arg_generator.generate_skeleton(shape)
        self.assertEqual(actual, generated_skeleton)

    def test_generate_string(self):
        self.assert_skeleton_from_model_is(
            model={
                'A': {'type': 'string'}
            },
            generated_skeleton={
                'A': ''
            }
        )

    def test_generate_scalars(self):
        self.assert_skeleton_from_model_is(
            model={
                'A': {'type': 'string'},
                'B': {'type': 'integer'},
                'C': {'type': 'float'},
                'D': {'type': 'boolean'},
            },
            generated_skeleton={
                'A': '',
                'B': 0,
                'C': 0.0,
                'D': True,
            }
        )

    def test_generate_nested_structure(self):
        self.assert_skeleton_from_model_is(
            model={
                'A': {
                    'type': 'structure',
                    'members': {
                        'B': {'type': 'string'},
                    }
                }
            },
            generated_skeleton={
                'A': {'B': ''}
            }
        )

    def test_generate_scalar_list(self):
        self.assert_skeleton_from_model_is(
            model={
                'A': {
                    'type': 'list',
                    'member': {
                        'type': 'string'
                    }
                },
            },
            generated_skeleton={
                'A': [''],
            }
        )

    def test_generate_scalar_map(self):
        self.assert_skeleton_from_model_is(
            model={
                'A': {
                    'type': 'map',
                    'key': {'type': 'string'},
                    'value':  {'type': 'string'},
                }
            },
            generated_skeleton={
                'A': {
                    'KeyName': '',
                }
            }
        )

    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)
コード例 #11
0
def _search_jmespath_expression(expression, op_model):
    arg_gen = ArgumentGenerator(use_member_names=True)
    sample_output = arg_gen.generate_skeleton(op_model.output_shape)
    search_result = jmespath.search(expression, sample_output)
    return search_result
コード例 #12
0
ファイル: test_utils.py プロジェクト: zined/botocore
 def setUp(self):
     self.arg_generator = ArgumentGenerator()
コード例 #13
0
ファイル: test_utils.py プロジェクト: zined/botocore
class TestArgumentGenerator(unittest.TestCase):
    def setUp(self):
        self.arg_generator = ArgumentGenerator()

    def assert_skeleton_from_model_is(self, model, generated_skeleton):
        shape = DenormalizedStructureBuilder().with_members(
            model).build_model()
        actual = self.arg_generator.generate_skeleton(shape)
        self.assertEqual(actual, generated_skeleton)

    def test_generate_string(self):
        self.assert_skeleton_from_model_is(model={'A': {
            'type': 'string'
        }},
                                           generated_skeleton={'A': ''})

    def test_generate_scalars(self):
        self.assert_skeleton_from_model_is(model={
            'A': {
                'type': 'string'
            },
            'B': {
                'type': 'integer'
            },
            'C': {
                'type': 'float'
            },
            'D': {
                'type': 'boolean'
            },
        },
                                           generated_skeleton={
                                               'A': '',
                                               'B': 0,
                                               'C': 0.0,
                                               'D': True,
                                           })

    def test_generate_nested_structure(self):
        self.assert_skeleton_from_model_is(model={
            'A': {
                'type': 'structure',
                'members': {
                    'B': {
                        'type': 'string'
                    },
                }
            }
        },
                                           generated_skeleton={'A': {
                                               'B': ''
                                           }})

    def test_generate_scalar_list(self):
        self.assert_skeleton_from_model_is(model={
            'A': {
                'type': 'list',
                'member': {
                    'type': 'string'
                }
            },
        },
                                           generated_skeleton={
                                               'A': [''],
                                           })

    def test_generate_scalar_map(self):
        self.assert_skeleton_from_model_is(
            model={
                'A': {
                    'type': 'map',
                    'key': {
                        'type': 'string'
                    },
                    'value': {
                        'type': 'string'
                    },
                }
            },
            generated_skeleton={'A': {
                'KeyName': '',
            }})

    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)
コード例 #14
0
ファイル: test_utils.py プロジェクト: rayluo/botocore
class TestArgumentGenerator(unittest.TestCase):
    def setUp(self):
        self.arg_generator = ArgumentGenerator()

    def assert_skeleton_from_model_is(self, model, generated_skeleton):
        shape = DenormalizedStructureBuilder().with_members(model).build_model()
        actual = self.arg_generator.generate_skeleton(shape)
        self.assertEqual(actual, generated_skeleton)

    def test_generate_string(self):
        self.assert_skeleton_from_model_is(model={"A": {"type": "string"}}, generated_skeleton={"A": ""})

    def test_generate_scalars(self):
        self.assert_skeleton_from_model_is(
            model={"A": {"type": "string"}, "B": {"type": "integer"}, "C": {"type": "float"}, "D": {"type": "boolean"}},
            generated_skeleton={"A": "", "B": 0, "C": 0.0, "D": True},
        )

    def test_generate_nested_structure(self):
        self.assert_skeleton_from_model_is(
            model={"A": {"type": "structure", "members": {"B": {"type": "string"}}}},
            generated_skeleton={"A": {"B": ""}},
        )

    def test_generate_scalar_list(self):
        self.assert_skeleton_from_model_is(
            model={"A": {"type": "list", "member": {"type": "string"}}}, generated_skeleton={"A": [""]}
        )

    def test_generate_scalar_map(self):
        self.assert_skeleton_from_model_is(
            model={"A": {"type": "map", "key": {"type": "string"}, "value": {"type": "string"}}},
            generated_skeleton={"A": {"KeyName": ""}},
        )

    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)
コード例 #15
0
def _search_jmespath_expression(expression, op_model):
    arg_gen = ArgumentGenerator(use_member_names=True)
    sample_output = arg_gen.generate_skeleton(op_model.output_shape)
    search_result = jmespath.search(expression, sample_output)
    return search_result
コード例 #16
0
def generator():
    return ArgumentGenerator()