Exemplo n.º 1
0
 def test_shadowed_args_are_replaced_when_pagination_set_off(self):
     operation_model = Mock(OperationModel)
     operation_model.can_paginate = True
     operation_model.paging_input_token = "Foo"
     operation_model.paging_page_size = "page-size"
     operation_model.paging_default_max_items = 100
     self.parsed_globals.paginate = False
     # Corresponds to --foo 10
     self.parsed_args.foo = 10
     self.parsed_args.bar = None
     argument_table = {
         'foo': mock.sentinel.FOO_ARG,
         'page-size': mock.sentinel.BAR_ARG,
         'bar-too': mock.sentinel.BAR_TOO_ARG
     }
     paginate.unify_paging_params(operation_model, argument_table)
     self.validate_page_param(argument_table['page-size'], True)
     paginate.check_should_enable_pagination(argument_table,
                                             operation_model,
                                             self.parsed_args,
                                             self.parsed_globals)
     # We should have turned paginate off because the
     # user specified --bar 10
     self.assertFalse(self.parsed_globals.paginate)
     self.assertEqual(argument_table['page-size'], mock.sentinel.BAR_ARG)
Exemplo n.º 2
0
 def __call__(self, client_creator, args, parsed_globals):
     # Handle extensions first, so OverrideRequiredArgs (CliInputJson,
     # GenerateCliSkeleton, etc) could have a chance to run.
     self._handle_extensions()
     # We need to handle overriding required arguments before we create
     # the parser as the parser will parse the arguments and decide which
     # argument is required before we have a chance to modify the argument
     # table.
     self._handle_override_required_args(args)
     # Once we know we're trying to call a particular operation
     # of a service we can go ahead and load the parameters.
     operation_parser = self._create_operation_parser(self.arg_table)
     self._add_help(operation_parser)
     parsed_args, remaining = operation_parser.parse_known_args(args)
     if parsed_args.help == 'help':
         return self.create_help_command()(client_creator, remaining,
                                           parsed_globals)
     elif parsed_args.help:
         remaining.append(parsed_args.help)
     if remaining:
         raise UnknownArgumentError("Unknown options: %s" %
                                    ', '.join(remaining))
     check_should_enable_pagination(self._arg_table, self._operation_model,
                                    parsed_args, parsed_globals)
     call_parameters = self._build_call_parameters(parsed_args,
                                                   self.arg_table)
     return self._invoke_operation_callers(client_creator, call_parameters,
                                           parsed_args, parsed_globals)
Exemplo n.º 3
0
 def test_should_enable_pagination_with_no_args(self):
     self.parsed_globals.paginate = True
     # Corresponds to not specifying --foo nor --bar
     self.parsed_args.foo = None
     self.parsed_args.bar = None
     self.parsed_args.bar_too = None
     paginate.check_should_enable_pagination(self.argument_table,
                                             self.operation_model,
                                             self.parsed_args,
                                             self.parsed_globals)
     self.assertTrue(self.parsed_globals.paginate)
Exemplo n.º 4
0
 def test_should_not_enable_pagination(self):
     # Here the user has specified a manual pagination argument,
     # so we should turn pagination off.
     self.parsed_globals.paginate = True
     # Corresponds to --bar 10
     self.parsed_args.foo = None
     self.parsed_args.bar = 10
     self.parsed_args.bar_too = None
     paginate.check_should_enable_pagination(self.argument_table,
                                             self.operation_model,
                                             self.parsed_args,
                                             self.parsed_globals)
     # We should have turned paginate off because the
     # user specified --bar 10
     self.assertFalse(self.parsed_globals.paginate)
Exemplo n.º 5
0
 def test_default_to_pagination_on_when_ambiguous(self):
     argument_table = {'foo': mock.Mock(), 'max-times': mock.Mock()}
     self.parsed_globals.paginate = True
     # Here the user specifies --max-items 10 This is ambiguous because the
     # input_token also contains 'max-items'.  Should we assume they want
     # pagination turned off or should we assume that this is the normalized
     # --max-items?
     # Will we default to assuming they meant the normalized
     # --max-items.
     self.parsed_args.foo = None
     self.parsed_args.bar = None
     self.parsed_args.bar_too = None
     self.parsed_args.max_items = 10
     paginate.check_should_enable_pagination(argument_table,
                                             self.operation_model,
                                             self.parsed_args,
                                             self.parsed_globals)
     self.assertTrue(self.parsed_globals.paginate,
                     "Pagination was not enabled.")
Exemplo n.º 6
0
    def __call__(self, client_creator, args, parsed_globals):
        # We need to handle overriding required arguments before we create
        # the parser as the parser will parse the arguments and decide which
        # argument is required before we have a chance to modify the argument
        # table.
        self._handle_override_required_args(args)
        # Once we know we're trying to call a particular operation
        # of a service we can go ahead and load the parameters.
        operation_parser = self._create_operation_parser(self.arg_table)
        self._add_help(operation_parser)
        parsed_args, remaining = operation_parser.parse_known_args(args)
        if parsed_args.help == 'help':
            return self.create_help_command()(client_creator, remaining,
                                              parsed_globals)
        elif parsed_args.help:
            remaining.append(parsed_args.help)
        if remaining:
            raise UnknownArgumentError("Unknown options: %s" %
                                       ', '.join(remaining))
        check_should_enable_pagination(self._arg_table, self._operation_model,
                                       parsed_args, parsed_globals)
        call_parameters = self._build_call_parameters(parsed_args,
                                                      self.arg_table)

        # The TLS verification value can be a boolean or a CA_BUNDLE path. This
        # is a little odd, but ultimately comes from the python HTTP requests
        # library we're using.
        tls_verification = parsed_globals.verify_tls
        ca_bundle = getattr(parsed_globals, 'ca_bundle', None)
        if parsed_globals.verify_tls and ca_bundle is not None:
            tls_verification = ca_bundle

        client = client_creator.create_client(
            self._operation_model.service_model.service_name,
            parsed_globals.endpoint_url, tls_verification,
            client_creator.context.get_credentials())
        return self._invoke_operation_callers(client, call_parameters,
                                              parsed_args, parsed_globals)