Beispiel #1
0
    def test_can_generate_entire_index(self):
        # The point of this test is to make sure generating the index
        # doesn't break in some obvious way.  The specifics of index
        # generation are tested in tests/unit/autocomplete.  Here we just
        # generate the entire index and perform basic sanity checks.  It's
        # just a functional smoke test.
        driver = create_clidriver()
        index_generator = generator.IndexGenerator([
            self.model_indexer,
            self.api_call_indexer,
        ])
        index_generator.generate_index(driver)

        # Basic sanity checks.  Index generation for the entire CLI
        # takes a while so all the sanity checks are combined in a single
        # test method.
        commands = self.model_index.command_names(lineage=['aws'])
        self.assertIn('ec2', commands)
        self.assertIn('s3', commands)
        self.assertIn('s3api', commands)
        global_args = self.model_index.arg_names(lineage=[],
                                                 command_name='aws')
        self.assertIn('region', global_args)
        self.assertIn('endpoint-url', global_args)

        single_arg = self.model_index.get_argument_data(
            lineage=[], command_name='aws',
            arg_name='output')
        self.assertEqual(single_arg.argname, 'output')
        self.assertEqual(single_arg.command, 'aws')
        self.assertEqual(single_arg.parent, '')
        self.assertIsNone(single_arg.nargs)
 def enable_addressing_mode_in_config(self, fileobj, mode):
     fileobj.write("[default]\n"
                   "s3 =\n"
                   "    addressing_style = %s\n" % mode)
     fileobj.flush()
     self.environ['AWS_CONFIG_FILE'] = fileobj.name
     self.driver = create_clidriver()
Beispiel #3
0
 def write_cli_pager_config(self, pager):
     config_file = self.files.create_file(
         'config',
         '[default]\n'
         'cli_pager = %s\n' % pager
     )
     self.environ['AWS_CONFIG_FILE'] = config_file
     self.driver = create_clidriver()
 def enable_addressing_mode_in_config(self, fileobj, mode):
     fileobj.write(
         "[default]\n"
         "s3 =\n"
         "    addressing_style = %s\n" % mode
     )
     fileobj.flush()
     self.environ['AWS_CONFIG_FILE'] = fileobj.name
     self.driver = create_clidriver()
 def enable_sigv4_from_config_file(self, fileobj):
     fileobj.write(
         "[default]\n"
         "s3 =\n"
         "    signature_version = s3v4\n"
     )
     fileobj.flush()
     self.environ['AWS_CONFIG_FILE'] = fileobj.name
     self.driver = create_clidriver()
Beispiel #6
0
    def filter_params_in_model(self, include_params):
        model = copy.deepcopy(DOCTYPE_MODEL)
        request_members = model['shapes']['DescribeResourceShape']['members']
        for request_member in list(request_members):
            if request_member not in include_params:
                del request_members[request_member]

        self.driver = create_clidriver()
        _add_doctype_service_model(self.files, self.driver.session, model)
def test_all_doc_examples():
    # CLIDriver can take up a lot of resources so we'll just create one
    # instance and use it for all the validation tests.
    driver = create_clidriver()
    command_validator = CommandValidator(driver)

    for example_file in iter_all_doc_examples():
        yield verify_has_only_ascii_chars, example_file
        yield verify_is_valid_rst, example_file
        yield verify_cli_commands_valid, example_file, command_validator
Beispiel #8
0
 def setUp(self):
     super(TestArgsResolution, self).setUp()
     self.files = FileCreator()
     config_contents = (
         '[profile bar]\n'
         'region = us-west-2\n'
     )
     self.environ['AWS_CONFIG_FILE'] = self.files.create_file(
         'myconfig', config_contents)
     self.driver = create_clidriver()
Beispiel #9
0
 def init_clidriver(self):
     with temporary_file('w') as f:
         f.write(
             '[default]\n'
             's3 =\n'
             '  max_concurrent_requests = 1\n'
         )
         f.flush()
         self.environ['AWS_CONFIG_FILE'] = f.name
         self.driver = create_clidriver()
