Skip to content

Commit 365987f

Browse files
committed
Fully test the argument parser.
1 parent 8da3c8e commit 365987f

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

Diff for: tests/test_cli.py

+41-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import argparse
12
import unittest
23

34
import stun
@@ -7,16 +8,54 @@
78
class TestCLI(unittest.TestCase):
89
"""Test the CLI API."""
910

11+
@classmethod
12+
def setUpClass(cls):
13+
cls.source_ip = '123.45.67.89'
14+
cls.source_port = 24816
15+
cls.stun_port = 13579
16+
cls.stun_host = 'stun.stub.org'
17+
1018
def test_cli_parser_default(self):
1119
parser = cli.make_argument_parser()
1220
options = parser.parse_args([])
1321

1422
self.assertEqual(options.source_ip, stun.DEFAULTS['source_ip'])
1523
self.assertEqual(options.source_port, stun.DEFAULTS['source_port'])
1624
self.assertEqual(options.stun_port, stun.DEFAULTS['stun_port'])
25+
self.assertIsNone(options.stun_host)
1726

18-
# TODO: Verify user arguments
19-
27+
def test_cli_parser_user_long_form(self):
28+
parser = cli.make_argument_parser()
29+
options = parser.parse_args([
30+
'--source-port', str(self.source_port),
31+
'--source-ip', self.source_ip,
32+
'--stun-port', str(self.stun_port),
33+
'--stun-host', self.stun_host,
34+
'--debug'
35+
])
36+
37+
38+
self.assertTrue(options.debug)
39+
self.assertEqual(options.source_ip, self.source_ip)
40+
self.assertEqual(options.source_port, self.source_port)
41+
self.assertEqual(options.stun_host, self.stun_host)
42+
self.assertEqual(options.stun_port, self.stun_port)
43+
44+
def test_cli_parser_user_short_form(self):
45+
parser = cli.make_argument_parser()
46+
options = parser.parse_args([
47+
'-p', str(self.source_port),
48+
'-i', self.source_ip,
49+
'-P', str(self.stun_port),
50+
'-H', self.stun_host,
51+
'-d'
52+
])
53+
54+
self.assertTrue(options.debug)
55+
self.assertEqual(options.source_ip, self.source_ip)
56+
self.assertEqual(options.source_port, self.source_port)
57+
self.assertEqual(options.stun_host, self.stun_host)
58+
self.assertEqual(options.stun_port, self.stun_port)
2059

2160
if __name__ == '__main__':
2261
unittest.main()

0 commit comments

Comments
 (0)