Example #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)
Example #2
0
def _generate_index(filename):
    # This will eventually be moved into some utility function.
    index_generator = generator.IndexGenerator(
        [indexer.create_model_indexer(filename)], )
    driver = clidriver.create_clidriver()
    driver.session.register('building-command-table.main',
                            _ec2_only_command_table)
    index_generator.generate_index(driver)
Example #3
0
 def setUpClass(cls):
     cls.db_connection = db.DatabaseConnection(":memory:")
     index_generator = generator.IndexGenerator([
         ModelIndexer(cls.db_connection),
         APICallIndexer(cls.db_connection)
     ], )
     driver = clidriver.create_clidriver()
     driver.session.register('building-command-table.main',
                             _ddb_only_command_table)
     index_generator.generate_index(driver)
Example #4
0
 def test_no_errors_when_missing_completion_data(self):
     index_generator = generator.IndexGenerator([
         ModelIndexer(self.db_connection),
         APICallIndexer(self.db_connection)
     ], )
     driver = clidriver.create_clidriver()
     # We're going to remove the CLI data path from the loader.
     # This will result in the loader not being able to find any
     # completion data, which allows us to verify the behavior when
     # there's no completion data.
     driver.session.register('building-command-table.main',
                             _ddb_only_command_table)
     driver.session.register('building-command-table.dynamodb',
                             self._disable_cli_loaders)
     index_generator.generate_index(driver)
     # We shouldn't get any data now because we couldn't load
     # completion data.
     lookup = model.DBCompletionLookup(self.db_connection)
     result = lookup.get_server_completion_data(['aws', 'dynamodb'],
                                                'delete-table',
                                                'table-name')
     self.assertIsNone(result)
Example #5
0
 def test_use_high_level_generator_for_index_creation(self):
     model_index = mock.Mock(spec=indexer.ModelIndexer)
     clidriver = mock.Mock(spec=CLIDriver)
     index = generator.IndexGenerator([model_index])
     index.generate_index(clidriver)
     model_index.generate_index.assert_called_with(clidriver)