Skip to content

Commit

Permalink
Add integration test for command lineage
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleknap committed Feb 9, 2015
1 parent 23c9f45 commit b5356ee
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
1 change: 1 addition & 0 deletions awscli/customizations/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def create_help_command_table(self):
commands = {}
for command in self.SUBCOMMANDS:
commands[command['name']] = command['command_class'](self._session)
self._add_lineage(commands)
return commands

def _build_arg_table(self):
Expand Down
50 changes: 50 additions & 0 deletions tests/integration/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,55 @@ def test_bad_lc_ctype_env_var_is_handled(self):
self.assertEqual(p.rc, 0)


class TestCommandLineage(unittest.TestCase):
def setUp(self):
self.driver = create_clidriver()
self.top_help = self.driver.create_help_command()

def assert_lineage_names(self, ref_lineage_names):
command_table = self.top_help.command_table
for i, cmd_name in enumerate(ref_lineage_names):
command = command_table[cmd_name]
help_command = command.create_help_command()
command_table = help_command.command_table

actual_lineage_names = []
for cmd in command.lineage:
actual_lineage_names.append(cmd.name)

self.assertEqual(actual_lineage_names, ref_lineage_names)

def test_service_level_commands(self):
# Check a normal unchanged service command
self.assert_lineage_names(['ec2'])

# Check a service that had its name changed.
self.assert_lineage_names(['s3api'])

# Check a couple custom service level commands.
self.assert_lineage_names(['s3'])
self.assert_lineage_names(['configure'])

def test_operation_level_commands(self):
# Check a normal unchanged service and operation command
self.assert_lineage_names(['dynamodb', 'create-table'])

# Check an operation commands with a service that had its name changed.
self.assert_lineage_names(['s3api', 'list-objects'])

# Check a custom operation level command with no
# custom service command.
self.assert_lineage_names(['emr', 'create-cluster'])

# Check a couple of operation level commands that
# are based off a custom service command
self.assert_lineage_names(['configure', 'set'])
self.assert_lineage_names(['s3', 'cp'])

def test_wait_commands(self):
self.assert_lineage_names(['ec2', 'wait'])
self.assert_lineage_names(['ec2', 'wait', 'instance-running'])


if __name__ == '__main__':
unittest.main()
17 changes: 9 additions & 8 deletions tests/unit/customizations/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ def test_load_lineage(self):
self.assertEqual(self.command.lineage, [self.command])

def test_pass_lineage_to_child_command(self):
subcommands = [{'name': 'bar', 'command_class': BasicCommand}]
basic_command_class = 'awscli.customizations.commands.BasicCommand'
subcommand_patch = basic_command_class + '.SUBCOMMANDS'
with mock.patch(subcommand_patch, subcommands):
lineage = self.command.subcommand_table['bar'].lineage
self.assertEqual(len(lineage), 2)
self.assertEqual(lineage[0], self.command)
self.assertIsInstance(lineage[1], BasicCommand)
class MockCustomCommand(BasicCommand):
NAME = 'mock'

SUBCOMMANDS = [{'name': 'basic', 'command_class': BasicCommand}]

self.command = MockCustomCommand(self.session)
lineage = self.command.subcommand_table['basic'].lineage
self.assertEqual(len(lineage), 2)
self.assertEqual(lineage[0], self.command)
self.assertIsInstance(lineage[1], BasicCommand)

0 comments on commit b5356ee

Please sign in to comment.