Skip to content

Commit 88391bf

Browse files
author
Gauvain Pocentek
committed
Add basic unit tests for v4 CLI
1 parent 7c6be94 commit 88391bf

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

gitlab/tests/test_cli.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
from gitlab import cli
3333
import gitlab.v3.cli
34+
import gitlab.v4.cli
3435

3536

3637
class TestCLI(unittest.TestCase):
@@ -86,6 +87,42 @@ def test_base_parser(self):
8687
self.assertEqual(args.config_file, ['foo.cfg', 'bar.cfg'])
8788

8889

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+
89126
class TestV3CLI(unittest.TestCase):
90127
def test_parse_args(self):
91128
parser = cli._get_parser(gitlab.v3.cli)

0 commit comments

Comments
 (0)