|
31 | 31 |
|
32 | 32 | from gitlab import cli
|
33 | 33 | import gitlab.v3.cli
|
| 34 | +import gitlab.v4.cli |
34 | 35 |
|
35 | 36 |
|
36 | 37 | class TestCLI(unittest.TestCase):
|
@@ -86,6 +87,42 @@ def test_base_parser(self):
|
86 | 87 | self.assertEqual(args.config_file, ['foo.cfg', 'bar.cfg'])
|
87 | 88 |
|
88 | 89 |
|
| 90 | +class TestV4CLI(unittest.TestCase): |
| 91 | + def test_parse_args(self): |
| 92 | + parser = cli._get_parser(gitlab.v4.cli) |
| 93 | + args = parser.parse_args(['project', 'list']) |
| 94 | + self.assertEqual(args.what, 'project') |
| 95 | + self.assertEqual(args.action, 'list') |
| 96 | + |
| 97 | + def test_parser(self): |
| 98 | + parser = cli._get_parser(gitlab.v4.cli) |
| 99 | + subparsers = None |
| 100 | + for action in parser._actions: |
| 101 | + if type(action) == argparse._SubParsersAction: |
| 102 | + subparsers = action |
| 103 | + break |
| 104 | + self.assertIsNotNone(subparsers) |
| 105 | + self.assertIn('project', subparsers.choices) |
| 106 | + |
| 107 | + user_subparsers = None |
| 108 | + for action in subparsers.choices['project']._actions: |
| 109 | + if type(action) == argparse._SubParsersAction: |
| 110 | + user_subparsers = action |
| 111 | + break |
| 112 | + self.assertIsNotNone(user_subparsers) |
| 113 | + self.assertIn('list', user_subparsers.choices) |
| 114 | + self.assertIn('get', user_subparsers.choices) |
| 115 | + self.assertIn('delete', user_subparsers.choices) |
| 116 | + self.assertIn('update', user_subparsers.choices) |
| 117 | + self.assertIn('create', user_subparsers.choices) |
| 118 | + self.assertIn('archive', user_subparsers.choices) |
| 119 | + self.assertIn('unarchive', user_subparsers.choices) |
| 120 | + |
| 121 | + actions = user_subparsers.choices['create']._option_string_actions |
| 122 | + self.assertFalse(actions['--description'].required) |
| 123 | + self.assertTrue(actions['--name'].required) |
| 124 | + |
| 125 | + |
89 | 126 | class TestV3CLI(unittest.TestCase):
|
90 | 127 | def test_parse_args(self):
|
91 | 128 | parser = cli._get_parser(gitlab.v3.cli)
|
|
0 commit comments