Beispiel #1
0
 def test_load_versioned_actions_with_args_not_in_version_range(self, mock_add_arg):
     parser = novaclient.shell.NovaClientArgumentParser(add_help=False)
     subparsers = parser.add_subparsers(metavar="<subcommand>")
     shell = novaclient.shell.OpenStackComputeShell()
     shell.subcommands = {}
     shell._find_actions(subparsers, fake_actions_module, api_versions.APIVersion("2.10000"), False)
     self.assertIn("fake-action2", shell.subcommands.keys())
     mock_add_arg.assert_has_calls([mock.call("-h", "--help", action="help", help="==SUPPRESS==")])
Beispiel #2
0
 def test_load_versioned_actions_not_in_version_range(self):
     parser = novaclient.shell.NovaClientArgumentParser()
     subparsers = parser.add_subparsers(metavar="<subcommand>")
     shell = novaclient.shell.OpenStackComputeShell()
     shell.subcommands = {}
     shell._find_actions(subparsers, fake_actions_module, api_versions.APIVersion("2.10000"), False)
     self.assertNotIn("fake-action", shell.subcommands.keys())
     self.assertIn("fake-action2", shell.subcommands.keys())
 def test_load_versioned_actions_not_in_version_range(self):
     parser = novaclient.shell.NovaClientArgumentParser()
     subparsers = parser.add_subparsers(metavar='<subcommand>')
     shell = novaclient.shell.OpenStackComputeShell()
     shell.subcommands = {}
     shell._find_actions(subparsers, fake_actions_module,
                         api_versions.APIVersion("2.10000"), False)
     self.assertNotIn('fake-action', shell.subcommands.keys())
     self.assertIn('fake-action2', shell.subcommands.keys())
Beispiel #4
0
 def test_load_versioned_actions_with_help(self):
     parser = novaclient.shell.NovaClientArgumentParser()
     subparsers = parser.add_subparsers(metavar="<subcommand>")
     shell = novaclient.shell.OpenStackComputeShell()
     shell.subcommands = {}
     shell._find_actions(subparsers, fake_actions_module, api_versions.APIVersion("2.10000"), True)
     self.assertIn("fake-action", shell.subcommands.keys())
     expected_desc = ("(Supported by API versions '%(start)s' - " "'%(end)s')") % {"start": "2.10", "end": "2.30"}
     self.assertIn(expected_desc, shell.subcommands["fake-action"].description)
 def test_load_versioned_actions_with_args_not_in_version_range(
         self, mock_add_arg):
     parser = novaclient.shell.NovaClientArgumentParser(add_help=False)
     subparsers = parser.add_subparsers(metavar='<subcommand>')
     shell = novaclient.shell.OpenStackComputeShell()
     shell.subcommands = {}
     shell._find_actions(subparsers, fake_actions_module,
                         api_versions.APIVersion("2.10000"), False)
     self.assertIn('fake-action2', shell.subcommands.keys())
     mock_add_arg.assert_has_calls(
         [mock.call('-h', '--help', action='help', help='==SUPPRESS==')])
Beispiel #6
0
 def test_load_versioned_actions_with_args_and_help(self, mock_add_arg):
     parser = novaclient.shell.NovaClientArgumentParser(add_help=False)
     subparsers = parser.add_subparsers(metavar='<subcommand>')
     shell = novaclient.shell.OpenStackComputeShell()
     shell.subcommands = {}
     shell._find_actions(subparsers, fake_actions_module,
                         api_versions.APIVersion("2.4"), True)
     mock_add_arg.assert_has_calls([
         mock.call('-h', '--help', action='help', help='==SUPPRESS=='),
         mock.call('--bar',
                   help=" (Supported by API versions '2.3' - '2.4')")])
 def test_load_versioned_actions_with_args2(self, mock_add_arg):
     parser = novaclient.shell.NovaClientArgumentParser(add_help=False)
     subparsers = parser.add_subparsers(metavar='<subcommand>')
     shell = novaclient.shell.OpenStackComputeShell()
     shell.subcommands = {}
     shell._find_actions(subparsers, fake_actions_module,
                         api_versions.APIVersion("2.4"), False)
     self.assertIn('fake-action2', shell.subcommands.keys())
     mock_add_arg.assert_has_calls([
         mock.call('-h', '--help', action='help', help='==SUPPRESS=='),
         mock.call('--bar')])