Beispiel #10
0
 def setUp(self):
     history_recorder = self._make_clean_history_recorder()
     super(BaseHistoryCommandParamsTest, self).setUp()
     self.history_recorder = history_recorder
     self.files = FileCreator()
     config_contents = ('[default]\n' 'cli_history = enabled')
     self.environ['AWS_CONFIG_FILE'] = self.files.create_file(
         'config', config_contents)
     self.environ['AWS_CLI_HISTORY_FILE'] = self.files.create_file(
         'history.db', '')
     self.driver = create_clidriver()
Beispiel #11
0
 def test_get_command(self):
     self.driver = create_clidriver()
     self.set_config_file_contents(
         "\n"
         "[default]\n"
         "aws_access_key_id=access_key\n"
         "aws_secret_access_key=secret_key\n"
         "region=us-west-2\n"
     )
     stdout, _, _ = self.run_cmd("configure get aws_access_key_id")
     self.assertEqual(stdout.strip(), "access_key")
Beispiel #12
0
 def set_config_file_content(self, content=None):
     if content is None:
         content = ('[default]\n'
                    'sso_start_url=%s\n'
                    'sso_region=%s\n'
                    'sso_role_name=%s\n'
                    'sso_account_id=%s\n' %
                    (self.start_url, self.sso_region, self.role_name,
                     self.account))
     self.files.create_file(self.config_file, content)
     # We need to recreate the driver (which includes its session) in order
     # for the config changes to be pulled in by the session.
     self.driver = create_clidriver()
 def setUp(self):
     super(TestAPIVersions, self).setUp()
     self.files = FileCreator()
     # We just pick ec2 because it is a service that actually has
     # multiple api versions.
     self.service_name = 'ec2'
     self.api_version = '2014-10-01'
     config_contents = ('[default]\n'
                        'api_versions =\n'
                        '    %s = %s\n' %
                        (self.service_name, self.api_version))
     self.environ['AWS_CONFIG_FILE'] = self.files.create_file(
         'myconfig', config_contents)
     self.driver = create_clidriver()
Beispiel #14
0
 def setUp(self):
     super(TestAPIVersions, self).setUp()
     self.files = FileCreator()
     # We just pick ec2 because it is a service that actually has
     # multiple api versions.
     self.service_name = 'ec2'
     self.api_version = '2014-10-01'
     config_contents = (
         '[default]\n'
         'api_versions =\n'
         '    %s = %s\n' % (self.service_name, self.api_version)
     )
     self.environ['AWS_CONFIG_FILE'] = self.files.create_file(
         'myconfig', config_contents)
     self.driver = create_clidriver()
Beispiel #15
0
def test_completions():
    environ = {
        'AWS_DATA_PATH': os.environ['AWS_DATA_PATH'],
        'AWS_DEFAULT_REGION': 'us-east-1',
        'AWS_ACCESS_KEY_ID': 'access_key',
        'AWS_SECRET_ACCESS_KEY': 'secret_key',
        'AWS_CONFIG_FILE': '',
    }
    with mock.patch('os.environ', environ):
        completer = Completer()
        completer.clidriver = create_clidriver()
        for cmdline, point, expected_results in COMPLETIONS:
            if point == -1:
                point = len(cmdline)
            results = set(completer.complete(cmdline, point))
            yield check_completer, cmdline, results, expected_results
Beispiel #16
0
 def test_show_nothing_when_no_history(self):
     self.environ['AWS_CONFIG_FILE'] = ''
     self.driver = create_clidriver()
     self.parsed_responses = [{
         "Regions": [
             {
                 "Endpoint": "ec2.ap-south-1.amazonaws.com",
                 "RegionName": "ap-south-1"
             },
         ]
     }]
     self.run_cmd('ec2 describe-regions', expected_rc=0)
     self.run_cmd('history show', expected_rc=0)
     # The history show should not display anything as no history should
     # have been collected
     self.assertEqual(b'', self.binary_stdout.getvalue())
Beispiel #17
0
def test_completions():
    environ = {
        'AWS_DATA_PATH': os.environ['AWS_DATA_PATH'],
        'AWS_DEFAULT_REGION': 'us-east-1',
        'AWS_ACCESS_KEY_ID': 'access_key',
        'AWS_SECRET_ACCESS_KEY': 'secret_key',
        'AWS_CONFIG_FILE': '',
    }
    with mock.patch('os.environ', environ):
        completer = Completer()
        completer.clidriver = create_clidriver()
        for cmdline, point, expected_results in COMPLETIONS:
            if point == -1:
                point = len(cmdline)
            results = set(completer.complete(cmdline, point))
            yield check_completer, cmdline, results, expected_results
