1
1
from __future__ import absolute_import
2
2
from tests import testlib
3
3
4
+ import unittest
5
+ import os
6
+ import sys
7
+
4
8
try :
5
9
from utils import *
6
10
except ImportError :
7
11
raise Exception ("Add the SDK repository to your PYTHONPATH to run the test cases "
8
12
"(e.g., export PYTHONPATH=~/splunk-sdk-python." )
9
13
10
-
11
14
TEST_DICT = {
12
- 'username' :'admin' ,
13
- 'password' :'changeme' ,
14
- 'port' : 8089 ,
15
- 'host' : 'localhost' ,
16
- 'scheme' : 'https'
17
- }
15
+ 'username' : 'admin' ,
16
+ 'password' : 'changeme' ,
17
+ 'port' : 8089 ,
18
+ 'host' : 'localhost' ,
19
+ 'scheme' : 'https'
20
+ }
21
+
18
22
19
23
class TestUtils (testlib .SDKTestCase ):
20
24
def setUp (self ):
@@ -23,16 +27,16 @@ def setUp(self):
23
27
# Test dslice when a dict is passed to change key names
24
28
def test_dslice_dict_args (self ):
25
29
args = {
26
- 'username' :'user-name' ,
27
- 'password' :'new_password' ,
28
- 'port' : 'admin_port' ,
29
- 'foo' :'bar'
30
- }
30
+ 'username' : 'user-name' ,
31
+ 'password' : 'new_password' ,
32
+ 'port' : 'admin_port' ,
33
+ 'foo' : 'bar'
34
+ }
31
35
expected = {
32
- 'user-name' :'admin' ,
33
- 'new_password' :'changeme' ,
34
- 'admin_port' :8089
35
- }
36
+ 'user-name' : 'admin' ,
37
+ 'new_password' : 'changeme' ,
38
+ 'admin_port' : 8089
39
+ }
36
40
self .assertTrue (expected == dslice (TEST_DICT , args ))
37
41
38
42
# Test dslice when a list is passed
@@ -43,40 +47,66 @@ def test_dslice_list_args(self):
43
47
'port' ,
44
48
'host' ,
45
49
'foo'
46
- ]
50
+ ]
47
51
expected = {
48
- 'username' :'admin' ,
49
- 'password' :'changeme' ,
50
- 'port' :8089 ,
51
- 'host' :'localhost'
52
- }
52
+ 'username' : 'admin' ,
53
+ 'password' : 'changeme' ,
54
+ 'port' : 8089 ,
55
+ 'host' : 'localhost'
56
+ }
53
57
self .assertTrue (expected == dslice (TEST_DICT , test_list ))
54
58
55
59
# Test dslice when a single string is passed
56
60
def test_dslice_arg (self ):
57
61
test_arg = 'username'
58
62
expected = {
59
- 'username' :'admin'
60
- }
63
+ 'username' : 'admin'
64
+ }
61
65
self .assertTrue (expected == dslice (TEST_DICT , test_arg ))
62
66
63
67
# Test dslice using all three types of arguments
64
68
def test_dslice_all_args (self ):
65
69
test_args = [
66
- {'username' :'new_username' },
70
+ {'username' : 'new_username' },
67
71
['password' ,
68
- 'host' ],
72
+ 'host' ],
69
73
'port'
70
74
]
71
75
expected = {
72
- 'new_username' :'admin' ,
73
- 'password' :'changeme' ,
74
- 'host' :'localhost' ,
75
- 'port' :8089
76
+ 'new_username' : 'admin' ,
77
+ 'password' : 'changeme' ,
78
+ 'host' : 'localhost' ,
79
+ 'port' : 8089
76
80
}
77
81
self .assertTrue (expected == dslice (TEST_DICT , * test_args ))
78
82
79
83
84
+ class FilePermissionTest (unittest .TestCase ):
85
+
86
+ def setUp (self ):
87
+ super (FilePermissionTest , self ).setUp ()
88
+
89
+ # Check for any change in the default file permission(i.e 644) for all files within splunklib
90
+ def test_filePermissions (self ):
91
+
92
+ def checkFilePermissions (dir_path ):
93
+ for file in os .listdir (dir_path ):
94
+ if file .__contains__ ('pycache' ):
95
+ continue
96
+ path = os .path .join (dir_path , file )
97
+ if os .path .isfile (path ):
98
+ permission = oct (os .stat (path ).st_mode )
99
+ if sys .version_info >= (3 , 0 ):
100
+ self .assertEqual (permission , '0o100644' )
101
+ else :
102
+ self .assertEqual (permission , '0100644' )
103
+ else :
104
+ checkFilePermissions (path )
105
+
106
+ dir_path = os .path .join ('..' , 'splunklib' )
107
+ checkFilePermissions (dir_path )
108
+
109
+
80
110
if __name__ == "__main__" :
81
111
try :
82
112
import unittest2 as unittest
0 commit comments