Beispiel #8
0
 def test_load_versioned_actions_with_help(self):
     parser = novaclient.shell.NovaClientArgumentParser()
     subparsers = parser.add_subparsers(metavar='<subcommand>')
     shell = novaclient.shell.OpenStackComputeShell()
     shell.subcommands = {}
     shell._find_actions(subparsers, fake_actions_module,
                         api_versions.APIVersion("2.15"), True)
     self.assertIn('fake-action', shell.subcommands.keys())
     expected_desc = (" (Supported by API versions '%(start)s' - "
                      "'%(end)s')") % {'start': '2.10', 'end': '2.30'}
     self.assertEqual(expected_desc,
                      shell.subcommands['fake-action'].description)
Beispiel #9
0
    def test_load_versioned_actions(self):
        parser = novaclient.shell.NovaClientArgumentParser()
        subparsers = parser.add_subparsers(metavar="<subcommand>")
        shell = novaclient.shell.OpenStackComputeShell()
        shell.subcommands = {}
        shell._find_actions(subparsers, fake_actions_module, api_versions.APIVersion("2.15"), False)
        self.assertIn("fake-action", shell.subcommands.keys())
        self.assertEqual(1, shell.subcommands["fake-action"].get_default("func")())

        shell.subcommands = {}
        shell._find_actions(subparsers, fake_actions_module, api_versions.APIVersion("2.25"), False)
        self.assertIn("fake-action", shell.subcommands.keys())
        self.assertEqual(2, shell.subcommands["fake-action"].get_default("func")())

        self.assertIn("fake-action2", shell.subcommands.keys())
        self.assertEqual(3, shell.subcommands["fake-action2"].get_default("func")())
    def test_load_actions_with_versioned_args(self, mock_add_arg):
        parser = novaclient.shell.NovaClientArgumentParser(add_help=False)
        subparsers = parser.add_subparsers(metavar='<subcommand>')
        shell = novaclient.shell.OpenStackComputeShell()
        shell.subcommands = {}
        shell._find_actions(subparsers, fake_actions_module,
                            api_versions.APIVersion("2.20"), 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("2.21"), 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_actions_with_versioned_args(self, mock_add_arg):
        parser = novaclient.shell.NovaClientArgumentParser(add_help=False)
        subparsers = parser.add_subparsers(metavar='<subcommand>')
        shell = novaclient.shell.OpenStackComputeShell()
        shell.subcommands = {}
        shell._find_actions(subparsers, fake_actions_module,
                            api_versions.APIVersion("2.20"), 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("2.21"), 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(self):
        parser = novaclient.shell.NovaClientArgumentParser()
        subparsers = parser.add_subparsers(metavar='<subcommand>')
        shell = novaclient.shell.OpenStackComputeShell()
        shell.subcommands = {}
        shell._find_actions(subparsers, fake_actions_module,
                            api_versions.APIVersion("2.15"), False)
        self.assertIn('fake-action', shell.subcommands.keys())
        self.assertEqual(
            1, shell.subcommands['fake-action'].get_default('func')())

        shell.subcommands = {}
        shell._find_actions(subparsers, fake_actions_module,
                            api_versions.APIVersion("2.25"), False)
        self.assertIn('fake-action', shell.subcommands.keys())
        self.assertEqual(
            2, shell.subcommands['fake-action'].get_default('func')())

        self.assertIn('fake-action2', shell.subcommands.keys())
        self.assertEqual(
            3, shell.subcommands['fake-action2'].get_default('func')())