Beispiel #18
0
def test_completions():
    environ = {
        "AWS_DATA_PATH": os.environ["AWS_DATA_PATH"],
        "AWS_DEFAULT_REGION": "us-east-1",
        "AWS_ACCESS_KEY_ID": "access_key",
        "AWS_SECRET_ACCESS_KEY": "secret_key",
        "AWS_CA_BUNDLE": "ca_bundle",
        "AWS_CONFIG_FILE": "",
    }
    with mock.patch("os.environ", environ):
        completer = Completer()
        completer.clidriver = create_clidriver()
        for cmdline, point, expected_results in COMPLETIONS:
            if point == -1:
                point = len(cmdline)
            results = set(completer.complete(cmdline, point))
            yield check_completer, cmdline, results, expected_results
Beispiel #19
0
 def test_show_nothing_when_no_history_and_call_made(self):
     self.environ['AWS_CONFIG_FILE'] = ''
     self.driver = create_clidriver()
     self.parsed_responses = [
         {
             "Regions": [
                 {
                     "Endpoint": "ec2.ap-south-1.amazonaws.com",
                     "RegionName": "ap-south-1"
                 },
             ]
         }
     ]
     self.run_cmd('ec2 describe-regions', expected_rc=0)
     self.run_cmd('history show', expected_rc=0)
     # The history show should not display anything as no history should
     # have been collected
     self.assertEqual(b'', self.binary_stdout.getvalue())
Beispiel #20
0
 def setUp(self):
     history_recorder = self._make_clean_history_recorder()
     super(BaseHistoryCommandParamsTest, self).setUp()
     self.history_recorder = history_recorder
     self.files = FileCreator()
     config_contents = ('[default]\n' 'cli_history = enabled')
     self.environ['AWS_CONFIG_FILE'] = self.files.create_file(
         'config', config_contents)
     self.environ['AWS_CLI_HISTORY_FILE'] = self.files.create_file(
         'history.db', '')
     self.driver = create_clidriver()
     # The run_cmd patches stdout with a StringIO object (similar to what
     # nose does). Therefore it will run into issues when
     # get_binary_stdout is called because it returns sys.stdout.buffer
     # for Py3 and StringIO does not have a buffer
     self.binary_stdout_patch = mock.patch('awscli.utils.get_binary_stdout')
     mock_get_binary_stdout = self.binary_stdout_patch.start()
     self.binary_stdout = BytesIO()
     mock_get_binary_stdout.return_value = self.binary_stdout
Beispiel #21
0
 def setUp(self):
     history_recorder = self._make_clean_history_recorder()
     super(BaseHistoryCommandParamsTest, self).setUp()
     self.history_recorder = history_recorder
     self.files = FileCreator()
     config_contents = (
         '[default]\n'
         'cli_history = enabled'
     )
     self.environ['AWS_CONFIG_FILE'] = self.files.create_file(
         'config', config_contents)
     self.environ['AWS_CLI_HISTORY_FILE'] = self.files.create_file(
         'history.db', '')
     self.driver = create_clidriver()
     # The run_cmd patches stdout with a StringIO object (similar to what
     # nose does). Therefore it will run into issues when
     # get_binary_stdout is called because it returns sys.stdout.buffer
     # for Py3 and StringIO does not have a buffer
     self.binary_stdout_patch = mock.patch(
         'awscli.utils.get_binary_stdout')
     mock_get_binary_stdout = self.binary_stdout_patch.start()
     self.binary_stdout = BytesIO()
     mock_get_binary_stdout.return_value = self.binary_stdout
Beispiel #22
0
 def setUp(self):
     self.driver = create_clidriver()
     self.help_command = self.driver.create_help_command()
     self.globals = GlobalOptionsDocumenter(self.help_command)
 def enable_sigv4_from_config_file(self, fileobj):
     fileobj.write("[default]\n" "s3 =\n" "    signature_version = s3v4\n")
     fileobj.flush()
     self.environ['AWS_CONFIG_FILE'] = fileobj.name
     self.driver = create_clidriver()
Beispiel #24
0
 def set_config_file_contents(self, contents):
     self.files.create_file(self.config_filename, contents)
     # Reset the session to pick up the new config file.
     self.driver = create_clidriver()