Skip to content

Commit 558bd3e

Browse files
committed
expand unittests
1 parent 1a8a690 commit 558bd3e

File tree

2 files changed

+70
-20
lines changed

2 files changed

+70
-20
lines changed

tests/test_cli_parser.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from source.confParser import parse_cmd_args
2+
from nose.tools import with_setup
3+
from argparse import Namespace
4+
5+
6+
def my_setup():
7+
global a, b, c, d, e, f
8+
a = ['-p', '8443', '-t', '/etc/my_tls']
9+
b = ['-a']
10+
c = ['-a', 'abc']
11+
d = ['-c', '10', '-v', '/opt/registry/certs']
12+
e = ['-c', '10', '-t', '/opt/registry/certs']
13+
f = ['-c', '10', '-s', '9.155.108.199', '-p', '8443', '-t', '/opt/registry/certs', '--tlsKeyFile', 'privkey.pem', '--tlsCertFile', 'cert.pem']
14+
15+
16+
def test_case01():
17+
args, msg = parse_cmd_args([])
18+
assert isinstance(args, Namespace)
19+
result = vars(args)
20+
assert isinstance(result, dict)
21+
22+
23+
def test_case02():
24+
args, msg = parse_cmd_args([])
25+
result = vars(args)
26+
assert len(result.keys()) > 0
27+
28+
29+
def test_case03():
30+
args, msg = parse_cmd_args([])
31+
result = vars(args)
32+
elements = list(result.keys())
33+
mandatoryItems = ['port', 'serverPort']
34+
assert all(item in elements for item in mandatoryItems)
35+
36+
37+
def test_case04():
38+
args, msg = parse_cmd_args([])
39+
result = vars(args)
40+
value = int(result['port'])
41+
assert value == 4242
42+
43+
44+
def test_case05():
45+
args, msg = parse_cmd_args([])
46+
result = vars(args)
47+
assert int(result['port']) == 4242 and int(result['serverPort']) == 9084
48+
49+
50+
@with_setup(my_setup)
51+
def test_case06():
52+
args, msg = parse_cmd_args(e)
53+
result = vars(args)
54+
assert len(result.keys()) > 0
55+
assert 'port' in result.keys()
56+
assert 'serverPort' in result.keys()
57+
58+
59+
@with_setup(my_setup)
60+
def test_case07():
61+
args, msg = parse_cmd_args(a)
62+
result = vars(args)
63+
assert len(result.keys()) > 0
64+
assert 'port' in result.keys()
65+
assert result.get('port') == 8443

tests/test_parser.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,15 @@
22

33

44
def test_case01():
5-
result = os.system("python ./source/zimonGrafanaIntf.py")
6-
assert result == 0
7-
8-
9-
def test_case02():
10-
result = os.system("python ./source/zimonGrafanaIntf.py --port 4242")
11-
assert result == 0
12-
13-
14-
def test_case03():
15-
result = os.system("python ./source/zimonGrafanaIntf.py -c 10")
16-
assert result == 0
17-
18-
19-
def test_case04():
20-
result = os.system("python ./source/zimonGrafanaIntf.py --port 8443")
5+
result = os.system('python ./source/zimonGrafanaIntf.py -a 2')
216
assert result > 0
227

238

24-
def test_case05():
25-
result = os.system('python ./source/zimonGrafanaIntf.py --port 8443 --tlsKeyPath "/tmp"')
9+
def test_case02():
10+
result = os.system('python ./source/zimonGrafanaIntf.py -a')
2611
assert result > 0
2712

2813

29-
def test_case06():
30-
result = os.system('python ./source/zimonGrafanaIntf.py -a 2')
14+
def test_case03():
15+
result = os.system('python ./source/zimonGrafanaIntf.py -c 10 -v "/opt/registry/certs"')
3116
assert result > 0

0 commit comments

Comments
 (0)