def test_load_versioned_actions_not_in_version_range(self): parser = cinderclient.shell.CinderClientArgumentParser() subparsers = parser.add_subparsers(metavar='<subcommand>') shell = cinderclient.shell.OpenStackCinderShell() shell.subcommands = {} shell._find_actions(subparsers, fake_actions_module, api_versions.APIVersion('3.10000'), False, []) self.assertNotIn('fake-action', shell.subcommands.keys()) self.assertIn('fake-action2', shell.subcommands.keys())
def test_load_versioned_actions_with_args_not_in_version_range( self, mock_add_arg): parser = cinderclient.shell.CinderClientArgumentParser(add_help=False) subparsers = parser.add_subparsers(metavar='<subcommand>') shell = cinderclient.shell.OpenStackCinderShell() shell.subcommands = {} shell._find_actions(subparsers, fake_actions_module, api_versions.APIVersion("3.10000"), False, []) self.assertIn('fake-action2', shell.subcommands.keys()) mock_add_arg.assert_has_calls( [mock.call('-h', '--help', action='help', help='==SUPPRESS==')])
def test_load_versioned_actions_with_args_not_in_version_range( self, mock_add_arg): parser = cinderclient.shell.CinderClientArgumentParser(add_help=False) subparsers = parser.add_subparsers(metavar='<subcommand>') shell = cinderclient.shell.OpenStackCinderShell() shell.subcommands = {} shell._find_actions(subparsers, fake_actions_module, api_versions.APIVersion("3.10000"), False, []) self.assertIn('fake-action2', shell.subcommands.keys()) mock_add_arg.assert_has_calls([ mock.call('-h', '--help', action='help', help='==SUPPRESS==')])
def test_load_versioned_actions_with_args_and_help(self, mock_add_arg): parser = cinderclient.shell.CinderClientArgumentParser(add_help=False) subparsers = parser.add_subparsers(metavar='<subcommand>') shell = cinderclient.shell.OpenStackCinderShell() shell.subcommands = {} shell._find_actions(subparsers, fake_actions_module, api_versions.APIVersion("3.4"), True, []) mock_add_arg.assert_has_calls([ mock.call('-h', '--help', action='help', help='==SUPPRESS=='), mock.call('--bar', help="bar help (Supported by API versions" " 3.3 - 3.4)")])
def test_load_versioned_actions_with_help_on_latest(self): parser = cinderclient.shell.CinderClientArgumentParser() subparsers = parser.add_subparsers(metavar='<subcommand>') shell = cinderclient.shell.OpenStackCinderShell() shell.subcommands = {} with mock.patch.object(subparsers, 'add_parser') as mock_add_parser: shell._find_actions(subparsers, fake_actions_module, api_versions.APIVersion("3.latest"), True, []) self.assertIn('another-fake-action', shell.subcommands.keys()) expected_help = (" (Supported by API versions %(start)s - " "%(end)s)%(hint)s") % { 'start': '3.6', 'end': '3.latest', 'hint': cinderclient.shell.HINT_HELP_MSG} mock_add_parser.assert_any_call( 'another-fake-action', help=expected_help, description='', add_help=False, formatter_class=cinderclient.shell.OpenStackHelpFormatter)
def test_load_actions_with_versioned_args(self, mock_add_arg): parser = cinderclient.shell.CinderClientArgumentParser(add_help=False) subparsers = parser.add_subparsers(metavar='<subcommand>') shell = cinderclient.shell.OpenStackCinderShell() shell.subcommands = {} shell._find_actions(subparsers, fake_actions_module, api_versions.APIVersion("3.6"), False, []) self.assertIn(mock.call('--foo', help="first foo"), mock_add_arg.call_args_list) self.assertNotIn(mock.call('--foo', help="second foo"), mock_add_arg.call_args_list) mock_add_arg.reset_mock() shell._find_actions(subparsers, fake_actions_module, api_versions.APIVersion("3.9"), False, []) self.assertNotIn(mock.call('--foo', help="first foo"), mock_add_arg.call_args_list) self.assertIn(mock.call('--foo', help="second foo"), mock_add_arg.call_args_list)
def test_load_versioned_actions_with_help(self): parser = cinderclient.shell.CinderClientArgumentParser() subparsers = parser.add_subparsers(metavar='<subcommand>') shell = cinderclient.shell.OpenStackCinderShell() shell.subcommands = {} with mock.patch.object(subparsers, 'add_parser') as mock_add_parser: shell._find_actions(subparsers, fake_actions_module, api_versions.APIVersion("3.1"), True, []) self.assertIn('fake-action', shell.subcommands.keys()) expected_help = ("help message (Supported by API versions " "%(start)s - %(end)s)") % { 'start': '3.0', 'end': '3.3'} expected_desc = ("help message\n\n " "This will not show up in help message\n ") mock_add_parser.assert_any_call( 'fake-action', help=expected_help, description=expected_desc, add_help=False, formatter_class=cinderclient.shell.OpenStackHelpFormatter)
def test_load_versioned_actions(self): parser = cinderclient.shell.CinderClientArgumentParser() subparsers = parser.add_subparsers(metavar='<subcommand>') shell = cinderclient.shell.OpenStackCinderShell() shell.subcommands = {} shell._find_actions(subparsers, fake_actions_module, api_versions.APIVersion("3.0"), False, []) self.assertIn('fake-action', shell.subcommands.keys()) self.assertEqual( "fake_action 3.0 to 3.1", shell.subcommands['fake-action'].get_default('func')()) shell.subcommands = {} shell._find_actions(subparsers, fake_actions_module, api_versions.APIVersion("3.2"), False, []) self.assertIn('fake-action', shell.subcommands.keys()) self.assertEqual( "fake_action 3.2 to 3.3", shell.subcommands['fake-action'].get_default('func')()) self.assertIn('fake-action2', shell.subcommands.keys()) self.assertEqual( "fake_action2", shell.subcommands['fake-action2'].get_default('func')())