Repository navigation
Expand file tree
/
Copy pathtest_utils.py
More file actions
85 lines (75 loc) · 2.25 KB
/
Copy pathtest_utils.py
File metadata and controls
85 lines (75 loc) · 2.25 KB
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
from __future__ import absolute_import
from tests import testlib
try:
from utils import *
except ImportError:
raise Exception("Add the SDK repository to your PYTHONPATH to run the examples "
"(e.g., export PYTHONPATH=~/splunk-sdk-python.")
TEST_DICT = {
'username':'admin',
'password':'changeme',
'port' : 8089,
'host' : 'localhost',
'scheme': 'https'
}
class TestUtils(testlib.SDKTestCase):
def setUp(self):
super(TestUtils, self).setUp()
# Test dslice when a dict is passed to change key names
def test_dslice_dict_args(self):
args = {
'username':'user-name',
'password':'new_password',
'port': 'admin_port',
'foo':'bar'
}
expected = {
'user-name':'admin',
'new_password':'changeme',
'admin_port':8089
}
self.assertTrue(expected == dslice(TEST_DICT, args))
# Test dslice when a list is passed
def test_dslice_list_args(self):
test_list = [
'username',
'password',
'port',
'host',
'foo'
]
expected = {
'username':'admin',
'password':'changeme',
'port':8089,
'host':'localhost'
}
self.assertTrue(expected == dslice(TEST_DICT, test_list))
# Test dslice when a single string is passed
def test_dslice_arg(self):
test_arg = 'username'
expected = {
'username':'admin'
}
self.assertTrue(expected == dslice(TEST_DICT, test_arg))
# Test dslice using all three types of arguments
def test_dslice_all_args(self):
test_args = [
{'username':'new_username'},
['password',
'host'],
'port'
]
expected = {
'new_username':'admin',
'password':'changeme',
'host':'localhost',
'port':8089
}
self.assertTrue(expected == dslice(TEST_DICT, *test_args))
if __name__ == "__main__":
try:
import unittest2 as unittest
except ImportError:
import unittest
unittest.main()