-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_test.py
100 lines (78 loc) · 2.39 KB
/
run_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from argparse import Namespace
from unittest import TestCase, mock
from run import get_arguments, call
from iress.xplan.session import Session
_RAW_ARGS = [
"-b",
"https://dev.xplan.iress.com.au",
"-u",
"testuser",
"-p",
"dummy",
"-o",
"dummyotp",
"-i",
"dummyclientid",
]
class TestGetArguments(TestCase):
def test_get_arguments(self):
# Execute
options = get_arguments(_RAW_ARGS)
# Validate
assert options.client_id == _RAW_ARGS[9]
assert options.otp_secret == _RAW_ARGS[7]
assert options.password == _RAW_ARGS[5]
assert options.user_name == _RAW_ARGS[3]
assert options.base_url == _RAW_ARGS[1]
@mock.patch("run.getpass")
def test_get_arguments_no_password(self, getpass):
# Set up
arg_copy = _RAW_ARGS.copy()
del arg_copy[4:6]
getpass.return_value = "s"
# Execute
options = get_arguments(arg_copy)
# Validate
assert options.password == "s"
assert getpass.call_count == 1
@mock.patch("run.getpass")
def test_get_arguments_no_otp_secret_2fa(self, getpass):
# Set up
arg_copy = _RAW_ARGS.copy()
del arg_copy[6:8]
arg_copy.append("--use-tfa")
getpass.return_value = "s"
# Execute
options = get_arguments(arg_copy)
# Validate
assert options.otp_secret == "s"
assert getpass.call_count == 1
@mock.patch("run.getpass")
def test_get_arguments_no_otp_secret_non_2fa(self, getpass):
# Set up
arg_copy = _RAW_ARGS.copy()
del arg_copy[6:8]
# Execute
options = get_arguments(arg_copy)
# Validate
assert options.otp_secret is None
assert getpass.call_count == 0
class TestCall(TestCase):
def setUp(self) -> None:
self.session = Session("dummy", "cid")
@mock.patch("run.EDAICall.get_value")
def test_call_edai(self, edai_call):
# Set up
options = Namespace(edai_example=True)
# Execute
call(self.session, options)
# Verify
assert edai_call.call_count == 2
@mock.patch("run.ResourcefulAPICall.call_content")
def test_call_api(self, api_call):
# Set up
options = Namespace(edai_example=False)
# Execute
call(self.session, options)
# Verify
assert api_call.call_count == 1